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
21     boost::shared_ptr<Model_Document> aDoc =
22       boost::dynamic_pointer_cast<Model_Document>(owner()->document());
23     myRef->Set(aData->label().Father());  // references to the feature label
24
25     owner()->data()->sendAttributeUpdated(this);
26   }
27 }
28
29 ObjectPtr Model_AttributeReference::value()
30 {
31   if (myIsInitialized) {
32     boost::shared_ptr<Model_Document> aDoc = boost::dynamic_pointer_cast<Model_Document>(
33         owner()->document());
34     if (aDoc) {
35       TDF_Label aRefLab = myRef->Get();
36       return aDoc->object(aRefLab);
37     }
38   }
39   // not initialized
40   return FeaturePtr();
41 }
42
43 Model_AttributeReference::Model_AttributeReference(TDF_Label& theLabel)
44 {
45   myIsInitialized = theLabel.FindAttribute(TDF_Reference::GetID(), myRef) == Standard_True;
46   if (!myIsInitialized) {
47     myRef = TDF_Reference::Set(theLabel, theLabel);  // not initialized references to itself
48   } else {
49     if (owner()) {
50       boost::shared_ptr<Model_Document> aDoc =
51         boost::dynamic_pointer_cast<Model_Document>(owner()->document());
52     }
53   }
54 }
55
56 void Model_AttributeReference::setObject(const boost::shared_ptr<ModelAPI_Object>& theObject)
57 {
58   if (owner() != theObject) {
59     ModelAPI_AttributeReference::setObject(theObject);
60     boost::shared_ptr<Model_Document> aDoc =
61       boost::dynamic_pointer_cast<Model_Document>(owner()->document());
62   }
63 }
64
65 Model_AttributeReference::~Model_AttributeReference()
66 {
67   boost::shared_ptr<Model_Document> aDoc =
68     boost::dynamic_pointer_cast<Model_Document>(owner()->document());
69   TDF_Label aLab = myRef->Get();
70 }