Salome HOME
1. Manage color of construction point using preferences dialog box.
[modules/shaper.git] / src / FeaturesPlugin / FeaturesPlugin_Fillet1D.cpp
index ee83fad2092e7f8b89c527ad198b315dac2169ec..c19cfa34d8ef0c9ad3326defbe48e3ab5602f0c7 100644 (file)
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeSelectionList.h>
 #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()
 {
@@ -59,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;
@@ -146,10 +164,24 @@ 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
+    sendMessageWithFailedShapes(myFailedVertices);
   }
 
   static const std::string THE_PREFIX = "Fillet1D";
@@ -165,5 +197,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;
 }