]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #3222: 1D fillet
authorvsv <vsv@opencascade.com>
Tue, 23 Jun 2020 14:09:12 +0000 (17:09 +0300)
committerArtem Zhidkov <Artem.Zhidkov@opencascade.com>
Thu, 2 Jul 2020 11:29:13 +0000 (14:29 +0300)
Send the message about failed vertices when creation method is changed.

src/FeaturesPlugin/FeaturesPlugin_Fillet1D.cpp
src/FeaturesPlugin/FeaturesPlugin_Fillet1D.h
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..c19cfa34d8ef0c9ad3326defbe48e3ab5602f0c7 100644 (file)
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_Events.h>
 
+void sendMessageWithFailedShapes(const ListOfShape& theVertices)
+{
+  std::shared_ptr<ModelAPI_ShapesFailedMessage> aMessage(
+      new ModelAPI_ShapesFailedMessage(Events_Loop::eventByName(EVENT_OPERATION_SHAPES_FAILED)));
+  aMessage->setShapes(theVertices);
+  Events_Loop::loop()->send(aMessage);
+}
+
 FeaturesPlugin_Fillet1D::FeaturesPlugin_Fillet1D()
 {
 }
@@ -60,6 +68,15 @@ void FeaturesPlugin_Fillet1D::execute()
   removeResults(aResultIndex);
 }
 
+void FeaturesPlugin_Fillet1D::attributeChanged(const std::string& theID)
+{
+  if (theID == CREATION_METHOD()) {
+    // creation method is changed, drop failed vertices and send the message
+    removeResults(0);
+    sendMessageWithFailedShapes(ListOfShape());
+  }
+}
+
 bool FeaturesPlugin_Fillet1D::baseShapes(ListOfShape& theWires, MapShapeSubs& theWireVertices)
 {
   std::set<GeomShapePtr, GeomAPI_Shape::Comparator> aProcessedWires;
@@ -164,10 +181,7 @@ 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);
-    Events_Loop::loop()->send(aMessage);
+    sendMessageWithFailedShapes(myFailedVertices);
   }
 
   static const std::string THE_PREFIX = "Fillet1D";
index 7cf37cc23cb2d456ee64b4dcee91e44e8a9d9693..074d03ce4c56c9ccb4a2fa547afab884808ade77 100644 (file)
@@ -91,6 +91,10 @@ public:
   /// Request for initialization of data model of the feature: adding all attributes.
   FEATURESPLUGIN_EXPORT virtual void initAttributes();
 
+  /// Called on change of any argument-attribute of this object
+  /// \param theID identifier of changed attribute
+  FEATURESPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
+
   /// Performs the fillet algorithm and stores it in the data structure.
   FEATURESPLUGIN_EXPORT virtual void execute();
 
index 19e664f81296e14bdac9e85ec43c5032deea7809..bf05de24f4be00aee013be2588962f2c5c46150e 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 2a63ab671d8643e617d9c9aac415298f1367883f..68af75b1b4acf3bff1ec651e78b4f172531ac338 100644 (file)
@@ -120,8 +120,8 @@ MAYBE_UNUSED static const char * EVENT_DOF_OBJECTS = "DoFObjects";
 MAYBE_UNUSED 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
@@ -545,26 +545,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 c61227cb0569151e04e617d4db6dd22439d4c7a7..7b98ee6198ba9b9852ce09a5fdf49b97198d719b 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 11f635666a5f1dddb44029dccfe46d29fe86e42a..117af4a14cefcd6dcaf8d858f56c4f5b1874abc4 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:
   ModuleBase_IWorkshop* myWorkshop; /// current workshop
   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 07faae3c454cbdc2ed657c73a9cea4585bc9c6e0..78b6430bc14753c2036bc2df5f1ae96b099b47b2 100644 (file)
@@ -242,24 +242,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,