]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1369: add contour functionality
authordbv <dbv@opencascade.com>
Mon, 18 Apr 2016 08:00:31 +0000 (11:00 +0300)
committerdbv <dbv@opencascade.com>
Mon, 18 Apr 2016 08:00:54 +0000 (11:00 +0300)
src/FeaturesPlugin/FeaturesPlugin_Validators.cpp
src/FeaturesPlugin/FeaturesPlugin_Wire.cpp
src/FeaturesPlugin/FeaturesPlugin_Wire.h
src/FeaturesPlugin/wire_widget.xml

index c8559d01175a10099e166643ccc633415079fcfd..9afdafd181a9ea9b4a9c4efd88716722d0d5009a 100644 (file)
@@ -352,7 +352,7 @@ bool FeaturesPlugin_ValidatorBaseForWire::isValid(const AttributePtr& theAttribu
       theError = "Attribute have empty context.";
       return false;
     }
-    
+
     GeomShapePtr aShape = aSelection->value();
     GeomShapePtr aContextShape = aContext->shape();
     if(!aShape.get()) {
index 6764df63967d44cb7f88246411db201bd638d159..b704d65e758222371d7963dc3ac4d6eaa7d6c6fc 100644 (file)
@@ -8,9 +8,19 @@
 
 #include <ModelAPI_AttributeSelectionList.h>
 #include <ModelAPI_ResultBody.h>
+#include <ModelAPI_ResultConstruction.h>
 
+#include <Events_Error.h>
+
+#include <GeomAPI_DataMapOfShapeShape.h>
+#include <GeomAPI_PlanarEdges.h>
+#include <GeomAPI_ShapeExplorer.h>
+
+#include <GeomAlgoAPI_ShapeTools.h>
 #include <GeomAlgoAPI_WireBuilder.h>
 
+#include <algorithm>
+
 //=================================================================================================
 FeaturesPlugin_Wire::FeaturesPlugin_Wire()
 {
@@ -67,3 +77,149 @@ void FeaturesPlugin_Wire::execute()
   setResult(aResultBody);
 }
 
+//=================================================================================================
+bool FeaturesPlugin_Wire::customAction(const std::string& theActionId)
+{
+  if(theActionId == "add_contour") {
+    return addContour();
+  } else {
+    Events_Error::send("Error: Feature \"" + getKind() + "\" does not support action \"" + theActionId + "\".");
+  }
+
+  return false;
+}
+
+//=================================================================================================
+bool FeaturesPlugin_Wire::addContour()
+{
+  // Get base objects list.
+  AttributeSelectionListPtr aSelectionList = selectionList(BASE_OBJECTS_ID());
+  if(aSelectionList->size() == 0) {
+    Events_Error::send("Error: Empty selection list.");
+    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);
+    GeomShapePtr anEdgeInList = aSelection->value();
+    if(!anEdgeInList.get()) {
+      continue;
+    }
+
+    // Check that it is edge.
+    if(anEdgeInList->shapeType() != GeomAPI_Shape::EDGE) {
+      continue;
+    }
+
+    // Check that it is edge on sketch.
+    ResultPtr aContext = aSelection->context();
+    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);
+    if(!aPlanarEdges.get()) {
+      continue;
+    }
+
+    // Check that sketch have faces.
+    if(aConstruction->facesNum() == 0) {
+      continue;
+    }
+
+    anAddedEdges.push_back(anEdgeInList);
+    anAttributesToCheck.push_back(aSelection);
+  }
+
+  // Check if edges have contours.
+  bool isAnyContourFound = 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()));
+    ResultConstructionPtr aConstruction = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aSelection->context());
+    std::shared_ptr<GeomAPI_PlanarEdges> aPlanarEdges = std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(aConstruction->shape());
+
+    ListOfShape aClosedWires;
+    GeomAlgoAPI_ShapeTools::getClosedWires(aPlanarEdges->getEdges(), aClosedWires);
+
+    //// Iterate on wires and add wire with this edge.
+    //std::shared_ptr<GeomAPI_Shape> aFoundWire;
+    //for(ListOfShape::const_iterator aWireIt = aClosedWires.cbegin();
+    //    aWireIt != aClosedWires.cend();
+    //    ++aWireIt) {
+    //  GeomShapePtr aWire = *aWireIt;
+    //  for(GeomAPI_ShapeExplorer anExp(aWire, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
+    //    GeomShapePtr anEdgeOnWire = anExp.current();
+    //    if(anEdgeInList->isSame(anEdgeOnWire)) {
+    //      aFoundWire = aWire;
+    //      break;
+    //    }
+    //  }
+
+    //  if(aFoundWire.get()) {
+    //    break;
+    //  }
+    //}
+
+    //// If wire with the same edge found add all other edges to list.
+    //if(aFoundWire.get()) {
+    //  isAnyContourFound = true;
+    //  anAddedEdges.bind(anEdgeInList, anEdgeInList);
+    //  for(GeomAPI_ShapeExplorer anExp(aFoundWire, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
+    //    GeomShapePtr anEdgeOnFace = anExp.current();
+    //    if(!anAddedEdges.isBound(anEdgeOnFace)) {
+    //      anAddedEdges.bind(anEdgeOnFace, anEdgeOnFace);
+    //      aSelectionList->append(aConstruction, anEdgeOnFace);
+    //    }
+    //  }
+    //}
+
+    // Iterate on faces and add face with this edge.
+    std::shared_ptr<GeomAPI_Face> aFoundFace;
+    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;
+        }
+      }
+
+      if(aFoundFace.get()) {
+        break;
+      }
+    }
+
+    // If face with the same edge found. Add all other edges to list.
+    if(aFoundFace.get()) {
+      isAnyContourFound = true;
+      for(GeomAPI_ShapeExplorer anExp(aFoundFace, GeomAPI_Shape::EDGE); anExp.more(); anExp.next()) {
+        std::shared_ptr<GeomAPI_Edge> anEdgeOnFace(new GeomAPI_Edge(anExp.current()));
+        ListOfShape::const_iterator anEdgesIt = anAddedEdges.cbegin();
+        for(; anEdgesIt != anAddedEdges.cend(); ++anEdgesIt) {
+          if(anEdgeOnFace->isEqual(*anEdgesIt)) {
+            break;
+          }
+        }
+        if(anEdgesIt == anAddedEdges.cend()) {
+          anAddedEdges.push_back(anEdgeOnFace);
+          aSelectionList->append(aConstruction, anEdgeOnFace);
+        }
+      }
+    }
+  }
+
+  if(!isAnyContourFound) {
+    Events_Error::send("Error: No contours found for selected edges.");
+    return false;
+  }
+
+  return false;
+}
index 6a265cd1b1af0ffdaf08340bf62f430a344af7c6..c456d1d001cbab916bde4d49c034ff929a0ba29d 100644 (file)
@@ -46,6 +46,17 @@ public:
 
   /// Creates a new part document if needed.
   FEATURESPLUGIN_EXPORT virtual void execute();
+
+  /// Performs some functionality by action id.
+  /// \param[in] theAttributeId action key id.
+  /// \return false in case if action not perfomed.
+  FEATURESPLUGIN_EXPORT virtual bool customAction(const std::string& theActionId);
+
+private:
+  /// Action: Adds to the list of segments other segments of the sketcher connected to
+  /// the already selected ones to create a closed contour.
+  /// \return false in case if no countours have been added.
+  bool addContour();
 };
 
 #endif
index a2b8c35a33995cfc335571e994674ad79a176113..2b49cb9d8ba0270b0684ba2ccc77e25524967bfb 100644 (file)
@@ -7,5 +7,8 @@
                   type_choice="edges objects">
     <validator id="FeaturesPlugin_ValidatorBaseForWire"/>
   </multi_selector>
-  <action id="Action_1" label="Action_1" tooltip="Tool tip information"/>
+  <action id="add_contour"
+          label="Add contour"
+          tooltip="Adds to the list of segments other segments of the sketcher
+                   connected to the already selected ones to create a closed contour."/>
 </source>