]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #3222: Show error shapes for fillet
authorvsv <vsv@opencascade.com>
Tue, 23 Jun 2020 14:09:12 +0000 (17:09 +0300)
committervsv <vsv@opencascade.com>
Tue, 23 Jun 2020 14:09:24 +0000 (17:09 +0300)
src/FeaturesPlugin/FeaturesPlugin_Fillet1D.cpp
src/ModelAPI/ModelAPI_Events.cpp
src/ModelAPI/ModelAPI_Events.h
src/PartSet/PartSet_CustomPrs.cpp
src/PartSet/PartSet_CustomPrs.h
src/PartSet/PartSet_OperationPrs.cpp

index d62fdee303b0f58619de778366ab0967663b29bc..d2b9bac9473ef164819468ce1b027a7c51950094 100644 (file)
@@ -164,9 +164,9 @@ bool FeaturesPlugin_Fillet1D::performFillet(const GeomShapePtr& theWire,
 
   if (isSendMessage) {
     // send message to highlight the failed vertices
-    std::shared_ptr<ModelAPI_Fillet1DFailedMessage> aMessage(
-        new ModelAPI_Fillet1DFailedMessage(Events_Loop::eventByName(EVENT_1DFILLET_FAILED)));
-    aMessage->setVertices(myFailedVertices);
+    std::shared_ptr<ModelAPI_ShapesFailedMessage> aMessage(
+        new ModelAPI_ShapesFailedMessage(Events_Loop::eventByName(EVENT_OPERATION_SHAPES_FAILED)));
+    aMessage->setShapes(myFailedVertices);
     Events_Loop::loop()->send(aMessage);
   }
 
index 57ae128392f42bab96cee53b89e53d10e0496c1c..29658fd69975d619ce48063112aa730355d3a632 100644 (file)
@@ -387,21 +387,21 @@ void ModelAPI_ObjectMovedMessage::setCurrentPosition(
 }
 
 
-// =====   ModelAPI_Fillet1DFailedMessage   =====
-ModelAPI_Fillet1DFailedMessage::ModelAPI_Fillet1DFailedMessage(const Events_ID theID,
+// =====   ModelAPI_ShapesFailedMessage   =====
+ModelAPI_ShapesFailedMessage::ModelAPI_ShapesFailedMessage(const Events_ID theID,
                                                                const void* theSender)
   : Events_Message(theID, theSender)
 {}
 
-ModelAPI_Fillet1DFailedMessage::~ModelAPI_Fillet1DFailedMessage()
+ModelAPI_ShapesFailedMessage::~ModelAPI_ShapesFailedMessage()
 {}
 
-void ModelAPI_Fillet1DFailedMessage::setVertices(const ListOfShape& theVertices)
+void ModelAPI_ShapesFailedMessage::setShapes(const ListOfShape& theShapes)
 {
-  myVertices = theVertices;
+  myShapes = theShapes;
 }
 
-const ListOfShape& ModelAPI_Fillet1DFailedMessage::vertices() const
+const ListOfShape& ModelAPI_ShapesFailedMessage::shapes() const
 {
-  return myVertices;
+  return myShapes;
 }
index fd2a7ff3430326ab2af359e9e798d1fc346e30c3..d951211ebf0605cf42d70a2647644fd5edd8dbae 100644 (file)
@@ -111,8 +111,8 @@ static const char * EVENT_DOF_OBJECTS = "DoFObjects";
 /// Event ID that requests updates visual attributes for presentations
 static const char * EVENT_VISUAL_ATTRIBUTES = "UpdateVisualAttributes";
 
-/// Event ID that 1D-fillet failed (comes with ModelAPI_Fillet1DFailedMessage)
-static const char * EVENT_1DFILLET_FAILED = "1DFilletFailed";
+/// Event ID that 1D-fillet failed (comes with ModelAPI_ShapesFailedMessage)
+static const char * EVENT_OPERATION_SHAPES_FAILED = "OperationShapesFailed";
 
 /// Message that feature was changed (used for Object Browser update): moved, updated and deleted
 class MODELAPI_EXPORT ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup
@@ -534,26 +534,26 @@ public:
 };
 
 /// Message that sends the failed vertices of 1D-fillet to highlight them in 3D viewer
-class ModelAPI_Fillet1DFailedMessage : public Events_Message
+class ModelAPI_ShapesFailedMessage : public Events_Message
 {
 public:
   /// Creates an message
-  MODELAPI_EXPORT ModelAPI_Fillet1DFailedMessage(const Events_ID theID, const void* theSender = 0);
+  MODELAPI_EXPORT ModelAPI_ShapesFailedMessage(const Events_ID theID, const void* theSender = 0);
   /// Default destructor
-  MODELAPI_EXPORT virtual ~ModelAPI_Fillet1DFailedMessage();
+  MODELAPI_EXPORT virtual ~ModelAPI_ShapesFailedMessage();
   /// Static. Returns EventID of the message.
   MODELAPI_EXPORT static Events_ID eventId()
   {
-    return Events_Loop::eventByName(EVENT_1DFILLET_FAILED);
+    return Events_Loop::eventByName(EVENT_OPERATION_SHAPES_FAILED);
   }
 
   /// Sets list of failed vertices
-  MODELAPI_EXPORT void setVertices(const std::list< std::shared_ptr<GeomAPI_Shape> >& theVertices);
+  MODELAPI_EXPORT void setShapes(const std::list< std::shared_ptr<GeomAPI_Shape> >& theVertices);
   /// Returns list of failed vertices
-  MODELAPI_EXPORT const std::list< std::shared_ptr<GeomAPI_Shape> >& vertices() const;
+  MODELAPI_EXPORT const std::list< std::shared_ptr<GeomAPI_Shape> >& shapes() const;
 
 private:
-  std::list< std::shared_ptr<GeomAPI_Shape> > myVertices;
+  std::list< std::shared_ptr<GeomAPI_Shape> > myShapes;
 };
 
 #endif
index e18ca5bb063b58a5716997908d3c8b078328ac4d..06299acd0ae3a7225d0c94cb5a4388cac9b92e93 100644 (file)
@@ -37,6 +37,7 @@
 #include <Config_PropManager.h>
 #include <Events_Loop.h>
 #include <ModelAPI_Events.h>
+#include <GeomAlgoAPI_CompoundBuilder.h>
 
 #include <AIS_InteractiveContext.hxx>
 #include <AIS_InteractiveObject.hxx>
@@ -50,6 +51,7 @@ PartSet_CustomPrs::PartSet_CustomPrs(ModuleBase_IWorkshop* theWorkshop)
 {
   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);
@@ -99,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;
 }
 
