Salome HOME
Make compilable on Linux
[modules/shaper.git] / src / Model / Model_AttributeRefList.cpp
index c9722835887b00258b8e1acbac9797dac0dd06c1..b1fcda04632516822a6a4ae3c9abdbd4d95320dd 100644 (file)
@@ -18,10 +18,7 @@ void Model_AttributeRefList::append(ObjectPtr theObject)
   myRef->Append(aData->label().Father());  // store label of the object
   // do it before the transaction finish to make just created/removed objects know dependencies
   // and reference from composite feature is removed automatically
-  FeaturePtr anOwnerFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(owner());
-  if (anOwnerFeature.get()) {
-    aData->addBackReference(anOwnerFeature, id());
-  }
+  ADD_BACK_REF(theObject);
 
   owner()->data()->sendAttributeUpdated(this);
 }
@@ -32,6 +29,7 @@ void Model_AttributeRefList::remove(ObjectPtr theObject)
   if (theObject.get() != NULL) {
     aData = std::dynamic_pointer_cast<Model_Data>(theObject->data());
     myRef->Remove(aData->label().Father());
+    REMOVE_BACK_REF(theObject);
   }
   else { // in case of empty object remove, the first empty object is removed from the list
     std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(
@@ -42,6 +40,7 @@ void Model_AttributeRefList::remove(ObjectPtr theObject)
         ObjectPtr anObj = aDoc->object(aLIter.Value());
         if (anObj.get() == NULL) {
           myRef->Remove(aLIter.Value());
+          REMOVE_BACK_REF(theObject);
           break;
         }
       }
@@ -55,6 +54,14 @@ int Model_AttributeRefList::size() const
   return myRef->Extent();
 }
 
+bool Model_AttributeRefList::isInitialized()
+{
+  if (size() == 0) { // empty list is not initialized list: sketch will be not valid after add/undo
+    return false;
+  }
+  return ModelAPI_AttributeRefList::isInitialized();
+}
+
 list<ObjectPtr> Model_AttributeRefList::list()
 {
   std::list<ObjectPtr> aResult;