1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_CustomPrs.cpp
4 // Created: 30 Jun 2015
5 // Author: Natalia ERMOLAEVA
7 #include <PartSet_CustomPrs.h>
8 #include <PartSet_Module.h>
9 #include "PartSet_OperationPrs.h"
11 #include <XGUI_ModuleConnector.h>
12 #include <XGUI_Workshop.h>
13 #include <XGUI_Displayer.h>
15 #include <ModuleBase_IWorkshop.h>
16 #include <ModuleBase_IViewer.h>
18 #include <GeomValidators_Tools.h>
20 #include <Config_PropManager.h>
22 #include <AIS_InteractiveContext.hxx>
23 #include <AIS_InteractiveObject.hxx>
24 #include <Prs3d_PointAspect.hxx>
26 #define OPERATION_PARAMETER_COLOR "255, 255, 0"
28 PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop)
29 : myWorkshop(theWorkshop)
34 bool PartSet_CustomPrs::isActive()
36 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
37 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
39 return aContext->IsDisplayed(anOperationPrs);
42 void PartSet_CustomPrs::activate(const FeaturePtr& theFeature)
44 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
46 if (anOperationPrs->canActivate(theFeature)) {
47 anOperationPrs->setFeature(theFeature);
49 displayPresentation();
53 void PartSet_CustomPrs::deactivate()
55 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
56 anOperationPrs->setFeature(FeaturePtr());
62 void PartSet_CustomPrs::displayPresentation()
64 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
66 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
67 if (!aContext->IsDisplayed(anOperationPrs)) {
68 PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
70 XGUI_Workshop* aWorkshop = workshop();
71 aWorkshop->displayer()->displayAIS(myOperationPrs, false/*load object in selection*/, true);
72 aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId());
75 anOperationPrs->Redisplay();
76 workshop()->displayer()->updateViewer();
80 void PartSet_CustomPrs::erasePresentation()
82 XGUI_Workshop* aWorkshop = workshop();
83 aWorkshop->displayer()->eraseAIS(myOperationPrs, true);
86 Handle(PartSet_OperationPrs) PartSet_CustomPrs::getPresentation()
88 if (!myOperationPrs.get())
90 Handle(AIS_InteractiveObject) anAISIO = myOperationPrs->impl<Handle(AIS_InteractiveObject)>();
91 return Handle(PartSet_OperationPrs)::DownCast(anAISIO);
94 void PartSet_CustomPrs::customize(const ObjectPtr& theObject)
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);
106 anOperationPrs->Redisplay();
110 void PartSet_CustomPrs::clearPrs()
112 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
113 if (!anOperationPrs.IsNull())
114 anOperationPrs.Nullify();
116 myOperationPrs.reset();
119 void PartSet_CustomPrs::initPrs()
121 myOperationPrs = AISObjectPtr(new GeomAPI_AISObject());
122 myOperationPrs->setImpl(new Handle(AIS_InteractiveObject)(new PartSet_OperationPrs(myWorkshop)));
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]);
128 myOperationPrs->setPointMarker(5, 2.);
129 myOperationPrs->setWidth(1);
132 XGUI_Workshop* PartSet_CustomPrs::workshop() const
134 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
135 return aConnector->workshop();