Salome HOME
Merge branch 'Dev_0.6.1' of newgeom:newgeom into Dev_0.6.1
[modules/shaper.git] / src / Model / Model_AttributeDocRef.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        ModelAPI_AttributeDocRef.cxx
4 // Created:     2 Apr 2014
5 // Author:      Mikhail PONIKAROV
6
7 #include "Model_AttributeDocRef.h"
8 #include "Model_Application.h"
9 #include <ModelAPI_Feature.h>
10 #include <ModelAPI_Data.h>
11
12 using namespace std;
13
14 void Model_AttributeDocRef::setValue(std::shared_ptr<ModelAPI_Document> theDoc)
15 {
16   myDoc = theDoc;
17   TCollection_ExtendedString aNewID(theDoc->id().c_str());
18   if (!myIsInitialized || myComment->Get() != aNewID) {
19     myComment->Set(TCollection_ExtendedString(theDoc->id().c_str()));
20     owner()->data()->sendAttributeUpdated(this);
21   }
22 }
23
24 std::shared_ptr<ModelAPI_Document> Model_AttributeDocRef::value()
25 {
26   return myDoc;
27 }
28
29 Model_AttributeDocRef::Model_AttributeDocRef(TDF_Label& theLabel)
30 {
31   myIsInitialized = theLabel.FindAttribute(TDataStd_Comment::GetID(), myComment) == Standard_True;
32   if (!myIsInitialized) {
33     // create attribute: not initialized by value yet, just empty string
34     myComment = TDataStd_Comment::Set(theLabel, "");
35   } else {  // document was already referenced: try to set it as loaded by demand
36     Handle(Model_Application) anApp = Model_Application::getApplication();
37     string anID(TCollection_AsciiString(myComment->Get()).ToCString());
38     if (!anApp->hasDocument(anID)) {
39       anApp->setLoadByDemand(anID);
40     }
41   }
42 }