From 46c9e67705c66f17c2b36ca884cf799712f8312d Mon Sep 17 00:00:00 2001 From: dbv Date: Fri, 15 Jan 2016 16:30:29 +0300 Subject: [PATCH] Improvement #630: Positive validator: avoid hard constants --- src/GeomValidators/GeomValidators_Positive.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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; } -- 2.39.2