1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: ModelAPI_AttributeDocRef.cxx
5 // Author: Mikhail PONIKAROV
7 #include "Model_AttributeDocRef.h"
8 #include "Model_Application.h"
9 #include <ModelAPI_Feature.h>
10 #include <ModelAPI_Data.h>
14 void Model_AttributeDocRef::setValue(std::shared_ptr<ModelAPI_Document> 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);
24 std::shared_ptr<ModelAPI_Document> Model_AttributeDocRef::value()
29 Model_AttributeDocRef::Model_AttributeDocRef(TDF_Label& theLabel)
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);