Salome HOME
Fix for the issue #910: never fully remove the results, just make them disabled when...
[modules/shaper.git] / src / PartSet / PartSet_CustomPrs.cpp
index 008640c20275c9e0de40b651ea83e36aaa0f4af3..3bf751b1e3874a141e2561f103a747859ab014b5 100755 (executable)
 PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop)
   : myWorkshop(theWorkshop)
 {
-  myOperationPrs = AISObjectPtr(new GeomAPI_AISObject());
-  myOperationPrs->setImpl(new Handle(AIS_InteractiveObject)(new PartSet_OperationPrs(theWorkshop)));
-
-  std::vector<int> aColor = Config_PropManager::color("Visualization", "operation_parameter_color",
-                                                      OPERATION_PARAMETER_COLOR);
-  myOperationPrs->setColor(aColor[0], aColor[1], aColor[2]);
-
-  myOperationPrs->setPointMarker(5, 2.);
-  myOperationPrs->setWidth(1);
+  initPrs();
 }
 
-bool PartSet_CustomPrs::isActive() const
+bool PartSet_CustomPrs::isActive()
 {
   Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
@@ -47,56 +39,74 @@ bool PartSet_CustomPrs::isActive() const
   return aContext->IsDisplayed(anOperationPrs);
 }
 
-void PartSet_CustomPrs::activate(const FeaturePtr& theFeature)
+bool PartSet_CustomPrs::activate(const FeaturePtr& theFeature, const bool theUpdateViewer)
 {
+  bool isModified = false;
   Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
 
   if (anOperationPrs->canActivate(theFeature)) {
     anOperationPrs->setFeature(theFeature);
-    if (theFeature.get())
-      displayPresentation();
+    if (theFeature.get()) {
+      displayPresentation(theUpdateViewer);
+      isModified = true;
+    }
   }
+  return isModified;
 }
 
-void PartSet_CustomPrs::deactivate()
+bool PartSet_CustomPrs::deactivate(const bool theUpdateViewer)
 {
+  bool isModified = false;
+
   Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
   anOperationPrs->setFeature(FeaturePtr());
 
-  erasePresentation();
+  Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
+  if (aContext->IsDisplayed(anOperationPrs)) {
+    erasePresentation(theUpdateViewer);
+    isModified = true;
+  }
+
+  return isModified;
 }
 
 
-void PartSet_CustomPrs::displayPresentation()
+void PartSet_CustomPrs::displayPresentation(const bool theUpdateViewer)
 {
   Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
 
   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
   if (!aContext->IsDisplayed(anOperationPrs)) {
     PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
-    aContext->Display(anOperationPrs);
+
+    XGUI_Workshop* aWorkshop = workshop();
+    aWorkshop->displayer()->displayAIS(myOperationPrs, false/*load object in selection*/, theUpdateViewer);
     aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId());
   }
-  else
+  else {
     anOperationPrs->Redisplay();
+    if (theUpdateViewer)
+      workshop()->displayer()->updateViewer();
+  }
 }
 
-void PartSet_CustomPrs::erasePresentation()
+void PartSet_CustomPrs::erasePresentation(const bool theUpdateViewer)
 {
-  Handle(AIS_InteractiveObject) anOperationPrs = myOperationPrs->impl<Handle(AIS_InteractiveObject)>();
-  Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
-  if (aContext->IsDisplayed(anOperationPrs))
-    aContext->Remove(anOperationPrs);
+  XGUI_Workshop* aWorkshop = workshop();
+  aWorkshop->displayer()->eraseAIS(myOperationPrs, theUpdateViewer);
 }
 
-Handle(PartSet_OperationPrs) PartSet_CustomPrs::getPresentation() const
+Handle(PartSet_OperationPrs) PartSet_CustomPrs::getPresentation()
 {
+  if (!myOperationPrs.get())
+    initPrs();
   Handle(AIS_InteractiveObject) anAISIO = myOperationPrs->impl<Handle(AIS_InteractiveObject)>();
   return Handle(PartSet_OperationPrs)::DownCast(anAISIO);
 }
 
-void PartSet_CustomPrs::customize(const ObjectPtr& theObject)
+bool PartSet_CustomPrs::redisplay(const ObjectPtr& theObject, const bool theUpdateViewer)
 {
+  bool isModified = false;
   // the presentation should be recomputed if the previous AIS depend on the result
   // [it should be hiddend] or the new AIS depend on it [it should be visualized]
   Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
@@ -108,5 +118,37 @@ void PartSet_CustomPrs::customize(const ObjectPtr& theObject)
     //aChanged = aChanged || anOperationPrs->dependOn(theObject);
     //if (aChanged)
     anOperationPrs->Redisplay();
+    isModified = true;
+    if (theUpdateViewer)
+      workshop()->displayer()->updateViewer();
   }
+  return isModified;
+}
+
+void PartSet_CustomPrs::clearPrs()
+{
+  Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
+  if (!anOperationPrs.IsNull())
+    anOperationPrs.Nullify();
+
+  myOperationPrs.reset();
+}
+
+void PartSet_CustomPrs::initPrs()
+{
+  myOperationPrs = AISObjectPtr(new GeomAPI_AISObject());
+  myOperationPrs->setImpl(new Handle(AIS_InteractiveObject)(new PartSet_OperationPrs(myWorkshop)));
+
+  std::vector<int> aColor = Config_PropManager::color("Visualization", "operation_parameter_color",
+                                                      OPERATION_PARAMETER_COLOR);
+  myOperationPrs->setColor(aColor[0], aColor[1], aColor[2]);
+
+  myOperationPrs->setPointMarker(5, 2.);
+  myOperationPrs->setWidth(1);
+}
+
+XGUI_Workshop* PartSet_CustomPrs::workshop() const
+{
+  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
+  return aConnector->workshop();
 }