1 // File: ModelAPI_AttributeRefAttr.cxx
3 // Author: Mikhail PONIKAROV
5 #include "Model_AttributeRefAttr.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_AttributeRefAttr::setValue(boost::shared_ptr<ModelAPI_Attribute> theAttr)
16 if (value() != theAttr) {
17 boost::shared_ptr<Model_Data> aData =
18 boost::dynamic_pointer_cast<Model_Data>(theAttr->feature()->data());
20 boost::shared_ptr<Model_Data> aMyData =
21 boost::dynamic_pointer_cast<Model_Data>(feature()->data());
22 TDF_Reference::Set(aMyData->label(), aData->label());
24 myRef->Set(aData->label());
26 myID->Set(aData->id(theAttr).c_str());
28 static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
29 Model_FeatureUpdatedMessage aMsg(feature(), anEvent);
30 Events_Loop::loop()->send(aMsg);
34 boost::shared_ptr<ModelAPI_Attribute> Model_AttributeRefAttr::value()
36 if (!myRef.IsNull()) {
37 boost::shared_ptr<Model_Document> aDoc =
38 boost::dynamic_pointer_cast<Model_Document>(feature()->document());
40 TDF_Label aRefLab = myRef->Get();
41 TDF_Label aFeatureLab = aRefLab.Father();
42 boost::shared_ptr<Model_Data> aData =
43 boost::dynamic_pointer_cast<Model_Data>(aDoc->feature(aRefLab)->data());
44 return aData->attribute(TCollection_AsciiString(myID->Get()).ToCString());
48 return boost::shared_ptr<ModelAPI_Attribute>();
51 Model_AttributeRefAttr::Model_AttributeRefAttr(TDF_Label& theLabel)
53 // check the attribute could be already presented in this doc (after load document)
54 if (!theLabel.FindAttribute(TDataStd_Comment::GetID(), myID)) {
55 // create attribute: not initialized by value yet
56 TDataStd_Comment::Set(theLabel, "");
57 // reference attribute is not set to the label!