- if (!myIsInitialized || value() != theFeature) {
- boost::shared_ptr<Model_Data> aData =
- boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
- if (myRef.IsNull()) {
- boost::shared_ptr<Model_Data> aMyData =
- boost::dynamic_pointer_cast<Model_Data>(owner()->data());
- myRef = TDF_Reference::Set(aMyData->label(), aData->label());
- } else {
- myRef->Set(aData->label());
+ // now allow to deselect in this attribute: extrusion from/to
+ //if(!theObject)
+ // return;
+ ObjectPtr aValue = value();
+ if (!myIsInitialized || aValue != theObject) {
+ REMOVE_BACK_REF(aValue);
+
+ TDF_Label anObjLab;
+ if (theObject.get() && theObject->data()->isValid()) {
+ std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(
+ theObject->data());
+ anObjLab = aData->label().Father(); // object label
+ }
+ // same document, use reference attribute
+ if (anObjLab.IsNull() || owner()->document() == theObject->document()) {
+
+ if (anObjLab.IsNull()) {
+ myRef->Set(myRef->Label());
+ } else {
+ 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
+ std::ostringstream anIdString; // string with document Id
+ anIdString<<theObject->document()->id();
+ TDataStd_Comment::Set(myRef->Label(), anIdString.str().c_str());
+ TCollection_AsciiString anEntry;
+ TDF_Tool::Entry(anObjLab, anEntry);
+ TDataStd_AsciiString::Set(myRef->Label(), anEntry);