]> SALOME platform Git repositories - modules/shaper.git/blob - src/Model/Model_AttributeRefAttr.cpp
Salome HOME
Merge branch 'master' of newgeom:newgeom
[modules/shaper.git] / src / Model / Model_AttributeRefAttr.cpp
1 // File:        ModelAPI_AttributeRefAttr.cxx
2 // Created:     2 Apr 2014
3 // Author:      Mikhail PONIKAROV
4
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>
11
12 using namespace std;
13
14 void Model_AttributeRefAttr::setValue(boost::shared_ptr<ModelAPI_Attribute> theAttr)
15 {
16   if (value() != theAttr) {
17     boost::shared_ptr<Model_Data> aData = 
18       boost::dynamic_pointer_cast<Model_Data>(theAttr->feature()->data());
19     if (myRef.IsNull()) {
20       boost::shared_ptr<Model_Data> aMyData = 
21         boost::dynamic_pointer_cast<Model_Data>(feature()->data());
22       TDF_Reference::Set(aMyData->label(), aData->label());
23     } else {
24       myRef->Set(aData->label());
25     }
26     myID->Set(aData->id(theAttr).c_str());
27
28     static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
29     Model_FeatureUpdatedMessage aMsg(feature(), anEvent);
30     Events_Loop::loop()->send(aMsg);
31   }
32 }
33
34 boost::shared_ptr<ModelAPI_Attribute> Model_AttributeRefAttr::value()
35 {
36   if (!myRef.IsNull()) {
37     boost::shared_ptr<Model_Document> aDoc = 
38       boost::dynamic_pointer_cast<Model_Document>(feature()->document());
39     if (aDoc) {
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());
45     }
46   }
47   // not initialized
48   return boost::shared_ptr<ModelAPI_Attribute>();
49 }
50
51 Model_AttributeRefAttr::Model_AttributeRefAttr(TDF_Label& theLabel)
52 {
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!
58   }
59 }