#include <Model_Data.h>
#include <Model_AttributeDocRef.h>
+#include <Model_AttributeInteger.h>
#include <Model_AttributeDouble.h>
#include <Model_AttributeReference.h>
#include <Model_AttributeRefAttr.h>
#include <TDataStd_Name.hxx>
+#include <string>
+
Model_Data::Model_Data()
{
}
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)
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()) {
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);
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);
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);
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();
ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent);
}
}
+
+void Model_Data::erase()
+{
+ if (!myLab.IsNull())
+ myLab.ForgetAllAttributes();
+}