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), myIsActive(false)
34 bool PartSet_CustomPrs::isActive()
37 /*Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
38 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
40 return !aContext.IsNull() && aContext->IsDisplayed(anOperationPrs);*/
43 bool PartSet_CustomPrs::activate(const FeaturePtr& theFeature, const bool theUpdateViewer)
45 bool isModified = false;
46 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
48 if (anOperationPrs->canActivate(theFeature)) {
50 anOperationPrs->setFeature(theFeature);
51 if (theFeature.get()) {
52 displayPresentation(theUpdateViewer);
59 bool PartSet_CustomPrs::deactivate(const bool theUpdateViewer)
62 bool isModified = false;
64 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
65 anOperationPrs->setFeature(FeaturePtr());
67 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
68 if (!aContext.IsNull() && aContext->IsDisplayed(anOperationPrs)) {
69 erasePresentation(theUpdateViewer);
77 void PartSet_CustomPrs::displayPresentation(const bool theUpdateViewer)
79 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
81 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
82 if (!aContext.IsNull() && !aContext->IsDisplayed(anOperationPrs)) {
83 if (anOperationPrs->hasShapes()) {
84 PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
85 XGUI_Workshop* aWorkshop = workshop();
86 aWorkshop->displayer()->displayAIS(myOperationPrs, false/*load object in selection*/, theUpdateViewer);
87 aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId());
91 if (!anOperationPrs->hasShapes())
92 erasePresentation(theUpdateViewer);
94 anOperationPrs->Redisplay();
96 workshop()->displayer()->updateViewer();
101 void PartSet_CustomPrs::erasePresentation(const bool theUpdateViewer)
103 XGUI_Workshop* aWorkshop = workshop();
104 aWorkshop->displayer()->eraseAIS(myOperationPrs, theUpdateViewer);
107 Handle(PartSet_OperationPrs) PartSet_CustomPrs::getPresentation()
109 if (!myOperationPrs.get())
111 Handle(AIS_InteractiveObject) anAISIO = myOperationPrs->impl<Handle(AIS_InteractiveObject)>();
112 return Handle(PartSet_OperationPrs)::DownCast(anAISIO);
115 bool PartSet_CustomPrs::redisplay(const ObjectPtr& theObject, const bool theUpdateViewer)
117 bool isModified = false;
118 // the presentation should be recomputed if the previous AIS depend on the result
119 // [it should be hiddend] or the new AIS depend on it [it should be visualized]
120 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
121 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
122 if (!aContext.IsNull()) {
123 if (aContext->IsDisplayed(anOperationPrs)) {
124 // if there are performance poblems, to improve them, the necessity of redisplay can be checked
125 //bool aChanged = anOperationPrs->dependOn(theObject);
126 anOperationPrs->updateShapes();
127 //aChanged = aChanged || anOperationPrs->dependOn(theObject);
129 anOperationPrs->Redisplay();
132 workshop()->displayer()->updateViewer();
135 anOperationPrs->updateShapes();
136 displayPresentation(theUpdateViewer);
142 void PartSet_CustomPrs::clearPrs()
144 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
145 if (!anOperationPrs.IsNull())
146 anOperationPrs.Nullify();
148 myOperationPrs.reset();
151 void PartSet_CustomPrs::initPrs()
153 myOperationPrs = AISObjectPtr(new GeomAPI_AISObject());
154 myOperationPrs->setImpl(new Handle(AIS_InteractiveObject)(new PartSet_OperationPrs(myWorkshop)));
156 std::vector<int> aColor = Config_PropManager::color("Visualization", "operation_parameter_color",
157 OPERATION_PARAMETER_COLOR);
158 myOperationPrs->setColor(aColor[0], aColor[1], aColor[2]);
160 myOperationPrs->setPointMarker(5, 2.);
161 myOperationPrs->setWidth(1);
164 XGUI_Workshop* PartSet_CustomPrs::workshop() const
166 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
167 return aConnector->workshop();