+// 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()
{
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;
}
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 =
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.";