Salome HOME
Issue #591 - Highlight of the first argument of constraints
[modules/shaper.git] / src / PartSet / PartSet_CustomPrs.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        PartSet_CustomPrs.cpp
4 // Created:     30 Jun 2015
5 // Author:      Natalia ERMOLAEVA
6
7 #include <PartSet_CustomPrs.h>
8 #include <PartSet_Module.h>
9 #include "PartSet_OperationPrs.h"
10
11 #include <XGUI_ModuleConnector.h>
12 #include <XGUI_Workshop.h>
13 #include <XGUI_Displayer.h>
14
15 #include <ModuleBase_IWorkshop.h>
16 #include <ModuleBase_IViewer.h>
17
18 #include <GeomValidators_Tools.h>
19
20 #include <ModelAPI_Attribute.h>
21 #include <ModelAPI_AttributeSelectionList.h>
22
23 #include <Config_PropManager.h>
24
25 #include <AIS_InteractiveContext.hxx>
26 #include <AIS_InteractiveObject.hxx>
27 #include <Prs3d_PointAspect.hxx>
28
29 #define OPERATION_PARAMETER_COLOR "255, 255, 0"
30
31 PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop)
32   : myWorkshop(theWorkshop)
33 {
34   myOperationPrs = AISObjectPtr(new GeomAPI_AISObject());
35   myOperationPrs->setImpl(new Handle(AIS_InteractiveObject)(new PartSet_OperationPrs(theWorkshop)));
36
37   std::vector<int> aColor = Config_PropManager::color("Visualization", "operation_parameter_color",
38                                                       OPERATION_PARAMETER_COLOR);
39   myOperationPrs->setColor(aColor[0], aColor[1], aColor[2]);
40
41   myOperationPrs->setPointMarker(5, 2.);
42   myOperationPrs->setWidth(1);
43 }
44
45 bool PartSet_CustomPrs::isActive() const
46 {
47   Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
48   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
49
50   return aContext->IsDisplayed(anOperationPrs);
51 }
52
53 void PartSet_CustomPrs::activate(const FeaturePtr& theFeature)
54 {
55   Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
56
57   if (anOperationPrs->canActivate(theFeature)) {
58     anOperationPrs->setFeature(theFeature);
59     if (theFeature.get())
60       displayPresentation();
61   }
62 }
63
64 void PartSet_CustomPrs::deactivate()
65 {
66   Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
67   anOperationPrs->setFeature(FeaturePtr());
68
69   erasePresentation();
70 }
71
72
73 void PartSet_CustomPrs::displayPresentation()
74 {
75   Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
76
77   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
78   if (!aContext->IsDisplayed(anOperationPrs)) {
79     PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
80     aContext->Display(anOperationPrs);
81     aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId());
82   }
83   else
84     anOperationPrs->Redisplay();
85 }
86
87 void PartSet_CustomPrs::erasePresentation()
88 {
89   Handle(AIS_InteractiveObject) anOperationPrs = myOperationPrs->impl<Handle(AIS_InteractiveObject)>();
90   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
91   if (aContext->IsDisplayed(anOperationPrs))
92     aContext->Remove(anOperationPrs);
93 }
94
95 Handle(PartSet_OperationPrs) PartSet_CustomPrs::getPresentation() const
96 {
97   Handle(AIS_InteractiveObject) anAISIO = myOperationPrs->impl<Handle(AIS_InteractiveObject)>();
98   return Handle(PartSet_OperationPrs)::DownCast(anAISIO);
99 }
100
101 bool PartSet_CustomPrs::customize(const ObjectPtr& theObject)
102 {
103   // the presentation should be recomputed if the previous AIS depend on the result
104   // [it should be hiddend] or the new AIS depend on it [it should be visualized]
105   Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
106   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
107   if (aContext->IsDisplayed(anOperationPrs)) {
108     bool aChanged = anOperationPrs->dependOn(theObject);
109
110     anOperationPrs->updateShapes();
111     aChanged = aChanged || anOperationPrs->dependOn(theObject);
112
113     //if (aChanged)
114     anOperationPrs->Redisplay();
115   }
116   return false;
117 }
118
119 bool PartSet_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
120                                               std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)
121 {
122   return false;
123 }