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 = boost::dynamic_pointer_cast<Model_Data>(
20 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().Father());
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 = boost::dynamic_pointer_cast<Model_Data>(anObj->data());
35 return aData->attribute(TCollection_AsciiString(myID->Get()).ToCString());
38 return boost::shared_ptr<ModelAPI_Attribute>();
41 void Model_AttributeRefAttr::setObject(ObjectPtr theObject)
43 if (!myIsInitialized || myID->Get().Length() != 0 || object() != theObject) {
44 boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(
46 myRef->Set(aData->label().Father());
47 myID->Set(""); // feature is identified by the empty ID
48 owner()->data()->sendAttributeUpdated(this);
52 ObjectPtr Model_AttributeRefAttr::object()
54 if (myRef->Get() != myRef->Label()) { // initialized
55 boost::shared_ptr<Model_Document> aDoc = boost::dynamic_pointer_cast<Model_Document>(
58 TDF_Label aRefLab = myRef->Get();
59 return aDoc->object(aRefLab);
66 Model_AttributeRefAttr::Model_AttributeRefAttr(TDF_Label& theLabel)
68 myIsInitialized = theLabel.FindAttribute(TDataStd_Comment::GetID(), myID) == Standard_True;
69 if (!myIsInitialized) {
70 // create attribute: not initialized by value yet
71 myID = TDataStd_Comment::Set(theLabel, "");
72 myRef = TDF_Reference::Set(theLabel, theLabel); // not initialized: reference to itself
74 theLabel.FindAttribute(TDF_Reference::GetID(), myRef);