Salome HOME
Issue #517: make sketch sub-elements are numbered (for naming) independently on featu...
[modules/shaper.git] / src / Model / Model_AttributeSelectionList.cpp
index 79eb5c714e12ee2e5565c209dfb271f3d793b389..f547a797fdcdbbc80bc10a844ed082a652a68d15 100644 (file)
@@ -1,6 +1,6 @@
 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
 
-// File:        Model_AttributeSelectionList.h
+// File:        Model_AttributeSelectionList.cpp
 // Created:     22 Oct 2014
 // Author:      Mikhail PONIKAROV
 
@@ -96,12 +96,28 @@ void Model_AttributeSelectionList::clear()
     mySize->Set(0);
     TDF_ChildIterator aSubIter(mySize->Label());
     for(; aSubIter.More(); aSubIter.Next()) {
-      aSubIter.Value().ForgetAllAttributes(Standard_True);
+      TDF_Label aLab = aSubIter.Value();
+      std::shared_ptr<Model_AttributeSelection> aNewAttr = 
+        std::shared_ptr<Model_AttributeSelection>(new Model_AttributeSelection(aLab));
+      if (owner()) {
+        aNewAttr->setObject(owner());
+      }
+      REMOVE_BACK_REF(aNewAttr->context());
+
+      aLab.ForgetAllAttributes(Standard_True);
     }
     owner()->data()->sendAttributeUpdated(this);
   }
 }
 
+bool Model_AttributeSelectionList::isInitialized()
+{
+  if (size() == 0) { // empty list is not initialized list: sketch will be not valid after add/undo
+    return false;
+  }
+  return ModelAPI_AttributeSelectionList::isInitialized();
+}
+
 Model_AttributeSelectionList::Model_AttributeSelectionList(TDF_Label& theLabel)
 {
   myIsInitialized = theLabel.FindAttribute(TDataStd_Integer::GetID(), mySize) == Standard_True;