]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #3222: 1D fillet
authorArtem Zhidkov <Artem.Zhidkov@opencascade.com>
Tue, 23 Jun 2020 08:09:21 +0000 (11:09 +0300)
committerArtem Zhidkov <Artem.Zhidkov@opencascade.com>
Tue, 23 Jun 2020 08:10:14 +0000 (11:10 +0300)
Process failed vertices and send the message to highlight them in 3D viewer.

src/FeaturesPlugin/FeaturesPlugin_Fillet1D.cpp
src/FeaturesPlugin/FeaturesPlugin_Fillet1D.h
src/GeomAlgoAPI/GeomAlgoAPI_Fillet1D.cpp
src/GeomAlgoAPI/GeomAlgoAPI_Fillet1D.h
src/ModelAPI/ModelAPI_Events.cpp
src/ModelAPI/ModelAPI_Events.h

index ee83fad2092e7f8b89c527ad198b315dac2169ec..d62fdee303b0f58619de778366ab0967663b29bc 100644 (file)
@@ -32,6 +32,7 @@
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_AttributeString.h>
+#include <ModelAPI_Events.h>
 
 FeaturesPlugin_Fillet1D::FeaturesPlugin_Fillet1D()
 {
@@ -146,10 +147,27 @@ bool FeaturesPlugin_Fillet1D::performFillet(const GeomShapePtr& theWire,
   std::shared_ptr<GeomAlgoAPI_Fillet1D> aFilletBuilder(
       new GeomAlgoAPI_Fillet1D(theWire, theVertices, aRadius));
 
+  bool isOk = true;
+  bool isSendMessage = !myFailedVertices.empty();
+  myFailedVertices = aFilletBuilder->failedVertices();
+
   std::string anError;
   if (GeomAlgoAPI_Tools::AlgoError::isAlgorithmFailed(aFilletBuilder, getKind(), anError)) {
-    setError(anError);
-    return false;
+    isOk = false;
+    // in case of vertices, the fillet completed, send message to highlight them in the viewer
+    isSendMessage = true;
+    bool isAllFailed = myFailedVertices.size() == theVertices.size();
+    setError(anError, isAllFailed);
+    if (isAllFailed)
+      return isOk;
+  }
+
+  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);
   }
 
   static const std::string THE_PREFIX = "Fillet1D";
@@ -165,5 +183,5 @@ bool FeaturesPlugin_Fillet1D::performFillet(const GeomShapePtr& theWire,
   for (ListOfShape::const_iterator anIt = theVertices.begin(); anIt != theVertices.end(); ++anIt)
     aResult->loadGeneratedShapes(aFilletBuilder, *anIt, GeomAPI_Shape::VERTEX, THE_PREFIX, true);
 
-  return true;
+  return isOk;
 }
index 961d69ee424ae259c650cfa6dbe95ca00fa46377..7cf37cc23cb2d456ee64b4dcee91e44e8a9d9693 100644 (file)
@@ -107,6 +107,9 @@ private:
   bool performFillet(const GeomShapePtr& theWire,
                      const ListOfShape& theVertices,
                      const int theResultIndex);
+
+private:
+  ListOfShape myFailedVertices;
 };
 
 #endif
