Salome HOME
Issue #2811: Update content of Object node on creation moment
[modules/shaper.git] / src / GeomValidators / GeomValidators_Positive.cpp
index 344cfe08d76369b799e9f6e59cef947ae670e341..139239be9aaac39a943194ec5d31c6f98d171eec 100644 (file)
@@ -1,15 +1,35 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        GeomValidators_ValidatorPositive.cpp
-// Created:     16 Sep 2014
-// Author:      Mikhail PONIKAROV
+// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
 
 #include "GeomValidators_Positive.h"
+
+#include <Config_PropManager.h>
+#include <Events_InfoMessage.h>
+
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
 
+#include <cmath>
+
 /// Global instance for validators factory
 GeomValidators_Positive MY_POSITIVE_INSTANCE;
 
@@ -21,10 +41,20 @@ GeomValidators_Positive::GeomValidators_Positive()
   aFactory->registerValidator("GeomValidators_Positive", this);
 }
 
-bool GeomValidators_Positive::isValid(const AttributePtr& theAttribute, 
+bool GeomValidators_Positive::isValid(const AttributePtr& theAttribute,
                                       const std::list<std::string>& theArguments,
-                                      std::string& theError) const
+                                      Events_InfoMessage& theError) const
 {
+  double aMinValue = 1.e-5;
+  if(theArguments.size() == 1) {
+    std::list<std::string>::const_iterator anIt = theArguments.begin();
+    double aValue = Config_PropManager::stringToDouble((*anIt).c_str());
+    if(aValue != 0) {
+      // very probably ok
+      aMinValue = aValue;
+    }
+  }
+
   if (theAttribute->attributeType() == ModelAPI_AttributeDouble::typeId()) {
     AttributeDoublePtr aDouble =
         std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
@@ -32,8 +62,8 @@ bool GeomValidators_Positive::isValid(const AttributePtr& theAttribute,
       theError = "Double is not initialized.";
       return false;
     }
-    if (aDouble->value() <= 1.e-5) {
-      theError = "Double is not positive.";
+    if (aDouble->value() <= aMinValue) {
+      theError = "Value is too small.";
       return false;
     }
   }
@@ -45,7 +75,7 @@ bool GeomValidators_Positive::isValid(const AttributePtr& theAttribute,
       theError = "Integer is not initialized.";
       return false;
     }
-    if (aInteger->value() <= 0) {
+    if (aInteger->value() <= floor(aMinValue)) {
       theError = "Integer is not positive.";
       return false;
     }