Salome HOME
Copyright update 2022
[modules/shaper.git] / src / Model / Model_AttributeSelection.cpp
index 432c6f1c2e7740d37293b040c46aafd89823e727..59c47cca2996cf49f55e8463308dcfc657820beb 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2021  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2022  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
@@ -454,10 +454,11 @@ bool Model_AttributeSelection::isInitialized()
 
 Model_AttributeSelection::Model_AttributeSelection(TDF_Label& theLabel)
 : myRef(theLabel),
+  myTmpCenterType(NOT_CENTER),
+  myParent(NULL),
   myIsGeometricalSelection(false)
 {
   myIsInitialized = myRef.isInitialized();
-  myParent = NULL;
 }
 
 void Model_AttributeSelection::setID(const std::string theID)
@@ -2011,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();
   }