From: vsv Date: Fri, 2 Sep 2016 14:19:30 +0000 (+0300) Subject: Check name of a new parameter defined by user X-Git-Tag: V_2.5.0~69 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=aac65bd42287261c227c8ac02fae9d0faf380ef2;p=modules%2Fshaper.git Check name of a new parameter defined by user --- diff --git a/src/ModelAPI/ModelAPI_Expression.cpp b/src/ModelAPI/ModelAPI_Expression.cpp index bc966b131..7d5f456a0 100644 --- a/src/ModelAPI/ModelAPI_Expression.cpp +++ b/src/ModelAPI/ModelAPI_Expression.cpp @@ -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; } + diff --git a/src/ModelAPI/ModelAPI_Expression.h b/src/ModelAPI/ModelAPI_Expression.h index dbfdeba69..5da1c0d69 100644 --- a/src/ModelAPI/ModelAPI_Expression.h +++ b/src/ModelAPI/ModelAPI_Expression.h @@ -53,6 +53,9 @@ class ModelAPI_Expression /// Returns the used parameters MODELAPI_EXPORT virtual std::set 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(); diff --git a/src/ParametersPlugin/ParametersPlugin_Validators.cpp b/src/ParametersPlugin/ParametersPlugin_Validators.cpp index d0549db52..7c5f839ab 100644 --- a/src/ParametersPlugin/ParametersPlugin_Validators.cpp +++ b/src/ParametersPlugin/ParametersPlugin_Validators.cpp @@ -15,6 +15,7 @@ #include #include #include +#include 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 { diff --git a/src/ParametersPlugin/ParametersPlugin_Validators.h b/src/ParametersPlugin/ParametersPlugin_Validators.h index 421c681b3..50b0e937d 100644 --- a/src/ParametersPlugin/ParametersPlugin_Validators.h +++ b/src/ParametersPlugin/ParametersPlugin_Validators.h @@ -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; diff --git a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp index 7ab7fbf73..291245b84 100644 --- a/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp +++ b/src/ParametersPlugin/ParametersPlugin_WidgetParamsMgr.cpp @@ -18,6 +18,7 @@ #include #include #include +#include #include @@ -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; }