Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / Model / Model_AttributeReference.cpp
index dfb54c5f10331298e535624aba6457cb10ee2cf9..134516972b2a2eecfacab366f3bb46f9204d5a8c 100644 (file)
@@ -12,10 +12,18 @@ using namespace std;
 
 void Model_AttributeReference::setValue(ObjectPtr theObject)
 {
+  if(!theObject)
+    return;
   if (!myIsInitialized || value() != theObject) {
     boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(
         theObject->data());
+
+    boost::shared_ptr<Model_Document> aDoc =
+      boost::dynamic_pointer_cast<Model_Document>(owner()->document());
+    if (aDoc) aDoc->objectIsNotReferenced(aDoc->object(myRef->Get()));
     myRef->Set(aData->label().Father());  // references to the feature label
+    boost::shared_dynamic_cast<Model_Document>(owner()->document())->objectIsReferenced(theObject);
+
     owner()->data()->sendAttributeUpdated(this);
   }
 }
@@ -37,6 +45,31 @@ ObjectPtr Model_AttributeReference::value()
 Model_AttributeReference::Model_AttributeReference(TDF_Label& theLabel)
 {
   myIsInitialized = theLabel.FindAttribute(TDF_Reference::GetID(), myRef) == Standard_True;
-  if (!myIsInitialized)
+  if (!myIsInitialized) {
     myRef = TDF_Reference::Set(theLabel, theLabel);  // not initialized references to itself
+  } else {
+    if (owner()) {
+      boost::shared_ptr<Model_Document> aDoc =
+        boost::dynamic_pointer_cast<Model_Document>(owner()->document());
+      if (aDoc) aDoc->objectIsReferenced(aDoc->object(myRef->Get()));
+    }
+  }
+}
+
+void Model_AttributeReference::setObject(const boost::shared_ptr<ModelAPI_Object>& theObject)
+{
+  if (owner() != theObject) {
+    ModelAPI_AttributeReference::setObject(theObject);
+    boost::shared_ptr<Model_Document> aDoc =
+      boost::dynamic_pointer_cast<Model_Document>(owner()->document());
+    if (aDoc) aDoc->objectIsReferenced(aDoc->object(myRef->Get()));
+  }
+}
+
+Model_AttributeReference::~Model_AttributeReference()
+{
+  boost::shared_ptr<Model_Document> aDoc =
+    boost::dynamic_pointer_cast<Model_Document>(owner()->document());
+  TDF_Label aLab = myRef->Get();
+  if (aDoc && !aLab.IsNull()) aDoc->objectIsNotReferenced(aDoc->object(myRef->Get()));
 }