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>
15 /// Global instance for validators factory
16 GeomValidators_Positive MY_POSITIVE_INSTANCE;
18 GeomValidators_Positive::GeomValidators_Positive()
20 // this validator is registered in the factory on this library loading
21 SessionPtr aMgr = ModelAPI_Session::get();
22 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
23 aFactory->registerValidator("GeomValidators_Positive", this);
26 bool GeomValidators_Positive::isValid(const AttributePtr& theAttribute,
27 const std::list<std::string>& theArguments,
28 std::string& theError) const
30 double aMinValue = 1.e-5;
31 if(theArguments.size() == 1) {
32 std::list<std::string>::const_iterator anIt = theArguments.begin();
34 double aValue = strtod((*anIt).c_str(), &aErr);
41 if (theAttribute->attributeType() == ModelAPI_AttributeDouble::typeId()) {
42 AttributeDoublePtr aDouble =
43 std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
44 if (!aDouble->isInitialized()) {
45 theError = "Double is not initialized.";
48 if (aDouble->value() <= aMinValue) {
49 theError = "Double is not positive.";
54 if (theAttribute->attributeType() == ModelAPI_AttributeInteger::typeId()) {
55 AttributeIntegerPtr aInteger =
56 std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(theAttribute);
57 if (!aInteger->isInitialized()) {
58 theError = "Integer is not initialized.";
61 if (aInteger->value() <= floor(aMinValue)) {
62 theError = "Integer is not positive.";