X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGeomValidators%2FGeomValidators_Different.cpp;h=b80026928804813ddde72d158c2391d3f67d1a99;hb=aba714fbb23139b15272ed816c9a30595165106c;hp=45de46f7dd605339a99fb8b051036bb28e2032ee;hpb=e074e769a363f00ed7e4fb1ddcb3d05081f84358;p=modules%2Fshaper.git diff --git a/src/GeomValidators/GeomValidators_Different.cpp b/src/GeomValidators/GeomValidators_Different.cpp index 45de46f7d..b80026928 100644 --- a/src/GeomValidators/GeomValidators_Different.cpp +++ b/src/GeomValidators/GeomValidators_Different.cpp @@ -1,11 +1,26 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: GeomValidators_Different.cpp -// Created: 08 July 2015 -// Author: Sergey POKHODENKO +// Copyright (C) 2014-2021 CEA/DEN, EDF R&D +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// #include +#include + #include #include @@ -25,22 +40,29 @@ To extend GeomValidators_Different validator with new attribute types: bool isEqual(const AttributePoint2DPtr& theLeft, const AttributePoint2DPtr& theRight) { - return theLeft->pnt()->distance(theRight->pnt()) < tolerance; + return theLeft->isInitialized() && theRight->isInitialized() && + theLeft->pnt()->distance(theRight->pnt()) < tolerance; } bool isEqualAttributes(const AttributePtr& theLeft, const AttributePtr& theRight) { - if (theLeft->attributeType() == GeomDataAPI_Point2D::typeId() && + if (theLeft->attributeType() == GeomDataAPI_Point2D::typeId() && theRight->attributeType() == GeomDataAPI_Point2D::typeId()) return isEqual(std::dynamic_pointer_cast(theLeft), std::dynamic_pointer_cast(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); } @@ -48,11 +70,11 @@ public: bool GeomValidators_Different::isValid(const std::shared_ptr& theFeature, const std::list& theArguments, - std::string& theError) const + Events_InfoMessage& theError) const { std::map > anAttributesMap; - // For all attributes referred by theArguments - // sort it using attributeType() and store into anAttributesMap + // For all attributes referred by theArguments + // sort it using attributeType() and store into anAttributesMap std::list::const_iterator anArgumentIt = theArguments.begin(); for (; anArgumentIt != theArguments.end(); ++anArgumentIt) { AttributePtr anAttribute = theFeature->attribute(*anArgumentIt); @@ -60,7 +82,8 @@ bool GeomValidators_Different::isValid(const std::shared_ptr& } // Search differences inside each attribute list - std::map >::const_iterator anAttributesMapIt = anAttributesMap.begin(); + std::map >::const_iterator + anAttributesMapIt = anAttributesMap.begin(); for (; anAttributesMapIt != anAttributesMap.end(); ++anAttributesMapIt) { const std::list& anAttributes = anAttributesMapIt->second; // for the list of attributes check that all elements are unique @@ -72,11 +95,12 @@ bool GeomValidators_Different::isValid(const std::shared_ptr& 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." ; + theError = "Attributes " + (*anAttributeIt)->id() + " and " + + (*aFindIt)->id() + " are equal." ; return false; } ++anAttributeIt; - ++aNextIt; + ++aNextIt; } } } @@ -84,7 +108,9 @@ bool GeomValidators_Different::isValid(const std::shared_ptr& return true; } +// LCOV_EXCL_START bool GeomValidators_Different::isNotObligatory(std::string theFeature, std::string theAttribute) { return true; } +// LCOV_EXCL_STOP