- if (value() != theAttr) {
- boost::shared_ptr<Model_Data> aData =
- boost::dynamic_pointer_cast<Model_Data>(theAttr->feature()->data());
- if (myRef.IsNull()) {
- boost::shared_ptr<Model_Data> aMyData =
- boost::dynamic_pointer_cast<Model_Data>(feature()->data());
- TDF_Reference::Set(aMyData->label(), aData->label());
- } else {
- myRef->Set(aData->label());
- }
- myID->Set(aData->id(theAttr).c_str());
+ std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(
+ theAttr->owner()->data());
+ std::string anID = aData->id(theAttr);
+ ObjectPtr anObj = object();
+ if (myIsInitialized && anObj == theAttr->owner() && myID->Get().IsEqual(anID.c_str()))
+ return; // nothing is changed
+ REMOVE_BACK_REF(anObj);
+ myRef->Set(aData->label().Father());
+ myID->Set(aData->id(theAttr).c_str());
+ ADD_BACK_REF(theAttr->owner());
+ owner()->data()->sendAttributeUpdated(this);
+}
+
+std::shared_ptr<ModelAPI_Attribute> Model_AttributeRefAttr::attr()
+{
+ ObjectPtr anObj = object();
+ if (anObj && anObj->data()) {
+ std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(anObj->data());
+ return aData->attribute(TCollection_AsciiString(myID->Get()).ToCString());
+ }
+ // not initialized
+ return std::shared_ptr<ModelAPI_Attribute>();
+}
+
+void Model_AttributeRefAttr::setObject(ObjectPtr theObject)
+{
+ // the back reference from the previous object to the attribute should be removed
+ ObjectPtr anObject = object();
+ if (theObject.get() && (!myIsInitialized || myID->Get().Length() != 0 || object() != theObject)) {
+ REMOVE_BACK_REF(anObject);
+
+ std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(
+ theObject->data());
+ myRef->Set(aData->label().Father());
+ myID->Set(""); // feature is identified by the empty ID