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 <ModelAPI_Attribute.h>
21 #include <ModelAPI_AttributeSelectionList.h>
23 #include <Config_PropManager.h>
25 #include <AIS_InteractiveContext.hxx>
26 #include <AIS_InteractiveObject.hxx>
27 #include <Prs3d_PointAspect.hxx>
29 #define OPERATION_PARAMETER_COLOR "255, 255, 0"
31 PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop)
32 : myWorkshop(theWorkshop)
34 myOperationPrs = AISObjectPtr(new GeomAPI_AISObject());
35 myOperationPrs->setImpl(new Handle(AIS_InteractiveObject)(new PartSet_OperationPrs(theWorkshop)));
37 std::vector<int> aColor = Config_PropManager::color("Visualization", "operation_parameter_color",
38 OPERATION_PARAMETER_COLOR);
39 myOperationPrs->setColor(aColor[0], aColor[1], aColor[2]);
41 myOperationPrs->setPointMarker(5, 2.);
42 myOperationPrs->setWidth(1);
45 bool PartSet_CustomPrs::isActive() const
47 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
48 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
50 return aContext->IsDisplayed(anOperationPrs);
53 void PartSet_CustomPrs::activate(const FeaturePtr& theFeature)
55 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
57 if (anOperationPrs->canActivate(theFeature)) {
58 anOperationPrs->setFeature(theFeature);
60 displayPresentation();
64 void PartSet_CustomPrs::deactivate()
66 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
67 anOperationPrs->setFeature(FeaturePtr());
73 void PartSet_CustomPrs::displayPresentation()
75 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
77 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
78 if (!aContext->IsDisplayed(anOperationPrs)) {
79 PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
80 aContext->Display(anOperationPrs);
81 aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId());
84 anOperationPrs->Redisplay();
87 void PartSet_CustomPrs::erasePresentation()
89 Handle(AIS_InteractiveObject) anOperationPrs = myOperationPrs->impl<Handle(AIS_InteractiveObject)>();
90 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
91 if (aContext->IsDisplayed(anOperationPrs))
92 aContext->Remove(anOperationPrs);
95 Handle(PartSet_OperationPrs) PartSet_CustomPrs::getPresentation() const
97 Handle(AIS_InteractiveObject) anAISIO = myOperationPrs->impl<Handle(AIS_InteractiveObject)>();
98 return Handle(PartSet_OperationPrs)::DownCast(anAISIO);
101 bool PartSet_CustomPrs::customize(const ObjectPtr& theObject)
103 // the presentation should be recomputed if the previous AIS depend on the result
104 // [it should be hiddend] or the new AIS depend on it [it should be visualized]
105 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
106 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
107 if (aContext->IsDisplayed(anOperationPrs)) {
108 bool aChanged = anOperationPrs->dependOn(theObject);
110 anOperationPrs->updateShapes();
111 aChanged = aChanged || anOperationPrs->dependOn(theObject);
114 anOperationPrs->Redisplay();
119 bool PartSet_CustomPrs::customisePresentation(ResultPtr theResult, AISObjectPtr thePrs,
120 std::shared_ptr<GeomAPI_ICustomPrs> theCustomPrs)