X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomValidators%2FGeomValidators_Positive.cpp;h=6737f289aaba4e180b893edfb664971858f2c7ee;hb=3e6012473696e5fd94e3c8240e2e1eda8def1743;hp=3362a47d3c33310193fb1301cfba2535d424da12;hpb=4783f146b71a48c651523fcf0e12367bcf3d1fa8;p=modules%2Fshaper.git diff --git a/src/GeomValidators/GeomValidators_Positive.cpp b/src/GeomValidators/GeomValidators_Positive.cpp index 3362a47d3..6737f289a 100644 --- a/src/GeomValidators/GeomValidators_Positive.cpp +++ b/src/GeomValidators/GeomValidators_Positive.cpp @@ -1,12 +1,20 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + // File: GeomValidators_ValidatorPositive.cpp // Created: 16 Sep 2014 // Author: Mikhail PONIKAROV #include "GeomValidators_Positive.h" + +#include + #include +#include #include #include +#include + /// Global instance for validators factory GeomValidators_Positive MY_POSITIVE_INSTANCE; @@ -18,10 +26,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, + Events_InfoMessage& theError) const { - std::shared_ptr aDouble = - std::dynamic_pointer_cast(theAttribute); - return aDouble->isInitialized() && aDouble->value() > 1.e-5; + 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; }