Salome HOME
Integer widget is created and used in translate rotate widgets
[modules/shaper.git] / src / GeomValidators / GeomValidators_Positive.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 // File:        GeomValidators_ValidatorPositive.cpp
4 // Created:     16 Sep 2014
5 // Author:      Mikhail PONIKAROV
6
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>
12
13 /// Global instance for validators factory
14 GeomValidators_Positive MY_POSITIVE_INSTANCE;
15
16 GeomValidators_Positive::GeomValidators_Positive()
17 {
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);
22 }
23
24 bool GeomValidators_Positive::isValid(
25     const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const
26 {
27   AttributeDoublePtr aDouble = 
28     std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
29   if (aDouble.get())
30     return aDouble->isInitialized() && aDouble->value() > 1.e-5;
31   AttributeIntegerPtr aInteger = 
32     std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(theAttribute);
33   return aInteger->isInitialized() && aInteger->value() > 0;
34 }