Salome HOME
This is an improvement to use one AND filter in the viewer context. It serves to...
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_SketchBuilder.cpp
index b7ef59f5d68b549f8198d52b6b88fbc69404ff4c..4e894827d7f63d037da9748132f9784a6107f721 100644 (file)
@@ -3,6 +3,7 @@
 // Author:      Artem ZHIDKOV
 
 #include <GeomAlgoAPI_SketchBuilder.h>
+#include <GeomAPI_PlanarEdges.h>
 
 #include <set>
 
@@ -79,11 +80,11 @@ static void removeWasteEdges(std::list<TopoDS_Vertex>::iterator& theStartVertex,
 
 
 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 std::list<boost::shared_ptr<GeomAPI_Shape> >& theFeatures,
-    std::list<boost::shared_ptr<GeomAPI_Shape> >& theResultFaces,
-    std::list<boost::shared_ptr<GeomAPI_Shape> >& theResultWires)
+    const std::shared_ptr<GeomAPI_Pnt>& theOrigin, const std::shared_ptr<GeomAPI_Dir>& theDirX,
+    const std::shared_ptr<GeomAPI_Dir>& theDirY, const std::shared_ptr<GeomAPI_Dir>& theNorm,
+    const std::list<std::shared_ptr<GeomAPI_Shape> >& theFeatures,
+    std::list<std::shared_ptr<GeomAPI_Shape> >& theResultFaces,
+    std::list<std::shared_ptr<GeomAPI_Shape> >& theResultWires)
 {
   if (theFeatures.empty())
     return;
@@ -94,10 +95,10 @@ void GeomAlgoAPI_SketchBuilder::createFaces(
   TopoDS_Shape aFeaturesCompound;
 
   // Obtain only edges from the features list
-  std::list<boost::shared_ptr<GeomAPI_Shape> > anEdges;
-  std::list<boost::shared_ptr<GeomAPI_Shape> >::const_iterator aFeatIt = theFeatures.begin();
+  std::list<std::shared_ptr<GeomAPI_Shape> > anEdges;
+  std::list<std::shared_ptr<GeomAPI_Shape> >::const_iterator aFeatIt = theFeatures.begin();
   for (; aFeatIt != theFeatures.end(); aFeatIt++) {
-    boost::shared_ptr<GeomAPI_Shape> aShape(*aFeatIt);
+    std::shared_ptr<GeomAPI_Shape> aShape(*aFeatIt);
     const TopoDS_Edge& anEdge = aShape->impl<TopoDS_Edge>();
     if (anEdge.ShapeType() == TopAbs_EDGE)
       anEdges.push_back(aShape);
@@ -106,9 +107,9 @@ void GeomAlgoAPI_SketchBuilder::createFaces(
   if (anEdges.size() == 1) {  // If there is only one feature, BOPAlgo_Builder will decline to work. Need to process it anyway
     aFeaturesCompound = anEdges.front()->impl<TopoDS_Shape>();
   } else {
-    std::list<boost::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = anEdges.begin();
+    std::list<std::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = anEdges.begin();
     for (; anIt != anEdges.end(); anIt++) {
-      boost::shared_ptr<GeomAPI_Shape> aPreview(*anIt);
+      std::shared_ptr<GeomAPI_Shape> aPreview(*anIt);
       aBuilder.AddArgument(aPreview->impl<TopoDS_Edge>());
     }
     aPF.SetArguments(aBuilder.Arguments());
@@ -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;
 
@@ -216,7 +219,7 @@ void GeomAlgoAPI_SketchBuilder::createFaces(
       TopoDS_Face aPatch;
       createFace(*aVertIter, anEdgeIter, aProcEdges.end(), aPlane, aPatch);
       if (!aPatch.IsNull()) {
-        boost::shared_ptr<GeomAPI_Shape> aFace(new GeomAPI_Shape);
+        std::shared_ptr<GeomAPI_Shape> aFace(new GeomAPI_Shape);
         aFace->setImpl(new TopoDS_Face(aPatch));
         theResultFaces.push_back(aFace);
       }
@@ -320,7 +323,7 @@ void GeomAlgoAPI_SketchBuilder::createFaces(
         std::list<TopoDS_Wire>::const_iterator aTailIter = aTail.begin();
         for (; aTailIter != aTail.end(); aTailIter++)
           if (!aTailIter->IsNull()) {
-            boost::shared_ptr<GeomAPI_Shape> aWire(new GeomAPI_Shape);
+            std::shared_ptr<GeomAPI_Shape> aWire(new GeomAPI_Shape);
             aWire->setImpl(new TopoDS_Shape(*aTailIter));
             theResultWires.push_back(aWire);
           }
@@ -368,13 +371,30 @@ void GeomAlgoAPI_SketchBuilder::createFaces(
     fixIntersections(theResultFaces);
 }
 
+void GeomAlgoAPI_SketchBuilder::createFaces(const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
+                                            const std::shared_ptr<GeomAPI_Dir>& theDirX,
+                                            const std::shared_ptr<GeomAPI_Dir>& theDirY,
+                                            const std::shared_ptr<GeomAPI_Dir>& theNorm,
+                                            const std::shared_ptr<GeomAPI_Shape>& theWire,
+                                            std::list<std::shared_ptr<GeomAPI_Shape> >& theResultFaces)
+{
+  std::shared_ptr<GeomAPI_PlanarEdges> aWire = std::dynamic_pointer_cast<GeomAPI_PlanarEdges>(theWire);
+  if(!aWire)
+    return;
+  // Filter wires, return only faces.
+  std::list<std::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)
+    std::list<std::shared_ptr<GeomAPI_Shape> >& theFaces)
 {
   BRepClass_FaceClassifier aClassifier;
 
-  std::list<boost::shared_ptr<GeomAPI_Shape> >::iterator anIter1 = theFaces.begin();
-  std::list<boost::shared_ptr<GeomAPI_Shape> >::iterator anIter2;
+  std::list<std::shared_ptr<GeomAPI_Shape> >::iterator anIter1 = theFaces.begin();
+  std::list<std::shared_ptr<GeomAPI_Shape> >::iterator anIter2;
   for (; anIter1 != theFaces.end(); anIter1++) {
     anIter2 = anIter1;
     for (++anIter2; anIter2 != theFaces.end(); anIter2++) {
@@ -410,7 +430,7 @@ void GeomAlgoAPI_SketchBuilder::fixIntersections(
               (*anIter2)->setImpl(new TopoDS_Shape(anExp.Current()));
               isFirstFace = false;
             } else {
-              boost::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
+              std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
               aShape->setImpl(new TopoDS_Shape(anExp.Current()));
               theFaces.push_back(aShape);
             }
@@ -427,7 +447,7 @@ void GeomAlgoAPI_SketchBuilder::fixIntersections(
             (*anIter1)->setImpl(new TopoDS_Shape(anExp.Current()));
             isFirstFace = false;
           } else {
-            boost::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
+            std::shared_ptr<GeomAPI_Shape> aShape(new GeomAPI_Shape);
             aShape->setImpl(new TopoDS_Shape(anExp.Current()));
             theFaces.push_back(aShape);
           }
@@ -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,