Salome HOME
Move MakeBrick*.py to examples module for availability for testing.
[modules/shaper.git] / src / GeomValidators / GeomValidators_Positive.cpp
index 58964c04f985a1ce4f9afc8bedd3c83f8ebc6926..344cfe08d76369b799e9f6e59cef947ae670e341 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "GeomValidators_Positive.h"
 #include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeInteger.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
 
@@ -20,10 +21,35 @@ GeomValidators_Positive::GeomValidators_Positive()
   aFactory->registerValidator("GeomValidators_Positive", this);
 }
 
-bool GeomValidators_Positive::isValid(
-    const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const
+bool GeomValidators_Positive::isValid(const AttributePtr& theAttribute, 
+                                      const std::list<std::string>& theArguments,
+                                      std::string& theError) const
 {
-  std::shared_ptr<ModelAPI_AttributeDouble> aDouble = 
-    std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
-  return aDouble->isInitialized() && aDouble->value() > 1.e-5;
+  if (theAttribute->attributeType() == ModelAPI_AttributeDouble::typeId()) {
+    AttributeDoublePtr aDouble =
+        std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
+    if (!aDouble->isInitialized()) {
+      theError = "Double is not initialized.";
+      return false;
+    }
+    if (aDouble->value() <= 1.e-5) {
+      theError = "Double is not positive.";
+      return false;
+    }
+  }
+
+  if (theAttribute->attributeType() == ModelAPI_AttributeInteger::typeId()) {
+    AttributeIntegerPtr aInteger =
+        std::dynamic_pointer_cast<ModelAPI_AttributeInteger>(theAttribute);
+    if (!aInteger->isInitialized()) {
+      theError = "Integer is not initialized.";
+      return false;
+    }
+    if (aInteger->value() <= 0) {
+      theError = "Integer is not positive.";
+      return false;
+    }
+  }
+
+  return true;
 }