Process failed vertices and send the message to highlight them in 3D viewer.
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeSelectionList.h>
#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_Events.h>
FeaturesPlugin_Fillet1D::FeaturesPlugin_Fillet1D()
{
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";
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;
}
bool performFillet(const GeomShapePtr& theWire,
const ListOfShape& theVertices,
const int theResultIndex);
+
+private:
+ ListOfShape myFailedVertices;
};
#endif
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();
// 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);
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()) {
myModified[theBaseWire].push_back(aShape);
setShape(aShape);
- setDone(true);
+ setDone(myFailedVertices.empty());
}
void GeomAlgoAPI_Fillet1D::generated(const GeomShapePtr theOldShape,
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
private:
MapModified myGenerated;
MapModified myModified;
+
+ ListOfShape myFailedVertices;
};
#endif
#include <ModelAPI_Events.h>
#include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_Shape.h>
//#define DEBUG_OBJECT_MOVED_MESSAGE
#ifdef DEBUG_OBJECT_MOVED_MESSAGE
<< 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;
+}
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";
/// 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
{
{ 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