]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_CustomPrs.cpp
Salome HOME
The preview presentation should be updated by the operation values changed.
[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 <Config_PropManager.h>
21
22 #include <AIS_InteractiveContext.hxx>
23 #include <AIS_InteractiveObject.hxx>
24 #include <Prs3d_PointAspect.hxx>
25
26 #define OPERATION_PARAMETER_COLOR "255, 255, 0"
27
28 PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop)
29   : myWorkshop(theWorkshop)
30 {
31   initPrs();
32 }
33
34 bool PartSet_CustomPrs::isActive()
35 {
36   Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
37   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
38
39   return aContext->IsDisplayed(anOperationPrs);
40 }
41
42 void PartSet_CustomPrs::activate(const FeaturePtr& theFeature)
43 {
44   Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
45
46   if (anOperationPrs->canActivate(theFeature)) {
47     anOperationPrs->setFeature(theFeature);
48     if (theFeature.get())
49       displayPresentation();
50   }
51 }
52
53 void PartSet_CustomPrs::deactivate()
54 {
55   Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
56   anOperationPrs->setFeature(FeaturePtr());
57
58   erasePresentation();
59 }
60
61
62 void PartSet_CustomPrs::displayPresentation()
63 {
64   Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
65
66   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
67   if (!aContext->IsDisplayed(anOperationPrs)) {
68     PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
69
70     XGUI_Workshop* aWorkshop = workshop();
71     aWorkshop->displayer()->displayAIS(myOperationPrs, false/*load object in selection*/, true);
72     aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId());
73   }
74   else {
75     anOperationPrs->Redisplay();
76     workshop()->displayer()->updateViewer();
77   }
78 }
79
80 void PartSet_CustomPrs::erasePresentation()
81 {
82   XGUI_Workshop* aWorkshop = workshop();
83   aWorkshop->displayer()->eraseAIS(myOperationPrs, true);
84 }
85
86 Handle(PartSet_OperationPrs) PartSet_CustomPrs::getPresentation()
87 {
88   if (!myOperationPrs.get())
89     initPrs();
90   Handle(AIS_InteractiveObject) anAISIO = myOperationPrs->impl<Handle(AIS_InteractiveObject)>();
91   return Handle(PartSet_OperationPrs)::DownCast(anAISIO);
92 }
93
94 void PartSet_CustomPrs::customize(const ObjectPtr& theObject)
95 {
96   // the presentation should be recomputed if the previous AIS depend on the result
97   // [it should be hiddend] or the new AIS depend on it [it should be visualized]
98   Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
99   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
100   if (aContext->IsDisplayed(anOperationPrs)) {
101     // if there are performance poblems, to improve them, the necessity of redisplay can be checked
102     //bool aChanged = anOperationPrs->dependOn(theObject);
103     anOperationPrs->updateShapes();
104     //aChanged = aChanged || anOperationPrs->dependOn(theObject);
105     //if (aChanged)
106     anOperationPrs->Redisplay();
107   }
108 }
109
110 void PartSet_CustomPrs::clearPrs()
111 {
112   Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
113   if (!anOperationPrs.IsNull())
114     anOperationPrs.Nullify();
115
116   myOperationPrs.reset();
117 }
118
119 void PartSet_CustomPrs::initPrs()
120 {
121   myOperationPrs = AISObjectPtr(new GeomAPI_AISObject());
122   myOperationPrs->setImpl(new Handle(AIS_InteractiveObject)(new PartSet_OperationPrs(myWorkshop)));
123
124   std::vector<int> aColor = Config_PropManager::color("Visualization", "operation_parameter_color",
125                                                       OPERATION_PARAMETER_COLOR);
126   myOperationPrs->setColor(aColor[0], aColor[1], aColor[2]);
127
128   myOperationPrs->setPointMarker(5, 2.);
129   myOperationPrs->setWidth(1);
130 }
131
132 XGUI_Workshop* PartSet_CustomPrs::workshop() const
133 {
134   XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
135   return aConnector->workshop();
136 }