Salome HOME
Boost has been removed from code
[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 <ModelAPI_Feature.h>
8 #include <ModelAPI_Data.h>
9
10 using namespace std;
11
12 void Model_AttributeDocRef::setValue(std::shared_ptr<ModelAPI_Document> theDoc)
13 {
14   myDoc = theDoc;
15   TCollection_ExtendedString aNewID(theDoc->id().c_str());
16   if (!myIsInitialized || myComment->Get() != aNewID) {
17     myComment->Set(TCollection_ExtendedString(theDoc->id().c_str()));
18     owner()->data()->sendAttributeUpdated(this);
19   }
20 }
21
22 std::shared_ptr<ModelAPI_Document> Model_AttributeDocRef::value()
23 {
24   return myDoc;
25 }
26
27 Model_AttributeDocRef::Model_AttributeDocRef(TDF_Label& theLabel)
28 {
29   myIsInitialized = theLabel.FindAttribute(TDataStd_Comment::GetID(), myComment) == Standard_True;
30   if (!myIsInitialized) {
31     // create attribute: not initialized by value yet, just empty string
32     myComment = TDataStd_Comment::Set(theLabel, "");
33   } else {  // document was already referenced: try to set it as loaded by demand
34     Handle(Model_Application) anApp = Model_Application::getApplication();
35     string anID(TCollection_AsciiString(myComment->Get()).ToCString());
36     if (!anApp->hasDocument(anID)) {
37       anApp->setLoadByDemand(anID);
38     }
39   }
40 }