Salome HOME
PLaneGCSSolver: It is not necessary to adjust Angle constraint (issue #1536)
[modules/shaper.git] / src / ParametersPlugin / ParametersPlugin_Validators.cpp
index d0b00ca8e8bff0494247b5cd4af0956a2c650333..d751c36bae268a1369436ca1c95d3eacb03e4cfe 100644 (file)
@@ -7,6 +7,8 @@
 
 #include <ParametersPlugin_Validators.h>
 
+#include <ParametersPlugin_Parameter.h>
+
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_ResultParameter.h>
@@ -25,6 +27,15 @@ bool ParametersPlugin_VariableValidator::isValid(const AttributePtr& theAttribut
                                                  std::string& theError) const
 {
   AttributeStringPtr aStrAttr = std::dynamic_pointer_cast<ModelAPI_AttributeString>(theAttribute);
+  if (!aStrAttr->isInitialized()) {
+    theError = "Attribute \"" + aStrAttr->id() + "\" is not initialized.";
+    return false;
+  }
+  bool isEmptyExpr = aStrAttr->value().empty();
+  if (isEmptyExpr) {
+    theError = "Attribute \"" + aStrAttr->id() + "\" value is empty.";
+    return false;
+  }
   if (!isVariable(aStrAttr->value())) {
     theError = "Incorrect variable name.";
     return false;
@@ -52,7 +63,7 @@ bool ParametersPlugin_VariableValidator::isVariable(const std::string& theString
   return true;
 }
 
-bool ParametersPlugin_VariableValidator::isUnique(const AttributePtr& theAttribute, 
+bool ParametersPlugin_VariableValidator::isUnique(const AttributePtr& theAttribute,
                                                   const std::string& theString) const
 {
   DocumentPtr aDocument = theAttribute->owner()->document();
@@ -92,17 +103,21 @@ bool ParametersPlugin_ExpressionValidator::isValid(const AttributePtr& theAttrib
 
   AttributeStringPtr aStrAttr =
       std::dynamic_pointer_cast<ModelAPI_AttributeString>(theAttribute);
+  if (!aStrAttr->isInitialized()) {
+    theError = "Attribute \"" + aStrAttr->id() + "\" is not initialized.";
+    return false;
+  }
   bool isEmptyExpr = aStrAttr->value().empty();
-  if(isEmptyExpr) {
+  if (isEmptyExpr) {
     theError = "Expression is empty.";
     return false;
   }
 
-  if(!aParam.get()) {
+  if (!aParam.get()) {
     theError = "Result is empty.";
     return false;
   }
 
-  theError = aFeature->error();
-  return aFeature->error().empty();
+  theError = aFeature->string(ParametersPlugin_Parameter::EXPRESSION_ERROR_ID())->value();
+  return theError.empty();
 }