Salome HOME
Fix sketcher bugs
[modules/shaper.git] / src / Model / Model_AttributeReference.cpp
index adcfe4ab46e0b1d62d038f8408dd7568a029afe7..a5540e7415845b1791a2860e8b40cfe6a8d30527 100644 (file)
@@ -7,37 +7,33 @@
 #include "Model_Events.h"
 #include "Model_Data.h"
 #include <ModelAPI_Feature.h>
-#include <Events_Loop.h>
 
 using namespace std;
 
-void Model_AttributeReference::setValue(FeaturePtr theFeature)
+void Model_AttributeReference::setValue(ObjectPtr theObject)
 {
-  if (value() != theFeature) {
+  if (!myIsInitialized || value() != theObject) {
     boost::shared_ptr<Model_Data> aData = 
-      boost::dynamic_pointer_cast<Model_Data>(theFeature->data());
+      boost::dynamic_pointer_cast<Model_Data>(theObject->data());
     if (myRef.IsNull()) {
       boost::shared_ptr<Model_Data> aMyData = 
         boost::dynamic_pointer_cast<Model_Data>(owner()->data());
-      myRef = TDF_Reference::Set(aMyData->label(), aData->label());
+      myRef = TDF_Reference::Set(aMyData->label(), aData->label().Father());
     } else {
       myRef->Set(aData->label());
     }
-
-    static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
-    Model_FeatureUpdatedMessage aMsg(owner(), anEvent);
-    Events_Loop::loop()->send(aMsg);
+    owner()->data()->sendAttributeUpdated(this);
   }
 }
 
-FeaturePtr Model_AttributeReference::value()
+ObjectPtr Model_AttributeReference::value()
 {
   if (!myRef.IsNull()) {
     boost::shared_ptr<Model_Document> aDoc = 
       boost::dynamic_pointer_cast<Model_Document>(owner()->document());
     if (aDoc) {
       TDF_Label aRefLab = myRef->Get();
-      return aDoc->feature(aRefLab);
+      return aDoc->object(aRefLab);
     }
   }
   // not initialized
@@ -46,8 +42,6 @@ FeaturePtr Model_AttributeReference::value()
 
 Model_AttributeReference::Model_AttributeReference(TDF_Label& theLabel)
 {
-  // check the attribute could be already presented in this doc (after load document)
-  if (!theLabel.FindAttribute(TDF_Reference::GetID(), myRef)) {
-    // create attribute: not initialized by value yet: attribute is not set to the label!
-  }
+  // not initialized by value yet: attribute is not set to the label!
+  myIsInitialized = theLabel.FindAttribute(TDF_Reference::GetID(), myRef) == Standard_True;
 }