From: spo Date: Fri, 4 Sep 2015 11:17:02 +0000 (+0300) Subject: Add error descriptions for some feture and attribute validators X-Git-Tag: V_1.4.0_beta4~121 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e074e769a363f00ed7e4fb1ddcb3d05081f84358;p=modules%2Fshaper.git Add error descriptions for some feture and attribute validators --- diff --git a/src/ExchangePlugin/ExchangePlugin_Validators.cpp b/src/ExchangePlugin/ExchangePlugin_Validators.cpp index d13b2c478..e05794640 100644 --- a/src/ExchangePlugin/ExchangePlugin_Validators.cpp +++ b/src/ExchangePlugin/ExchangePlugin_Validators.cpp @@ -41,17 +41,23 @@ bool ExchangePlugin_FormatValidator::isValid(const AttributePtr& theAttribute, const std::list& theArguments, std::string& theError) const { - if (!theAttribute->isInitialized()) + if (!theAttribute->isInitialized()) { + theError = "Is not initialized."; return false; + } const AttributeStringPtr aStrAttr = std::dynamic_pointer_cast(theAttribute); - if (!aStrAttr) + if (!aStrAttr) { + theError = "Is not a string attribute."; return false; + } std::string aFileName = aStrAttr->value(); - if (aFileName.empty()) + if (aFileName.empty()) { + theError = "File name is empty."; return false; + } std::list aFormats; ExchangePlugin_FormatValidator::parseFormats(theArguments, aFormats); @@ -67,5 +73,6 @@ bool ExchangePlugin_FormatValidator::isValid(const AttributePtr& theAttribute, } } } + theError = "File name does not end with any available format."; return false; } diff --git a/src/GeomValidators/GeomValidators_BooleanArguments.cpp b/src/GeomValidators/GeomValidators_BooleanArguments.cpp index c8a75ead5..b54344510 100644 --- a/src/GeomValidators/GeomValidators_BooleanArguments.cpp +++ b/src/GeomValidators/GeomValidators_BooleanArguments.cpp @@ -15,6 +15,7 @@ bool GeomValidators_BooleanArguments::isValid(const std::shared_ptr (theAttribute); - if (aSelectionAttr.get() == NULL) + if (aSelectionAttr.get() == NULL) { + theError = "Is not a selection attribute."; return aValid; + } ResultPtr aResult = aSelectionAttr->context(); GeomShapePtr aShape = aSelectionAttr->value(); @@ -32,7 +34,7 @@ bool GeomValidators_ConstructionComposite::isValid(const AttributePtr& theAttrib } else { // an empty shape is used in attribute selection if the shape of the result is equal to - // the selected shape, so according to the upper condifition, the result is true + // the selected shape, so according to the upper condition, the result is true aValid = true; } } @@ -40,7 +42,7 @@ bool GeomValidators_ConstructionComposite::isValid(const AttributePtr& theAttrib ResultConstructionPtr aConstr = std::dynamic_pointer_cast(aResult); if (aConstr != NULL) { - // it provides selection only on compositie features, construction without composite + // it provides selection only on composite features, construction without composite // feature is not selectable FeaturePtr aFeature = ModelAPI_Feature::feature(aConstr); CompositeFeaturePtr aComposite = diff --git a/src/GeomValidators/GeomValidators_Different.cpp b/src/GeomValidators/GeomValidators_Different.cpp index 85921c0d4..45de46f7d 100644 --- a/src/GeomValidators/GeomValidators_Different.cpp +++ b/src/GeomValidators/GeomValidators_Different.cpp @@ -69,8 +69,12 @@ bool GeomValidators_Different::isValid(const std::shared_ptr& std::list::const_iterator aNextIt = anAttributeIt; ++aNextIt; while (aNextIt != anAttributes.end()) { // if equal attribute is found then all attributes are not different - if (std::find_if(aNextIt, anAttributes.end(), IsEqual(*anAttributeIt)) != anAttributes.end()) + std::list::const_iterator aFindIt = + std::find_if(aNextIt, anAttributes.end(), IsEqual(*anAttributeIt)); + if (aFindIt != anAttributes.end()) { + theError = "Attributes " + anAttributeIt->id() + " and " + aFindIt->id() + " are equal." ; return false; + } ++anAttributeIt; ++aNextIt; } diff --git a/src/GeomValidators/GeomValidators_Face.cpp b/src/GeomValidators/GeomValidators_Face.cpp index 90eb2aac3..be0d9270e 100644 --- a/src/GeomValidators/GeomValidators_Face.cpp +++ b/src/GeomValidators/GeomValidators_Face.cpp @@ -44,8 +44,13 @@ bool GeomValidators_Face::isValid(const AttributePtr& theAttribute, ObjectPtr anObject = GeomValidators_Tools::getObject(theAttribute); if (anObject.get() != NULL) { - AttributeSelectionPtr aSelectionAttr = std::dynamic_pointer_cast - (theAttribute); + AttributeSelectionPtr aSelectionAttr = + std::dynamic_pointer_cast(theAttribute); + if (aSelectionAttr.get() == NULL) { + theError = "Is not a selection attribute."; + return aValid; + } + std::shared_ptr aGeomShape = aSelectionAttr->value(); if (!aGeomShape.get()) { // if the shape is empty, apply the validator to the shape of result @@ -60,15 +65,21 @@ bool GeomValidators_Face::isValid(const AttributePtr& theAttribute, switch(aFaceType) { case GeomAbs_Plane: aValid = aGeomFace->isPlanar(); + if (!aValid) + theError = "The shape is not a plane." break; case GeomAbs_Cylinder: aValid = aGeomFace->isCylindrical(); + if (!aValid) + theError = "The shape is not a cylinder." break; default: + theError = "The shape is not an available face." break; } } - } + } else + theError = "The shape is not a face." } else aValid = true; // an empty face selected is valid. diff --git a/src/GeomValidators/GeomValidators_Positive.cpp b/src/GeomValidators/GeomValidators_Positive.cpp index cd7dcc68c..344cfe08d 100644 --- a/src/GeomValidators/GeomValidators_Positive.cpp +++ b/src/GeomValidators/GeomValidators_Positive.cpp @@ -25,11 +25,31 @@ bool GeomValidators_Positive::isValid(const AttributePtr& theAttribute, const std::list& theArguments, std::string& theError) const { - AttributeDoublePtr aDouble = - std::dynamic_pointer_cast(theAttribute); - if (aDouble.get()) - return aDouble->isInitialized() && aDouble->value() > 1.e-5; - AttributeIntegerPtr aInteger = - std::dynamic_pointer_cast(theAttribute); - return aInteger->isInitialized() && aInteger->value() > 0; + if (theAttribute->attributeType() == ModelAPI_AttributeDouble::typeId()) { + AttributeDoublePtr aDouble = + std::dynamic_pointer_cast(theAttribute); + if (!aDouble->isInitialized()) { + theError = "Double is not initialized."; + return false; + } + if (aDouble->value() <= 1.e-5) { + theError = "Double is not positive."; + return false; + } + } + + if (theAttribute->attributeType() == ModelAPI_AttributeInteger::typeId()) { + AttributeIntegerPtr aInteger = + std::dynamic_pointer_cast(theAttribute); + if (!aInteger->isInitialized()) { + theError = "Integer is not initialized."; + return false; + } + if (aInteger->value() <= 0) { + theError = "Integer is not positive."; + return false; + } + } + + return true; } diff --git a/src/GeomValidators/GeomValidators_ZeroOffset.cpp b/src/GeomValidators/GeomValidators_ZeroOffset.cpp index f2857f935..9f0d5ede1 100644 --- a/src/GeomValidators/GeomValidators_ZeroOffset.cpp +++ b/src/GeomValidators/GeomValidators_ZeroOffset.cpp @@ -17,6 +17,7 @@ bool GeomValidators_ZeroOffset::isValid(const std::shared_ptr& std::string& theError) const { if(theArguments.size() != 8) { + theError = "Wrong number of arguments (expected 8)."; return false; } @@ -44,6 +45,7 @@ bool GeomValidators_ZeroOffset::isValid(const std::shared_ptr& if(aSelectedMethod == aCreationMethod) { if(aToSize == -aFromSize) { + theError = "ToSize = -FromSize."; return false; } else { return true; @@ -84,6 +86,7 @@ bool GeomValidators_ZeroOffset::isValid(const std::shared_ptr& if(((!aFromShape && !aToShape) || ((aFromShape && aToShape) && aFromShape->isEqual(aToShape))) && (aFromSize == -aToSize)) { + theError = "FromSize = -ToSize and bounding planes are equal."; return false; } diff --git a/src/SketchPlugin/SketchPlugin_ExternalValidator.cpp b/src/SketchPlugin/SketchPlugin_ExternalValidator.cpp index 3302e4c1e..362dd94f1 100644 --- a/src/SketchPlugin/SketchPlugin_ExternalValidator.cpp +++ b/src/SketchPlugin/SketchPlugin_ExternalValidator.cpp @@ -28,8 +28,10 @@ bool SketchPlugin_ExternalValidator::isValid(const AttributePtr& theAttribute, bool isParameterExternal = isExternalAttribute(aFeature->attribute(aFrontArgument)); // it is not possible that both features, attribute and attribute in parameter, are external - if (isAttributeExternal && isParameterExternal) + if (isAttributeExternal && isParameterExternal) { + theError = "Both features, attribute and attribute in parameter, are external."; return false; + } return true; }