From 7d4237b5694f5b41f69282f52ef19fbd7c3cba88 Mon Sep 17 00:00:00 2001 From: mpv Date: Thu, 20 Feb 2020 14:09:34 +0300 Subject: [PATCH] Fix for the issue #18739 : EDF - move to the end and split Keep order of modified results in the move to the end algorithm. --- src/CollectionPlugin/CMakeLists.txt | 1 + src/CollectionPlugin/Test/Test18739.py | 47 ++++++++++++++++++++++++++ src/Model/Model_AttributeSelection.cpp | 31 +++++++++++------ 3 files changed, 68 insertions(+), 11 deletions(-) create mode 100644 src/CollectionPlugin/Test/Test18739.py diff --git a/src/CollectionPlugin/CMakeLists.txt b/src/CollectionPlugin/CMakeLists.txt index 3e3c16463..e13a28446 100644 --- a/src/CollectionPlugin/CMakeLists.txt +++ b/src/CollectionPlugin/CMakeLists.txt @@ -164,4 +164,5 @@ ADD_UNIT_TESTS( TestGroupMoveAndSplit2.py TestGroupMoveAndSplit3.py Test3114.py + Test18739.py ) diff --git a/src/CollectionPlugin/Test/Test18739.py b/src/CollectionPlugin/Test/Test18739.py new file mode 100644 index 000000000..54b3568e0 --- /dev/null +++ b/src/CollectionPlugin/Test/Test18739.py @@ -0,0 +1,47 @@ +# Copyright (C) 2014-2019 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 +# + +# Test of move to the end and split on LinearCopy: check that order in result is correct + +from salome.shaper import model + +model.begin() +partSet = model.moduleDocument() +Part_1 = model.addPart(partSet) +Part_1_doc = Part_1.document() +model.addParameter(Part_1_doc, "d", "8") +model.addParameter(Part_1_doc, "nb", "3") +Sketch_1 = model.addSketch(Part_1_doc, model.defaultPlane("XOY")) +SketchCircle_1 = Sketch_1.addCircle(-34, 28, 1) +SketchCircle_2 = Sketch_1.addCircle(-34, 28, 3) +SketchConstraintCoincidence_1 = Sketch_1.setCoincident(SketchCircle_1.center(), SketchCircle_2.center()) +model.do() +Extrusion_1 = model.addExtrusion(Part_1_doc, [model.selection("WIRE", "Sketch_1/Face-SketchCircle_2_2f-SketchCircle_1_2r_wire_2")], model.selection(), 2, -1) +Extrusion_2 = model.addExtrusion(Part_1_doc, [model.selection("WIRE", "Sketch_1/Face-SketchCircle_2_2f-SketchCircle_1_2r_wire")], model.selection(), 5, 0) +Partition_1 = model.addPartition(Part_1_doc, [model.selection("COMPOUND", "all-in-Extrusion_1"), model.selection("COMPOUND", "all-in-Extrusion_2")]) +Group_1 = model.addGroup(Part_1_doc, "Solids", [model.selection("SOLID", "Partition_1_1_1")]) +LinearCopy_1 = model.addMultiTranslation(Part_1_doc, [model.selection("COMPSOLID", "Partition_1_1")], model.selection("EDGE", "PartSet/OX"), "d", "nb", model.selection("EDGE", "PartSet/OY"), "d", "nb") +model.do() +Part_1_doc.moveFeature(Group_1.feature(), LinearCopy_1.feature(), True) +model.end() + +for a in range(9): + aGroup = Part_1_doc.objectByName("Features", "Group_1_" + str(a + 1)) + aSelName = aGroup.data().selectionList("group_list").value(0).context().data().name() + assert(aSelName == "LinearCopy_1_1_" + str(a + 1) + "_1") diff --git a/src/Model/Model_AttributeSelection.cpp b/src/Model/Model_AttributeSelection.cpp index 10dfe84b2..5c85b0237 100644 --- a/src/Model/Model_AttributeSelection.cpp +++ b/src/Model/Model_AttributeSelection.cpp @@ -1381,7 +1381,8 @@ bool Model_AttributeSelection::searchNewContext(std::shared_ptr TDF_Label theAccessLabel, std::list& theResults, TopTools_ListOfShape& theValShapes) { - std::set aResults; // to avoid duplicates, new context, null if deleted + std::list aResults; // keep order, new context, null if deleted + std::set aResultsSet; // to avoid duplicates // iterate context and shape, but also if it is sub-shape of main shape, check also it TopTools_ListOfShape aContextList; aContextList.Append(theContShape); @@ -1417,23 +1418,32 @@ bool Model_AttributeSelection::searchNewContext(std::shared_ptr Handle(TNaming_NamedShape) aNewNS; aModifIter.Label().FindAttribute(TNaming_NamedShape::GetID(), aNewNS); if (aNewNS->Evolution() == TNaming_MODIFY || aNewNS->Evolution() == TNaming_GENERATED) { - aResults.insert(aModifierObj); + if (aResultsSet.find(aModifierObj) == aResultsSet.end()) { + aResultsSet.insert(aModifierObj); + aResults.push_back(aModifierObj); + } } else if (aNewNS->Evolution() == TNaming_DELETE) { // a shape was deleted => result is empty - aResults.insert(ResultPtr()); + aResults.push_back(ResultPtr()); } else { // not-processed modification => don't support it continue; } } } // if there exist context composite and sub-result(s), leave only sub(s) - for(std::set::iterator aResIter = aResults.begin(); aResIter != aResults.end();) { + for(std::list::iterator aResIter = aResults.begin(); aResIter != aResults.end();) { ResultPtr aParent = ModelAPI_Tools::bodyOwner(*aResIter); for(; aParent.get(); aParent = ModelAPI_Tools::bodyOwner(aParent)) - if (aResults.count(aParent)) + if (aResultsSet.count(aParent)) break; - if (aParent.get()) { // erase from set, so, restart iteration - aResults.erase(aParent); - aResIter = aResults.begin(); + if (aParent.get()) { + aResultsSet.erase(aParent); + for(std::list::iterator anIt = aResults.begin(); anIt != aResults.end(); anIt++) { + if (*anIt == aParent) { + aResults.erase(anIt); + aResIter = aResults.begin(); // erase from set, so, restart iteration + break; + } + } } else aResIter++; } @@ -1458,7 +1468,7 @@ bool Model_AttributeSelection::searchNewContext(std::shared_ptr continue; if (aRefShape->impl().IsSame(theContShape)) { // add the new context result with the same shape - aResults.insert(aRefBody); + aResults.push_back(aRefBody); } } if (aResults.empty()) @@ -1468,7 +1478,6 @@ bool Model_AttributeSelection::searchNewContext(std::shared_ptr } if (myParent && myParent->isMakeCopy()) { // check there are copies before the new results, so, make a copy - std::set::iterator aResIter = aResults.begin(); std::list aCopyContext; std::list aCopyVals; // features between the new and the old: check the "Move" interface to get a copy @@ -1527,7 +1536,7 @@ bool Model_AttributeSelection::searchNewContext(std::shared_ptr return false; // iterate all results to find further modifications - std::set::iterator aResIter = aResults.begin(); + std::list::iterator aResIter = aResults.begin(); for(aResIter = aResults.begin(); aResIter != aResults.end(); aResIter++) { if (aResIter->get() != NULL) { ResultPtr aNewResObj = *aResIter; -- 2.30.2