Salome HOME
Copyright update 2022
[modules/shaper.git] / src / GeomValidators / GeomValidators_Different.cpp
index 617161f9c1624faad28e75b0ceaab38191e0c956..a2d625543df58c88f084e76ce480dba997a5bf45 100644 (file)
@@ -1,8 +1,21 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        GeomValidators_Different.cpp
-// Created:     08 July 2015
-// Author:      Sergey POKHODENKO
+// Copyright (C) 2014-2022  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 <GeomValidators_Different.h>
 
@@ -27,12 +40,13 @@ 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<GeomDataAPI_Point2D>(theLeft),
                    std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theRight));
@@ -59,8 +73,8 @@ bool GeomValidators_Different::isValid(const std::shared_ptr<ModelAPI_Feature>&
                                        Events_InfoMessage& theError) const
 {
   std::map<std::string, std::list<AttributePtr> > 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<std::string>::const_iterator anArgumentIt = theArguments.begin();
   for (; anArgumentIt != theArguments.end(); ++anArgumentIt) {
     AttributePtr anAttribute = theFeature->attribute(*anArgumentIt);
@@ -68,7 +82,8 @@ bool GeomValidators_Different::isValid(const std::shared_ptr<ModelAPI_Feature>&
   }
 
   // Search differences inside each attribute list
-  std::map<std::string, std::list<AttributePtr> >::const_iterator anAttributesMapIt = anAttributesMap.begin();
+  std::map<std::string, std::list<AttributePtr> >::const_iterator
+    anAttributesMapIt = anAttributesMap.begin();
   for (; anAttributesMapIt != anAttributesMap.end(); ++anAttributesMapIt) {
     const std::list<AttributePtr>& anAttributes = anAttributesMapIt->second;
     // for the list of attributes check that all elements are unique
@@ -80,11 +95,12 @@ bool GeomValidators_Different::isValid(const std::shared_ptr<ModelAPI_Feature>&
         std::list<AttributePtr>::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;
       }
     }
   }
@@ -92,7 +108,9 @@ bool GeomValidators_Different::isValid(const std::shared_ptr<ModelAPI_Feature>&
   return true;
 }
 
+// LCOV_EXCL_START
 bool GeomValidators_Different::isNotObligatory(std::string theFeature, std::string theAttribute)
 {
   return true;
 }
+// LCOV_EXCL_STOP