From: spo Date: Wed, 22 Jul 2015 06:21:15 +0000 (+0300) Subject: Error management -- Improve validators. X-Git-Tag: V_1.4.0_beta4~428 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=17ea124ce9fa25dc815f24cb6369309d3bcaf0ba;p=modules%2Fshaper.git Error management -- Improve validators. --- diff --git a/src/Model/Model_FeatureValidator.cpp b/src/Model/Model_FeatureValidator.cpp index 99fc08fe7..303a46567 100644 --- a/src/Model/Model_FeatureValidator.cpp +++ b/src/Model/Model_FeatureValidator.cpp @@ -25,10 +25,10 @@ bool Model_FeatureValidator::isValid(const std::shared_ptr& th std::shared_ptr aData = theFeature->data(); // "Action" features has no data, but still valid. e.g "Remove Part" if (!aData->isValid()) { + if (!theFeature->isAction()) + theError = "There is no data."; return theFeature->isAction(); } - if (!aData->isValid()) - return false; const std::string kAllTypes = ""; std::list aLtAttributes = aData->attributesIDs(kAllTypes); std::list::iterator it = aLtAttributes.begin(); @@ -41,6 +41,7 @@ bool Model_FeatureValidator::isValid(const std::shared_ptr& th myNotObligatory.find(theFeature->getKind()); if (aFeatureFind == myNotObligatory.end() || // and it is obligatory for filling aFeatureFind->second.find(*it) == aFeatureFind->second.end()) { + theError = "Attribute \"" + anAttr->id() + "\" is not initialized."; return false; } } diff --git a/src/ParametersPlugin/ParametersPlugin_Validators.cpp b/src/ParametersPlugin/ParametersPlugin_Validators.cpp index 8242713d8..d0b00ca8e 100644 --- a/src/ParametersPlugin/ParametersPlugin_Validators.cpp +++ b/src/ParametersPlugin/ParametersPlugin_Validators.cpp @@ -25,8 +25,15 @@ bool ParametersPlugin_VariableValidator::isValid(const AttributePtr& theAttribut std::string& theError) const { AttributeStringPtr aStrAttr = std::dynamic_pointer_cast(theAttribute); - bool result = isVariable(aStrAttr->value()) && isUnique(theAttribute, aStrAttr->value()); - return result; + 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 @@ -84,13 +91,18 @@ bool ParametersPlugin_ExpressionValidator::isValid(const AttributePtr& theAttrib std::dynamic_pointer_cast(aFeature->firstResult()); AttributeStringPtr aStrAttr = - std::dynamic_pointer_cast(theAttribute); + std::dynamic_pointer_cast(theAttribute); 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; + } + theError = aFeature->error(); return aFeature->error().empty(); }