Salome HOME
Make attributes may be defined as not-arguments: if they don't make result updated
[modules/shaper.git] / src / Model / Model_Data.cpp
index 80eba05b0e5a4cac492a4c0930e6d2e2100fca5e..e08e565bd5274c0e02cf9083ea1f91d81535f3de 100644 (file)
@@ -15,6 +15,8 @@
 #include <TDataStd_Name.hxx>
 #include "Model_Events.h"
 #include <Events_Loop.h>
+#include <Events_Error.h>
+
 
 using namespace std;
 
@@ -22,12 +24,12 @@ Model_Data::Model_Data()
 {
 }
 
-void Model_Data::setLabel(TDF_Label& theLab)
+void Model_Data::setLabel(TDF_Label theLab)
 {
   myLab = theLab;
 }
 
-string Model_Data::getName()
+string Model_Data::name()
 {
   Handle(TDataStd_Name) aName;
   if (myLab.FindAttribute(TDataStd_Name::GetID(), aName))
@@ -47,11 +49,11 @@ void Model_Data::setName(string theName)
     if (isModified)
       aName->Set(theName.c_str());
   }
-  if (isModified) {
-    static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
-    Model_FeatureUpdatedMessage aMsg(myFeature, anEvent);
-    Events_Loop::loop()->send(aMsg, false);
-  }
+  // to do not cause the update of the result on name change
+  /*if (isModified) {
+    static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
+    ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent, false);
+  }*/
 }
 
 void Model_Data::addAttribute(string theID, string theAttrType)
@@ -79,10 +81,11 @@ void Model_Data::addAttribute(string theID, string theAttrType)
 
   if (anAttr) {
     myAttrs[theID] = boost::shared_ptr<ModelAPI_Attribute>(anAttr);
-    anAttr->setFeature(myFeature);
+    anAttr->setObject(myObject);
+  }
+  else {
+    Events_Error::send("Can not create unknown type of attribute " + theAttrType);
   }
-  else
-    ; // TODO: generate error on unknown attribute request and/or add mechanism for customization
 }
 
 boost::shared_ptr<ModelAPI_AttributeDocRef> Model_Data::docRef(const string theID)
@@ -222,38 +225,8 @@ list<boost::shared_ptr<ModelAPI_Attribute> > Model_Data::attributes(const string
 void Model_Data::sendAttributeUpdated(ModelAPI_Attribute* theAttr)
 {
   theAttr->setInitialized();
-  static const Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_UPDATED);
-  Model_FeatureUpdatedMessage aMsg(myFeature, anEvent);
-  Events_Loop::loop()->send(aMsg);
-}
-
-#include <TNaming_Builder.hxx>
-#include <TNaming_NamedShape.hxx>
-#include <TopoDS_Shape.hxx>
-#include <GeomAPI_Shape.h>
-
-void Model_Data::store(const boost::shared_ptr<GeomAPI_Shape>& theShape)
-{
-  // the simplest way is to keep this attribute here, on Data
-  // TODO: add naming structure in separated document for shape storage
-  TNaming_Builder aBuilder(myLab);
-  if (!theShape) return; // bad shape
-  TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
-  if (aShape.IsNull()) return; // null shape inside
-
-  aBuilder.Generated(aShape);
-}
-
-boost::shared_ptr<GeomAPI_Shape> Model_Data::shape()
-{
-  Handle(TNaming_NamedShape) aName;
-  if (myLab.FindAttribute(TNaming_NamedShape::GetID(), aName)) {
-    TopoDS_Shape aShape = aName->Get();
-    if (!aShape.IsNull()) {
-      boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
-      aRes->setImpl(new TopoDS_Shape(aShape));
-      return aRes;
-    }
+  if (theAttr->isArgument()) {
+    static const Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
+    ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent);
   }
-  return boost::shared_ptr<GeomAPI_Shape>();
 }