From d400668ba119991a05de96e8d57cd7a4e91ba03c Mon Sep 17 00:00:00 2001 From: mpv Date: Wed, 14 Mar 2018 16:56:42 +0300 Subject: [PATCH] Fix for the issue #2454 --- src/BuildPlugin/CMakeLists.txt | 1 + src/BuildPlugin/Test/Test2454.py | 42 ++++++++++++++++++ src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.cpp | 44 ++++++++++++------- 3 files changed, 70 insertions(+), 17 deletions(-) create mode 100644 src/BuildPlugin/Test/Test2454.py diff --git a/src/BuildPlugin/CMakeLists.txt b/src/BuildPlugin/CMakeLists.txt index ec8947b4a..05a97327d 100644 --- a/src/BuildPlugin/CMakeLists.txt +++ b/src/BuildPlugin/CMakeLists.txt @@ -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 index 000000000..f56d1d122 --- /dev/null +++ b/src/BuildPlugin/Test/Test2454.py @@ -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 +## + +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()) diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.cpp index a6da1e785..bbeccf7b2 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_SketchBuilder.cpp @@ -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 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 aNewArray(1, aNewList.Extent()); - NCollection_List::Iterator aListIter(aNewList); - for(int anIndex = 1; aListIter.More(); aListIter.Next(), anIndex++) { - aNewArray.SetValue(anIndex, aListIter.Value()); + if (aNewList.Extent()) { + NCollection_Array1 aNewArray(1, aNewList.Extent()); + NCollection_List::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::Iterator aFirstList(theAreaToIndex.ChangeFind(theFirst)); - NCollection_Array1::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::Iterator aFirstList(theAreaToIndex.ChangeFind(theFirst)); + NCollection_Array1::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 anEdges; + NCollection_List::Iterator aShapeIt; std::list >::const_iterator aFeatIt = theFeatures.begin(); for (; aFeatIt != theFeatures.end(); aFeatIt++) { std::shared_ptr aShape(*aFeatIt); -- 2.30.2