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;
}
+
/// 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();
#include <ModelAPI_Feature.h>
#include <ModelAPI_ResultParameter.h>
#include <ModelAPI_Tools.h>
+#include <ModelAPI_Expression.h>
ParametersPlugin_VariableValidator::ParametersPlugin_VariableValidator()
{
theError.arg(aStrAttr->id());
return false;
}
- if (!isVariable(aStrAttr->value())) {
+ if (!ModelAPI_Expression::isVariable(aStrAttr->value())) {
theError = "Incorrect variable name.";
return false;
}
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
{
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;
#include <ModelAPI_Events.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Tools.h>
+#include <ModelAPI_Expression.h>
#include <ModuleBase_Tools.h>
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;
}