Salome HOME
Merge branch 'Dev_2.1.0' of salome:modules/shaper into Dev_2.1.0
[modules/shaper.git] / src / PartSet / PartSet_CustomPrs.cpp
index 3bf751b1e3874a141e2561f103a747859ab014b5..b2315bffb8d578dffb406e9742b6241f3be9e72d 100755 (executable)
 #include <ModuleBase_IWorkshop.h>
 #include <ModuleBase_IViewer.h>
 
-#include <GeomValidators_Tools.h>
-
 #include <Config_PropManager.h>
 
 #include <AIS_InteractiveContext.hxx>
 #include <AIS_InteractiveObject.hxx>
 #include <Prs3d_PointAspect.hxx>
 
+//#define DO_NOT_VISUALIZE_CUSTOM_PRESENTATION
+
 #define OPERATION_PARAMETER_COLOR "255, 255, 0"
 
 PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop)
-  : myWorkshop(theWorkshop)
+  : myWorkshop(theWorkshop), myIsActive(false)
 {
   initPrs();
 }
 
 bool PartSet_CustomPrs::isActive()
 {
-  Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
+  return myIsActive;
+  /*Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
 
-  return aContext->IsDisplayed(anOperationPrs);
+  return !aContext.IsNull() && aContext->IsDisplayed(anOperationPrs);*/
 }
 
 bool PartSet_CustomPrs::activate(const FeaturePtr& theFeature, const bool theUpdateViewer)
 {
+#ifdef DO_NOT_VISUALIZE_CUSTOM_PRESENTATION
+  return false;
+#endif
+
   bool isModified = false;
   Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
 
   if (anOperationPrs->canActivate(theFeature)) {
+    myIsActive = true;
     anOperationPrs->setFeature(theFeature);
     if (theFeature.get()) {
       displayPresentation(theUpdateViewer);
@@ -56,13 +62,14 @@ bool PartSet_CustomPrs::activate(const FeaturePtr& theFeature, const bool theUpd
 
 bool PartSet_CustomPrs::deactivate(const bool theUpdateViewer)
 {
+  myIsActive = false;
   bool isModified = false;
 
   Handle(PartSet_OperationPrs) anOperationPrs = getPresentation();
   anOperationPrs->setFeature(FeaturePtr());
 
   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
-  if (aContext->IsDisplayed(anOperationPrs)) {
+  if (!aContext.IsNull() && aContext->IsDisplayed(anOperationPrs)) {
     erasePresentation(theUpdateViewer);
     isModified = true;
   }
@@ -76,17 +83,22 @@ 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());
-
-    XGUI_Workshop* aWorkshop = workshop();
-    aWorkshop->displayer()->displayAIS(myOperationPrs, false/*load object in selection*/, theUpdateViewer);
-    aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId());
+  if (!aContext.IsNull() && !aContext->IsDisplayed(anOperationPrs)) {
+    if (anOperationPrs->hasShapes()) {
+      PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
+      XGUI_Workshop* aWorkshop = workshop();
+      aWorkshop->displayer()->displayAIS(myOperationPrs, false/*load object in selection*/, theUpdateViewer);
+      aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId());
+    }
   }
   else {
-    anOperationPrs->Redisplay();
-    if (theUpdateViewer)
-      workshop()->displayer()->updateViewer();
+    if (!anOperationPrs->hasShapes())
+      erasePresentation(theUpdateViewer);
+    else {
+      anOperationPrs->Redisplay();
+      if (theUpdateViewer)
+        workshop()->displayer()->updateViewer();
+    }
   }
 }
 
@@ -106,21 +118,31 @@ Handle(PartSet_OperationPrs) PartSet_CustomPrs::getPresentation()
 
 bool PartSet_CustomPrs::redisplay(const ObjectPtr& theObject, const bool theUpdateViewer)
 {
+#ifdef DO_NOT_VISUALIZE_CUSTOM_PRESENTATION
+  return false;
+#endif
+
   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();
   Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
-  if (aContext->IsDisplayed(anOperationPrs)) {
-    // if there are performance poblems, to improve them, the necessity of redisplay can be checked
-    //bool aChanged = anOperationPrs->dependOn(theObject);
-    anOperationPrs->updateShapes();
-    //aChanged = aChanged || anOperationPrs->dependOn(theObject);
-    //if (aChanged)
-    anOperationPrs->Redisplay();
-    isModified = true;
-    if (theUpdateViewer)
-      workshop()->displayer()->updateViewer();
+  if (!aContext.IsNull()) {
+    if (aContext->IsDisplayed(anOperationPrs)) {
+      // if there are performance poblems, to improve them, the necessity of redisplay can be checked
+      //bool aChanged = anOperationPrs->dependOn(theObject);
+      anOperationPrs->updateShapes();
+      //aChanged = aChanged || anOperationPrs->dependOn(theObject);
+      //if (aChanged)
+      anOperationPrs->Redisplay();
+      isModified = true;
+      if (theUpdateViewer)
+        workshop()->displayer()->updateViewer();
+    }
+    else {
+      anOperationPrs->updateShapes();
+      displayPresentation(theUpdateViewer);
+    }
   }
   return isModified;
 }