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), myIsActive(false)
30 initPresentation(ModuleBase_IModule::CustomizeDependedAndResults);
31 initPresentation(ModuleBase_IModule::CustomizeHighlightedObjects);
34 bool PartSet_CustomPrs::isActive()
39 bool PartSet_CustomPrs::activate(const FeaturePtr& theFeature, const bool theUpdateViewer)
41 #ifdef DO_NOT_VISUALIZE_CUSTOM_PRESENTATION
48 bool isModified = false;
49 getPresentation(ModuleBase_IModule::CustomizeDependedAndResults)->setFeature(theFeature);
50 getPresentation(ModuleBase_IModule::CustomizeHighlightedObjects)->setFeature(theFeature);
51 if (theFeature.get()) {
52 displayPresentation(ModuleBase_IModule::CustomizeDependedAndResults, theUpdateViewer);
53 displayPresentation(ModuleBase_IModule::CustomizeHighlightedObjects, theUpdateViewer);
59 bool PartSet_CustomPrs::deactivate(const bool theUpdateViewer)
62 bool isModified = false;
64 getPresentation(ModuleBase_IModule::CustomizeDependedAndResults)->setFeature(FeaturePtr());
65 getPresentation(ModuleBase_IModule::CustomizeHighlightedObjects)->setFeature(FeaturePtr());
67 erasePresentation(ModuleBase_IModule::CustomizeDependedAndResults, theUpdateViewer);
68 erasePresentation(ModuleBase_IModule::CustomizeHighlightedObjects, theUpdateViewer);
74 bool PartSet_CustomPrs::displayPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
75 const bool theUpdateViewer)
77 bool isModified = false;
78 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(theFlag);
79 if (theFlag == ModuleBase_IModule::CustomizeDependedAndResults) {
80 PartSet_OperationPrs::getFeatureShapes(anOperationPrs->getFeature(), myWorkshop,
81 anOperationPrs->featureShapes());
82 anOperationPrs->updateShapes();
84 else if (theFlag == ModuleBase_IModule::CustomizeHighlightedObjects) {
85 PartSet_OperationPrs::getHighlightedShapes(myWorkshop, anOperationPrs->featureShapes());
88 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
89 if (!aContext.IsNull() && !aContext->IsDisplayed(anOperationPrs)) {
90 if (anOperationPrs->hasShapes()) {
91 // set color here because it can be changed in preferences
92 Quantity_Color aShapeColor, aResultColor;
93 getAISColors(theFlag, aShapeColor, aResultColor);
94 anOperationPrs->setColors(aShapeColor, aResultColor);
96 PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
97 XGUI_Workshop* aWorkshop = workshop();
98 aWorkshop->displayer()->displayAIS(myPresentations[theFlag], false/*load object in selection*/,
100 aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId());
105 if (!anOperationPrs->hasShapes()) {
106 erasePresentation(theFlag, theUpdateViewer);
110 anOperationPrs->Redisplay();
113 workshop()->displayer()->updateViewer();
119 void PartSet_CustomPrs::erasePresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
120 const bool theUpdateViewer)
122 XGUI_Workshop* aWorkshop = workshop();
123 aWorkshop->displayer()->eraseAIS(myPresentations[theFlag], theUpdateViewer);
126 void PartSet_CustomPrs::clearPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag)
128 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation(theFlag);
129 if (!anOperationPrs.IsNull())
130 anOperationPrs.Nullify();
133 Handle(PartSet_OperationPrs) PartSet_CustomPrs::getPresentation(
134 const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag)
136 Handle(PartSet_OperationPrs) aPresentation;
138 if (myPresentations.contains(theFlag)) {
139 AISObjectPtr anOperationPrs = myPresentations[theFlag];
140 if (!anOperationPrs.get())
141 initPresentation(theFlag);
142 Handle(AIS_InteractiveObject) anAISIO = anOperationPrs->impl<Handle(AIS_InteractiveObject)>();
143 aPresentation = Handle(PartSet_OperationPrs)::DownCast(anAISIO);
145 return aPresentation;
148 bool PartSet_CustomPrs::redisplay(const ObjectPtr& theObject,
149 const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
150 const bool theUpdateViewer)
152 #ifdef DO_NOT_VISUALIZE_CUSTOM_PRESENTATION
155 return displayPresentation(theFlag, theUpdateViewer);
158 void PartSet_CustomPrs::clearPrs()
160 clearPresentation(ModuleBase_IModule::CustomizeDependedAndResults);
161 clearPresentation(ModuleBase_IModule::CustomizeHighlightedObjects);
164 void PartSet_CustomPrs::initPresentation(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag)
166 AISObjectPtr anOperationPrs = AISObjectPtr(new GeomAPI_AISObject());
167 Handle(PartSet_OperationPrs) anAISPrs = new PartSet_OperationPrs(myWorkshop);
168 anOperationPrs->setImpl(new Handle(AIS_InteractiveObject)(anAISPrs));
169 if (theFlag == ModuleBase_IModule::CustomizeDependedAndResults) {
170 anOperationPrs->setPointMarker(5, 2.);
171 anOperationPrs->setWidth(1);
173 else if (theFlag == ModuleBase_IModule::CustomizeHighlightedObjects) {
174 anAISPrs->useAISWidth();
177 if (anOperationPrs.get())
178 myPresentations[theFlag] = anOperationPrs;
181 void PartSet_CustomPrs::getAISColors(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag,
182 Quantity_Color& theShapeColor, Quantity_Color& theResultColor)
184 if (theFlag == ModuleBase_IModule::CustomizeDependedAndResults) {
185 theShapeColor = ModuleBase_Tools::color("Visualization", "operation_parameter_color",
186 OPERATION_PARAMETER_COLOR());
187 theResultColor = ModuleBase_Tools::color("Visualization", "operation_result_color",
188 OPERATION_RESULT_COLOR());
190 else if (theFlag == ModuleBase_IModule::CustomizeHighlightedObjects) {
191 theShapeColor = ModuleBase_Tools::color("Visualization", "operation_highlight_color",
192 OPERATION_HIGHLIGHT_COLOR());
193 theResultColor = ModuleBase_Tools::color("Visualization", "operation_result_color",
194 OPERATION_RESULT_COLOR());
198 XGUI_Workshop* PartSet_CustomPrs::workshop() const
200 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
201 return aConnector->workshop();