Salome HOME
Fix for the issue #2573: Wrong position of created part
[modules/shaper.git] / src / Model / Model_Objects.cpp
index 199b249c34ce234e396e11a4670ec7960bfe3fa7..21120233efc24c06231694386b37440745599082 100644 (file)
@@ -576,7 +576,8 @@ ObjectPtr Model_Objects::object(TDF_Label theLabel)
           if (aSub.get()) {
             std::shared_ptr<Model_Data> aSubData = std::dynamic_pointer_cast<Model_Data>(
               aSub->data());
-            if (aSubData->label().Father().IsEqual(aSubLab.ChangeValue())) {
+            const TDF_Label& aSubLabVal = aSubLab.ChangeValue();
+            if (aSubData->label().Father().IsEqual(aSubLabVal)) {
               aCurrentResult = aSub;
               break;
             }
@@ -588,7 +589,8 @@ ObjectPtr Model_Objects::object(TDF_Label theLabel)
         const std::list<ResultPtr>& aResults = aFeature->results();
         std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.cbegin();
         for(; aRIter != aResults.cend(); aRIter++) {
-          std::shared_ptr<Model_Data> aResData = std::dynamic_pointer_cast<Model_Data>((*aRIter)->data());
+          std::shared_ptr<Model_Data> aResData =
+            std::dynamic_pointer_cast<Model_Data>((*aRIter)->data());
           if (aResData->label().Father().IsEqual(aSubLab.ChangeValue())) {
             aCurrentResult = *aRIter;
             break;
@@ -682,8 +684,8 @@ std::shared_ptr<ModelAPI_Object> Model_Objects::parent(
   if (theChild.get()) {
     std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(theChild->data());
     TDF_Label aLab = aData->label();
-    if (!aLab.IsNull() && aLab.Depth() > 1) {
-      ObjectPtr anObj = object(aLab.Father().Father());
+    if (!aLab.IsNull() && aLab.Depth() > 2) {
+      ObjectPtr anObj = object(aLab.Father().Father().Father());
       return anObj;
     }
   }
@@ -1180,7 +1182,8 @@ bool Model_Objects::hasCustomName(DataPtr theFeatureData,
                                   std::string& theParentName) const
 {
   ResultBodyPtr aBodyRes = std::dynamic_pointer_cast<ModelAPI_ResultBody>(theFeatureData->owner());
-  if(aBodyRes) {
+  if (aBodyRes && std::dynamic_pointer_cast<Model_Data>(theFeatureData)->label().Depth() < 7) {
+    // 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,