X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomValidators%2FGeomValidators_DifferentShapes.cpp;h=985f7acf061df9d556354343f239a7d42f1bd584;hb=9ec274edd77cf6baba26d4571fbef143597d52df;hp=75f3535004cd3e7a0c841a7d84afbf08c7da9421;hpb=7318a07336a28c7b95703b15672e4a43df03dabb;p=modules%2Fshaper.git diff --git a/src/GeomValidators/GeomValidators_DifferentShapes.cpp b/src/GeomValidators/GeomValidators_DifferentShapes.cpp index 75f353500..985f7acf0 100644 --- a/src/GeomValidators/GeomValidators_DifferentShapes.cpp +++ b/src/GeomValidators/GeomValidators_DifferentShapes.cpp @@ -23,17 +23,76 @@ #include #include +#include #include "ModelAPI_Object.h" #include +#include +//================================================================================================= bool GeomValidators_DifferentShapes::isValid(const AttributePtr& theAttribute, const std::list& theArguments, Events_InfoMessage& theError) const { - FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); + bool isValid = false; + + std::string anAttributeType = theAttribute->attributeType(); + bool isList = anAttributeType == ModelAPI_AttributeSelectionList::typeId(); + + std::list anAttrs; + if (isList) { + AttributeSelectionListPtr aListAttr = + std::dynamic_pointer_cast(theAttribute); + // get all selection attributes from the list + for (int anIndex = 0; anIndex < aListAttr->size(); ++anIndex) { + anAttrs.push_back(aListAttr->value(anIndex)); + } + + isValid = checkEquals(anAttrs); + } + else { + // get all feature selection attributes + FeaturePtr aFeature = std::dynamic_pointer_cast(theAttribute->owner()); + anAttrs = aFeature->data()->attributes(ModelAPI_AttributeSelection::typeId()); + + isValid = checkEqualToCurrent(anAttrs, theAttribute); + } + + if (!isValid) { + theError = isList ? "The selection list contains equal shapes." : + "The feature uses equal shapes."; + return false; + } + + return true; +} + +//================================================================================================= +bool GeomValidators_DifferentShapes::checkEquals(std::list& theAttributes) +{ + std::list::iterator anIt = theAttributes.begin(); + for (; anIt != theAttributes.end(); anIt++) { + AttributePtr anAttribute = *anIt; + + std::list::iterator anOthersIt = std::next(anIt); + for (; anOthersIt != theAttributes.end(); anOthersIt++) { + AttributePtr anOtherAttribute = *anOthersIt; + if (isAttrShapesEqual(anAttribute, anOtherAttribute)) { + return false; + } + } + } + + return true; +} + +//================================================================================================= +bool GeomValidators_DifferentShapes::checkEqualToCurrent(std::list& theAttributes, + const AttributePtr& theCurrentAttribute) +{ AttributeSelectionPtr aSelectionAttribute = - std::dynamic_pointer_cast(theAttribute); + std::dynamic_pointer_cast(theCurrentAttribute); + GeomShapePtr aShape = aSelectionAttribute->value(); if (!aShape.get()) { ResultPtr aResult = aSelectionAttribute->context(); @@ -41,13 +100,10 @@ bool GeomValidators_DifferentShapes::isValid(const AttributePtr& theAttribute, aShape = aResult->shape(); } - std::string aCurrentAttributeId = theAttribute->id(); - // get all feature attributes - std::list anAttrs = - aFeature->data()->attributes(ModelAPI_AttributeSelection::typeId()); - if (anAttrs.size() > 0 && aShape.get() != NULL) { - std::list::iterator anAttr = anAttrs.begin(); - for(; anAttr != anAttrs.end(); anAttr++) { + std::string aCurrentAttributeId = theCurrentAttribute->id(); + if (theAttributes.size() > 0 && aShape.get() != NULL) { + std::list::iterator anAttr = theAttributes.begin(); + for (; anAttr != theAttributes.end(); anAttr++) { AttributePtr anAttribute = *anAttr; // take into concideration only other attributes if (anAttribute.get() != NULL && anAttribute->id() != aCurrentAttributeId) { @@ -62,12 +118,39 @@ bool GeomValidators_DifferentShapes::isValid(const AttributePtr& theAttribute, anAttrShape = aResult->shape(); } if (aShape->isEqual(anAttrShape)) { - theError = "The feature uses equal shapes."; return false; } } } } } + return true; } + +bool GeomValidators_DifferentShapes::isAttrShapesEqual(const AttributePtr& theAttribute, + const AttributePtr& theOtherAttribute) +{ + AttributeSelectionPtr aSelectionAttribute = + std::dynamic_pointer_cast(theAttribute); + AttributeSelectionPtr anOtherSelectionAttribute = + std::dynamic_pointer_cast(theOtherAttribute); + + GeomShapePtr aShape = aSelectionAttribute->value(); + if (!aShape.get()) { + ResultPtr aResult = aSelectionAttribute->context(); + if (aResult.get()) + aShape = aResult->shape(); + } + GeomShapePtr aTypedShape = GeomAPI_Tools::getTypedShape(aShape); + + GeomShapePtr anOtherShape = anOtherSelectionAttribute->value(); + if (!anOtherShape.get()) { + ResultPtr aResult = anOtherSelectionAttribute->context(); + if (aResult.get()) + anOtherShape = aResult->shape(); + } + GeomShapePtr aOtherTypedShape = GeomAPI_Tools::getTypedShape(anOtherShape); + + return aTypedShape->isEqual(aOtherTypedShape); +} \ No newline at end of file