X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FParametersPlugin%2FParametersPlugin_Validators.cpp;h=3bd228d2a666805c60f71b3d962946054b8293c7;hb=04e2497fc973f0afc95d0a4a6f95e37fb27f45e8;hp=d0b00ca8e8bff0494247b5cd4af0956a2c650333;hpb=17ea124ce9fa25dc815f24cb6369309d3bcaf0ba;p=modules%2Fshaper.git diff --git a/src/ParametersPlugin/ParametersPlugin_Validators.cpp b/src/ParametersPlugin/ParametersPlugin_Validators.cpp index d0b00ca8e..3bd228d2a 100644 --- a/src/ParametersPlugin/ParametersPlugin_Validators.cpp +++ b/src/ParametersPlugin/ParametersPlugin_Validators.cpp @@ -1,16 +1,35 @@ -/* - * Parameters_VariableValidator.cpp - * - * Created on: Apr 9, 2015 - * Author: sbh - */ +// Copyright (C) 2014-2022 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// #include +#include + +#include + +#include + #include #include #include #include +#include ParametersPlugin_VariableValidator::ParametersPlugin_VariableValidator() { @@ -21,45 +40,40 @@ ParametersPlugin_VariableValidator::~ParametersPlugin_VariableValidator() } bool ParametersPlugin_VariableValidator::isValid(const AttributePtr& theAttribute, - const std::list& theArguments, - std::string& theError) const + const std::list& /*theArguments*/, + Events_InfoMessage& theError) const { AttributeStringPtr aStrAttr = std::dynamic_pointer_cast(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_VariableValidator::isUnique(const AttributePtr& theAttribute, +bool ParametersPlugin_VariableValidator::isUnique(const AttributePtr& theAttribute, const std::string& theString) const { DocumentPtr aDocument = theAttribute->owner()->document(); for (int anIndex = 0, aSize = aDocument->size(ModelAPI_ResultParameter::group()); anIndex < aSize; ++anIndex) { ObjectPtr aParamObj = aDocument->object(ModelAPI_ResultParameter::group(), anIndex); - if (aParamObj->data()->name() != theString) + if (Locale::Convert::toString(aParamObj->data()->name()) != theString) continue; ResultParameterPtr aParam = std::dynamic_pointer_cast(aParamObj); if (!aParam.get()) @@ -83,26 +97,24 @@ ParametersPlugin_ExpressionValidator::~ParametersPlugin_ExpressionValidator() } bool ParametersPlugin_ExpressionValidator::isValid(const AttributePtr& theAttribute, - const std::list& theArguments, - std::string& theError) const + const std::list& /*theArguments*/, + Events_InfoMessage& theError) const { FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); - ResultParameterPtr aParam = - std::dynamic_pointer_cast(aFeature->firstResult()); AttributeStringPtr aStrAttr = std::dynamic_pointer_cast(theAttribute); - bool isEmptyExpr = aStrAttr->value().empty(); - if(isEmptyExpr) { - theError = "Expression is empty."; + if (!aStrAttr->isInitialized()) { + theError = "Attribute \"%1\" is not initialized."; + theError.arg(aStrAttr->id()); return false; } - - if(!aParam.get()) { - theError = "Result is empty."; + bool isEmptyExpr = aStrAttr->value().empty(); + if (isEmptyExpr) { + theError = "Expression is empty."; return false; } - theError = aFeature->error(); - return aFeature->error().empty(); + theError = aFeature->string(ParametersPlugin_Parameter::EXPRESSION_ERROR_ID())->value(); + return theError.empty(); }