Salome HOME
008640c20275c9e0de40b651ea83e36aaa0f4af3
[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   myOperationPrs = AISObjectPtr(new GeomAPI_AISObject());
32   myOperationPrs->setImpl(new Handle(AIS_InteractiveObject)(new PartSet_OperationPrs(theWorkshop)));
33
34   std::vector<int> aColor = Config_PropManager::color("Visualization", "operation_parameter_color",
35                                                       OPERATION_PARAMETER_COLOR);
36   myOperationPrs->setColor(aColor[0], aColor[1], aColor[2]);
37
38   myOperationPrs->setPointMarker(5, 2.);
39   myOperationPrs->setWidth(1);
40 }
41
42 bool PartSet_CustomPrs::isActive() const
43 {
44   Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
45   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
46
47   return aContext->IsDisplayed(anOperationPrs);
48 }
49
50 void PartSet_CustomPrs::activate(const FeaturePtr& theFeature)
51 {
52   Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
53
54   if (anOperationPrs->canActivate(theFeature)) {
55     anOperationPrs->setFeature(theFeature);
56     if (theFeature.get())
57       displayPresentation();
58   }
59 }
60
61 void PartSet_CustomPrs::deactivate()
62 {
63   Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
64   anOperationPrs->setFeature(FeaturePtr());
65
66   erasePresentation();
67 }
68
69
70 void PartSet_CustomPrs::displayPresentation()
71 {
72   Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
73
74   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
75   if (!aContext->IsDisplayed(anOperationPrs)) {
76     PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
77     aContext->Display(anOperationPrs);
78     aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId());
79   }
80   else
81     anOperationPrs->Redisplay();
82 }
83
84 void PartSet_CustomPrs::erasePresentation()
85 {
86   Handle(AIS_InteractiveObject) anOperationPrs = myOperationPrs->impl<Handle(AIS_InteractiveObject)>();
87   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
88   if (aContext->IsDisplayed(anOperationPrs))
89     aContext->Remove(anOperationPrs);
90 }
91
92 Handle(PartSet_OperationPrs) PartSet_CustomPrs::getPresentation() const
93 {
94   Handle(AIS_InteractiveObject) anAISIO = myOperationPrs->impl<Handle(AIS_InteractiveObject)>();
95   return Handle(PartSet_OperationPrs)::DownCast(anAISIO);
96 }
97
98 void PartSet_CustomPrs::customize(const ObjectPtr& theObject)
99 {
100   // the presentation should be recomputed if the previous AIS depend on the result
101   // [it should be hiddend] or the new AIS depend on it [it should be visualized]
102   Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
103   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
104   if (aContext->IsDisplayed(anOperationPrs)) {
105     // if there are performance poblems, to improve them, the necessity of redisplay can be checked
106     //bool aChanged = anOperationPrs->dependOn(theObject);
107     anOperationPrs->updateShapes();
108     //aChanged = aChanged || anOperationPrs->dependOn(theObject);
109     //if (aChanged)
110     anOperationPrs->Redisplay();
111   }
112 }