From: spo Date: Wed, 22 Jul 2015 11:29:08 +0000 (+0300) Subject: Error management -- Improve Model_Validator X-Git-Tag: V_1.4.0_beta4~432 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=1d31c2cfbaa3adda4c8a7b4a7d44827cd3b5bd03;p=modules%2Fshaper.git Error management -- Improve Model_Validator --- diff --git a/src/Model/Model_Validator.cpp b/src/Model/Model_Validator.cpp index ea64242f0..62715db6e 100644 --- a/src/Model/Model_Validator.cpp +++ b/src/Model/Model_Validator.cpp @@ -149,23 +149,37 @@ void Model_ValidatorsFactory::addDefaultValidators(std::list& theFeature) const { const static std::string kDefaultId = "Model_FeatureValidator"; + + ModelAPI_ExecState anExecState = theFeature->data()->execState(); + theFeature->setError("", false); + theFeature->data()->execState(anExecState); + // check feature validators first std::map::const_iterator aFeature = myFeatures.find(theFeature->getKind()); if (aFeature != myFeatures.end()) { AttrValidators::const_iterator aValidator = aFeature->second.begin(); for(; aValidator != aFeature->second.end(); aValidator++) { + const std::string& aValidatorID = aValidator->first; + const std::list& anArguments = aValidator->second; std::map::const_iterator aValFind = - myIDs.find(aValidator->first); + myIDs.find(aValidatorID); if (aValFind == myIDs.end()) { - Events_Error::send(std::string("Validator ") + aValidator->first + " was not registered"); + Events_Error::send(std::string("Validator ") + aValidatorID + " was not registered"); continue; } const ModelAPI_FeatureValidator* aFValidator = dynamic_cast(aValFind->second); if (aFValidator) { - if (!aFValidator->isValid(theFeature, aValidator->second)) + std::string anError; + if (!aFValidator->isValid(theFeature, anArguments, anError)) { + if (anError.empty()) + anError = "Unknown error."; + theFeature->setValidationError(aValidatorID, anError); return false; + } else { + theFeature->setValidationError(aValidatorID, ""); + } } } } @@ -176,8 +190,15 @@ bool Model_ValidatorsFactory::validate(const std::shared_ptr& const ModelAPI_FeatureValidator* aFValidator = dynamic_cast(aDefaultVal->second); if (aFValidator) { - if (!aFValidator->isValid(theFeature, anEmptyArgList)) + std::string anError; + if (!aFValidator->isValid(theFeature, anEmptyArgList, anError)) { + if (anError.empty()) + anError = "Unknown error."; + theFeature->setValidationError(kDefaultId, anError); return false; + } else { + theFeature->setValidationError(kDefaultId, ""); + } } } @@ -193,25 +214,33 @@ bool Model_ValidatorsFactory::validate(const std::shared_ptr& std::list aLtAttributes = aData->attributesIDs(kAllTypes); std::list::iterator anAttrIter = aLtAttributes.begin(); for (; anAttrIter != aLtAttributes.end(); anAttrIter++) { + const std::string& anAttributeID = *anAttrIter; std::map::const_iterator anAttr = - aFeatureIter->second.find(*anAttrIter); + aFeatureIter->second.find(anAttributeID); if (anAttr != aFeatureIter->second.end()) { // skip not-case attributres, that really may be invalid (issue 671) - if (!const_cast(this)->isCase(theFeature, anAttr->first)) + if (!const_cast(this)->isCase(theFeature, anAttributeID)) continue; AttrValidators::const_iterator aValIter = anAttr->second.cbegin(); for (; aValIter != anAttr->second.cend(); aValIter++) { - std::map::const_iterator aFound = myIDs.find( - aValIter->first); + const std::string& aValidatorID = aValIter->first; + const std::list& anArguments = aValIter->second; + std::map::const_iterator aFound = myIDs.find(aValidatorID); if (aFound == myIDs.end()) { - Events_Error::send(std::string("Validator ") + aValIter->first + " was not registered"); + Events_Error::send(std::string("Validator ") + aValidatorID + " was not registered"); } else { const ModelAPI_AttributeValidator* anAttrValidator = dynamic_cast(aFound->second); if (anAttrValidator) { - AttributePtr anAttribute = theFeature->data()->attribute(*anAttrIter); - if (!anAttrValidator->isValid(anAttribute, aValIter->second)) { - return false; + AttributePtr anAttribute = theFeature->data()->attribute(anAttributeID); + std::string anError; + if (!anAttrValidator->isValid(anAttribute, anArguments, anError)) { + if (anError.empty()) + anError = "Unknown error."; + theFeature->setAttributeValidationError(anAttributeID, aValidatorID, anError); + return false; + } else { + theFeature->setAttributeValidationError(anAttributeID, aValidatorID, ""); } } }