1 // File: ModelAPI_AttributeRefAttr.cxx
3 // Author: Mikhail PONIKAROV
5 #include "Model_AttributeRefAttr.h"
6 #include "Model_Application.h"
7 #include "Model_Data.h"
8 #include <ModelAPI_Feature.h>
12 bool Model_AttributeRefAttr::isObject()
14 return myID->Get().Length() == 0;
17 void Model_AttributeRefAttr::setAttr(boost::shared_ptr<ModelAPI_Attribute> theAttr)
19 boost::shared_ptr<Model_Data> aData =
20 boost::dynamic_pointer_cast<Model_Data>(theAttr->owner()->data());
21 string anID = aData->id(theAttr);
22 if (myIsInitialized && object() == theAttr->owner() && myID->Get().IsEqual(anID.c_str()))
23 return; // nothing is changed
25 myRef->Set(aData->label());
26 myID->Set(aData->id(theAttr).c_str());
27 owner()->data()->sendAttributeUpdated(this);
30 boost::shared_ptr<ModelAPI_Attribute> Model_AttributeRefAttr::attr()
32 ObjectPtr anObj = object();
34 boost::shared_ptr<Model_Data> aData =
35 boost::dynamic_pointer_cast<Model_Data>(anObj->data());
36 return aData->attribute(TCollection_AsciiString(myID->Get()).ToCString());
39 return boost::shared_ptr<ModelAPI_Attribute>();
42 void Model_AttributeRefAttr::setObject(ObjectPtr theObject)
44 if (!myIsInitialized || myID->Get().Length() != 0 || object() != theObject) {
45 boost::shared_ptr<Model_Data> aData =
46 boost::dynamic_pointer_cast<Model_Data>(theObject->data());
47 myRef->Set(aData->label());
48 myID->Set(""); // feature is identified by the empty ID
49 owner()->data()->sendAttributeUpdated(this);
53 ObjectPtr Model_AttributeRefAttr::object()
55 if (myRef->Get() != myRef->Label()) { // initialized
56 boost::shared_ptr<Model_Document> aDoc =
57 boost::dynamic_pointer_cast<Model_Document>(owner()->document());
59 TDF_Label aRefLab = myRef->Get();
60 TDF_Label anObjLab = aRefLab.Father();
61 return aDoc->object(aRefLab);
68 Model_AttributeRefAttr::Model_AttributeRefAttr(TDF_Label& theLabel)
70 myIsInitialized = theLabel.FindAttribute(TDataStd_Comment::GetID(), myID) == Standard_True;
71 if (!myIsInitialized) {
72 // create attribute: not initialized by value yet
73 myID = TDataStd_Comment::Set(theLabel, "");
74 myRef = TDF_Reference::Set(theLabel, theLabel); // not initialized: reference to itself
76 theLabel.FindAttribute(TDF_Reference::GetID(), myRef);