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.IsNull() && aContext->IsDisplayed(anOperationPrs);
42 bool PartSet_CustomPrs::activate(const FeaturePtr& theFeature, const bool theUpdateViewer)
44 bool isModified = false;
45 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
47 if (anOperationPrs->canActivate(theFeature)) {
48 anOperationPrs->setFeature(theFeature);
49 if (theFeature.get()) {
50 displayPresentation(theUpdateViewer);
57 bool PartSet_CustomPrs::deactivate(const bool theUpdateViewer)
59 bool isModified = false;
61 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
62 anOperationPrs->setFeature(FeaturePtr());
64 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
65 if (!aContext.IsNull() && aContext->IsDisplayed(anOperationPrs)) {
66 erasePresentation(theUpdateViewer);
74 void PartSet_CustomPrs::displayPresentation(const bool theUpdateViewer)
76 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
78 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
79 if (!aContext.IsNull() && !aContext->IsDisplayed(anOperationPrs)) {
80 PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
82 XGUI_Workshop* aWorkshop = workshop();
83 aWorkshop->displayer()->displayAIS(myOperationPrs, false/*load object in selection*/, theUpdateViewer);
84 aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId());
87 anOperationPrs->Redisplay();
89 workshop()->displayer()->updateViewer();
93 void PartSet_CustomPrs::erasePresentation(const bool theUpdateViewer)
95 XGUI_Workshop* aWorkshop = workshop();
96 aWorkshop->displayer()->eraseAIS(myOperationPrs, theUpdateViewer);
99 Handle(PartSet_OperationPrs) PartSet_CustomPrs::getPresentation()
101 if (!myOperationPrs.get())
103 Handle(AIS_InteractiveObject) anAISIO = myOperationPrs->impl<Handle(AIS_InteractiveObject)>();
104 return Handle(PartSet_OperationPrs)::DownCast(anAISIO);
107 bool PartSet_CustomPrs::redisplay(const ObjectPtr& theObject, const bool theUpdateViewer)
109 bool isModified = false;
110 // the presentation should be recomputed if the previous AIS depend on the result
111 // [it should be hiddend] or the new AIS depend on it [it should be visualized]
112 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
113 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
114 if (!aContext.IsNull() && aContext->IsDisplayed(anOperationPrs)) {
115 // if there are performance poblems, to improve them, the necessity of redisplay can be checked
116 //bool aChanged = anOperationPrs->dependOn(theObject);
117 anOperationPrs->updateShapes();
118 //aChanged = aChanged || anOperationPrs->dependOn(theObject);
120 anOperationPrs->Redisplay();
123 workshop()->displayer()->updateViewer();
128 void PartSet_CustomPrs::clearPrs()
130 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
131 if (!anOperationPrs.IsNull())
132 anOperationPrs.Nullify();
134 myOperationPrs.reset();
137 void PartSet_CustomPrs::initPrs()
139 myOperationPrs = AISObjectPtr(new GeomAPI_AISObject());
140 myOperationPrs->setImpl(new Handle(AIS_InteractiveObject)(new PartSet_OperationPrs(myWorkshop)));
142 std::vector<int> aColor = Config_PropManager::color("Visualization", "operation_parameter_color",
143 OPERATION_PARAMETER_COLOR);
144 myOperationPrs->setColor(aColor[0], aColor[1], aColor[2]);
146 myOperationPrs->setPointMarker(5, 2.);
147 myOperationPrs->setWidth(1);
150 XGUI_Workshop* PartSet_CustomPrs::workshop() const
152 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
153 return aConnector->workshop();