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>
17 #include <ModuleBase_Tools.h>
19 #include <Config_PropManager.h>
21 #include <AIS_InteractiveContext.hxx>
22 #include <AIS_InteractiveObject.hxx>
23 #include <Prs3d_PointAspect.hxx>
25 //#define DO_NOT_VISUALIZE_CUSTOM_PRESENTATION
27 PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop)
28 : myWorkshop(theWorkshop), myFeature(FeaturePtr())
30 initPresentation(ModuleBase_IModule::CustomizeArguments);
31 initPresentation(ModuleBase_IModule::CustomizeResults);
32 initPresentation(ModuleBase_IModule::CustomizeHighlightedObjects);
34 myIsActive[ModuleBase_IModule::CustomizeArguments] = false;
35 myIsActive[ModuleBase_IModule::CustomizeResults] = false;
36 myIsActive[ModuleBase_IModule::CustomizeHighlightedObjects] = false;
39 bool PartSet_CustomPrs::isActive(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag)
41 return myIsActive[theFlag];
44 bool PartSet_CustomPrs::activate(const FeaturePtr& theFeature,
45 const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
46 const bool theUpdateViewer)
48 #ifdef DO_NOT_VISUALIZE_CUSTOM_PRESENTATION
52 myIsActive[theFlag] = true;
53 myFeature = theFeature;
55 bool isModified = false;
56 if (theFeature.get()) {
57 displayPresentation(ModuleBase_IModule::CustomizeArguments, theUpdateViewer);
58 displayPresentation(ModuleBase_IModule::CustomizeResults, theUpdateViewer);
59 displayPresentation(ModuleBase_IModule::CustomizeHighlightedObjects, theUpdateViewer);
65 bool PartSet_CustomPrs::deactivate(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
66 const bool theUpdateViewer)
68 myIsActive[theFlag] = false;
69 bool isModified = false;
71 erasePresentation(ModuleBase_IModule::CustomizeArguments, theUpdateViewer);
72 erasePresentation(ModuleBase_IModule::CustomizeResults, theUpdateViewer);
73 erasePresentation(ModuleBase_IModule::CustomizeHighlightedObjects, theUpdateViewer);
79 bool PartSet_CustomPrs::displayPresentation(
80 const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
81 const bool theUpdateViewer)
83 bool isModified = false;
85 // update the AIS objects content
86 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(theFlag);
87 // do nothing if the feature can not be displayed [is moved from presentation, to be checked]
92 case ModuleBase_IModule::CustomizeArguments:
93 PartSet_OperationPrs::getFeatureShapes(myFeature, myWorkshop, anOperationPrs->featureShapes());
95 case ModuleBase_IModule::CustomizeResults:
96 PartSet_OperationPrs::getResultShapes(myFeature, myWorkshop, anOperationPrs->featureShapes());
98 case ModuleBase_IModule::CustomizeHighlightedObjects:
99 PartSet_OperationPrs::getHighlightedShapes(myWorkshop, anOperationPrs->featureShapes());
105 // redisplay AIS objects
106 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
107 if (!aContext.IsNull() && !aContext->IsDisplayed(anOperationPrs)) {
108 // when the feature can not be visualized in the module, the operation preview should not
109 // be visualized also
110 if (anOperationPrs->hasShapes() && myWorkshop->module()->canDisplayObject(myFeature)) {
111 // set color here because it can be changed in preferences
112 Quantity_Color aShapeColor = getShapeColor(theFlag);
113 anOperationPrs->setShapeColor(aShapeColor);
115 PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
116 XGUI_Workshop* aWorkshop = workshop();
117 aWorkshop->displayer()->displayAIS(myPresentations[theFlag], false/*load object in selection*/,
119 aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId());
124 // when the feature can not be visualized in the module, the operation preview should not
125 // be visualized also
126 if (!anOperationPrs->hasShapes() || !myWorkshop->module()->canDisplayObject(myFeature)) {
127 erasePresentation(theFlag, theUpdateViewer);
131 anOperationPrs->Redisplay();
134 workshop()->displayer()->updateViewer();
140 void PartSet_CustomPrs::erasePresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
141 const bool theUpdateViewer)
143 XGUI_Workshop* aWorkshop = workshop();
144 aWorkshop->displayer()->eraseAIS(myPresentations[theFlag], theUpdateViewer);
147 void PartSet_CustomPrs::clearPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag)
149 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(theFlag);
150 if (!anOperationPrs.IsNull())
151 anOperationPrs.Nullify();
154 Handle(PartSet_OperationPrs) PartSet_CustomPrs::getPresentation(
155 const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag)
157 Handle(PartSet_OperationPrs) aPresentation;
159 if (myPresentations.contains(theFlag)) {
160 AISObjectPtr anOperationPrs = myPresentations[theFlag];
161 if (!anOperationPrs.get())
162 initPresentation(theFlag);
163 Handle(AIS_InteractiveObject) anAISIO = anOperationPrs->impl<Handle(AIS_InteractiveObject)>();
164 aPresentation = Handle(PartSet_OperationPrs)::DownCast(anAISIO);
166 return aPresentation;
169 bool PartSet_CustomPrs::redisplay(const ObjectPtr& theObject,
170 const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
171 const bool theUpdateViewer)
173 #ifdef DO_NOT_VISUALIZE_CUSTOM_PRESENTATION
176 return displayPresentation(theFlag, theUpdateViewer);
179 void PartSet_CustomPrs::clearPrs()
181 clearPresentation(ModuleBase_IModule::CustomizeArguments);
182 clearPresentation(ModuleBase_IModule::CustomizeResults);
183 clearPresentation(ModuleBase_IModule::CustomizeHighlightedObjects);
186 void PartSet_CustomPrs::initPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag)
188 AISObjectPtr anOperationPrs = AISObjectPtr(new GeomAPI_AISObject());
189 Handle(PartSet_OperationPrs) anAISPrs = new PartSet_OperationPrs(myWorkshop);
190 anOperationPrs->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs));
191 if (theFlag == ModuleBase_IModule::CustomizeArguments ||
192 theFlag == ModuleBase_IModule::CustomizeResults) {
193 anOperationPrs->setPointMarker(5, 2.);
194 anOperationPrs->setWidth(1);
196 else if (theFlag == ModuleBase_IModule::CustomizeHighlightedObjects)
197 anAISPrs->useAISWidth();
199 if (anOperationPrs.get())
200 myPresentations[theFlag] = anOperationPrs;
203 Quantity_Color PartSet_CustomPrs::getShapeColor(
204 const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag)
206 Quantity_Color aColor;
208 case ModuleBase_IModule::CustomizeArguments:
209 aColor = ModuleBase_Tools::color("Visualization", "operation_parameter_color",
210 OPERATION_PARAMETER_COLOR());
212 case ModuleBase_IModule::CustomizeResults:
213 aColor = ModuleBase_Tools::color("Visualization", "operation_result_color",
214 OPERATION_RESULT_COLOR());
216 case ModuleBase_IModule::CustomizeHighlightedObjects:
217 aColor = ModuleBase_Tools::color("Visualization", "operation_highlight_color",
218 OPERATION_HIGHLIGHT_COLOR());
226 XGUI_Workshop* PartSet_CustomPrs::workshop() const
228 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
229 return aConnector->workshop();