Salome HOME
Issue #591 - Highlight of the first argument of constraints
[modules/shaper.git] / src / SketchSolver / SketchSolver_ConstraintMirror.cpp
index e76afd2ca40f34495c189481a0bf463e4b769343..6ce1ab65d69907dc56bb577202aeb03a2b565396 100644 (file)
@@ -10,6 +10,7 @@
 #include <GeomAPI_Dir2d.h>
 #include <GeomAPI_XY.h>
 
+#include <cmath>
 
 void SketchSolver_ConstraintMirror::getAttributes(
     Slvs_Entity& theMirrorLine,
@@ -342,11 +343,11 @@ void SketchSolver_ConstraintMirror::adjustArcPoints(const Slvs_Entity& theArc) c
   }
   double aRad2 = anArcParams[1][0] * anArcParams[1][0] + anArcParams[1][1] * anArcParams[1][1];
   double aDist2 = anArcParams[2][0] * anArcParams[2][0] + anArcParams[2][1] * anArcParams[2][1];
-  if (fabs(aRad2 - aDist2) < tolerance)
+  if (std::fabs(aRad2 - aDist2) < tolerance)
     return; // nothing to update (last point already on the arc)
   if (aDist2 < tolerance)
     return; // unable to update
-  double aCoeff = sqrt(aRad2 / aDist2);
+  double aCoeff = std::sqrt(aRad2 / aDist2);
   anArcParams[2][0] *= aCoeff;
   anArcParams[2][1] *= aCoeff;
 
@@ -393,6 +394,8 @@ void SketchSolver_ConstraintMirror::adjustConstraint()
     aMirror = myStorage->getConstraint(*aConstrIter);
     if (aMirror.type != SLVS_C_SYMMETRIC_LINE)
       continue;
+    if (aMirror.entityA != aMirrorLine.h)
+      continue; // don't update another Mirror constraints
     Slvs_Constraint aPonCircA, aPonCircB;
     aPonCircA.h = SLVS_E_UNKNOWN;
     aPonCircB.h = SLVS_E_UNKNOWN;
@@ -415,6 +418,8 @@ void SketchSolver_ConstraintMirror::adjustConstraint()
   std::list<Slvs_Constraint> aMirrorList = myStorage->getConstraintsByType(SLVS_C_SYMMETRIC_LINE);
   std::list<Slvs_Constraint>::iterator aMirIter = aMirrorList.begin();
   for (; aMirIter != aMirrorList.end(); aMirIter++) {
+    if (aMirIter->entityA != aMirrorLine.h)
+      continue; // don't update another Mirror constraints
     if (aPointsOnCircles.find(aMirIter->ptA) != aPointsOnCircles.end())
       continue; // Avoid mirroring points on circles
     Slvs_Entity aBase = myStorage->getEntity(aMirIter->ptA);
@@ -424,25 +429,25 @@ void SketchSolver_ConstraintMirror::adjustConstraint()
 
   bool aNeedToResolve = myStorage->isNeedToResolve();
   for (aMirIter = aMirrorPonCirc.begin(); aMirIter != aMirrorPonCirc.end(); aMirIter++) {
-    // Calculate middle point for base arc and mirrored point on mirror arc
+    // Make centers of arcs symmetric
     Slvs_Entity aBaseArc = myStorage->getEntity(aPointsOnCircles[aMirIter->ptA]);
-    Slvs_Entity aBasePoint = myStorage->getEntity(aMirIter->ptA);
+    Slvs_Entity aBasePoint = myStorage->getEntity(aBaseArc.point[0]);
+    Slvs_Entity aMirrorArc = myStorage->getEntity(aPointsOnCircles[aMirIter->ptB]);
+    Slvs_Entity aMirrorPoint = myStorage->getEntity(aMirrorArc.point[0]);
+    makeMirrorEntity(aBasePoint, aMirrorPoint, aStartEnd);
+    // Calculate middle point for base arc and mirrored point on mirror arc
+    aBasePoint = myStorage->getEntity(aMirIter->ptA);
     Slvs_Param aParamX = myStorage->getParameter(aBasePoint.param[0]);
     Slvs_Param aParamY = myStorage->getParameter(aBasePoint.param[1]);
     calculateMiddlePoint(aBaseArc, 0.5, aParamX.val, aParamY.val);
     myStorage->updateParameter(aParamX);
     myStorage->updateParameter(aParamY);
-    Slvs_Entity aMirrorArc = myStorage->getEntity(aPointsOnCircles[aMirIter->ptB]);
-    Slvs_Entity aMirrorPoint = myStorage->getEntity(aMirIter->ptB);
+    aMirrorPoint = myStorage->getEntity(aMirIter->ptB);
     aParamX = myStorage->getParameter(aMirrorPoint.param[0]);
     aParamY = myStorage->getParameter(aMirrorPoint.param[1]);
     calculateMiddlePoint(aMirrorArc, 0.5, aParamX.val, aParamY.val);
     myStorage->updateParameter(aParamX);
     myStorage->updateParameter(aParamY);
-    // make centers of arcs symmetric
-    aBasePoint = myStorage->getEntity(aBaseArc.point[0]);
-    aMirrorPoint = myStorage->getEntity(aMirrorArc.point[0]);
-    makeMirrorEntity(aBasePoint, aMirrorPoint, aStartEnd);
   }
   // Restore previous value to avoid looped recalculations of sketch
   myStorage->setNeedToResolve(aNeedToResolve);