1 // Copyright (C) 2014-2019 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 email : webmaster.salome@opencascade.com
20 #include "GeomValidators_Positive.h"
22 #include <Config_PropManager.h>
23 #include <Events_InfoMessage.h>
25 #include <ModelAPI_AttributeDouble.h>
26 #include <ModelAPI_AttributeInteger.h>
27 #include <ModelAPI_Session.h>
28 #include <ModelAPI_Validator.h>
32 /// Global instance for validators factory
33 GeomValidators_Positive MY_POSITIVE_INSTANCE;
35 GeomValidators_Positive::GeomValidators_Positive()
37 // this validator is registered in the factory on this library loading
38 SessionPtr aMgr = ModelAPI_Session::get();
39 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
40 aFactory->registerValidator("GeomValidators_Positive", this);
43 bool GeomValidators_Positive::isValid(const AttributePtr& theAttribute,
44 const std::list<std::string>& theArguments,
45 Events_InfoMessage& theError) const
47 double aMinValue = 1.e-5;
48 if(theArguments.size() == 1) {
49 std::list<std::string>::const_iterator anIt = theArguments.begin();
50 double aValue = Config_PropManager::stringToDouble((*anIt).c_str());
57 if (theAttribute->attributeType() == ModelAPI_AttributeDouble::typeId()) {
58 AttributeDoublePtr aDouble =
59 std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
60 if (!aDouble->isInitialized()) {
61 theError = "Double is not initialized.";
64 if (aDouble->value() <= aMinValue) {
65 theError = "Value is too small.";
70 if (theAttribute->attributeType() == ModelAPI_AttributeInteger::typeId()) {
71 AttributeIntegerPtr aInteger =
72 std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(theAttribute);
73 if (!aInteger->isInitialized()) {
74 theError = "Integer is not initialized.";
77 if (aInteger->value() <= floor(aMinValue)) {
78 theError = "Integer is not positive.";