X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FParametersPlugin%2FParametersPlugin_Validators.cpp;h=d751c36bae268a1369436ca1c95d3eacb03e4cfe;hb=09dabb6acd9664f589a0bd9415d804d7a37ab801;hp=788e163980f6308e9a1740ee45418c016db22b9c;hpb=6bb3ec6c114b55c02bad00ec953cd5b867eb7083;p=modules%2Fshaper.git diff --git a/src/ParametersPlugin/ParametersPlugin_Validators.cpp b/src/ParametersPlugin/ParametersPlugin_Validators.cpp index 788e16398..d751c36ba 100644 --- a/src/ParametersPlugin/ParametersPlugin_Validators.cpp +++ b/src/ParametersPlugin/ParametersPlugin_Validators.cpp @@ -7,9 +7,12 @@ #include +#include + #include #include #include +#include ParametersPlugin_VariableValidator::ParametersPlugin_VariableValidator() { @@ -20,15 +23,34 @@ ParametersPlugin_VariableValidator::~ParametersPlugin_VariableValidator() } bool ParametersPlugin_VariableValidator::isValid(const AttributePtr& theAttribute, - const std::list& theArguments) const + const std::list& theArguments, + std::string& theError) const { AttributeStringPtr aStrAttr = std::dynamic_pointer_cast(theAttribute); - bool result = isVariable(aStrAttr->value()); - return result; + if (!aStrAttr->isInitialized()) { + theError = "Attribute \"" + aStrAttr->id() + "\" is not initialized."; + return false; + } + bool isEmptyExpr = aStrAttr->value().empty(); + if (isEmptyExpr) { + theError = "Attribute \"" + aStrAttr->id() + "\" value is empty."; + return false; + } + if (!isVariable(aStrAttr->value())) { + theError = "Incorrect variable name."; + return false; + } + if (!isUnique(theAttribute, aStrAttr->value())) { + theError = "Variable name is not unique."; + 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; @@ -41,6 +63,26 @@ bool ParametersPlugin_VariableValidator::isVariable(const std::string& theString return true; } +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) + continue; + ResultParameterPtr aParam = std::dynamic_pointer_cast(aParamObj); + if (!aParam.get()) + continue; + FeaturePtr aFeature = ModelAPI_Feature::feature(aParam); + if (aFeature == theAttribute->owner()) + continue; + return false; + } + return true; +} + ParametersPlugin_ExpressionValidator::ParametersPlugin_ExpressionValidator() { @@ -52,20 +94,30 @@ ParametersPlugin_ExpressionValidator::~ParametersPlugin_ExpressionValidator() } bool ParametersPlugin_ExpressionValidator::isValid(const AttributePtr& theAttribute, - const std::list& theArguments) const + const std::list& theArguments, + std::string& 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); + std::dynamic_pointer_cast(theAttribute); + if (!aStrAttr->isInitialized()) { + theError = "Attribute \"" + aStrAttr->id() + "\" is not initialized."; + return false; + } bool isEmptyExpr = aStrAttr->value().empty(); - if(isEmptyExpr) + if (isEmptyExpr) { + theError = "Expression is empty."; return false; + } - if(!aParam.get()) + if (!aParam.get()) { + theError = "Result is empty."; return false; + } - return aFeature->error().empty(); + theError = aFeature->string(ParametersPlugin_Parameter::EXPRESSION_ERROR_ID())->value(); + return theError.empty(); }