1 // File: ModelAPI_AttributeReference.cxx
3 // Author: Mikhail PONIKAROV
5 #include "Model_AttributeReference.h"
6 #include "Model_Application.h"
7 #include "Model_Events.h"
8 #include "Model_Data.h"
9 #include <ModelAPI_Feature.h>
13 void Model_AttributeReference::setValue(ObjectPtr theObject)
17 if (!myIsInitialized || value() != theObject) {
18 boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(
21 boost::shared_ptr<Model_Document> aDoc =
22 boost::dynamic_pointer_cast<Model_Document>(owner()->document());
23 if (aDoc) aDoc->objectIsNotReferenced(aDoc->object(myRef->Label()));
24 myRef->Set(aData->label().Father()); // references to the feature label
25 boost::shared_dynamic_cast<Model_Document>(owner()->document())->objectIsReferenced(theObject);
27 owner()->data()->sendAttributeUpdated(this);
31 ObjectPtr Model_AttributeReference::value()
33 if (myIsInitialized) {
34 boost::shared_ptr<Model_Document> aDoc = boost::dynamic_pointer_cast<Model_Document>(
37 TDF_Label aRefLab = myRef->Get();
38 return aDoc->object(aRefLab);
45 Model_AttributeReference::Model_AttributeReference(TDF_Label& theLabel)
47 myIsInitialized = theLabel.FindAttribute(TDF_Reference::GetID(), myRef) == Standard_True;
48 if (!myIsInitialized) {
49 myRef = TDF_Reference::Set(theLabel, theLabel); // not initialized references to itself
51 boost::shared_ptr<Model_Document> aDoc =
52 boost::dynamic_pointer_cast<Model_Document>(owner()->document());
53 if (aDoc) aDoc->objectIsReferenced(aDoc->object(myRef->Label()));
57 Model_AttributeReference::~Model_AttributeReference()
59 boost::shared_ptr<Model_Document> aDoc =
60 boost::dynamic_pointer_cast<Model_Document>(owner()->document());
61 if (aDoc) aDoc->objectIsNotReferenced(aDoc->object(myRef->Label()));