- boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(
- theObject->data());
- myRef->Set(aData->label().Father()); // references to the feature 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::shared_ptr<Model_Document> aDoc =
+ std::dynamic_pointer_cast<Model_Document>(owner()->document());
+ myRef->Set(anObjLab); // references to the object label
+ // remove external link attributes (if any)
+ 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());
+ TCollection_AsciiString anEntry;
+ TDF_Tool::Entry(anObjLab, anEntry);
+ TDataStd_AsciiString::Set(myRef->Label(), anEntry);
+ }
+