- std::map<std::string, std::map<std::string, AttrValidators> >::const_iterator aFeatureIter =
- myAttrs.find(theFeature->getKind());
- if (aFeatureIter != myAttrs.cend()) {
- std::list<std::string> aLtAttributes = aData->attributesIDs(kAllTypes);
- std::list<std::string>::iterator anAttrIter = aLtAttributes.begin();
- for (; anAttrIter != aLtAttributes.end(); anAttrIter++) {
- const std::string& anAttributeID = *anAttrIter;
- std::map<std::string, AttrValidators>::const_iterator anAttr =
- aFeatureIter->second.find(anAttributeID);
- if (anAttr != aFeatureIter->second.end()) {
- // skip not-case attributres, that really may be invalid (issue 671)
- if (!const_cast<Model_ValidatorsFactory*>(this)->isCase(theFeature, anAttributeID))
- continue;
- AttrValidators::const_iterator aValIter = anAttr->second.cbegin();
- for (; aValIter != anAttr->second.cend(); aValIter++) {
- const std::string& aValidatorID = aValIter->first;
- const std::list<std::string>& anArguments = aValIter->second;
- std::map<std::string, ModelAPI_Validator*>::const_iterator aFound = myIDs.find(aValidatorID);
- if (aFound == myIDs.end()) {
- Events_Error::send(std::string("Validator ") + aValidatorID + " was not registered");
- } else {
- const ModelAPI_AttributeValidator* anAttrValidator =
- dynamic_cast<const ModelAPI_AttributeValidator*>(aFound->second);
- if (anAttrValidator) {
- 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, "");
- }
- }
- }
- }
- }
- }
+ std::list<std::string> aLtAttributes = aData->attributesIDs(kAllTypes);
+ std::list<std::string>::const_iterator anAttrIt = aLtAttributes.cbegin();
+ for (; anAttrIt != aLtAttributes.cend(); anAttrIt++) {
+ const std::string& anAttributeID = *anAttrIt;
+ AttributePtr anAttribute = theFeature->data()->attribute(anAttributeID);
+
+ std::string aValidatorID;
+ std::string anError;
+ if (!validate(anAttribute, aValidatorID, anError)) {
+ if (anError.empty())
+ anError = "Unknown error.";
+ anError = anAttributeID + " - " + aValidatorID + ": " + anError;
+ theFeature->setError(anError, false);
+ theFeature->data()->execState(ModelAPI_StateInvalidArgument);
+ return false;
+ }
+ }
+
+ return true;
+}
+
+bool Model_ValidatorsFactory::validate(const std::shared_ptr<ModelAPI_Attribute>& theAttribute,
+ std::string& theValidator,
+ std::string& theError) const
+{
+ FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
+ if (!aFeature.get()) {
+ theValidator = "Model_ValidatorsFactory";
+ theError = "Attribute has no feature.";
+ return false;