Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[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(!theObject)
16     return;
17   if (!myIsInitialized || value() != theObject) {
18     boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(
19         theObject->data());
20     myRef->Set(aData->label().Father());  // references to the feature label
21     owner()->data()->sendAttributeUpdated(this);
22   }
23 }
24
25 ObjectPtr Model_AttributeReference::value()
26 {
27   if (myIsInitialized) {
28     boost::shared_ptr<Model_Document> aDoc = boost::dynamic_pointer_cast<Model_Document>(
29         owner()->document());
30     if (aDoc) {
31       TDF_Label aRefLab = myRef->Get();
32       return aDoc->object(aRefLab);
33     }
34   }
35   // not initialized
36   return FeaturePtr();
37 }
38
39 Model_AttributeReference::Model_AttributeReference(TDF_Label& theLabel)
40 {
41   myIsInitialized = theLabel.FindAttribute(TDF_Reference::GetID(), myRef) == Standard_True;
42   if (!myIsInitialized)
43     myRef = TDF_Reference::Set(theLabel, theLabel);  // not initialized references to itself
44 }