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 if (theAttribute->attributeType() == ModelAPI_AttributeDouble::typeId()) {
29 AttributeDoublePtr aDouble =
30 std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
31 if (!aDouble->isInitialized()) {
32 theError = "Double is not initialized.";
35 if (aDouble->value() <= 1.e-5) {
36 theError = "Double is not positive.";
41 if (theAttribute->attributeType() == ModelAPI_AttributeInteger::typeId()) {
42 AttributeIntegerPtr aInteger =
43 std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(theAttribute);
44 if (!aInteger->isInitialized()) {
45 theError = "Integer is not initialized.";
48 if (aInteger->value() <= 0) {
49 theError = "Integer is not positive.";