1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: GeomValidators_ValidatorPositive.cpp
4 // Created: 16 Sep 2014
5 // Author: Mikhail PONIKAROV
7 #include "GeomValidators_Positive.h"
9 #include <Config_PropManager.h>
10 #include <Events_InfoMessage.h>
12 #include <ModelAPI_AttributeDouble.h>
13 #include <ModelAPI_AttributeInteger.h>
14 #include <ModelAPI_Session.h>
15 #include <ModelAPI_Validator.h>
19 /// Global instance for validators factory
20 GeomValidators_Positive MY_POSITIVE_INSTANCE;
22 GeomValidators_Positive::GeomValidators_Positive()
24 // this validator is registered in the factory on this library loading
25 SessionPtr aMgr = ModelAPI_Session::get();
26 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
27 aFactory->registerValidator("GeomValidators_Positive", this);
30 bool GeomValidators_Positive::isValid(const AttributePtr& theAttribute,
31 const std::list<std::string>& theArguments,
32 Events_InfoMessage& theError) const
34 double aMinValue = 1.e-5;
35 if(theArguments.size() == 1) {
36 std::list<std::string>::const_iterator anIt = theArguments.begin();
38 double aValue = Config_PropManager::stringToDouble((*anIt).c_str());
45 if (theAttribute->attributeType() == ModelAPI_AttributeDouble::typeId()) {
46 AttributeDoublePtr aDouble =
47 std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
48 if (!aDouble->isInitialized()) {
49 theError = "Double is not initialized.";
52 if (aDouble->value() <= aMinValue) {
53 theError = "Double is not positive.";
58 if (theAttribute->attributeType() == ModelAPI_AttributeInteger::typeId()) {
59 AttributeIntegerPtr aInteger =
60 std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(theAttribute);
61 if (!aInteger->isInitialized()) {
62 theError = "Integer is not initialized.";
65 if (aInteger->value() <= floor(aMinValue)) {
66 theError = "Integer is not positive.";