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"
10 #include "PartSet_OverconstraintListener.h"
12 #include <XGUI_ModuleConnector.h>
13 #include <XGUI_Workshop.h>
14 #include <XGUI_Displayer.h>
16 #include <ModuleBase_IWorkshop.h>
17 #include <ModuleBase_IViewer.h>
18 #include <ModuleBase_Tools.h>
20 #include <Config_PropManager.h>
22 #include <AIS_InteractiveContext.hxx>
23 #include <AIS_InteractiveObject.hxx>
24 #include <Prs3d_PointAspect.hxx>
26 //#define DO_NOT_VISUALIZE_CUSTOM_PRESENTATION
28 PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop)
29 : myWorkshop(theWorkshop), myFeature(FeaturePtr())
31 initPresentation(ModuleBase_IModule::CustomizeArguments);
32 initPresentation(ModuleBase_IModule::CustomizeResults);
33 initPresentation(ModuleBase_IModule::CustomizeHighlightedObjects);
35 myIsActive[ModuleBase_IModule::CustomizeArguments] = false;
36 myIsActive[ModuleBase_IModule::CustomizeResults] = false;
37 myIsActive[ModuleBase_IModule::CustomizeHighlightedObjects] = false;
40 bool PartSet_CustomPrs::isActive(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag)
42 return myIsActive[theFlag];
45 bool PartSet_CustomPrs::activate(const FeaturePtr& theFeature,
46 const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
47 const bool theUpdateViewer)
49 #ifdef DO_NOT_VISUALIZE_CUSTOM_PRESENTATION
53 myIsActive[theFlag] = true;
54 myFeature = theFeature;
56 bool isModified = false;
57 if (theFeature.get()) {
58 displayPresentation(ModuleBase_IModule::CustomizeArguments, theUpdateViewer);
59 displayPresentation(ModuleBase_IModule::CustomizeResults, theUpdateViewer);
60 displayPresentation(ModuleBase_IModule::CustomizeHighlightedObjects, theUpdateViewer);
66 bool PartSet_CustomPrs::deactivate(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
67 const bool theUpdateViewer)
69 myIsActive[theFlag] = false;
70 bool isModified = false;
72 erasePresentation(ModuleBase_IModule::CustomizeArguments, theUpdateViewer);
73 erasePresentation(ModuleBase_IModule::CustomizeResults, theUpdateViewer);
74 erasePresentation(ModuleBase_IModule::CustomizeHighlightedObjects, theUpdateViewer);
80 bool PartSet_CustomPrs::displayPresentation(
81 const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
82 const bool theUpdateViewer)
84 bool isModified = false;
86 // update the AIS objects content
87 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(theFlag);
88 // do nothing if the feature can not be displayed [is moved from presentation, to be checked]
93 case ModuleBase_IModule::CustomizeArguments:
94 PartSet_OperationPrs::getFeatureShapes(myFeature, myWorkshop, anOperationPrs->featureShapes());
96 case ModuleBase_IModule::CustomizeResults:
97 PartSet_OperationPrs::getResultShapes(myFeature, myWorkshop, anOperationPrs->featureShapes());
99 case ModuleBase_IModule::CustomizeHighlightedObjects:
100 PartSet_OperationPrs::getHighlightedShapes(myWorkshop, anOperationPrs->featureShapes());
106 // redisplay AIS objects
107 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
108 if (!aContext.IsNull() && !aContext->IsDisplayed(anOperationPrs)) {
109 // when the feature can not be visualized in the module, the operation preview should not
110 // be visualized also
111 if (anOperationPrs->hasShapes() && myWorkshop->module()->canDisplayObject(myFeature)) {
112 // set color here because it can be changed in preferences
113 Quantity_Color aShapeColor = getShapeColor(theFlag);
114 anOperationPrs->setShapeColor(aShapeColor);
116 PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
117 XGUI_Workshop* aWorkshop = workshop();
118 aWorkshop->displayer()->displayAIS(myPresentations[theFlag], false/*load object in selection*/,
120 aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId());
125 // when the feature can not be visualized in the module, the operation preview should not
126 // be visualized also
127 if (!anOperationPrs->hasShapes() || !myWorkshop->module()->canDisplayObject(myFeature)) {
128 erasePresentation(theFlag, theUpdateViewer);
132 anOperationPrs->Redisplay();
135 workshop()->displayer()->updateViewer();
141 void PartSet_CustomPrs::erasePresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
142 const bool theUpdateViewer)
144 XGUI_Workshop* aWorkshop = workshop();
145 aWorkshop->displayer()->eraseAIS(myPresentations[theFlag], theUpdateViewer);
148 void PartSet_CustomPrs::clearPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag)
150 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(theFlag);
151 anOperationPrs->featureShapes().clear();
152 if (!anOperationPrs.IsNull())
153 anOperationPrs.Nullify();
154 myPresentations[theFlag] = AISObjectPtr();
157 Handle(PartSet_OperationPrs) PartSet_CustomPrs::getPresentation(
158 const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag)
160 Handle(PartSet_OperationPrs) aPresentation;
162 if (myPresentations.contains(theFlag)) {
163 AISObjectPtr anOperationPrs = myPresentations[theFlag];
164 if (!anOperationPrs.get()) {
165 initPresentation(theFlag);
166 anOperationPrs = myPresentations[theFlag];
168 Handle(AIS_InteractiveObject) anAISIO = anOperationPrs->impl<Handle(AIS_InteractiveObject)>();
169 aPresentation = Handle(PartSet_OperationPrs)::DownCast(anAISIO);
171 return aPresentation;
174 bool PartSet_CustomPrs::redisplay(const ObjectPtr& theObject,
175 const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
176 const bool theUpdateViewer)
178 #ifdef DO_NOT_VISUALIZE_CUSTOM_PRESENTATION
181 bool aRedisplayed = false;
182 if (myIsActive[theFlag])
183 aRedisplayed = displayPresentation(theFlag, theUpdateViewer);
188 void PartSet_CustomPrs::clearPrs()
190 clearPresentation(ModuleBase_IModule::CustomizeArguments);
191 clearPresentation(ModuleBase_IModule::CustomizeResults);
192 clearPresentation(ModuleBase_IModule::CustomizeHighlightedObjects);
195 void PartSet_CustomPrs::initPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag)
197 AISObjectPtr anOperationPrs = AISObjectPtr(new GeomAPI_AISObject());
198 Handle(PartSet_OperationPrs) anAISPrs = new PartSet_OperationPrs(myWorkshop);
199 anOperationPrs->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs));
200 if (theFlag == ModuleBase_IModule::CustomizeArguments ||
201 theFlag == ModuleBase_IModule::CustomizeResults) {
202 anOperationPrs->setPointMarker(5, 2.);
203 anOperationPrs->setWidth(1);
205 else if (theFlag == ModuleBase_IModule::CustomizeHighlightedObjects)
206 anAISPrs->useAISWidth();
208 if (anOperationPrs.get())
209 myPresentations[theFlag] = anOperationPrs;
212 Quantity_Color PartSet_CustomPrs::getShapeColor(
213 const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag)
215 Quantity_Color aColor;
217 case ModuleBase_IModule::CustomizeArguments:
218 aColor = ModuleBase_Tools::color("Visualization", "operation_parameter_color",
219 OPERATION_PARAMETER_COLOR());
221 case ModuleBase_IModule::CustomizeResults:
222 aColor = ModuleBase_Tools::color("Visualization", "operation_result_color",
223 OPERATION_RESULT_COLOR());
225 case ModuleBase_IModule::CustomizeHighlightedObjects:
226 aColor = ModuleBase_Tools::color("Visualization", "operation_highlight_color",
227 OPERATION_HIGHLIGHT_COLOR());
235 XGUI_Workshop* PartSet_CustomPrs::workshop() const
237 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
238 return aConnector->workshop();