Salome HOME
Updated copyright comment
[modules/shaper.git] / src / SketchSolver / PlaneGCSSolver / PlaneGCSSolver_UpdateCoincidence.cpp
index bad62522a08fc57b1d689c9865e1d93b8a0f4819..d2f6a625433fe4c63a41d77ec0b18e4f7f82253a 100644 (file)
@@ -1,8 +1,21 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:    PlaneGCSSolver_UpdateCoincidence.cpp
-// Created: 17 Feb 2017
-// Author:  Artem ZHIDKOV
+// Copyright (C) 2014-2024  CEA, EDF
+//
+// 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 <PlaneGCSSolver_UpdateCoincidence.h>
 #include <PlaneGCSSolver_EdgeWrapper.h>
 #include <SketchSolver_Constraint.h>
 
 #include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_ConstraintCoincidenceInternal.h>
 #include <SketchPlugin_ConstraintCollinear.h>
 #include <SketchPlugin_ConstraintMiddle.h>
 
+static bool hasSamePoint(const std::set<EntityWrapperPtr>& theList,
+                         const EntityWrapperPtr& thePoint);
+
+
 void PlaneGCSSolver_UpdateCoincidence::attach(SketchSolver_Constraint* theObserver,
                                               const std::string& theType)
 {
@@ -31,6 +49,7 @@ void PlaneGCSSolver_UpdateCoincidence::attach(SketchSolver_Constraint* theObserv
 void PlaneGCSSolver_UpdateCoincidence::update(const FeaturePtr& theFeature)
 {
   if (theFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID() ||
+      theFeature->getKind() == SketchPlugin_ConstraintCoincidenceInternal::ID() ||
       theFeature->getKind() == SketchPlugin_ConstraintMiddle::ID() ||
       theFeature->getKind() == SketchPlugin_ConstraintCollinear::ID()) {
     myCoincident.clear();
@@ -72,17 +91,21 @@ bool PlaneGCSSolver_UpdateCoincidence::addCoincidence(
   } else if (aFound[0] == aFound[1]) { // same group => already coincident
     isAccepted = false;
   } else { // merge two groups
-    EntityWrapperPtr anEntityToAdd = theEntity1;
-    if (theEntity1->isExternal()) { // swap found groups;
-      anEntityToAdd = theEntity2;
-      std::list<CoincidentEntities>::iterator aTempIt = aFound[0];
-      aFound[0] = aFound[1];
-      aFound[1] = aTempIt;
+    // first check the external points are equal
+    EntityWrapperPtr anExternal0 = aFound[0]->externalPoint();
+    EntityWrapperPtr anExternal1 = aFound[1]->externalPoint();
+    if (anExternal0 && anExternal1) {
+      std::set<EntityWrapperPtr> anExtList;
+      anExtList.insert(anExternal0);
+      if (hasSamePoint(anExtList, anExternal1)) {
+        // no need to add coincidence, because all points are
+        // already coincident to correct external points
+        isAccepted = false;
+      }
     }
 
-    aFound[1]->remove(anEntityToAdd);
+    // merge
     aFound[0]->merge(*aFound[1]);
-    isAccepted = aFound[0]->add(anEntityToAdd);
     myCoincident.erase(aFound[1]);
   }
 
@@ -126,9 +149,7 @@ bool PlaneGCSSolver_UpdateCoincidence::addToGroupOfCoincidence(
 {
   if (theGroup.isExist(theEntity))
     return false;
-
-  theGroup.add(theEntity);
-  return true;
+  return theGroup.add(theEntity);
 }
 
 
@@ -157,8 +178,8 @@ static bool hasSamePoint(const std::set<EntityWrapperPtr>& theList, const GCS::P
   return false;
 }
 
-static bool hasSamePoint(const std::set<EntityWrapperPtr>& theList,
-                         const EntityWrapperPtr& thePoint)
+bool hasSamePoint(const std::set<EntityWrapperPtr>& theList,
+                  const EntityWrapperPtr& thePoint)
 {
   return hasSamePoint(theList, toPoint(thePoint));
 }
@@ -225,3 +246,8 @@ bool PlaneGCSSolver_UpdateCoincidence::CoincidentEntities::isExist(
 {
   return hasSamePoint(myExternalPoints, thePoint) || hasSamePoint(myPoints, thePoint);
 }
+
+EntityWrapperPtr PlaneGCSSolver_UpdateCoincidence::CoincidentEntities::externalPoint() const
+{
+  return myExternalPoints.empty() ? EntityWrapperPtr() : *myExternalPoints.begin();
+}