Salome HOME
Check name of a new parameter defined by user
authorvsv <vitaly.smetannikov@opencascade.com>
Fri, 2 Sep 2016 14:19:30 +0000 (17:19 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Fri, 2 Sep 2016 14:19:43 +0000 (17:19 +0300)
src/ModelAPI/ModelAPI_Expression.cpp
src/ModelAPI/ModelAPI_Expression.h
src/ParametersPlugin/ParametersPlugin_Validators.cpp
src/ParametersPlugin/ParametersPlugin_Validators.h
src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp

index bc966b1312d63f68c66249d96e7ee3cfbaa4eaa5..7d5f456a0de037a5d389b68a3b1c31676a31acc4 100644 (file)
@@ -34,4 +34,21 @@ ModelAPI_ExpressionDouble::ModelAPI_ExpressionDouble()
 ModelAPI_ExpressionInteger::ModelAPI_ExpressionInteger()
 {
 
+
+}
+bool ModelAPI_Expression::isVariable(const std::string& theString)
+{
+  if (theString.empty())
+    return false;
+  std::string::const_iterator it = theString.begin();
+  if (!(isalpha(*it) || (*it) == '_') || it == theString.end())
+    return false;
+  it++;
+  for ( ; it != theString.end(); ++it ) {
+    if(!(isalnum(*it) || (*it) == '_')) {
+      return false;
+    }
+  }
+  return true;
 }
+
index dbfdeba6955b4ff5350a35ac2c88329862c4ba9a..5da1c0d69cd7be2a3b4f65dd4c6a90925b3e1c90 100644 (file)
@@ -53,6 +53,9 @@ class ModelAPI_Expression
   /// Returns the used parameters
   MODELAPI_EXPORT virtual std::set<std::string> usedParameters() const = 0;
 
+  /// Returns True if the given string can be defined as a name of an expression variable
+  MODELAPI_EXPORT static bool isVariable(const std::string& theString);
+
  protected:
   /// Objects are created for features automatically
   MODELAPI_EXPORT ModelAPI_Expression();
index d0549db529e82fb0216d4d12574843e9b0faff0f..7c5f839ab7298f18f73089d39b25578b881b2a16 100644 (file)
@@ -15,6 +15,7 @@
 #include <ModelAPI_Feature.h>
 #include <ModelAPI_ResultParameter.h>
 #include <ModelAPI_Tools.h>
+#include <ModelAPI_Expression.h>
 
 ParametersPlugin_VariableValidator::ParametersPlugin_VariableValidator()
 {
@@ -40,7 +41,7 @@ bool ParametersPlugin_VariableValidator::isValid(const AttributePtr& theAttribut
     theError.arg(aStrAttr->id());
     return false;
   }
-  if (!isVariable(aStrAttr->value())) {
+  if (!ModelAPI_Expression::isVariable(aStrAttr->value())) {
     theError = "Incorrect variable name.";
     return false;
   } 
@@ -51,22 +52,6 @@ bool ParametersPlugin_VariableValidator::isValid(const AttributePtr& theAttribut
   return true;
 }
 
-bool ParametersPlugin_VariableValidator::isVariable(const std::string& theString) const
-{
-  if (theString.empty())
-    return false;
-  std::string::const_iterator it = theString.begin();
-  if (!(isalpha(*it) || (*it) == '_') || it == theString.end())
-    return false;
-  it++;
-  for ( ; it != theString.end(); ++it ) {
-    if(!(isalnum(*it) || (*it) == '_')) {
-      return false;
-    }
-  }
-  return true;
-}
-
 bool ParametersPlugin_VariableValidator::isUnique(const AttributePtr& theAttribute,
                                                   const std::string& theString) const
 {
index 421c681b33f8f8651650b52702b60894ba965649..50b0e937d1afacd8fea0e1142563a6dce5eab436 100644 (file)
@@ -37,8 +37,6 @@ class ParametersPlugin_VariableValidator : public ModelAPI_AttributeValidator
                                                Events_InfoMessage& theError) const;
 
  protected:
-  /// Returns true if theString is a valid variable name.
-  PARAMETERSPLUGIN_EXPORT bool isVariable(const std::string& theString) const;
   /// Returns true if theString is unique parameter name in the document of theAttribute.
   PARAMETERSPLUGIN_EXPORT bool isUnique(const AttributePtr& theAttribute,
                                         const std::string& theString) const;
index 7ab7fbf7397719ec3d2415bcbae757fa19af5fe2..291245b841c8693b509565d7beaa7a26c72e96f8 100644 (file)
@@ -18,6 +18,7 @@
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Tools.h>
+#include <ModelAPI_Expression.h>
 
 #include <ModuleBase_Tools.h>
 
@@ -752,7 +753,9 @@ bool ParametersPlugin_WidgetParamsMgr::isValid()
   bool aIsValid = true;
   for(int i = 0; i < myParameters->childCount(); i++) {
     aItem = myParameters->child(i);
-    if ((aItem->text(Col_Name) == NoName) || (aItem->text(Col_Equation) == NoValue)) {
+    if ((aItem->text(Col_Name) == NoName) || 
+        (aItem->text(Col_Equation) == NoValue) ||
+        (!ModelAPI_Expression::isVariable(aItem->text(Col_Name).toStdString())) ) {
       aIsValid = false;
       break;
     }