From afa680fb1b028e59da7d4d8ef869db23fcf6cc06 Mon Sep 17 00:00:00 2001 From: Artem Zhidkov Date: Tue, 23 Jun 2020 11:09:21 +0300 Subject: [PATCH] Issue #3222: 1D fillet Process failed vertices and send the message to highlight them in 3D viewer. --- .../FeaturesPlugin_Fillet1D.cpp | 24 ++++++++++++++--- src/FeaturesPlugin/FeaturesPlugin_Fillet1D.h | 3 +++ src/GeomAlgoAPI/GeomAlgoAPI_Fillet1D.cpp | 14 +++++++--- src/GeomAlgoAPI/GeomAlgoAPI_Fillet1D.h | 5 ++++ src/ModelAPI/ModelAPI_Events.cpp | 21 +++++++++++++++ src/ModelAPI/ModelAPI_Events.h | 27 +++++++++++++++++++ 6 files changed, 87 insertions(+), 7 deletions(-) diff --git a/src/FeaturesPlugin/FeaturesPlugin_Fillet1D.cpp b/src/FeaturesPlugin/FeaturesPlugin_Fillet1D.cpp index ee83fad20..d62fdee30 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Fillet1D.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Fillet1D.cpp @@ -32,6 +32,7 @@ #include #include #include +#include FeaturesPlugin_Fillet1D::FeaturesPlugin_Fillet1D() { @@ -146,10 +147,27 @@ bool FeaturesPlugin_Fillet1D::performFillet(const GeomShapePtr& theWire, std::shared_ptr 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 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; } diff --git a/src/FeaturesPlugin/FeaturesPlugin_Fillet1D.h b/src/FeaturesPlugin/FeaturesPlugin_Fillet1D.h index 961d69ee4..7cf37cc23 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Fillet1D.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Fillet1D.h @@ -107,6 +107,9 @@ private: bool performFillet(const GeomShapePtr& theWire, const ListOfShape& theVertices, const int theResultIndex); + +private: + ListOfShape myFailedVertices; }; #endif diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Fillet1D.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Fillet1D.cpp index 344ac9415..440822088 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Fillet1D.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Fillet1D.cpp @@ -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()); - 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(), 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, diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Fillet1D.h b/src/GeomAlgoAPI/GeomAlgoAPI_Fillet1D.h index b386bc44a..578f91cc2 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Fillet1D.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Fillet1D.h @@ -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 diff --git a/src/ModelAPI/ModelAPI_Events.cpp b/src/ModelAPI/ModelAPI_Events.cpp index 92474383c..57ae12839 100644 --- a/src/ModelAPI/ModelAPI_Events.cpp +++ b/src/ModelAPI/ModelAPI_Events.cpp @@ -21,6 +21,7 @@ #include #include +#include //#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; +} diff --git a/src/ModelAPI/ModelAPI_Events.h b/src/ModelAPI/ModelAPI_Events.h index 02fdadb09..fd2a7ff34 100644 --- a/src/ModelAPI/ModelAPI_Events.h +++ b/src/ModelAPI/ModelAPI_Events.h @@ -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 >& theVertices); + /// Returns list of failed vertices + MODELAPI_EXPORT const std::list< std::shared_ptr >& vertices() const; + +private: + std::list< std::shared_ptr > myVertices; +}; + #endif -- 2.39.2