From: mpv Date: Wed, 13 Sep 2017 07:53:30 +0000 (+0300) Subject: Fix for the issue #2248 and issue #2251 : same curves sketch edges (splitted to make... X-Git-Tag: V_2.8.0~13 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2c85e3024f4ad62f461132496a1bf5e6d09ef692;p=modules%2Fshaper.git Fix for the issue #2248 and issue #2251 : same curves sketch edges (splitted to make sketch faces) are positioned to different sub-labels. --- diff --git a/src/FeaturesPlugin/CMakeLists.txt b/src/FeaturesPlugin/CMakeLists.txt index 70d0ff271..94ec4f78c 100644 --- a/src/FeaturesPlugin/CMakeLists.txt +++ b/src/FeaturesPlugin/CMakeLists.txt @@ -179,4 +179,6 @@ ADD_UNIT_TESTS(TestExtrusion.py Test2231.py Test2240.py Test2246.py + Test2248.py + Test2251.py ) diff --git a/src/FeaturesPlugin/Test/Test2172.py b/src/FeaturesPlugin/Test/Test2172.py index af8c163a3..65c4daca7 100644 --- a/src/FeaturesPlugin/Test/Test2172.py +++ b/src/FeaturesPlugin/Test/Test2172.py @@ -82,7 +82,7 @@ from ModelAPI import * aFactory = ModelAPI_Session.get().validators() assert(aFactory.validate(Group_1.feature())) assert(Group_1.groupList().size() == 10) -for a in range(3): +for a in range(10): assert(Group_1.groupList().value(a).value().shapeTypeStr() == "EDGE") assert(len(Group_1.groupList().value(a).namingName()) > 0) diff --git a/src/FeaturesPlugin/Test/Test2248.py b/src/FeaturesPlugin/Test/Test2248.py new file mode 100644 index 000000000..85ef22df9 --- /dev/null +++ b/src/FeaturesPlugin/Test/Test2248.py @@ -0,0 +1,63 @@ +## 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 +## + +# check that extrusion of sketch with intersected edges produces well-named edges + +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")) +SketchLine_1 = Sketch_1.addLine(394.1014919414247, 282.461820162796, -355.0948596332293, 282.461820162796) +SketchLine_2 = Sketch_1.addLine(-355.0948596332293, 282.461820162796, -355.0948596332293, -224.6243998437472) +SketchLine_3 = Sketch_1.addLine(-355.0948596332293, -224.6243998437472, 394.1014919414247, -224.6243998437472) +SketchLine_4 = Sketch_1.addLine(394.1014919414247, -224.6243998437472, 394.1014919414247, 282.461820162796) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint()) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint()) +SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint()) +SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result()) +SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result()) +SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result()) +SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_4.result()) +SketchArc_1 = Sketch_1.addArc(-7.174842024158346, 282.461820162796, -355.0948596332293, 282.461820162796, 143.9210226543769, -30.9362945892586, False) +SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_2.startPoint(), SketchArc_1.startPoint()) +SketchConstraintTangent_1 = Sketch_1.setTangent(SketchLine_2.result(), SketchArc_1.results()[1]) +SketchArc_2 = Sketch_1.addArc(394.1014919414247, 441.436567364073, 394.1014919414247, -224.6243998437472, -125.0902346435239, 24.21101315681109, True) +SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchArc_2.startPoint()) +SketchConstraintTangent_2 = Sketch_1.setTangent(SketchLine_3.result(), SketchArc_2.results()[1]) +SketchCircle_1 = Sketch_1.addCircle(-13.45056286489504, 169.4770920976776, 150.6703210346195) +model.do() +Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_1")], model.selection(), 10, 0) +Group_1 = model.addGroup(Part_1_doc, [model.selection("EDGE", "Extrusion_1_1/Generated_Face_1&Extrusion_1_1/To_Face_3"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_2&Extrusion_1_1/From_Face_3"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_2&Extrusion_1_1/To_Face_3"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_1&Extrusion_1_1/From_Face_3"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_6&Extrusion_1_1/To_Face_4"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_6&Extrusion_1_1/From_Face_4"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_1&Extrusion_1_1/To_Face_4"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_1&Extrusion_1_1/From_Face_4"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_1&Extrusion_1_1/Generated_Face_6"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_5&Extrusion_1_1/Generated_Face_6"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_5&Extrusion_1_1/To_Face_4"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_5&Extrusion_1_1/From_Face_4"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_1&Extrusion_1_1/Generated_Face_5"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_10&Extrusion_1_1/To_Face_2"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_10&Extrusion_1_1/From_Face_2"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_7&Extrusion_1_1/Generated_Face_10"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_7&Extrusion_1_1/To_Face_2"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_7&Extrusion_1_1/From_Face_2"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_7&Extrusion_1_1/Generated_Face_6"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_9&Extrusion_1_1/Generated_Face_10"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_6&Extrusion_1_1/From_Face_2"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_6&Extrusion_1_1/To_Face_2"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_9&Extrusion_1_1/From_Face_2"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_9&Extrusion_1_1/To_Face_2"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_3&Extrusion_1_1/Generated_Face_9"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_3&Extrusion_1_1/To_Face_2"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_3&Extrusion_1_1/From_Face_2"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_6&Extrusion_1_1/Generated_Face_5"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_5&Extrusion_1_1/From_Face_2"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_5&Extrusion_1_1/To_Face_2"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_5&Extrusion_1_1/Generated_Face_4"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_4&Extrusion_1_1/To_Face_2"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_4&Extrusion_1_1/From_Face_2"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_4&Extrusion_1_1/Generated_Face_3"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_11&Extrusion_1_1/Generated_Face_8"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_11&Extrusion_1_1/To_Face_1"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_11&Extrusion_1_1/From_Face_1"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_10&Extrusion_1_1/From_Face_1"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_10&Extrusion_1_1/To_Face_1"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_11&Extrusion_1_1/Generated_Face_10"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_10&Extrusion_1_1/Generated_Face_9"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_8&Extrusion_1_1/From_Face_1"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_9&Extrusion_1_1/From_Face_1"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_9&Extrusion_1_1/To_Face_1"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_8&Extrusion_1_1/To_Face_1"), model.selection("EDGE", "Extrusion_1_1/Generated_Face_9&Extrusion_1_1/Generated_Face_8")]) +model.end() + +# check that resulting group selection is valid +from ModelAPI import * +aFactory = ModelAPI_Session.get().validators() +assert(aFactory.validate(Group_1.feature())) +assert(Group_1.groupList().size() == 46) +for a in range(46): + assert(Group_1.groupList().value(a).value().shapeTypeStr() == "EDGE") + assert(len(Group_1.groupList().value(a).namingName()) > 0) + +assert(model.checkPythonDump()) diff --git a/src/FeaturesPlugin/Test/Test2251.py b/src/FeaturesPlugin/Test/Test2251.py new file mode 100644 index 000000000..c2694960e --- /dev/null +++ b/src/FeaturesPlugin/Test/Test2251.py @@ -0,0 +1,71 @@ +## 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 +## + +# check that extrusion of sketch with intersected edges produces well-named faces + +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")) +SketchLine_1 = Sketch_1.addLine(500.0000311770457, 317.8294573643411, -308.1395348837211, 317.8294573643411) +SketchLine_2 = Sketch_1.addLine(-308.1395348837211, 317.8294573643411, -308.1395348837211, -263.9724263224183) +SketchLine_3 = Sketch_1.addLine(-308.1395348837211, -263.9724263224183, 500.0000311770457, -263.9724263224183) +SketchLine_4 = Sketch_1.addLine(500.0000311770457, -263.9724263224183, 500.0000311770457, 317.8294573643411) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchLine_4.endPoint(), SketchLine_1.startPoint()) +SketchConstraintCoincidence_2 = Sketch_1.setCoincident(SketchLine_1.endPoint(), SketchLine_2.startPoint()) +SketchConstraintCoincidence_3 = Sketch_1.setCoincident(SketchLine_2.endPoint(), SketchLine_3.startPoint()) +SketchConstraintCoincidence_4 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchLine_4.startPoint()) +SketchConstraintHorizontal_1 = Sketch_1.setHorizontal(SketchLine_1.result()) +SketchConstraintVertical_1 = Sketch_1.setVertical(SketchLine_2.result()) +SketchConstraintHorizontal_2 = Sketch_1.setHorizontal(SketchLine_3.result()) +SketchConstraintVertical_2 = Sketch_1.setVertical(SketchLine_4.result()) +SketchCircle_1 = Sketch_1.addCircle(-118.2170542635659, 222.8682170542636, 141.685090902591) +SketchCircle_2 = Sketch_1.addCircle(294.5736434108529, -40.69767441860468, 113.2187726277406) +SketchArc_1 = Sketch_1.addArc(500.0000311770867, -335287.7996679137, 500.0000311770457, -263.9724263224183, -639.534183538502, -265.9104108427558, True) +SketchConstraintCoincidence_5 = Sketch_1.setCoincident(SketchLine_3.endPoint(), SketchArc_1.startPoint()) +SketchConstraintTangent_1 = Sketch_1.setTangent(SketchLine_3.result(), SketchArc_1.results()[1]) +SketchArc_2 = Sketch_1.addArc(-638.1195022375863, -681.8252609710054, -639.534183538502, -265.9104108427558, -316.014851248167, -418.6983758160058, True) +SketchConstraintCoincidence_6 = Sketch_1.setCoincident(SketchArc_1.endPoint(), SketchArc_2.startPoint()) +SketchConstraintTangent_2 = Sketch_1.setTangent(SketchArc_1.results()[1], SketchArc_2.results()[1]) +SketchArc_3 = Sketch_1.addArc(-167.5780303038277, -297.4405230733651, -316.014851248167, -418.6983758160058, -17.4411870157839, -178.2940378070349, False) +SketchConstraintCoincidence_7 = Sketch_1.setCoincident(SketchArc_2.endPoint(), SketchArc_3.startPoint()) +SketchConstraintTangent_3 = Sketch_1.setTangent(SketchArc_2.results()[1], SketchArc_3.results()[1]) +SketchArc_4 = Sketch_1.addArc(-301.8048538198685, -403.9610406236078, -17.4411870157839, -178.2940378070349, -637.5573748460384, -265.908384788777, False) +SketchConstraintCoincidence_8 = Sketch_1.setCoincident(SketchArc_3.endPoint(), SketchArc_4.startPoint()) +SketchConstraintTangent_4 = Sketch_1.setTangent(SketchArc_3.results()[1], SketchArc_4.results()[1]) +SketchConstraintCoincidence_9 = Sketch_1.setCoincident(SketchArc_2.results()[1], SketchArc_4.endPoint()) +model.do() +Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("COMPOUND", "Sketch_1")], model.selection(), 100, 0) +Group_1 = model.addGroup(Part_1_doc, [model.selection("FACE", "Extrusion_1_1/Generated_Face_19"), model.selection("FACE", "Extrusion_1_1/Generated_Face_18"), model.selection("FACE", "Extrusion_1_1/Generated_Face_16"), model.selection("FACE", "Extrusion_1_1/Generated_Face_15"), model.selection("FACE", "Extrusion_1_1/Generated_Face_15"), model.selection("FACE", "Extrusion_1_1/Generated_Face_5"), model.selection("FACE", "Extrusion_1_1/Generated_Face_4"), model.selection("FACE", "Extrusion_1_1/From_Face_3"), model.selection("FACE", "Extrusion_1_1/Generated_Face_3"), model.selection("FACE", "Extrusion_1_1/To_Face_3"), model.selection("FACE", "Extrusion_1_1/Generated_Face_19"), model.selection("FACE", "Extrusion_1_1/Generated_Face_4"), model.selection("FACE", "Extrusion_1_1/From_Face_4"), model.selection("FACE", "Extrusion_1_1/To_Face_4"), model.selection("FACE", "Extrusion_1_1/Generated_Face_8"), model.selection("FACE", "Extrusion_1_1/Generated_Face_3"), model.selection("FACE", "Extrusion_1_1/Generated_Face_9"), model.selection("FACE", "Extrusion_1_1/From_Face_6"), model.selection("FACE", "Extrusion_1_1/Generated_Face_13"), model.selection("FACE", "Extrusion_1_1/To_Face_6"), model.selection("FACE", "Extrusion_1_1/Generated_Face_1"), model.selection("FACE", "Extrusion_1_1/Generated_Face_12"), model.selection("FACE", "Extrusion_1_1/To_Face_5"), model.selection("FACE", "Extrusion_1_1/Generated_Face_2"), model.selection("FACE", "Extrusion_1_1/From_Face_5"), model.selection("FACE", "Extrusion_1_1/Generated_Face_1"), model.selection("FACE", "Extrusion_1_1/Generated_Face_8"), model.selection("FACE", "Extrusion_1_1/Generated_Face_9"), model.selection("FACE", "Extrusion_1_1/Generated_Face_13"), model.selection("FACE", "Extrusion_1_1/Generated_Face_7"), model.selection("FACE", "Extrusion_1_1/Generated_Face_14"), model.selection("FACE", "Extrusion_1_1/Generated_Face_12"), model.selection("FACE", "Extrusion_1_1/Generated_Face_18"), model.selection("FACE", "Extrusion_1_1/From_Face_2"), model.selection("FACE", "Extrusion_1_1/Generated_Face_11"), model.selection("FACE", "Extrusion_1_1/Generated_Face_6"), model.selection("FACE", "Extrusion_1_1/To_Face_2"), model.selection("FACE", "Extrusion_1_1/Generated_Face_10"), model.selection("FACE", "Extrusion_1_1/Generated_Face_6"), model.selection("FACE", "Extrusion_1_1/To_Face_7"), model.selection("FACE", "Extrusion_1_1/From_Face_7"), model.selection("FACE", "Extrusion_1_1/Generated_Face_17"), model.selection("FACE", "Extrusion_1_1/From_Face_1"), model.selection("FACE", "Extrusion_1_1/To_Face_1")]) +model.end() + +# check that resulting group selection is valid +from ModelAPI import * +aFactory = ModelAPI_Session.get().validators() +assert(aFactory.validate(Group_1.feature())) +assert(Group_1.groupList().size() == 44) +for a in range(44): + assert(Group_1.groupList().value(a).value().shapeTypeStr() == "FACE") + assert(len(Group_1.groupList().value(a).namingName()) > 0) + +assert(model.checkPythonDump()) diff --git a/src/Model/Model_BodyBuilder.cpp b/src/Model/Model_BodyBuilder.cpp index ad63bee3e..39fbea9b6 100755 --- a/src/Model/Model_BodyBuilder.cpp +++ b/src/Model/Model_BodyBuilder.cpp @@ -253,6 +253,8 @@ void Model_BodyBuilder::storeWithoutNaming(const std::shared_ptr void Model_BodyBuilder::clean() { TDF_Label aLab = std::dynamic_pointer_cast(data())->shapeLab(); + if (aLab.IsNull()) + return; std::map::iterator aBuilder = myBuilders.begin(); for(; aBuilder != myBuilders.end(); aBuilder++) { delete aBuilder->second; diff --git a/src/Model/Model_ResultCompSolid.cpp b/src/Model/Model_ResultCompSolid.cpp index 0fa8b4fd1..231c0b6ed 100755 --- a/src/Model/Model_ResultCompSolid.cpp +++ b/src/Model/Model_ResultCompSolid.cpp @@ -237,7 +237,8 @@ void Model_ResultCompSolid::updateSubs(const std::shared_ptr& the } else if (!mySubs.empty()) { // erase all subs while(!mySubs.empty()) { ResultBodyPtr anErased = *(mySubs.rbegin()); - anErased->setDisabled(anErased, true); + if (anErased->data()->isValid()) + anErased->setDisabled(anErased, true); mySubs.pop_back(); } // redisplay this because result with and without subs are displayed differently diff --git a/src/Model/Model_ResultConstruction.cpp b/src/Model/Model_ResultConstruction.cpp index 371d4062b..4962932bf 100644 --- a/src/Model/Model_ResultConstruction.cpp +++ b/src/Model/Model_ResultConstruction.cpp @@ -413,6 +413,9 @@ int Model_ResultConstruction::select(const std::shared_ptr& theSu // iterate and store the result ids of sub-elements and sub-elements to sub-labels Handle(TDataStd_IntPackedMap) aRefs = TDataStd_IntPackedMap::Set(aLab); const int aSubNum = aComposite->numberOfSubs(); + // subs are placed one by one because of #2248): sketch curve may produce several edges + int aSubLabId = 1; + for(int a = 0; a < aSubNum; a++) { FeaturePtr aSub = aComposite->subFeature(a); const std::list >& aResults = aSub->results(); @@ -442,8 +445,9 @@ int Model_ResultConstruction::select(const std::shared_ptr& theSu Handle(Geom_Curve) aFaceCurve = BRep_Tool::Curve(anEdge, aFirst, aLast); if (aFaceCurve == aCurve) { TDF_Label aSubLab = aLab.FindChild(anID); + TDF_Label aShapeSubLab = aLab.FindChild(aSubLabId++); std::string aFullNameSub = fullName(aComposite, anEdge); - saveSubName(aSubLab, isSelectionMode, anEdge, aMyDoc, aFullNameSub); + saveSubName(aShapeSubLab, isSelectionMode, anEdge, aMyDoc, aFullNameSub); int anOrient = Model_SelectionNaming::edgeOrientation(aSubShape, anEdge); if (anOrient != 0) { @@ -454,14 +458,12 @@ int Model_ResultConstruction::select(const std::shared_ptr& theSu } } else { // put vertices of the selected edge to sub-labels // add edges to sub-label to support naming for edges selection - int aTagIndex = anID + kSTART_VERTEX_DELTA; for(TopExp_Explorer anEdgeExp(aSubShape, TopAbs_VERTEX); - anEdgeExp.More(); - anEdgeExp.Next(), aTagIndex += kSTART_VERTEX_DELTA) { + anEdgeExp.More(); anEdgeExp.Next()) { TopoDS_Vertex aV = TopoDS::Vertex(anEdgeExp.Current()); - TDF_Label aSubLab = aLab.FindChild(aTagIndex); + TDF_Label aShapeSubLab = aLab.FindChild(aSubLabId++); std::string aFullNameSub = fullName(aComposite, aV); - saveSubName(aSubLab, isSelectionMode, aV, aMyDoc, aFullNameSub); + saveSubName(aShapeSubLab, isSelectionMode, aV, aMyDoc, aFullNameSub); } } } diff --git a/src/Model/Model_SelectionNaming.cpp b/src/Model/Model_SelectionNaming.cpp index 2f88d7e65..878059198 100644 --- a/src/Model/Model_SelectionNaming.cpp +++ b/src/Model/Model_SelectionNaming.cpp @@ -154,6 +154,57 @@ bool isTrivial (const TopTools_ListOfShape& theAncestors, TopTools_IndexedMapOfS return true; } +const TopoDS_Shape findCommonShape( + const TopAbs_ShapeEnum theType, const TopTools_ListOfShape& theList) +{ + if(theList.Extent() < 1) { + return TopoDS_Shape(); + } else if (theList.Extent() == 1) { // check that sub-shape is bounded by this alone shape + TopTools_MapOfShape aSubsInShape; + TopExp_Explorer anExp(theList.First(), theType); + for(; anExp.More(); anExp.Next()) { + if (aSubsInShape.Contains(anExp.Current())) { // found duplicate + return anExp.Current(); + } + aSubsInShape.Add(anExp.Current()); + } + } + + // Store in maps sub-shapes from each face. + std::vector aVec; + for(TopTools_ListIteratorOfListOfShape anIt(theList); anIt.More(); anIt.Next()) { + const TopoDS_Shape aFace = anIt.Value(); + TopTools_MapOfShape aMap; + for(TopExp_Explorer anExp(aFace, theType); anExp.More(); anExp.Next()) { + const TopoDS_Shape& aSubShape = anExp.Current(); + aMap.Add(anExp.Current()); + } + aVec.push_back(aMap); + } + + // Find sub-shape shared between all faces. + TopoDS_Shape aSharedShape; + for(TopTools_MapIteratorOfMapOfShape anIt(aVec[0]); anIt.More(); anIt.Next()) { + const TopoDS_Shape& aSubShape = anIt.Value(); + int aSharedNb = 1; + for(int anIndex = 1; anIndex < aVec.size(); ++anIndex) { + if(aVec[anIndex].Contains(aSubShape)) { + ++aSharedNb; + } + } + if(aSharedNb == theList.Extent()) { + if(aSharedShape.IsNull()) { + aSharedShape = aSubShape; + } else { + // More than one shape shared between all faces, return null shape in this case. + return TopoDS_Shape(); + } + } + } + + return aSharedShape; +} + std::string Model_SelectionNaming::namingName(ResultPtr& theContext, std::shared_ptr theSubSh, const std::string& theDefaultName, const bool theAnotherDoc) @@ -218,6 +269,9 @@ std::string Model_SelectionNaming::namingName(ResultPtr& theContext, const TopTools_ListOfShape& anAncestors = aMap.FindFromKey(aSubShape); // check that it is not a trivial case (F1 & F2: aNumber = 1) isTrivialCase = isTrivial(anAncestors, aSMap); + if (!isTrivialCase) { // another try: check that getting of common shape can be done simply + isTrivialCase = !findCommonShape(TopAbs_EDGE, anAncestors).IsNull(); + } } else break; TopTools_ListOfShape aListOfNbs; @@ -455,57 +509,6 @@ size_t ParseName(const std::string& theSubShapeName, std::list& t return theList.size(); } -const TopoDS_Shape findCommonShape( - const TopAbs_ShapeEnum theType, const TopTools_ListOfShape& theList) -{ - if(theList.Extent() < 1) { - return TopoDS_Shape(); - } else if (theList.Extent() == 1) { // check that sub-shape is bounded by this alone shape - TopTools_MapOfShape aSubsInShape; - TopExp_Explorer anExp(theList.First(), theType); - for(; anExp.More(); anExp.Next()) { - if (aSubsInShape.Contains(anExp.Current())) { // found duplicate - return anExp.Current(); - } - aSubsInShape.Add(anExp.Current()); - } - } - - // Store in maps sub-shapes from each face. - std::vector aVec; - for(TopTools_ListIteratorOfListOfShape anIt(theList); anIt.More(); anIt.Next()) { - const TopoDS_Shape aFace = anIt.Value(); - TopTools_MapOfShape aMap; - for(TopExp_Explorer anExp(aFace, theType); anExp.More(); anExp.Next()) { - const TopoDS_Shape& aSubShape = anExp.Current(); - aMap.Add(anExp.Current()); - } - aVec.push_back(aMap); - } - - // Find sub-shape shared between all faces. - TopoDS_Shape aSharedShape; - for(TopTools_MapIteratorOfMapOfShape anIt(aVec[0]); anIt.More(); anIt.Next()) { - const TopoDS_Shape& aSubShape = anIt.Value(); - int aSharedNb = 1; - for(int anIndex = 1; anIndex < aVec.size(); ++anIndex) { - if(aVec[anIndex].Contains(aSubShape)) { - ++aSharedNb; - } - } - if(aSharedNb == theList.Extent()) { - if(aSharedShape.IsNull()) { - aSharedShape = aSubShape; - } else { - // More than one shape shared between all faces, return null shape in this case. - return TopoDS_Shape(); - } - } - } - - return aSharedShape; -} - std::string getContextName(const std::string& theSubShapeName) { std::string aName;