Salome HOME
[bos #24727] [CEA] Selection mechanism not working on a re-opened study
[modules/shaper.git] / src / Model / Model_AttributeSelection.cpp
index 9f48443fa5e4aa95eecb068156e18a72a393133e..7874924922a162e635da723e048cc61ef21cf5d6 100644 (file)
@@ -2012,6 +2012,23 @@ bool Model_AttributeSelection::restoreContext(std::wstring theName,
     }
   }
 
+  // Fix for opened study (aDoc->myNamingNames is empty)
+  if (theValue.IsNull() && aCont->groupName() != ModelAPI_ResultConstruction::group()) {
+    std::wstring::size_type aSlash = aSubShapeName.rfind(L'/');
+    if (aSlash != std::wstring::npos) {
+      std::wstring aCompName = aSubShapeName.substr(aSlash + 1);
+      TDF_Label aLab = std::dynamic_pointer_cast<Model_Data>(aCont->data())->shapeLab();
+      TDF_ChildIDIterator aSubNames (aLab, TDataStd_Name::GetID());
+      for (; aSubNames.More(); aSubNames.Next()) {
+        if (Handle(TDataStd_Name)::DownCast(aSubNames.Value())->Get().IsEqual(aCompName.c_str())) {
+          theValue = aSubNames.Value()->Label();
+          aDoc->addNamingName(theValue, aSubShapeName);
+          break;
+        }
+      }
+    }
+  }
+
   if (aCont.get()) {
     theContext = std::dynamic_pointer_cast<Model_Data>(aCont->data())->label();
   }