X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomValidators%2FGeomValidators_Different.cpp;h=94c369c5a516f796d1c6f4f8fe9023901ddd3a25;hb=752c9e02e6aa8ced24e9b53097cb42540d5e6a08;hp=65b834d3af46624a5e0da5791b1e705581659e56;hpb=364cef2e3a61f6d511a8389ae445c03319b7bbca;p=modules%2Fshaper.git diff --git a/src/GeomValidators/GeomValidators_Different.cpp b/src/GeomValidators/GeomValidators_Different.cpp index 65b834d3a..94c369c5a 100644 --- a/src/GeomValidators/GeomValidators_Different.cpp +++ b/src/GeomValidators/GeomValidators_Different.cpp @@ -7,11 +7,14 @@ #include #include +#include #include #include #include +const double tolerance = 1e-7; + //================================================================================================= /* Help To extend GeomValidators_Different validator with new attribute types: @@ -22,8 +25,7 @@ To extend GeomValidators_Different validator with new attribute types: bool isEqual(const AttributePoint2DPtr& theLeft, const AttributePoint2DPtr& theRight) { - return theLeft->x() == theRight->x() && - theLeft->y() == theRight->y(); + return theLeft->pnt()->distance(theRight->pnt()) < tolerance; } bool isEqualAttributes(const AttributePtr& theLeft, const AttributePtr& theRight) @@ -35,17 +37,24 @@ bool isEqualAttributes(const AttributePtr& theLeft, const AttributePtr& theRight return false; } +/** \class IsEqual + * \ingroup Validators + * \brief Auxiliary class used in std::find_if + */ class IsEqual { AttributePtr myAttribute; public: + /// Constructor IsEqual(const AttributePtr& theAttribute) : myAttribute(theAttribute) {} + /// \return true in case if AttributePtr is equal with myAttribute bool operator()(const AttributePtr& theAttribute) { return isEqualAttributes(myAttribute, theAttribute); } }; bool GeomValidators_Different::isValid(const std::shared_ptr& theFeature, - const std::list& theArguments) const + const std::list& theArguments, + std::string& theError) const { std::map > anAttributesMap; // For all attributes referred by theArguments @@ -66,8 +75,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; }