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 <Events_InfoMessage.h>
11 #include <ModelAPI_AttributeDouble.h>
12 #include <ModelAPI_AttributeInteger.h>
13 #include <ModelAPI_Session.h>
14 #include <ModelAPI_Validator.h>
18 /// Global instance for validators factory
19 GeomValidators_Positive MY_POSITIVE_INSTANCE;
21 GeomValidators_Positive::GeomValidators_Positive()
23 // this validator is registered in the factory on this library loading
24 SessionPtr aMgr = ModelAPI_Session::get();
25 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
26 aFactory->registerValidator("GeomValidators_Positive", this);
29 bool GeomValidators_Positive::isValid(const AttributePtr& theAttribute,
30 const std::list<std::string>& theArguments,
31 Events_InfoMessage& theError) const
33 double aMinValue = 1.e-5;
34 if(theArguments.size() == 1) {
35 std::list<std::string>::const_iterator anIt = theArguments.begin();
37 double aValue = strtod((*anIt).c_str(), &aErr);
44 if (theAttribute->attributeType() == ModelAPI_AttributeDouble::typeId()) {
45 AttributeDoublePtr aDouble =
46 std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
47 if (!aDouble->isInitialized()) {
48 theError = "Double is not initialized.";
51 if (aDouble->value() <= aMinValue) {
52 theError = "Double is not positive.";
57 if (theAttribute->attributeType() == ModelAPI_AttributeInteger::typeId()) {
58 AttributeIntegerPtr aInteger =
59 std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(theAttribute);
60 if (!aInteger->isInitialized()) {
61 theError = "Integer is not initialized.";
64 if (aInteger->value() <= floor(aMinValue)) {
65 theError = "Integer is not positive.";