Salome HOME
updated copyright message
[modules/shaper.git] / src / PartSet / PartSet_CustomPrs.cpp
old mode 100755 (executable)
new mode 100644 (file)
index f60a591..c38e894
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#include <PartSet_CustomPrs.h>
-#include <PartSet_Module.h>
+#include "PartSet_CustomPrs.h"
+#include "PartSet_Module.h"
 #include "PartSet_OperationPrs.h"
 #include "PartSet_OverconstraintListener.h"
+#include "PartSet_SketcherMgr.h"
 
 #include <XGUI_ModuleConnector.h>
 #include <XGUI_Workshop.h>
 #include <ModuleBase_IViewer.h>
 #include <ModuleBase_Tools.h>
 
+#include <ModelAPI_Tools.h>
+#include <SketchPlugin_Sketch.h>
+
 #include <Config_PropManager.h>
 #include <Events_Loop.h>
 #include <ModelAPI_Events.h>
+#include <GeomAlgoAPI_CompoundBuilder.h>
 
 #include <AIS_InteractiveContext.hxx>
 #include <AIS_InteractiveObject.hxx>
 //#define DO_NOT_VISUALIZE_CUSTOM_PRESENTATION
 
 PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop)
-  : myWorkshop(theWorkshop), myFeature(FeaturePtr()), myPresentationIsEmpty(false)
+  : myWorkshop(theWorkshop), myFeature(FeaturePtr()), myPresentationIsEmpty(false),
+  myDisabledMode(-1)
 {
   Events_Loop* aLoop = Events_Loop::loop();
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_EMPTY_OPERATION_PRESENTATION));
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OPERATION_SHAPES_FAILED));
 
   initPresentation(ModuleBase_IModule::CustomizeArguments);
   initPresentation(ModuleBase_IModule::CustomizeResults);
