X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModel%2FModel_Data.cpp;h=b384b49d77846c29b47a856eeca3280fe9cc5bac;hb=7b76b534d04e5d50f1ad319e58e0e22c6bb742a3;hp=dc80d902407594bf1794ad48ce6a5ed69877b567;hpb=853952fd4ddc93c0cd6a7122d37b618199864396;p=modules%2Fshaper.git diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index dc80d9024..b384b49d7 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include #include @@ -20,6 +21,8 @@ #include +#include + 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(anAttr); @@ -119,6 +119,21 @@ boost::shared_ptr Model_Data::real(const std::string& return aRes; } +boost::shared_ptr Model_Data::integer(const std::string& theID) +{ + std::map >::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(); + } + boost::shared_ptr aRes = boost::dynamic_pointer_cast< + ModelAPI_AttributeInteger>(aFound->second); + if (!aRes) { + // TODO: generate error on invalid attribute type request + } + return aRes; +} + boost::shared_ptr Model_Data::boolean(const std::string& theID) { std::map >::iterator aFound = myAttrs.find(theID); @@ -231,7 +246,8 @@ bool Model_Data::isValid() std::list > Model_Data::attributes(const std::string& theType) { std::list > aResult; - std::map >::iterator anAttrsIter = myAttrs.begin(); + std::map >::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 > Model_Data::attributes(const s return aResult; } +std::list Model_Data::attributesIDs(const std::string& theType) +{ + std::list aResult; + std::map >::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(); +}