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>
10 #include <Events_Loop.h>
14 void Model_AttributeReference::setValue(FeaturePtr theFeature)
16 if (value() != theFeature) {
17 boost::shared_ptr<Model_Data> aData =
18 boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
20 boost::shared_ptr<Model_Data> aMyData =
21 boost::dynamic_pointer_cast<Model_Data>(owner()->data());
22 myRef = TDF_Reference::Set(aMyData->label(), aData->label());
24 myRef->Set(aData->label());
27 static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
28 Model_FeatureUpdatedMessage aMsg(owner(), anEvent);
29 Events_Loop::loop()->send(aMsg);
33 FeaturePtr Model_AttributeReference::value()
35 if (!myRef.IsNull()) {
36 boost::shared_ptr<Model_Document> aDoc =
37 boost::dynamic_pointer_cast<Model_Document>(owner()->document());
39 TDF_Label aRefLab = myRef->Get();
40 return aDoc->feature(aRefLab);
47 Model_AttributeReference::Model_AttributeReference(TDF_Label& theLabel)
49 // check the attribute could be already presented in this doc (after load document)
50 if (!theLabel.FindAttribute(TDF_Reference::GetID(), myRef)) {
51 // create attribute: not initialized by value yet: attribute is not set to the label!