]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Make SketchBuilder more deterministic
authorazv <azv@opencascade.com>
Wed, 20 Jan 2016 07:18:20 +0000 (10:18 +0300)
committerdbv <dbv@opencascade.com>
Tue, 16 Feb 2016 14:04:23 +0000 (17:04 +0300)
src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.cpp
src/ModelAPI/Test/Test1064.py
src/PythonAPI/examples/Platine.py

index 9713fda503f839eb42b77fa19d9725fcdd31d295..5098b37408ecc68e2c8b3da52f77f057d408947c 100644 (file)
 #include <BRepTopAdaptor_FClass2d.hxx>
 #include <Geom_Plane.hxx>
 #include <Precision.hxx>
+#include <TopExp.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopoDS.hxx>
 #include <TopoDS_Edge.hxx>
 #include <TopTools_ListIteratorOfListOfShape.hxx>
 
+#include <list>
+
+
+static TopoDS_Vertex findStartVertex(const TopoDS_Face& aFace)
+{
+  TopExp_Explorer anExp(aFace, TopAbs_VERTEX);
+  TopoDS_Vertex aStart = TopoDS::Vertex(anExp.Current());
+  gp_Pnt aStartPnt(BRep_Tool::Pnt(aStart));
+  TopoDS_Vertex aCurrent;
+  gp_Pnt aCurrentPnt;
+
+  for (anExp.Next(); anExp.More(); anExp.Next()) {
+    aCurrent = TopoDS::Vertex(anExp.Current());
+    aCurrentPnt = BRep_Tool::Pnt(aCurrent);
+    if ((aCurrentPnt.X() > aStartPnt.X()) ||
+        (aCurrentPnt.X() == aStartPnt.X() && aCurrentPnt.Y() > aStartPnt.Y()) ||
+        (aCurrentPnt.X() == aStartPnt.X() && aCurrentPnt.Y() == aStartPnt.Y() &&
+            aCurrentPnt.Z() > aStartPnt.Z())) {
+      aStart = aCurrent;
+      aStartPnt = aCurrentPnt;
+    }
+  }
+  return aStart;
+}
 
 void GeomAlgoAPI_SketchBuilder::createFaces(
     const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
@@ -61,24 +86,43 @@ void GeomAlgoAPI_SketchBuilder::createFaces(
     if (aFClass.PerformInfinitePoint() == TopAbs_IN)
       continue;
 
-    // remove internal edges from faces
+    // to make faces equal on different platforms, we will find
+    // a vertex with greater coordinates and start wire from it
+    TopoDS_Vertex aStartVertex = findStartVertex(aFace);
+    TopoDS_Wire aNewWire;
+    aBuilder.MakeWire(aNewWire);
+    std::list<TopoDS_Edge> aSkippedEdges;
+    bool aStartFound = false;
+
+    // remove internal edges from faces and make wire start from found vertex
     TopExp_Explorer anExp(aFace, TopAbs_EDGE);
-    for (; anExp.More(); anExp.Next())
+    for (; anExp.More(); anExp.Next()) {
       if (anExp.Current().Orientation() == TopAbs_INTERNAL)
-        break;
-    if (anExp.More()) {
-      TopoDS_Face aNewFace;
-      aBuilder.MakeFace(aNewFace, aPlane, Precision::Confusion());
-      TopoDS_Wire aWire;
-      aBuilder.MakeWire(aWire);
-      for (anExp.ReInit(); anExp.More(); anExp.Next())
-        if (anExp.Current().Orientation() != TopAbs_INTERNAL)
-          aBuilder.Add(aWire, anExp.Current());
-      aBuilder.Add(aNewFace, aWire);
-      aFace = aNewFace;
+        continue;
+      if (!aStartFound) {
+        const TopoDS_Edge& anEdge = TopoDS::Edge(anExp.Current());
+        TopoDS_Vertex aV1, aV2;
+        TopExp::Vertices(anEdge, aV1, aV2);
+        if (aV1.IsSame(aStartVertex) == Standard_True)
+          aStartFound = true;
+        else
+          aSkippedEdges.push_back(anEdge);
+      }
+      if (aStartFound)
+        aBuilder.Add(aNewWire, anExp.Current());
     }
+    // add skipped edges to the end of wire
+    std::list<TopoDS_Edge>::const_iterator aSkIt = aSkippedEdges.begin();
+    for (; aSkIt != aSkippedEdges.end(); ++aSkIt)
+      aBuilder.Add(aNewWire, *aSkIt);
+
+    // rebuild face
+    TopoDS_Face aNewFace;
+    aBuilder.MakeFace(aNewFace, aPlane, Precision::Confusion());
+    aBuilder.Add(aNewFace, aNewWire);
+    aFace = aNewFace;
 
-    // Store face
+    // store face
     std::shared_ptr<GeomAPI_Shape> aResFace(new GeomAPI_Shape);
     aResFace->setImpl(new TopoDS_Face(aFace));
     theResultFaces.push_back(aResFace);
index e5c24f218c3c6b0e5289105d42e3c2d7a37127a2..c73dfd17d9633503c56894647420408ff1975c1f 100644 (file)
@@ -73,7 +73,7 @@ aSession.setActiveDocument(aPartSet)
 aPlane = aPartSet.addFeature("Plane")
 aPlane.string("CreationMethod").setValue("PlaneByFaceAndDistance")
 aPlane.real("distance").setValue(0)
-aPlane.selection("planeFace").selectSubShape("face", "Part_1/Extrusion_1_1/LateralFace_2")
+aPlane.selection("planeFace").selectSubShape("face", "Part_1/Extrusion_1_1/LateralFace_3")
 aSession.finishOperation()
 
 #=========================================================================
index 96afd1ac07553443836085a67e45f3f8dcfa0339..063e2c63949ed44e662990a215f38f276949fcf9 100644 (file)
@@ -54,7 +54,7 @@ def vertical_body():
 
 def bottom_body():
     # Create XOY sketch
-    sketch = model.addSketch(part, "Extrusion_1_1/LateralFace_5")
+    sketch = model.addSketch(part, "Extrusion_1_1/LateralFace_4")
 
     # Create base polygon
     points = [(0, 0), (0, L), (P, L), (P, 16 + 16), (P - 20, 16 + 16), (P - 20, 16), (P, 16), (P, 0)]
@@ -87,7 +87,7 @@ def bottom_body():
     sketch.setCoincident(arc.endPoint(), h1.startPoint())
 
     # Binding
-    left_e = sketch.addLine("Extrusion_1_1/LateralFace_5&Extrusion_1_1/ToFace_1")
+    left_e = sketch.addLine("Extrusion_1_1/LateralFace_4&Extrusion_1_1/ToFace_1")
     sketch.setCoincident(left_e.startPoint(), left.endPoint())
     sketch.setCoincident(left_e.endPoint(), left.startPoint())
 
@@ -162,7 +162,7 @@ def body_3():
 
 def body_4():
     # Create XOZ 2nd sketch
-    sketch = model.addSketch(part, "Boolean_2_1/Modified_7")
+    sketch = model.addSketch(part, "Boolean_2_1/Modified_8")
 
     # Create base polygon
     points = [(0, 0), (0, 1), (1, 0)]