@@ -244,12 +248,50 @@ 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);
+  }
 }
 
 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);
+      }
+    }
+  }
 }
 
 void PartSet_CustomPrs::initPresentation(
index 75638bc5b9dd2b039585fa23743c84506442b68d..2714ea71749febddc97e3d0b5a9c05d452995dff 100644 (file)
@@ -151,6 +151,9 @@ private:
   /// \return theShapeColor a color
   Quantity_Color getShapeColor(const ModuleBase_IModule::ModuleBase_CustomizeFlag& theFlag);
 
+  /// Removes error shapes presentation
+  void clearErrorShape();
+
 private:
   bool myPresentationIsEmpty; /// Boolean state about empty presentation
   FeaturePtr myFeature; /// Reference to a feature object
@@ -161,6 +164,8 @@ private:
   QMap<ModuleBase_IModule::ModuleBase_CustomizeFlag, bool> myIsActive;
 
   int myDisabledMode;
+
+  Handle(AIS_Shape) myErrorShapes;
 };
 
 #endif
index f782ca3c0c60d5263be8dddc626b01552f8d9a88..c98b82d28e3f7095f8f83c4b2652a23dbf4db60c 100644 (file)
@@ -123,7 +123,6 @@ void PartSet_OperationPrs::Compute(
   thePresentation->Clear();
   bool aReadyToDisplay = !myShapeToPrsMap.IsEmpty();
 
-  XGUI_Displayer* aDisplayer = XGUI_Tools::workshop(myWorkshop)->displayer();
   Handle(Prs3d_Drawer) aDrawer = Attributes();
   // create presentations on the base of the shapes
   BRep_Builder aBuilder;
@@ -244,24 +243,20 @@ void PartSet_OperationPrs::appendShapeIfVisible(ModuleBase_IWorkshop* theWorksho
                               GeomShapePtr theGeomShape,
                               QMap<ObjectPtr, QList<GeomShapePtr> >& theObjectShapes)
 {
-  XGUI_Displayer* aDisplayer = XGUI_Tools::workshop(theWorkshop)->displayer();
-  // VSV: Do not use isVisible checking because it can be used when state "Show Only" is ON
-  //if (XGUI_Displayer::isVisible(aDisplayer, theObject)) {
-    if (theGeomShape.get()) {
-      if (theObjectShapes.contains(theObject))
-        theObjectShapes[theObject].append(theGeomShape);
-      else {
-        QList<GeomShapePtr> aShapes;
-        aShapes.append(theGeomShape);
-        theObjectShapes[theObject] = aShapes;
-      }
-    } else {
-  #ifdef DEBUG_EMPTY_SHAPE
-      qDebug(QString("Empty shape in result, result: %1")
-              .arg(ModuleBase_Tools::objectInfo(theObject)).toStdString().c_str());
-  #endif
+  if (theGeomShape.get()) {
+    if (theObjectShapes.contains(theObject))
+      theObjectShapes[theObject].append(theGeomShape);
+    else {
+      QList<GeomShapePtr> aShapes;
+      aShapes.append(theGeomShape);
+      theObjectShapes[theObject] = aShapes;
     }
-  //}
+  } else {
+#ifdef DEBUG_EMPTY_SHAPE
+    qDebug(QString("Empty shape in result, result: %1")
+            .arg(ModuleBase_Tools::objectInfo(theObject)).toStdString().c_str());
+#endif
+  }
 }
 
 void PartSet_OperationPrs::getFeatureShapes(const FeaturePtr& theFeature,
@@ -364,8 +359,6 @@ void PartSet_OperationPrs::getResultShapes(const FeaturePtr& theFeature,
   if (!theFeature.get())
     return;
 
-  XGUI_Displayer* aDisplayer = XGUI_Tools::workshop(theWorkshop)->displayer();
-
   std::list<ResultPtr> aResults;
   ModelAPI_Tools::allResults(theFeature, aResults);
   std::list<ResultPtr>::const_iterator aRIt = aResults.begin(),