From: dbv Date: Fri, 15 Jan 2016 13:30:29 +0000 (+0300) Subject: Improvement #630: Positive validator: avoid hard constants X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=46c9e67705c66f17c2b36ca884cf799712f8312d;p=modules%2Fshaper.git Improvement #630: Positive validator: avoid hard constants --- diff --git a/src/GeomValidators/GeomValidators_Positive.cpp b/src/GeomValidators/GeomValidators_Positive.cpp index 344cfe08d..1435e5995 100644 --- a/src/GeomValidators/GeomValidators_Positive.cpp +++ b/src/GeomValidators/GeomValidators_Positive.cpp @@ -25,6 +25,17 @@ bool GeomValidators_Positive::isValid(const AttributePtr& theAttribute, const std::list& theArguments, std::string& theError) const { + 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); @@ -32,7 +43,7 @@ bool GeomValidators_Positive::isValid(const AttributePtr& theAttribute, theError = "Double is not initialized."; return false; } - if (aDouble->value() <= 1.e-5) { + if (aDouble->value() <= aMinValue) { theError = "Double is not positive."; return false; } @@ -45,7 +56,7 @@ bool GeomValidators_Positive::isValid(const AttributePtr& theAttribute, theError = "Integer is not initialized."; return false; } - if (aInteger->value() <= 0) { + if (aInteger->value() <= floor(aMinValue)) { theError = "Integer is not positive."; return false; }