Salome HOME
Issue #1740 The visualization of selected point in the graphic scene is not visible
[modules/shaper.git] / src / BuildPlugin / BuildPlugin_Wire.cpp
index a66975f9871eb30b67ec2151ea6c3f15dd97fba0..c8004f617fe6bed1e243e9325ef75496bb743907 100644 (file)
@@ -10,9 +10,8 @@
 #include <ModelAPI_ResultBody.h>
 #include <ModelAPI_ResultConstruction.h>
 
-#include <Events_Error.h>
+#include <Events_InfoMessage.h>
 
-#include <GeomAPI_DataMapOfShapeShape.h>
 #include <GeomAPI_PlanarEdges.h>
 #include <GeomAPI_ShapeExplorer.h>
 
@@ -47,43 +46,50 @@ void BuildPlugin_Wire::execute()
   }
 
   // Collect base shapes.
-  ListOfShape aListOfShapes;
+  ListOfShape anEdges;
   for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
     AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
     GeomShapePtr aShape = aSelection->value();
     if(!aShape.get()) {
-      setError("Error: Empty shape selected.");
-      return;
+      aShape = aSelection->context()->shape();
     }
-
-    if(aShape->shapeType() != GeomAPI_Shape::EDGE && aShape->shapeType() != GeomAPI_Shape::WIRE) {
-      setError("Error: Selected shape has wrong type. Only edges and wires acceptable.");
-      return;
+    for(GeomAPI_ShapeExplorer anExp(aShape, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
+      GeomShapePtr anEdge = anExp.current();
+      anEdges.push_back(anEdge);
     }
-
-    aListOfShapes.push_back(aShape);
   }
 
   // Create wire.
-  GeomShapePtr aWire = GeomAlgoAPI_WireBuilder::wire(aListOfShapes);
+  GeomShapePtr aWire = GeomAlgoAPI_WireBuilder::wire(anEdges);
   if(!aWire.get()) {
-    setError("Error: Result wire empty. Probably it has disconnected edges or non-manifold.");
+    setError("Error: Result wire is empty. Probably it has disconnected edges or non-manifold.");
     return;
   }
 
   // Store result.
   ResultBodyPtr aResultBody = document()->createBody(data());
   aResultBody->store(aWire);
+  for(GeomAPI_ShapeExplorer anExp(aWire, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
+    GeomShapePtr anEdgeInResult = anExp.current();
+    for(ListOfShape::const_iterator anIt = anEdges.cbegin(); anIt != anEdges.cend(); ++anIt) {
+      std::shared_ptr<GeomAPI_Edge> anEdgeInList(new GeomAPI_Edge(*anIt));
+      if(anEdgeInList->isEqual(anEdgeInResult)) {
+        aResultBody->modified(anEdgeInList, anEdgeInResult, "Edge");
+        break;
+      }
+    }
+  }
   setResult(aResultBody);
 }
 
 //=================================================================================================
 bool BuildPlugin_Wire::customAction(const std::string& theActionId)
 {
-  if(theActionId == "add_contour") {
+  if(theActionId == ADD_CONTOUR_ACTION_ID()) {
     return addContour();
   } else {
-    Events_Error::send("Error: Feature \"" + getKind() + "\" does not support action \"" + theActionId + "\".");
+    std::string aMsg = "Error: Feature \"%1\" does not support action \"%2\".";
+    Events_InfoMessage("BuildPlugin_Wire", aMsg).arg(getKind()).arg(theActionId).send();
   }
 
   return false;
@@ -95,11 +101,12 @@ bool BuildPlugin_Wire::addContour()
   // Get base objects list.
   AttributeSelectionListPtr aSelectionList = selectionList(BASE_OBJECTS_ID());
   if(aSelectionList->size() == 0) {
-    Events_Error::send("Error: Empty selection list.");
+    Events_InfoMessage("BuildPlugin_Wire", "Error: Empty selection list.").send();
     return false;
   }
 
   // Collect attributes to check.
+  ListOfShape anAddedEdges;
   std::list<AttributeSelectionPtr> anAttributesToCheck;
   for(int anIndex = 0; anIndex < aSelectionList->size(); ++anIndex) {
     AttributeSelectionPtr aSelection = aSelectionList->value(anIndex);
@@ -115,12 +122,14 @@ bool BuildPlugin_Wire::addContour()
 
     // Check that it is edge on sketch.
     ResultPtr aContext = aSelection->context();
-    ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
+    ResultConstructionPtr aConstruction =
+      std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aContext);
     if(!aConstruction.get()) {
       continue;
     }
     GeomShapePtr aContextShape = aConstruction->shape();
-    std::shared_ptr<GeomAPI_PlanarEdges> aPlanarEdges = std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aContextShape);
+    std::shared_ptr<GeomAPI_PlanarEdges> aPlanarEdges =
+      std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aContextShape);
     if(!aPlanarEdges.get()) {
       continue;
     }
@@ -130,62 +139,55 @@ bool BuildPlugin_Wire::addContour()
       continue;
     }
 
