Salome HOME
93c8af71346ce82569f5cea6cf867f8b0d8ac55b
[modules/shaper.git] / src / Model / Model_AttributeDocRef.cpp
1 // File:        ModelAPI_AttributeDocRef.cxx
2 // Created:     2 Apr 2014
3 // Author:      Mikhail PONIKAROV
4
5 #include "Model_AttributeDocRef.h"
6 #include "Model_Application.h"
7 #include "Model_Events.h"
8 #include <Events_Loop.h>
9
10 using namespace std;
11
12 void Model_AttributeDocRef::setValue(boost::shared_ptr<ModelAPI_Document> theDoc)
13 {
14   TCollection_ExtendedString aNewID(theDoc->id().c_str());
15   if (myComment->Get() != aNewID) {
16     myComment->Set(TCollection_ExtendedString(theDoc->id().c_str()));
17
18     static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
19     Model_FeatureUpdatedMessage aMsg(owner(), anEvent);
20     Events_Loop::loop()->send(aMsg);
21   }
22 }
23
24 boost::shared_ptr<ModelAPI_Document> Model_AttributeDocRef::value()
25 {
26   if (myComment->Get().Length())
27     return Model_Application::getApplication()->getDocument(
28       TCollection_AsciiString(myComment->Get()).ToCString());
29   // not initialized
30   return boost::shared_ptr<ModelAPI_Document>();
31 }
32
33 Model_AttributeDocRef::Model_AttributeDocRef(TDF_Label& theLabel)
34 {
35   // check the attribute could be already presented in this doc (after load document)
36   if (!theLabel.FindAttribute(TDataStd_Comment::GetID(), myComment)) {
37     // create attribute: not initialized by value yet, just empty string
38     myComment = TDataStd_Comment::Set(theLabel, "");
39   }
40 }