From 77d52a238fd0426b2e3e6b72dac4047c04a2b4c0 Mon Sep 17 00:00:00 2001 From: mpv Date: Wed, 29 Aug 2018 14:14:37 +0300 Subject: [PATCH] Fix for the issue #2607 : Bad naming of result when use renamed object as an input --- src/Model/Model_Objects.cpp | 28 +++++++++++++---------- src/ModelAPI/CMakeLists.txt | 1 + src/ModelAPI/Test/Test2607.py | 43 +++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 12 deletions(-) create mode 100644 src/ModelAPI/Test/Test2607.py diff --git a/src/Model/Model_Objects.cpp b/src/Model/Model_Objects.cpp index b3b217930..1fdd49ac3 100644 --- a/src/Model/Model_Objects.cpp +++ b/src/Model/Model_Objects.cpp @@ -1182,24 +1182,28 @@ bool Model_Objects::hasCustomName(DataPtr theFeatureData, std::string& theParentName) const { ResultBodyPtr aBodyRes = std::dynamic_pointer_cast(theFeatureData->owner()); - if (aBodyRes && std::dynamic_pointer_cast(theFeatureData)->label().Depth() < 7) { + if (aBodyRes) { // only for top-results (works for the cases when results are not yet added to the feature) FeaturePtr anOwner = ModelAPI_Feature::feature(theResult); // names of sub-solids in CompSolid should be default (for example, // result of boolean operation 'Boolean_1' is a CompSolid which is renamed to 'MyBOOL', // however, sub-elements of 'MyBOOL' should be named 'Boolean_1_1', 'Boolean_1_2' etc.) - std::ostringstream aDefaultName; - aDefaultName << anOwner->name(); - // compute default name of CompSolid (name of feature + index of CompSolid's result) - int aBodyResultIndex = 0; - const std::list& aResults = anOwner->results(); - std::list::const_iterator anIt = aResults.begin(); - for(; anIt != aResults.end(); ++anIt, ++aBodyResultIndex) - if(aBodyRes == *anIt) - break; - aDefaultName << "_" << (aBodyResultIndex + 1); - theParentName = aDefaultName.str(); + if (std::dynamic_pointer_cast(aBodyRes->data())->label().Depth() == 6) { + std::ostringstream aDefaultName; + // compute default name of CompSolid (name of feature + index of CompSolid's result) + int aBodyResultIndex = 0; + const std::list& aResults = anOwner->results(); + std::list::const_iterator anIt = aResults.begin(); + for (; anIt != aResults.end(); ++anIt, ++aBodyResultIndex) + if (aBodyRes == *anIt) + break; + aDefaultName << anOwner->name(); + aDefaultName << "_" << (aBodyResultIndex + 1); + theParentName = aDefaultName.str(); + } else { // just name of the parent result if it is deeper than just a sub-result + theParentName = aBodyRes->data()->name(); + } return false; } diff --git a/src/ModelAPI/CMakeLists.txt b/src/ModelAPI/CMakeLists.txt index 2c828ff96..3d7782365 100644 --- a/src/ModelAPI/CMakeLists.txt +++ b/src/ModelAPI/CMakeLists.txt @@ -207,4 +207,5 @@ ADD_UNIT_TESTS(TestConstants.py Test2510.py TestFeatureSelection_1.py TestFeatureSelection_2.py + Test2607.py ) diff --git a/src/ModelAPI/Test/Test2607.py b/src/ModelAPI/Test/Test2607.py new file mode 100644 index 000000000..c2eabb4b8 --- /dev/null +++ b/src/ModelAPI/Test/Test2607.py @@ -0,0 +1,43 @@ +## 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() +Cylinder_1 = model.addCylinder(Part_1_doc, model.selection("VERTEX", "PartSet/Origin"), model.selection("EDGE", "PartSet/OZ"), 10, 10) +Box_1 = model.addBox(Part_1_doc, 2, 20, 5) +AngularCopy_1 = model.addMultiRotation(Part_1_doc, [model.selection("COMPOUND", "all-in-Box_1")], model.selection("EDGE", "PartSet/OZ"), 90, 2) +AngularCopy_1.setName("Cross") +AngularCopy_1.result().setName("Cross") + +LinearCopy_1 = model.addMultiTranslation(Part_1_doc, [model.selection("COMPOUND", "all-in-Cross")], model.selection("EDGE", "PartSet/OZ"), -5, 2) + +model.end() + +# check names of the Linear copy: only higher level result must inherit the result name +assert(LinearCopy_1.result().name() == "Cross") +assert(LinearCopy_1.result().subResult(0).name() == "LinearCopy_1_1_1") +assert(LinearCopy_1.result().subResult(0).subResult(0).name() == "LinearCopy_1_1_1_1") +assert(LinearCopy_1.result().subResult(1).subResult(0).name() == "LinearCopy_1_1_2_1") +assert(LinearCopy_1.result().subResult(1).subResult(0).subResult(0).name() == "LinearCopy_1_1_2_1_1") +assert(LinearCopy_1.result().subResult(1).subResult(0).subResult(0).subResult(0).name() == "LinearCopy_1_1_2_1_1_1") -- 2.39.2