Salome HOME
updated copyright message
[modules/shaper.git] / src / Model / Model_AttributeSelection.cpp
index 9f48443fa5e4aa95eecb068156e18a72a393133e..9ee407686c351f148d2d3c3668dd348fee298c8d 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2021  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -785,23 +785,6 @@ std::wstring Model_AttributeSelection::namingName(const std::wstring& theDefault
   if(!this->isInitialized())
     return !theDefaultName.empty() ? theDefaultName : aName;
 
-  // not argument has not parametric name (filters)
-  if (!this->isArgument() || (myParent && !myParent->isArgument())) {
-    GeomShapePtr aShape = value();
-    if (!aShape.get() && context().get())
-      aShape = context()->shape();
-    std::wstring aNotArgName;
-    if (aShape.get()) {
-      aNotArgName = Locale::Convert::toWString(aShape->shapeTypeStr());
-      if (myParent) {
-        std::wostringstream aStream;
-        aStream << "_" << selectionLabel().Father().Tag();
-        aNotArgName += aStream.str();
-      }
-    }
-    return aNotArgName;
-  }
-
   CenterType aCenterType = NOT_CENTER;
   std::shared_ptr<GeomAPI_Shape> aSubSh = internalValue(aCenterType);
 
@@ -2012,6 +1995,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();
   }