+ eraseHash();
+ if (theObject.get() != NULL) {
+ if (owner()->document() == theObject->document()) {
+ std::shared_ptr<Model_Data> aData;
+ aData = std::dynamic_pointer_cast<Model_Data>(theObject->data());
+ myRef->Remove(aData->label().Father());
+ REMOVE_BACK_REF(theObject);
+ owner()->data()->sendAttributeUpdated(this);
+ } else {
+ // LCOV_EXCL_START
+ // create new lists because for the current moment remove one of the duplicated elements
+ // from the list is buggy
+ TDF_LabelList anOldList = myRef->List();
+ myRef->Clear();
+ TDataStd_ListOfExtendedString anOldExts = myExtDocRef->List();
+ myExtDocRef->Clear();
+
+ std::ostringstream anIdString; // string with document Id
+ anIdString<<theObject->document()->id();
+ std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(theObject->data());
+ TCollection_AsciiString anEntry;
+ TDF_Tool::Entry(aData->label().Father(), anEntry);
+ bool aFound = false;
+ TDataStd_ListIteratorOfListOfExtendedString anExtIter(anOldExts);
+ for (TDF_ListIteratorOfLabelList aLIter(anOldList); aLIter.More(); aLIter.Next()) {
+ if (aLIter.Value() == myRef->Label()) {
+ if (anExtIter.Value() == anIdString.str().c_str()) {
+ TDataStd_ListIteratorOfListOfExtendedString anExtIter2 = anExtIter;
+ anExtIter2.Next();
+ if (anExtIter2.Value() == anEntry) { // fully matches, so, remove(don't copy)
+ aFound = true;
+ continue;
+ }
+ }
+ myExtDocRef->Append(anExtIter.Value());
+ anExtIter.Next();
+ myExtDocRef->Append(anExtIter.Value());
+ anExtIter.Next();
+ }
+ myRef->Append(aLIter.Value());
+ }
+ if (aFound) {
+ REMOVE_BACK_REF(theObject);
+ owner()->data()->sendAttributeUpdated(this);
+ }
+ // LCOV_EXCL_STOP
+ }
+ }
+ 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>(
+ owner()->document());
+ if (aDoc) {
+ const TDF_LabelList& aList = myRef->List();
+ for (TDF_ListIteratorOfLabelList aLIter(aList); aLIter.More(); aLIter.Next()) {
+ ObjectPtr anObj = aDoc->objects()->object(aLIter.Value());
+ if (anObj.get() == NULL) {
+ myRef->Remove(aLIter.Value());
+ REMOVE_BACK_REF(theObject);
+ owner()->data()->sendAttributeUpdated(this);
+ break;
+ }
+ }
+ }
+ }
+}