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 <Config_PropManager.h>
22 #include <AIS_InteractiveContext.hxx>
23 #include <AIS_InteractiveObject.hxx>
24 #include <Prs3d_PointAspect.hxx>
26 #define OPERATION_PARAMETER_COLOR "255, 255, 0"
28 PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop)
29 : myWorkshop(theWorkshop)
31 myOperationPrs = AISObjectPtr(new GeomAPI_AISObject());
32 myOperationPrs->setImpl(new Handle(AIS_InteractiveObject)(new PartSet_OperationPrs(theWorkshop)));
34 std::vector<int> aColor = Config_PropManager::color("Visualization", "operation_parameter_color",
35 OPERATION_PARAMETER_COLOR);
36 myOperationPrs->setColor(aColor[0], aColor[1], aColor[2]);
38 myOperationPrs->setPointMarker(5, 2.);
39 myOperationPrs->setWidth(1);
42 bool PartSet_CustomPrs::isActive() const
44 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
45 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
47 return aContext->IsDisplayed(anOperationPrs);
50 void PartSet_CustomPrs::activate(const FeaturePtr& theFeature)
52 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
54 if (anOperationPrs->canActivate(theFeature)) {
55 anOperationPrs->setFeature(theFeature);
57 displayPresentation();
61 void PartSet_CustomPrs::deactivate()
63 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
64 anOperationPrs->setFeature(FeaturePtr());
70 void PartSet_CustomPrs::displayPresentation()
72 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
74 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
75 if (!aContext->IsDisplayed(anOperationPrs)) {
76 PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
77 aContext->Display(anOperationPrs);
78 aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId());
81 anOperationPrs->Redisplay();
84 void PartSet_CustomPrs::erasePresentation()
86 Handle(AIS_InteractiveObject) anOperationPrs = myOperationPrs->impl<Handle(AIS_InteractiveObject)>();
87 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
88 if (aContext->IsDisplayed(anOperationPrs))
89 aContext->Remove(anOperationPrs);
92 Handle(PartSet_OperationPrs) PartSet_CustomPrs::getPresentation() const
94 Handle(AIS_InteractiveObject) anAISIO = myOperationPrs->impl<Handle(AIS_InteractiveObject)>();
95 return Handle(PartSet_OperationPrs)::DownCast(anAISIO);
98 void PartSet_CustomPrs::customize(const ObjectPtr& theObject)
100 // the presentation should be recomputed if the previous AIS depend on the result
101 // [it should be hiddend] or the new AIS depend on it [it should be visualized]
102 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
103 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
104 if (aContext->IsDisplayed(anOperationPrs)) {
105 // if there are performance poblems, to improve them, the necessity of redisplay can be checked
106 //bool aChanged = anOperationPrs->dependOn(theObject);
107 anOperationPrs->updateShapes();
108 //aChanged = aChanged || anOperationPrs->dependOn(theObject);
110 anOperationPrs->Redisplay();