index 344ac9415ee5535967dd0c9f720904d2a10bfc19..440822088b3ee32b7c07e1dff2e231d413061659 100644 (file)
@@ -73,6 +73,7 @@ void GeomAlgoAPI_Fillet1D::build(const GeomShapePtr& theBaseWire,
   if (!theBaseWire || theFilletVertices.empty() || theRadius < 0.)
     return;
 
+  myFailedVertices.clear();
   // store all edges of a base wire as modified, because they will be rebuild by ShapeFix
   for (GeomAPI_WireExplorer aWExp(theBaseWire->wire()); aWExp.more(); aWExp.next()) {
     GeomShapePtr aCurrent = aWExp.current();
@@ -109,8 +110,11 @@ void GeomAlgoAPI_Fillet1D::build(const GeomShapePtr& theBaseWire,
 
     // create fillet builder
     GEOMImpl_Fillet1d aFilletBuilder(anEdge1, anEdge2, aPlane->impl<gp_Pln>());
-    if (!aFilletBuilder.Perform(theRadius))
-      return; // fillet is failed, no way to continue
+    if (!aFilletBuilder.Perform(theRadius)) {
+      // store the failed vertex and continue
+      myFailedVertices.push_back(*aVIt);
+      continue;
+    }
 
     GeomPointPtr aPoint = aVE->first->vertex()->point();
     TopoDS_Edge aFilletEdge = aFilletBuilder.Result(aPoint->impl<gp_Pnt>(), anEdge1, anEdge2);
@@ -149,8 +153,10 @@ void GeomAlgoAPI_Fillet1D::build(const GeomShapePtr& theBaseWire,
   aFixWire.ClosedWireMode() = aBaseWire->isClosed();
   aFixWire.FixReorder();
   aNewWire = aFixWire.WireAPIMake();
-  if (aNewWire.IsNull())
+  if (aNewWire.IsNull()) {
+    myFailedVertices = theFilletVertices;
     return;
+  }
 
   // update the map of modified shapes, because the edges are changed by ShapeFix
   for (BRepTools_WireExplorer anExp(aNewWire); anExp.More(); anExp.Next()) {
@@ -190,7 +196,7 @@ void GeomAlgoAPI_Fillet1D::build(const GeomShapePtr& theBaseWire,
   myModified[theBaseWire].push_back(aShape);
 
   setShape(aShape);
-  setDone(true);
+  setDone(myFailedVertices.empty());
 }
 
 void GeomAlgoAPI_Fillet1D::generated(const GeomShapePtr theOldShape,
index b386bc44aad0944745cd3ce3ab5109f4d3a23ad2..578f91cc227f830dee2c4b7c7f0a8f29554d5bb9 100644 (file)
@@ -53,6 +53,9 @@ public:
   GEOMALGOAPI_EXPORT virtual void modified(const GeomShapePtr theOldShape,
                                            ListOfShape& theNewShapes);
 
+  /// \return List of failed vertices
+  const ListOfShape& failedVertices() const { return myFailedVertices; }
+
 private:
   /// Perform 1d-fillet on wire
   /// \param theBaseWire        a changing wire
@@ -65,6 +68,8 @@ private:
 private:
   MapModified myGenerated;
   MapModified myModified;
+
+  ListOfShape myFailedVertices;
 };
 
 #endif
index 92474383c6e743179f0c96e25b445fe2cfa95977..57ae128392f42bab96cee53b89e53d10e0496c1c 100644 (file)
@@ -21,6 +21,7 @@
 #include <ModelAPI_Events.h>
 
 #include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_Shape.h>
 
 //#define DEBUG_OBJECT_MOVED_MESSAGE
 #ifdef DEBUG_OBJECT_MOVED_MESSAGE
@@ -384,3 +385,23 @@ void ModelAPI_ObjectMovedMessage::setCurrentPosition(
             << myCurrentPosition->y() - myOriginalPosition->y() << std::endl;
 #endif
 }
+
+
+// =====   ModelAPI_Fillet1DFailedMessage   =====
+ModelAPI_Fillet1DFailedMessage::ModelAPI_Fillet1DFailedMessage(const Events_ID theID,
+                                                               const void* theSender)
+  : Events_Message(theID, theSender)
+{}
+
+ModelAPI_Fillet1DFailedMessage::~ModelAPI_Fillet1DFailedMessage()
+{}
+
+void ModelAPI_Fillet1DFailedMessage::setVertices(const ListOfShape& theVertices)
+{
+  myVertices = theVertices;
+}
+
+const ListOfShape& ModelAPI_Fillet1DFailedMessage::vertices() const
+{
+  return myVertices;
+}
index 02fdadb0936d97a68e6167a9aa5e4476b4364ac1..fd2a7ff3430326ab2af359e9e798d1fc346e30c3 100644 (file)
@@ -36,6 +36,7 @@
 class ModelAPI_Document;
 class ModelAPI_ResultParameter;
 class GeomAPI_Pnt2d;
+class GeomAPI_Shape;
 
 /// Event ID that feature is created (comes with ModelAPI_ObjectUpdatedMessage)
 static const char * EVENT_OBJECT_CREATED = "ObjectCreated";
@@ -110,6 +111,9 @@ 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";
+
 /// Message that feature was changed (used for Object Browser update): moved, updated and deleted
 class MODELAPI_EXPORT ModelAPI_ObjectUpdatedMessage : public Events_MessageGroup
 {
@@ -529,4 +533,27 @@ public:
   { return myCurrentPosition; }
 };
 
+/// Message that sends the failed vertices of 1D-fillet to highlight them in 3D viewer
+class ModelAPI_Fillet1DFailedMessage : public Events_Message
+{
+public:
+  /// Creates an message
+  MODELAPI_EXPORT ModelAPI_Fillet1DFailedMessage(const Events_ID theID, const void* theSender = 0);
+  /// Default destructor
+  MODELAPI_EXPORT virtual ~ModelAPI_Fillet1DFailedMessage();
+  /// Static. Returns EventID of the message.
+  MODELAPI_EXPORT static Events_ID eventId()
+  {
+    return Events_Loop::eventByName(EVENT_1DFILLET_FAILED);
+  }
+
+  /// Sets list of failed vertices
+  MODELAPI_EXPORT void setVertices(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;
+
+private:
+  std::list< std::shared_ptr<GeomAPI_Shape> > myVertices;
+};
+
 #endif