1 // File: ModelAPI_AttributeDocRef.cxx
3 // Author: Mikhail PONIKAROV
5 #include "Model_AttributeDocRef.h"
6 #include "Model_Application.h"
7 #include "Model_Events.h"
8 #include <Events_Loop.h>
12 void Model_AttributeDocRef::setValue(boost::shared_ptr<ModelAPI_Document> theDoc)
14 TCollection_ExtendedString aNewID(theDoc->id().c_str());
15 if (myComment->Get() != aNewID) {
16 myComment->Set(TCollection_ExtendedString(theDoc->id().c_str()));
18 static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
19 Model_FeatureUpdatedMessage aMsg(owner(), anEvent);
20 Events_Loop::loop()->send(aMsg);
24 boost::shared_ptr<ModelAPI_Document> Model_AttributeDocRef::value()
26 if (myComment->Get().Length())
27 return Model_Application::getApplication()->getDocument(
28 TCollection_AsciiString(myComment->Get()).ToCString());
30 return boost::shared_ptr<ModelAPI_Document>();
33 Model_AttributeDocRef::Model_AttributeDocRef(TDF_Label& theLabel)
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 } else { // document was already referenced: try to set it as loaded by demand
40 Handle(Model_Application) anApp = Model_Application::getApplication();
41 string anID(TCollection_AsciiString(myComment->Get()).ToCString());
42 if (!anApp->hasDocument(anID)) {
43 anApp->setLoadByDemand(anID);