Salome HOME
Refactoring: GeomAPI_Wire renamed to GeomAPI_PlanarEdges
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_SketchBuilder.cpp
index b7ef59f5d68b549f8198d52b6b88fbc69404ff4c..ddd6d397712e5bcf3aa29e2ae2b38616ad4a71e3 100644 (file)
@@ -3,6 +3,7 @@
 // Author:      Artem ZHIDKOV
 
 #include <GeomAlgoAPI_SketchBuilder.h>
+#include <GeomAPI_PlanarEdges.h>
 
 #include <set>
 
@@ -155,6 +156,8 @@ void GeomAlgoAPI_SketchBuilder::createFaces(
   while (aMapVE.Extent() > 0) {
     if (aCurVertex.IsNull())
       return;
+    if (!aProcEdges.empty())
+      aBindingEdge = aProcEdges.back();
     findNextVertex(aCurVertex, aMapVE, aCurDir, aCurNorm, aNextVertex, aBindingEdge, aNextDir);
     aCurNorm = aNorm;
 
@@ -368,6 +371,23 @@ void GeomAlgoAPI_SketchBuilder::createFaces(
     fixIntersections(theResultFaces);
 }
 
+void GeomAlgoAPI_SketchBuilder::createFaces(const boost::shared_ptr<GeomAPI_Pnt>& theOrigin,
+                                            const boost::shared_ptr<GeomAPI_Dir>& theDirX,
+                                            const boost::shared_ptr<GeomAPI_Dir>& theDirY,
+                                            const boost::shared_ptr<GeomAPI_Dir>& theNorm,
+                                            const boost::shared_ptr<GeomAPI_Shape>& theWire,
+                                            std::list<boost::shared_ptr<GeomAPI_Shape> >& theResultFaces)
+{
+  boost::shared_ptr<GeomAPI_PlanarEdges> aWire = boost::dynamic_pointer_cast<GeomAPI_PlanarEdges>(theWire);
+  if(!aWire)
+    return;
+  // Filter wires, return only faces.
+  std::list<boost::shared_ptr<GeomAPI_Shape> > aFilteredWires;
+  createFaces(theOrigin, theDirX, theDirY, theNorm,
+              aWire->getEdges(), theResultFaces, aFilteredWires);
+}
+
+
 void GeomAlgoAPI_SketchBuilder::fixIntersections(
     std::list<boost::shared_ptr<GeomAPI_Shape> >& theFaces)
 {
@@ -466,6 +486,7 @@ void findNextVertex(const TopoDS_Vertex& theStartVertex,
                     const gp_Dir& theStartDir, const gp_Dir& theNormal, TopoDS_Vertex& theNextVertex,
                     TopoDS_Edge& theNextEdge, gp_Dir& theNextDir)
 {
+  theNextVertex = TopoDS_Vertex();
   const BOPCol_ListOfShape& anEdgesList = theVertexEdgeMap.FindFromKey(theStartVertex);
   int anEdgesNum = anEdgesList.Extent();
   BOPCol_ListOfShape::Iterator aEdIter(anEdgesList);
@@ -505,6 +526,18 @@ void findNextVertex(const TopoDS_Vertex& theStartVertex,
       }
     }
   }
+
+  // Probably there are two tangent edges. We will take the edge differs from current one
+  if (theNextVertex.IsNull() && anEdgesNum == 2) {
+    BOPCol_ListOfShape::Iterator aEdIter(anEdgesList);
+    if (aEdIter.Value() == theNextEdge)
+      aEdIter.Next();
+    theNextEdge = static_cast<const TopoDS_Edge&>(aEdIter.Value());
+    TopoDS_Vertex aV1, aV2;
+    TopExp::Vertices(theNextEdge, aV1, aV2);
+    theNextVertex = theStartVertex.IsSame(aV1) ? aV2 : aV1;
+    theNextDir = getOuterEdgeDirection(theNextEdge, theNextVertex);
+  }
 }
 
 static void addEdgeToWire(const TopoDS_Edge& theEdge, const BRep_Builder& theBuilder,