X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FParametersPlugin%2FParametersPlugin_Validators.cpp;h=1b47e66b6f6e499403ba88aa3a5dbb0b8137499e;hb=b6cb9a5e9ecc1c5dae69d686fa73a8afec92d04f;hp=ec550aecaad95bd2be334bddbff623d9fc6eed91;hpb=7e9e955376b504dc7d9e0a5e79a9a38943a53fcd;p=modules%2Fshaper.git diff --git a/src/ParametersPlugin/ParametersPlugin_Validators.cpp b/src/ParametersPlugin/ParametersPlugin_Validators.cpp index ec550aeca..1b47e66b6 100644 --- a/src/ParametersPlugin/ParametersPlugin_Validators.cpp +++ b/src/ParametersPlugin/ParametersPlugin_Validators.cpp @@ -1,9 +1,21 @@ -/* - * Parameters_VariableValidator.cpp - * - * Created on: Apr 9, 2015 - * Author: sbh - */ +// Copyright (C) 2014-2019 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 @@ -15,6 +27,7 @@ #include #include #include +#include ParametersPlugin_VariableValidator::ParametersPlugin_VariableValidator() { @@ -30,18 +43,20 @@ bool ParametersPlugin_VariableValidator::isValid(const AttributePtr& theAttribut { AttributeStringPtr aStrAttr = std::dynamic_pointer_cast(theAttribute); if (!aStrAttr->isInitialized()) { - theError = "Attribute \"" + aStrAttr->id() + "\" is not initialized."; + theError = "Attribute \"%1\" is not initialized."; + theError.arg(aStrAttr->id()); return false; } bool isEmptyExpr = aStrAttr->value().empty(); if (isEmptyExpr) { - theError = "Attribute \"" + aStrAttr->id() + "\" value is empty."; + theError = "Attribute \"%1\" value is empty."; + theError.arg(aStrAttr->id()); return false; } - if (!isVariable(aStrAttr->value())) { + if (!ModelAPI_Expression::isVariable(aStrAttr->value())) { theError = "Incorrect variable name."; return false; - } + } if (!isUnique(theAttribute, aStrAttr->value())) { theError = "Variable name is not unique."; return false; @@ -49,22 +64,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 { @@ -100,13 +99,12 @@ bool ParametersPlugin_ExpressionValidator::isValid(const AttributePtr& theAttrib 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); if (!aStrAttr->isInitialized()) { - theError = "Attribute \"" + aStrAttr->id() + "\" is not initialized."; + theError = "Attribute \"%1\" is not initialized."; + theError.arg(aStrAttr->id()); return false; } bool isEmptyExpr = aStrAttr->value().empty(); @@ -115,11 +113,6 @@ bool ParametersPlugin_ExpressionValidator::isValid(const AttributePtr& theAttrib return false; } - if (!aParam.get()) { - theError = "Result is empty."; - return false; - } - theError = aFeature->string(ParametersPlugin_Parameter::EXPRESSION_ERROR_ID())->value(); return theError.empty(); }