X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomValidators%2FGeomValidators_Positive.cpp;h=13e9a0241e4bd6edf077998d133c4e5056e412d1;hb=d5d78920316491975a67f76578982b401cdfe71d;hp=58964c04f985a1ce4f9afc8bedd3c83f8ebc6926;hpb=38afbd899a8645c83e17f2c24a17a2b7414911b4;p=modules%2Fshaper.git diff --git a/src/GeomValidators/GeomValidators_Positive.cpp b/src/GeomValidators/GeomValidators_Positive.cpp index 58964c04f..13e9a0241 100644 --- a/src/GeomValidators/GeomValidators_Positive.cpp +++ b/src/GeomValidators/GeomValidators_Positive.cpp @@ -1,14 +1,34 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: GeomValidators_ValidatorPositive.cpp -// Created: 16 Sep 2014 -// Author: Mikhail PONIKAROV +// Copyright (C) 2014-2019 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// #include "GeomValidators_Positive.h" + +#include +#include + #include +#include #include #include +#include + /// Global instance for validators factory GeomValidators_Positive MY_POSITIVE_INSTANCE; @@ -20,10 +40,45 @@ 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(); + double aValue = Config_PropManager::stringToDouble((*anIt).c_str()); + if(aValue != 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 = "Value is too small."; + 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; }