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 <Config_PropManager.h>
20 #include <AIS_InteractiveContext.hxx>
21 #include <AIS_InteractiveObject.hxx>
22 #include <Prs3d_PointAspect.hxx>
24 #define OPERATION_PARAMETER_COLOR "255, 255, 0"
26 PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop)
27 : myWorkshop(theWorkshop), myIsActive(false)
32 bool PartSet_CustomPrs::isActive()
35 /*Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
36 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
38 return !aContext.IsNull() && aContext->IsDisplayed(anOperationPrs);*/
41 bool PartSet_CustomPrs::activate(const FeaturePtr& theFeature, const bool theUpdateViewer)
43 bool isModified = false;
44 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
46 if (anOperationPrs->canActivate(theFeature)) {
48 anOperationPrs->setFeature(theFeature);
49 if (theFeature.get()) {
50 displayPresentation(theUpdateViewer);
57 bool PartSet_CustomPrs::deactivate(const bool theUpdateViewer)
60 bool isModified = false;
62 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
63 anOperationPrs->setFeature(FeaturePtr());
65 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
66 if (!aContext.IsNull() && aContext->IsDisplayed(anOperationPrs)) {
67 erasePresentation(theUpdateViewer);
75 void PartSet_CustomPrs::displayPresentation(const bool theUpdateViewer)
77 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
79 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
80 if (!aContext.IsNull() && !aContext->IsDisplayed(anOperationPrs)) {
81 if (anOperationPrs->hasShapes()) {
82 PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
83 XGUI_Workshop* aWorkshop = workshop();
84 aWorkshop->displayer()->displayAIS(myOperationPrs, false/*load object in selection*/, theUpdateViewer);
85 aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId());
89 if (!anOperationPrs->hasShapes())
90 erasePresentation(theUpdateViewer);
92 anOperationPrs->Redisplay();
94 workshop()->displayer()->updateViewer();
99 void PartSet_CustomPrs::erasePresentation(const bool theUpdateViewer)
101 XGUI_Workshop* aWorkshop = workshop();
102 aWorkshop->displayer()->eraseAIS(myOperationPrs, theUpdateViewer);
105 Handle(PartSet_OperationPrs) PartSet_CustomPrs::getPresentation()
107 if (!myOperationPrs.get())
109 Handle(AIS_InteractiveObject) anAISIO = myOperationPrs->impl<Handle(AIS_InteractiveObject)>();
110 return Handle(PartSet_OperationPrs)::DownCast(anAISIO);
113 bool PartSet_CustomPrs::redisplay(const ObjectPtr& theObject, const bool theUpdateViewer)
115 bool isModified = false;
116 // the presentation should be recomputed if the previous AIS depend on the result
117 // [it should be hiddend] or the new AIS depend on it [it should be visualized]
118 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
119 Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
120 if (!aContext.IsNull()) {
121 if (aContext->IsDisplayed(anOperationPrs)) {
122 // if there are performance poblems, to improve them, the necessity of redisplay can be checked
123 //bool aChanged = anOperationPrs->dependOn(theObject);
124 anOperationPrs->updateShapes();
125 //aChanged = aChanged || anOperationPrs->dependOn(theObject);
127 anOperationPrs->Redisplay();
130 workshop()->displayer()->updateViewer();
133 anOperationPrs->updateShapes();
134 displayPresentation(theUpdateViewer);
140 void PartSet_CustomPrs::clearPrs()
142 Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
143 if (!anOperationPrs.IsNull())
144 anOperationPrs.Nullify();
146 myOperationPrs.reset();
149 void PartSet_CustomPrs::initPrs()
151 myOperationPrs = AISObjectPtr(new GeomAPI_AISObject());
152 myOperationPrs->setImpl(new Handle(AIS_InteractiveObject)(new PartSet_OperationPrs(myWorkshop)));
154 std::vector<int> aColor = Config_PropManager::color("Visualization", "operation_parameter_color",
155 OPERATION_PARAMETER_COLOR);
156 myOperationPrs->setColor(aColor[0], aColor[1], aColor[2]);
158 myOperationPrs->setPointMarker(5, 2.);
159 myOperationPrs->setWidth(1);
162 XGUI_Workshop* PartSet_CustomPrs::workshop() const
164 XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
165 return aConnector->workshop();