X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomValidators%2FGeomValidators_Positive.cpp;h=b127ffe033a688edf64981f0c222287d5ea8cb71;hb=33c5fdce3cd63dd95a738439a0399dd982abcd73;hp=9d3fbf983cbb233da6fbd89d8ee71c3aae325a99;hpb=5352bbb1915f98d1f02b1cb953a2de19b286a28c;p=modules%2Fshaper.git diff --git a/src/GeomValidators/GeomValidators_Positive.cpp b/src/GeomValidators/GeomValidators_Positive.cpp index 9d3fbf983..b127ffe03 100644 --- a/src/GeomValidators/GeomValidators_Positive.cpp +++ b/src/GeomValidators/GeomValidators_Positive.cpp @@ -10,6 +10,8 @@ #include #include +#include + /// Global instance for validators factory GeomValidators_Positive MY_POSITIVE_INSTANCE; @@ -21,14 +23,46 @@ GeomValidators_Positive::GeomValidators_Positive() aFactory->registerValidator("GeomValidators_Positive", this); } -bool GeomValidators_Positive::isValid( - const AttributePtr& theAttribute, const std::list& theArguments) const +bool GeomValidators_Positive::isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + std::string& theError) const { - AttributeDoublePtr aDouble = - std::dynamic_pointer_cast(theAttribute); - if (aDouble.get()) - return aDouble->isInitialized() && aDouble->value() > 1.e-5; - AttributeIntegerPtr aInteger = - std::dynamic_pointer_cast(theAttribute); - return aInteger->isInitialized() && aInteger->value() > 0; + double aMinValue = 1.e-5; + if(theArguments.size() == 1) { + std::list::const_iterator anIt = theArguments.begin(); + char *aErr; + double aValue = strtod((*anIt).c_str(), &aErr); + if(*aErr == 0) { + // very probably ok + aMinValue = aValue; + } + } + + if (theAttribute->attributeType() == ModelAPI_AttributeDouble::typeId()) { + AttributeDoublePtr aDouble = + std::dynamic_pointer_cast(theAttribute); + if (!aDouble->isInitialized()) { + theError = "Double is not initialized."; + return false; + } + if (aDouble->value() <= aMinValue) { + theError = "Double is not positive."; + return false; + } + } + + if (theAttribute->attributeType() == ModelAPI_AttributeInteger::typeId()) { + AttributeIntegerPtr aInteger = + std::dynamic_pointer_cast(theAttribute); + if (!aInteger->isInitialized()) { + theError = "Integer is not initialized."; + return false; + } + if (aInteger->value() <= floor(aMinValue)) { + theError = "Integer is not positive."; + return false; + } + } + + return true; }