Salome HOME
Fix for the issue #2454
authormpv <mpv@opencascade.com>
Wed, 14 Mar 2018 13:56:42 +0000 (16:56 +0300)
committermpv <mpv@opencascade.com>
Wed, 14 Mar 2018 13:56:42 +0000 (16:56 +0300)
src/BuildPlugin/CMakeLists.txt
src/BuildPlugin/Test/Test2454.py [new file with mode: 0644]
src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.cpp

index ec8947b4a6d981fc7ad05fb86d6507930a479704..05a97327da1386407eb65aa95febb9078521f1fd 100644 (file)
@@ -114,4 +114,5 @@ ADD_UNIT_TESTS(TestVertex.py
                Test2398.py
                Test2415.py
                Test2439.py
+               Test2454.py
 )
diff --git a/src/BuildPlugin/Test/Test2454.py b/src/BuildPlugin/Test/Test2454.py
new file mode 100644 (file)
index 0000000..f56d1d1
--- /dev/null
@@ -0,0 +1,42 @@
+## Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+##
+## This library is free software; you can redistribute it and/or
+## modify it under the terms of the GNU Lesser General Public
+## License as published by the Free Software Foundation; either
+## version 2.1 of the License, or (at your option) any later version.
+##
+## This library is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+## Lesser General Public License for more details.
+##
+## You should have received a copy of the GNU Lesser General Public
+## License along with this library; if not, write to the Free Software
+## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+##
+## See http:##www.salome-platform.org/ or
+## email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+##
+
+from salome.shaper import model
+
+model.begin()
+partSet = model.moduleDocument()
+Part_1 = model.addPart(partSet)
+Part_1_doc = Part_1.document()
+Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY"))
+SketchCircle_1 = Sketch_1.addCircle(0.1822176134072968, -1.34047565209109, 35.08968954114807)
+model.do()
+Wire_1 = model.addWire(Part_1_doc, [model.selection("EDGE", "Sketch_1/Edge-SketchCircle_1_2")])
+Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("WIRE", "Wire_1_1")], model.selection(), 100, 0)
+Recover_1 = model.addRecover(Part_1_doc, Extrusion_1, [Wire_1.result()])
+Face_1 = model.addFace(Part_1_doc, [model.selection("WIRE", "Recover_1_1")])
+Wire_2 = model.addWire(Part_1_doc, [model.selection("EDGE", "Extrusion_1_1/To_Edge_1")])
+Face_2 = model.addFace(Part_1_doc, [model.selection("WIRE", "Wire_2_1")])
+model.end()
+
+from ModelAPI import *
+aFactory = ModelAPI_Session.get().validators()
+assert(aFactory.validate(Face_2.feature()))
+
+assert(model.checkPythonDump())
index a6da1e785e24b70d0a84b515c1afd0b7805fbc94..bbeccf7b2a310dc48e8fcddbe45ed3cd5ecdf546 100644 (file)
@@ -114,7 +114,7 @@ bool isFirst(const TopoDS_Shape& theFirst, const TopoDS_Shape& theSecond,
     if (!theAreaToIndex.IsBound(aShape)) { // fill the list of curve indices
       NCollection_List<int> aNewList;
       TopExp_Explorer anEdgesExp(aShape, TopAbs_EDGE);
-      for(; anEdgesExp.More(); anEdgesExp.Next()) {
+      for (; anEdgesExp.More(); anEdgesExp.Next()) {
         double aFirst, aLast;
         Handle(Geom_Curve) aCurve = BRep_Tool::Curve(
           TopoDS::Edge(anEdgesExp.Current()), aFirst, aLast);
@@ -124,24 +124,34 @@ bool isFirst(const TopoDS_Shape& theFirst, const TopoDS_Shape& theSecond,
           aNewList.Append(theCurveToIndex.Find(aCurve));
         }
       }
-      NCollection_Array1<int> aNewArray(1, aNewList.Extent());
-      NCollection_List<int>::Iterator aListIter(aNewList);
-      for(int anIndex = 1; aListIter.More(); aListIter.Next(), anIndex++) {
-        aNewArray.SetValue(anIndex, aListIter.Value());
+      if (aNewList.Extent()) {
+        NCollection_Array1<int> aNewArray(1, aNewList.Extent());
+        NCollection_List<int>::Iterator aListIter(aNewList);
+        for (int anIndex = 1; aListIter.More(); aListIter.Next(), anIndex++) {
+          aNewArray.SetValue(anIndex, aListIter.Value());
+        }
+        std::sort(aNewArray.begin(), aNewArray.end());
+        theAreaToIndex.Bind(aShape, aNewArray);
       }
-      std::sort(aNewArray.begin(), aNewArray.end());
-      theAreaToIndex.Bind(aShape, aNewArray);
     }
   }
-  // compare lists of indices one by one to find chich list indices are lower
-  NCollection_Array1<int>::Iterator aFirstList(theAreaToIndex.ChangeFind(theFirst));
-  NCollection_Array1<int>::Iterator aSecondList(theAreaToIndex.ChangeFind(theSecond));
-  for(; aFirstList.More() && aSecondList.More(); aFirstList.Next(), aSecondList.Next()) {
-    if (aFirstList.Value() < aSecondList.Value()) return true;
-    if (aFirstList.Value() > aSecondList.Value()) return false;
+  bool isFirst;
+  bool aGeomCompare = !theAreaToIndex.IsBound(theFirst) || !theAreaToIndex.IsBound(theSecond);
+  if (!aGeomCompare) {
+    // compare lists of indices one by one to find chich list indices are lower
+    NCollection_Array1<int>::Iterator aFirstList(theAreaToIndex.ChangeFind(theFirst));
+    NCollection_Array1<int>::Iterator aSecondList(theAreaToIndex.ChangeFind(theSecond));
+    for (; aFirstList.More() && aSecondList.More(); aFirstList.Next(), aSecondList.Next()) {
+      if (aFirstList.Value() < aSecondList.Value()) return true;
+      if (aFirstList.Value() > aSecondList.Value()) return false;
+    }
+    aGeomCompare = !aFirstList.More() && !aSecondList.More();
+    isFirst = !aFirstList.More();
+  } else {
+    isFirst = !theAreaToIndex.IsBound(theFirst);
   }
   // if faces are identical by curves names (circle splitted by line in seam-point), use parameters
-  if (!aFirstList.More() && !aSecondList.More()) {
+  if (aGeomCompare) {
     GProp_GProps aGProps;
     BRepGProp::SurfaceProperties(theFirst, aGProps);
     gp_Pnt aCentre1 = aGProps.CentreOfMass();
@@ -150,7 +160,7 @@ bool isFirst(const TopoDS_Shape& theFirst, const TopoDS_Shape& theSecond,
     return aCentre1.X() + aCentre1.Y() + aCentre1.Z() < aCentre2.X() + aCentre2.Y() + aCentre2.Z();
   }
   // if in first list there is no elements left, it is the first
-  return !aFirstList.More();
+  return isFirst;
 }
 
 // sorts faces (in theAreas list) to make persistent order: by initial shapes edges
@@ -209,8 +219,8 @@ void GeomAlgoAPI_SketchBuilder::createFaces(
   BOPAlgo_Builder aBB;
   aBB.AddArgument(aPlnFace);
 
-  BOPCol_ListOfShape anEdges;
-  BOPCol_ListIteratorOfListOfShape aShapeIt;
+  NCollection_List<TopoDS_Shape> anEdges;
+  NCollection_List<TopoDS_Shape>::Iterator aShapeIt;
   std::list<std::shared_ptr<GeomAPI_Shape> >::const_iterator aFeatIt = theFeatures.begin();
   for (; aFeatIt != theFeatures.end(); aFeatIt++) {
     std::shared_ptr<GeomAPI_Shape> aShape(*aFeatIt);