Salome HOME
Add dumping named of copied entities in the sketch (issue #1924)
[modules/shaper.git] / src / ParametersPlugin / ParametersPlugin_Validators.cpp
index f2a9573846e25afb7472b5b0ca918708a00e1cfb..c5804aeaed66fa06eed53648552635101f3e7b3a 100644 (file)
@@ -1,3 +1,4 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
 /*
  * Parameters_VariableValidator.cpp
  *
 
 #include <ParametersPlugin_Parameter.h>
 
+#include <Events_InfoMessage.h>
+
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_ResultParameter.h>
 #include <ModelAPI_Tools.h>
+#include <ModelAPI_Expression.h>
 
 ParametersPlugin_VariableValidator::ParametersPlugin_VariableValidator()
 {
@@ -24,32 +28,27 @@ ParametersPlugin_VariableValidator::~ParametersPlugin_VariableValidator()
 
 bool ParametersPlugin_VariableValidator::isValid(const AttributePtr& theAttribute,
                                                  const std::list<std::string>& theArguments,
-                                                 std::string& theError) const
+                                                 Events_InfoMessage& theError) const
 {
   AttributeStringPtr aStrAttr = std::dynamic_pointer_cast<ModelAPI_AttributeString>(theAttribute);
-  if (!isVariable(aStrAttr->value())) {
-    theError = "Incorrect variable name.";
+  if (!aStrAttr->isInitialized()) {
+    theError = "Attribute \"%1\" is not initialized.";
+    theError.arg(aStrAttr->id());
     return false;
-  } 
-  if (!isUnique(theAttribute, aStrAttr->value())) {
-    theError = "Variable name is not unique.";
+  }
+  bool isEmptyExpr = aStrAttr->value().empty();
+  if (isEmptyExpr) {
+    theError = "Attribute \"%1\" value is empty.";
+    theError.arg(aStrAttr->id());
     return false;
   }
-  return true;
-}
-
-bool ParametersPlugin_VariableValidator::isVariable(const std::string& theString) const
-{
-  if (theString.empty())
+  if (!ModelAPI_Expression::isVariable(aStrAttr->value())) {
+    theError = "Incorrect variable name.";
     return false;
-  std::string::const_iterator it = theString.begin();
-  if (!(isalpha(*it) || (*it) == '_') || it == theString.end())
+  }
+  if (!isUnique(theAttribute, aStrAttr->value())) {
+    theError = "Variable name is not unique.";
     return false;
-  it++;
-  for ( ; it != theString.end(); ++it ) {
-    if(!(isalnum(*it) || (*it) == '_')) {
-      return false;
-    }
   }
   return true;
 }
@@ -86,7 +85,7 @@ ParametersPlugin_ExpressionValidator::~ParametersPlugin_ExpressionValidator()
 
 bool ParametersPlugin_ExpressionValidator::isValid(const AttributePtr& theAttribute,
                                                    const std::list<std::string>& theArguments,
-                                                   std::string& theError) const
+                                                   Events_InfoMessage& theError) const
 {
   FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
   ResultParameterPtr aParam =
@@ -94,6 +93,11 @@ bool ParametersPlugin_ExpressionValidator::isValid(const AttributePtr& theAttrib
 
   AttributeStringPtr aStrAttr =
       std::dynamic_pointer_cast<ModelAPI_AttributeString>(theAttribute);
+  if (!aStrAttr->isInitialized()) {
+    theError = "Attribute \"%1\" is not initialized.";
+    theError.arg(aStrAttr->id());
+    return false;
+  }
   bool isEmptyExpr = aStrAttr->value().empty();
   if (isEmptyExpr) {
     theError = "Expression is empty.";