Salome HOME
dfb54c5f10331298e535624aba6457cb10ee2cf9
[modules/shaper.git] / src / Model / Model_AttributeReference.cpp
1 // File:        ModelAPI_AttributeReference.cxx
2 // Created:     2 Apr 2014
3 // Author:      Mikhail PONIKAROV
4
5 #include "Model_AttributeReference.h"
6 #include "Model_Application.h"
7 #include "Model_Events.h"
8 #include "Model_Data.h"
9 #include <ModelAPI_Feature.h>
10
11 using namespace std;
12
13 void Model_AttributeReference::setValue(ObjectPtr theObject)
14 {
15   if (!myIsInitialized || value() != theObject) {
16     boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(
17         theObject->data());
18     myRef->Set(aData->label().Father());  // references to the feature label
19     owner()->data()->sendAttributeUpdated(this);
20   }
21 }
22
23 ObjectPtr Model_AttributeReference::value()
24 {
25   if (myIsInitialized) {
26     boost::shared_ptr<Model_Document> aDoc = boost::dynamic_pointer_cast<Model_Document>(
27         owner()->document());
28     if (aDoc) {
29       TDF_Label aRefLab = myRef->Get();
30       return aDoc->object(aRefLab);
31     }
32   }
33   // not initialized
34   return FeaturePtr();
35 }
36
37 Model_AttributeReference::Model_AttributeReference(TDF_Label& theLabel)
38 {
39   myIsInitialized = theLabel.FindAttribute(TDF_Reference::GetID(), myRef) == Standard_True;
40   if (!myIsInitialized)
41     myRef = TDF_Reference::Set(theLabel, theLabel);  // not initialized references to itself
42 }