+    anAddedEdges.push_back(anEdgeInList);
     anAttributesToCheck.push_back(aSelection);
   }
 
   // Check if edges have contours.
-  ListOfShape anAddedEdges;
-  bool isAnyContourFound = false;
+  bool isAnyContourAdded = false;
   for(std::list<AttributeSelectionPtr>::const_iterator aListIt = anAttributesToCheck.cbegin();
       aListIt != anAttributesToCheck.cend();
       ++aListIt) {
     AttributeSelectionPtr aSelection = *aListIt;
     std::shared_ptr<GeomAPI_Edge> anEdgeInList(new GeomAPI_Edge(aSelection->value()));
 
-    ListOfShape::const_iterator anEdgesIt = anAddedEdges.cbegin();
-    for(; anEdgesIt != anAddedEdges.cend(); ++anEdgesIt) {
-      if(anEdgeInList->isEqual(*anEdgesIt)) {
-        break;
-      }
-    }
-    if(anEdgesIt != anAddedEdges.cend()) {
-      // This edge is already in list.
-      continue;
-    }
-
-    ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aSelection->context());
-    std::shared_ptr<GeomAPI_PlanarEdges> aPlanarEdges = std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aConstruction->shape());
+    ResultConstructionPtr aConstruction =
+      std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aSelection->context());
 
-    // Iterate on faces and add face with this edge.
-    std::shared_ptr<GeomAPI_Face> aFoundFace;
+    // Iterate on wires and add wire with this edge.
+    std::shared_ptr<GeomAPI_Shape> aFoundWire;
     for(int anIndex = 0; anIndex < aConstruction->facesNum(); ++anIndex) {
       std::shared_ptr<GeomAPI_Face> aFace = aConstruction->face(anIndex);
-      for(GeomAPI_ShapeExplorer anExp(aFace, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
-        std::shared_ptr<GeomAPI_Edge> anEdgeOnFace(new GeomAPI_Edge(anExp.current()));
-        if(anEdgeInList->isEqual(anEdgeOnFace)) {
-          aFoundFace = aFace;
-          break;
+      for(GeomAPI_ShapeExplorer
+          aWireExp(aFace, GeomAPI_Shape::WIRE); aWireExp.more(); aWireExp.next()) {
+        GeomShapePtr aWireOnFace = aWireExp.current();
+        for(GeomAPI_ShapeExplorer
+            anExp(aWireOnFace, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
+          std::shared_ptr<GeomAPI_Edge> anEdgeOnFace(new GeomAPI_Edge(anExp.current()));
+          if(anEdgeInList->isEqual(anEdgeOnFace)) {
+            aFoundWire = aWireOnFace;
+            break;
+          }
         }
       }
-
-      if(aFoundFace.get()) {
+      if(aFoundWire.get()) {
         break;
       }
     }
 
-    // If face with the same edge found. Add all other edges to list.
-    if(aFoundFace.get()) {
-      isAnyContourFound = true;
-      anAddedEdges.push_back(anEdgeInList);
-      for(GeomAPI_ShapeExplorer anExp(aFoundFace, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
+    // If wire with the same edge found. Add all other edges to list.
+    if(aFoundWire.get()) {
+      for(GeomAPI_ShapeExplorer
+          anExp(aFoundWire, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
         std::shared_ptr<GeomAPI_Edge> anEdgeOnFace(new GeomAPI_Edge(anExp.current()));
-        anEdgesIt = anAddedEdges.cbegin();
+        ListOfShape::const_iterator anEdgesIt = anAddedEdges.cbegin();
         for(; anEdgesIt != anAddedEdges.cend(); ++anEdgesIt) {
           if(anEdgeOnFace->isEqual(*anEdgesIt)) {
             break;
           }
         }
         if(anEdgesIt == anAddedEdges.cend()) {
+          isAnyContourAdded = true;
           anAddedEdges.push_back(anEdgeOnFace);
           aSelectionList->append(aConstruction, anEdgeOnFace);
         }
@@ -193,8 +195,9 @@ bool BuildPlugin_Wire::addContour()
     }
   }
 
-  if(!isAnyContourFound) {
-    Events_Error::send("Error: Contours already closed or no contours found for selected edges.");
+  if(!isAnyContourAdded) {
+    Events_InfoMessage("BuildPlugin_Wire",
+      "Error: Contours already closed or no contours found for selected edges.").send();
     return false;
   }