Salome HOME
Issue #83: rename and transfer some methods related to document
[modules/shaper.git] / src / Model / Model_Data.cpp
index dc80d902407594bf1794ad48ce6a5ed69877b567..b384b49d77846c29b47a856eeca3280fe9cc5bac 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <Model_Data.h>
 #include <Model_AttributeDocRef.h>
+#include <Model_AttributeInteger.h>
 #include <Model_AttributeDouble.h>
 #include <Model_AttributeReference.h>
 #include <Model_AttributeRefAttr.h>
@@ -20,6 +21,8 @@
 
 #include <TDataStd_Name.hxx>
 
+#include <string>
+
 Model_Data::Model_Data()
 {
 }
@@ -49,11 +52,6 @@ void Model_Data::setName(const std::string& theName)
     if (isModified)
       aName->Set(theName.c_str());
   }
-  // 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(const std::string& theID, const std::string theAttrType)
@@ -62,8 +60,14 @@ void Model_Data::addAttribute(const std::string& theID, const std::string theAtt
   ModelAPI_Attribute* anAttr = 0;
   if (theAttrType == ModelAPI_AttributeDocRef::type()) {
     anAttr = new Model_AttributeDocRef(anAttrLab);
+  } else if (theAttrType == Model_AttributeInteger::type()) {
+    anAttr = new Model_AttributeInteger(anAttrLab);
   } else if (theAttrType == ModelAPI_AttributeDouble::type()) {
     anAttr = new Model_AttributeDouble(anAttrLab);
+  } else if (theAttrType == Model_AttributeBoolean::type()) {
+    anAttr = new Model_AttributeBoolean(anAttrLab);
+  } else if (theAttrType == Model_AttributeString::type()) {
+    anAttr = new Model_AttributeString(anAttrLab);
   } else if (theAttrType == ModelAPI_AttributeReference::type()) {
     anAttr = new Model_AttributeReference(anAttrLab);
   } else if (theAttrType == ModelAPI_AttributeRefAttr::type()) {
@@ -76,10 +80,6 @@ void Model_Data::addAttribute(const std::string& theID, const std::string theAtt
     anAttr = new GeomData_Dir(anAttrLab);
   } else if (theAttrType == GeomData_Point2D::type()) {
     anAttr = new GeomData_Point2D(anAttrLab);
-  } else if (theAttrType == Model_AttributeBoolean::type()) {
-    anAttr = new Model_AttributeBoolean(anAttrLab);
-  } else if (theAttrType == Model_AttributeString::type()) {
-    anAttr = new Model_AttributeString(anAttrLab);
   }
   if (anAttr) {
     myAttrs[theID] = boost::shared_ptr<ModelAPI_Attribute>(anAttr);
@@ -119,6 +119,21 @@ boost::shared_ptr<ModelAPI_AttributeDouble> Model_Data::real(const std::string&
   return aRes;
 }
 
+boost::shared_ptr<ModelAPI_AttributeInteger> Model_Data::integer(const std::string& theID)
+{
+  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
+  if (aFound == myAttrs.end()) {
+    // TODO: generate error on unknown attribute request and/or add mechanism for customization
+    return boost::shared_ptr<ModelAPI_AttributeInteger>();
+  }
+  boost::shared_ptr<ModelAPI_AttributeInteger> aRes = boost::dynamic_pointer_cast<
+      ModelAPI_AttributeInteger>(aFound->second);
+  if (!aRes) {
+    // TODO: generate error on invalid attribute type request
+  }
+  return aRes;
+}
+
 boost::shared_ptr<ModelAPI_AttributeBoolean> Model_Data::boolean(const std::string& theID)
 {
   std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator aFound = myAttrs.find(theID);
@@ -231,7 +246,8 @@ bool Model_Data::isValid()
 std::list<boost::shared_ptr<ModelAPI_Attribute> > Model_Data::attributes(const std::string& theType)
 {
   std::list<boost::shared_ptr<ModelAPI_Attribute> > aResult;
-  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttrsIter = myAttrs.begin();
+  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttrsIter = 
+    myAttrs.begin();
   for (; anAttrsIter != myAttrs.end(); anAttrsIter++) {
     if (theType.empty() || anAttrsIter->second->attributeType() == theType) {
       aResult.push_back(anAttrsIter->second);
@@ -240,6 +256,19 @@ std::list<boost::shared_ptr<ModelAPI_Attribute> > Model_Data::attributes(const s
   return aResult;
 }
 
+std::list<std::string> Model_Data::attributesIDs(const std::string& theType) 
+{
+  std::list<std::string> aResult;
+  std::map<std::string, boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttrsIter = 
+    myAttrs.begin();
+  for (; anAttrsIter != myAttrs.end(); anAttrsIter++) {
+    if (theType.empty() || anAttrsIter->second->attributeType() == theType) {
+      aResult.push_back(anAttrsIter->first);
+    }
+  }
+  return aResult;
+}
+
 void Model_Data::sendAttributeUpdated(ModelAPI_Attribute* theAttr)
 {
   theAttr->setInitialized();
@@ -248,3 +277,9 @@ void Model_Data::sendAttributeUpdated(ModelAPI_Attribute* theAttr)
     ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent);
   }
 }
+
+void Model_Data::erase()
+{
+  if (!myLab.IsNull())
+    myLab.ForgetAllAttributes();
+}