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 <Config_PropManager.h>
20 #include <AIS_InteractiveContext.hxx>
21 #include <AIS_InteractiveObject.hxx>
22 #include <Prs3d_PointAspect.hxx>
24 //#define DO_NOT_VISUALIZE_CUSTOM_PRESENTATION
26 #define OPERATION_PARAMETER_COLOR "255, 255, 0"
28 PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop)
29 : myWorkshop(theWorkshop), myIsActive(false)
34 bool PartSet_CustomPrs::isActive()
37 /*Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
38 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
40 return !aContext.IsNull() && aContext->IsDisplayed(anOperationPrs);*/
43 bool PartSet_CustomPrs::activate(const FeaturePtr& theFeature, const bool theUpdateViewer)
45 #ifdef DO_NOT_VISUALIZE_CUSTOM_PRESENTATION
49 bool isModified = false;
50 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
52 if (anOperationPrs->canActivate(theFeature)) {
54 anOperationPrs->setFeature(theFeature);
55 if (theFeature.get()) {
56 displayPresentation(theUpdateViewer);
63 bool PartSet_CustomPrs::deactivate(const bool theUpdateViewer)
66 bool isModified = false;
68 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
69 anOperationPrs->setFeature(FeaturePtr());
71 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
72 if (!aContext.IsNull() && aContext->IsDisplayed(anOperationPrs)) {
73 erasePresentation(theUpdateViewer);
81 void PartSet_CustomPrs::displayPresentation(const bool theUpdateViewer)
83 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
85 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
86 if (!aContext.IsNull() && !aContext->IsDisplayed(anOperationPrs)) {
87 if (anOperationPrs->hasShapes()) {
88 PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
89 XGUI_Workshop* aWorkshop = workshop();
90 aWorkshop->displayer()->displayAIS(myOperationPrs, false/*load object in selection*/, theUpdateViewer);
91 aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId());
95 if (!anOperationPrs->hasShapes())
96 erasePresentation(theUpdateViewer);
98 anOperationPrs->Redisplay();
100 workshop()->displayer()->updateViewer();
105 void PartSet_CustomPrs::erasePresentation(const bool theUpdateViewer)
107 XGUI_Workshop* aWorkshop = workshop();
108 aWorkshop->displayer()->eraseAIS(myOperationPrs, theUpdateViewer);
111 Handle(PartSet_OperationPrs) PartSet_CustomPrs::getPresentation()
113 if (!myOperationPrs.get())
115 Handle(AIS_InteractiveObject) anAISIO = myOperationPrs->impl<Handle(AIS_InteractiveObject)>();
116 return Handle(PartSet_OperationPrs)::DownCast(anAISIO);
119 bool PartSet_CustomPrs::redisplay(const ObjectPtr& theObject,
120 const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
121 const bool theUpdateViewer)
123 #ifdef DO_NOT_VISUALIZE_CUSTOM_PRESENTATION
127 bool isModified = false;
128 // the presentation should be recomputed if the previous AIS depend on the result
129 // [it should be hiddend] or the new AIS depend on it [it should be visualized]
130 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
131 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
132 if (!aContext.IsNull()) {
133 if (aContext->IsDisplayed(anOperationPrs)) {
134 // if there are performance poblems, to improve them, the necessity of redisplay can be checked
135 //bool aChanged = anOperationPrs->dependOn(theObject);
136 anOperationPrs->updateShapes();
137 //aChanged = aChanged || anOperationPrs->dependOn(theObject);
139 anOperationPrs->Redisplay();
142 workshop()->displayer()->updateViewer();
145 anOperationPrs->updateShapes();
146 displayPresentation(theUpdateViewer);
152 void PartSet_CustomPrs::clearPrs()
154 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
155 if (!anOperationPrs.IsNull())
156 anOperationPrs.Nullify();
158 myOperationPrs.reset();
161 void PartSet_CustomPrs::initPrs()
163 myOperationPrs = AISObjectPtr(new GeomAPI_AISObject());
164 myOperationPrs->setImpl(new Handle(AIS_InteractiveObject)(new PartSet_OperationPrs(myWorkshop)));
166 std::vector<int> aColor = Config_PropManager::color("Visualization", "operation_parameter_color",
167 OPERATION_PARAMETER_COLOR);
168 myOperationPrs->setColor(aColor[0], aColor[1], aColor[2]);
170 myOperationPrs->setPointMarker(5, 2.);
171 myOperationPrs->setWidth(1);
174 XGUI_Workshop* PartSet_CustomPrs::workshop() const
176 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
177 return aConnector->workshop();