1 // File: ModelAPI_AttributeDocRef.cxx
3 // Author: Mikhail PONIKAROV
5 #include "Model_AttributeDocRef.h"
6 #include "Model_Application.h"
7 #include <ModelAPI_Feature.h>
8 #include <ModelAPI_Data.h>
12 void Model_AttributeDocRef::setValue(boost::shared_ptr<ModelAPI_Document> theDoc)
14 TCollection_ExtendedString aNewID(theDoc->id().c_str());
15 if (!myIsInitialized || myComment->Get() != aNewID) {
16 myComment->Set(TCollection_ExtendedString(theDoc->id().c_str()));
17 owner()->data()->sendAttributeUpdated(this);
21 boost::shared_ptr<ModelAPI_Document> Model_AttributeDocRef::value()
23 if (myComment->Get().Length())
24 return Model_Application::getApplication()->getDocument(
25 TCollection_AsciiString(myComment->Get()).ToCString());
27 return boost::shared_ptr<ModelAPI_Document>();
30 Model_AttributeDocRef::Model_AttributeDocRef(TDF_Label& theLabel)
32 myIsInitialized = theLabel.FindAttribute(TDataStd_Comment::GetID(), myComment) == Standard_True;
33 if (!myIsInitialized) {
34 // create attribute: not initialized by value yet, just empty string
35 myComment = TDataStd_Comment::Set(theLabel, "");
36 } else { // document was already referenced: try to set it as loaded by demand
37 Handle(Model_Application) anApp = Model_Application::getApplication();
38 string anID(TCollection_AsciiString(myComment->Get()).ToCString());
39 if (!anApp->hasDocument(anID)) {
40 anApp->setLoadByDemand(anID);