@@ -67,12 +74,22 @@ bool PartSet_CustomPrs::activate(const FeaturePtr& theFeature,
 #ifdef DO_NOT_VISUALIZE_CUSTOM_PRESENTATION
   return false;
 #endif
+  bool isModified = false;
 
-  myIsActive[theFlag] = true;
-  myFeature = theFeature;
+  // Do not call customisation for sketcher and all its sub-objects
+  if (theFeature->getKind() == SketchPlugin_Sketch::ID())
+    return isModified;
+
+  FeaturePtr aParent = ModelAPI_Tools::compositeOwner(theFeature);
+  if (aParent.get()) {
+    std::string aType = aParent->getKind();
+    if (aType == SketchPlugin_Sketch::ID())
+      return isModified;
+  }
 
-  bool isModified = false;
   if (theFeature.get()) {
+    myIsActive[theFlag] = true;
+    myFeature = theFeature;
     displayPresentation(theFlag, theUpdateViewer);
     isModified = true;
   }
@@ -84,6 +101,8 @@ bool PartSet_CustomPrs::deactivate(const ModuleBase_IModule::ModuleBase_Customiz
 {
   myIsActive[theFlag] = false;
   erasePresentation(theFlag, theUpdateViewer);
+  if (theFlag == ModuleBase_IModule::CustomizeResults)
+    clearErrorShape();
   return true;
 }
 
@@ -93,6 +112,9 @@ bool PartSet_CustomPrs::displayPresentation(
 {
   bool isModified = false;
 
+  if (myDisabledMode == theFlag)
+    return isModified;
+
   // update the AIS objects content
   AISObjectPtr aPresentation = getPresentation(theFlag, true);
   Handle(AIS_InteractiveObject) anAISIO = aPresentation->impl<Handle(AIS_InteractiveObject)>();
@@ -117,7 +139,7 @@ bool PartSet_CustomPrs::displayPresentation(
     default:
       return isModified;
   }
-  NCollection_DataMap<TopoDS_Shape, Handle_AIS_InteractiveObject>& aShapeMap =
+  NCollection_DataMap<TopoDS_Shape, Handle(AIS_InteractiveObject)>& aShapeMap =
                                                                  anOperationPrs->shapesMap();
   PartSet_OperationPrs::fillShapeList(aFeatureShapes, myWorkshop, aShapeMap);
 
@@ -136,7 +158,7 @@ bool PartSet_CustomPrs::displayPresentation(
       PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
       XGUI_Workshop* aWorkshop = workshop();
       aRedisplayed = aWorkshop->displayer()->displayAIS(myPresentations[theFlag],
-                                         false/*load object in selection*/, false);
+                                         false/*load object in selection*/, 0, false);
       aContext->SetZLayer(anOperationPrs, aModule->getVisualLayerId());
       isModified = true;
     }
@@ -149,6 +171,9 @@ bool PartSet_CustomPrs::displayPresentation(
       isModified = true;
     }
     else {
+      if (myFeature->firstResult().get()) {
+        PartSet_Module::setTexture(aPresentation, myFeature->firstResult());
+      }
       anOperationPrs->Redisplay();
       isModified = true;
       aRedisplayed = true;
@@ -226,12 +251,53 @@ void PartSet_CustomPrs::clearPrs()
   clearPresentation(ModuleBase_IModule::CustomizeArguments);
   clearPresentation(ModuleBase_IModule::CustomizeResults);
   clearPresentation(ModuleBase_IModule::CustomizeHighlightedObjects);
+  clearErrorShape();
+}
+
+void PartSet_CustomPrs::clearErrorShape()
+{
+  if (!myErrorShapes.IsNull()) {
+    Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
+    if (aContext->IsDisplayed(myErrorShapes)) {
+      aContext->Remove(myErrorShapes, true);
+      myErrorShapes.Nullify();
+    }
+  }
 }
 
 void PartSet_CustomPrs::processEvent(const std::shared_ptr<Events_Message>& theMessage)
 {
   if (theMessage->eventID() == Events_Loop::eventByName(EVENT_EMPTY_OPERATION_PRESENTATION))
     myPresentationIsEmpty = true; /// store state to analize it after display/erase is finished
+  else if (theMessage->eventID() == Events_Loop::eventByName(EVENT_OPERATION_SHAPES_FAILED)) {
+    std::shared_ptr<ModelAPI_ShapesFailedMessage> aErrMsg =
+      std::dynamic_pointer_cast<ModelAPI_ShapesFailedMessage>(theMessage);
+    Handle(AIS_InteractiveContext) aContext = myWorkshop->viewer()->AISContext();
+    ListOfShape aShapes = aErrMsg->shapes();
+    if (aShapes.size() > 0) {
+      GeomShapePtr aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
+      TopoDS_Shape aErrShape = aCompound->impl<TopoDS_Shape>();
+      if (myErrorShapes.IsNull()) {
+        myErrorShapes = new AIS_Shape(aErrShape);
+        myErrorShapes->SetColor(Quantity_NOC_RED);
+        Handle(Prs3d_Drawer) aDrawer = myErrorShapes->Attributes();
+        aDrawer->SetPointAspect(new Prs3d_PointAspect(Aspect_TOM_RING1, Quantity_NOC_RED, 2.));
+        aDrawer->SetLineAspect(new Prs3d_LineAspect(Quantity_NOC_RED, Aspect_TOL_SOLID, 2.));
+        aContext->Display(myErrorShapes, true);
+        aContext->Deactivate(myErrorShapes);
+      }
+      else {
+        myErrorShapes->Set(aErrShape);
+        aContext->Redisplay(myErrorShapes, true);
+      }
+    }
+    else {
+      if (!myErrorShapes.IsNull()) {
+        aContext->Remove(myErrorShapes, true);
+        myErrorShapes.Nullify();
+      }
+    }
+  }
 }
 
 void PartSet_CustomPrs::initPresentation(
@@ -243,7 +309,7 @@ void PartSet_CustomPrs::initPresentation(
   if (theFlag == ModuleBase_IModule::CustomizeArguments ||
       theFlag == ModuleBase_IModule::CustomizeResults) {
     anOperationPrs->setPointMarker(5, 2.);
-    anOperationPrs->setWidth(1);
+    anOperationPrs->setWidth((theFlag == ModuleBase_IModule::CustomizeHighlightedObjects)? 2 : 1);
   }
   else if (theFlag == ModuleBase_IModule::CustomizeHighlightedObjects)
     anAISPrs->useAISWidth();