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"
8 #include <ModelAPI_AttributeDouble.h>
9 #include <ModelAPI_AttributeInteger.h>
10 #include <ModelAPI_Session.h>
11 #include <ModelAPI_Validator.h>
13 /// Global instance for validators factory
14 GeomValidators_Positive MY_POSITIVE_INSTANCE;
16 GeomValidators_Positive::GeomValidators_Positive()
18 // this validator is registered in the factory on this library loading
19 SessionPtr aMgr = ModelAPI_Session::get();
20 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
21 aFactory->registerValidator("GeomValidators_Positive", this);
24 bool GeomValidators_Positive::isValid(const AttributePtr& theAttribute,
25 const std::list<std::string>& theArguments,
26 std::string& theError) const
28 double aMinValue = 1.e-5;
29 if(theArguments.size() == 1) {
30 std::list<std::string>::const_iterator anIt = theArguments.begin();
32 double aValue = strtod((*anIt).c_str(), &aErr);
39 if (theAttribute->attributeType() == ModelAPI_AttributeDouble::typeId()) {
40 AttributeDoublePtr aDouble =
41 std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
42 if (!aDouble->isInitialized()) {
43 theError = "Double is not initialized.";
46 if (aDouble->value() <= aMinValue) {
47 theError = "Double is not positive.";
52 if (theAttribute->attributeType() == ModelAPI_AttributeInteger::typeId()) {
53 AttributeIntegerPtr aInteger =
54 std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(theAttribute);
55 if (!aInteger->isInitialized()) {
56 theError = "Integer is not initialized.";
59 if (aInteger->value() <= floor(aMinValue)) {
60 theError = "Integer is not positive.";