1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #include "GeomValidators_Positive.h"
23 #include <Config_PropManager.h>
24 #include <Events_InfoMessage.h>
26 #include <ModelAPI_AttributeDouble.h>
27 #include <ModelAPI_AttributeInteger.h>
28 #include <ModelAPI_Session.h>
29 #include <ModelAPI_Validator.h>
33 /// Global instance for validators factory
34 GeomValidators_Positive MY_POSITIVE_INSTANCE;
36 GeomValidators_Positive::GeomValidators_Positive()
38 // this validator is registered in the factory on this library loading
39 SessionPtr aMgr = ModelAPI_Session::get();
40 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
41 aFactory->registerValidator("GeomValidators_Positive", this);
44 bool GeomValidators_Positive::isValid(const AttributePtr& theAttribute,
45 const std::list<std::string>& theArguments,
46 Events_InfoMessage& theError) const
48 double aMinValue = 1.e-5;
49 if(theArguments.size() == 1) {
50 std::list<std::string>::const_iterator anIt = theArguments.begin();
51 double aValue = Config_PropManager::stringToDouble((*anIt).c_str());
58 if (theAttribute->attributeType() == ModelAPI_AttributeDouble::typeId()) {
59 AttributeDoublePtr aDouble =
60 std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
61 if (!aDouble->isInitialized()) {
62 theError = "Double is not initialized.";
65 if (aDouble->value() <= aMinValue) {
66 theError = "Value is too small.";
71 if (theAttribute->attributeType() == ModelAPI_AttributeInteger::typeId()) {
72 AttributeIntegerPtr aInteger =
73 std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(theAttribute);
74 if (!aInteger->isInitialized()) {
75 theError = "Integer is not initialized.";
78 if (aInteger->value() <= floor(aMinValue)) {
79 theError = "Integer is not positive.";