]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Fix for the issue #2607 : Bad naming of result when use renamed object as an input
authormpv <mpv@opencascade.com>
Wed, 29 Aug 2018 11:14:37 +0000 (14:14 +0300)
committermpv <mpv@opencascade.com>
Wed, 29 Aug 2018 11:14:52 +0000 (14:14 +0300)
src/Model/Model_Objects.cpp
src/ModelAPI/CMakeLists.txt
src/ModelAPI/Test/Test2607.py [new file with mode: 0644]

index b3b21793043789b434d0c4b7a51e2f4123786290..1fdd49ac3c83d260168fe0fcf01059cd7ba0bf4f 100644 (file)
@@ -1182,24 +1182,28 @@ bool Model_Objects::hasCustomName(DataPtr theFeatureData,
                                   std::string& theParentName) const
 {
   ResultBodyPtr aBodyRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theFeatureData->owner());
-  if (aBodyRes && std::dynamic_pointer_cast<Model_Data>(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<ResultPtr>& aResults = anOwner->results();
-    std::list<ResultPtr>::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<Model_Data>(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<ResultPtr>& aResults = anOwner->results();
+      std::list<ResultPtr>::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;
   }
 
index 2c828ff9656955c292ef6510c814cfbc95374a11..3d7782365c07471eb4112a174888f8cb8cc2639a 100644 (file)
@@ -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 (file)
index 0000000..c2eabb4
--- /dev/null
@@ -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<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()
+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")