+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
// File: ModelAPI_AttributeReference.cxx
// Created: 2 Apr 2014
// Author: Mikhail PONIKAROV
if(!theObject)
return;
if (!myIsInitialized || value() != theObject) {
- std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(
- theObject->data());
- TDF_Label anObjLab = aData->label().Father(); // object label
+ std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(
+ theObject->data());
+ TDF_Label anObjLab = aData->label().Father(); // object label
if (owner()->document() == theObject->document()) { // same document, use reference attribute
std::dynamic_pointer_cast<Model_Document>(owner()->document());
myRef->Set(anObjLab); // references to the object label
// remove external link attributes (if any)
- anObjLab.ForgetAttribute(TDataStd_Comment::GetID());
- anObjLab.ForgetAttribute(TDataStd_AsciiString::GetID());
+ myRef->Label().ForgetAttribute(TDataStd_Comment::GetID());
+ myRef->Label().ForgetAttribute(TDataStd_AsciiString::GetID());
} else { // different document: store the document name (comment) and entry (string): external
// if these attributes exist, the link is external: keep reference to access the label
TDataStd_Comment::Set(myRef->Label(), theObject->document()->id().c_str());
TDF_Tool::Entry(anObjLab, anEntry);
TDataStd_AsciiString::Set(myRef->Label(), anEntry);
}
+ // 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());
+ }
owner()->data()->sendAttributeUpdated(this);
}
owner()->document());
if (aDoc) {
TDF_Label aRefLab = myRef->Get();
- return aDoc->object(aRefLab);
+ if (!aRefLab.IsNull()) { // it may happen with old document, issue #285
+ return aDoc->object(aRefLab);
+ }
}
}
}