From a8da198c8d44d38c9caf10acd5b6982b2f56a3c5 Mon Sep 17 00:00:00 2001 From: azv Date: Fri, 21 Aug 2015 09:32:02 +0300 Subject: [PATCH] Update constrain Mirror to keep non-zero the length of mirror line (issue #809) --- .../SketchSolver_ConstraintMirror.cpp | 28 +++++++++++++++++++ .../SketchSolver_ConstraintMirror.h | 6 ++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/SketchSolver/SketchSolver_ConstraintMirror.cpp b/src/SketchSolver/SketchSolver_ConstraintMirror.cpp index 6ce1ab65d..9d1477545 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMirror.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintMirror.cpp @@ -385,6 +385,34 @@ void SketchSolver_ConstraintMirror::adjustConstraint() aStartEnd[2*i+j] = myStorage->getParameter(aPoint.param[j]).val; } + // Calculate length of the mirror line and create temporary constraint + double aLength = sqrt((aStartEnd[2] - aStartEnd[0]) * (aStartEnd[2] - aStartEnd[0]) + + (aStartEnd[3] - aStartEnd[1]) * (aStartEnd[3] - aStartEnd[1])); + if (aLength < tolerance) { + if (myMirrorLineLength < 1.0) + myMirrorLineLength = 1.0; + } else + myMirrorLineLength = aLength; + std::list aDist = myStorage->getConstraintsByType(SLVS_C_PT_PT_DISTANCE); + std::list::const_iterator aDIt = aDist.begin(); + for (; aDIt != aDist.end(); ++aDIt) + if ((aDIt->ptA == aMirrorLine.point[0] && aDIt->ptB == aMirrorLine.point[1]) || + (aDIt->ptA == aMirrorLine.point[1] && aDIt->ptB == aMirrorLine.point[0])) + break; // length of mirror line is already set + if (aDIt == aDist.end()) { + // check the points of mirror line is not fixed + Slvs_hConstraint aFixed; + if (!myStorage->isPointFixed(aMirrorLine.point[0], aFixed, true) || + !myStorage->isPointFixed(aMirrorLine.point[1], aFixed, true)) { + // Add length constraint + aMirror = Slvs_MakeConstraint(SLVS_E_UNKNOWN, myGroup->getId(), SLVS_C_PT_PT_DISTANCE, + myGroup->getWorkplaneId(), aLength, aMirrorLine.point[0], aMirrorLine.point[1], + SLVS_E_UNKNOWN, SLVS_E_UNKNOWN); + aMirror.h = myStorage->addConstraint(aMirror); + myStorage->addTemporaryConstraint(aMirror.h); + } + } + // Search mirror between middle points on the arcs and recompute their coordinates std::map aPointsOnCircles; std::list aMirrorPonCirc; diff --git a/src/SketchSolver/SketchSolver_ConstraintMirror.h b/src/SketchSolver/SketchSolver_ConstraintMirror.h index 26d97ff98..2e156cff3 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMirror.h +++ b/src/SketchSolver/SketchSolver_ConstraintMirror.h @@ -19,7 +19,8 @@ class SketchSolver_ConstraintMirror : public SketchSolver_Constraint public: SketchSolver_ConstraintMirror(ConstraintPtr theConstraint) : SketchSolver_Constraint(theConstraint), - myNumberOfObjects(0) + myNumberOfObjects(0), + myMirrorLineLength(0.0) {} virtual int getType() const @@ -70,7 +71,8 @@ private: void adjustArcPoints(const Slvs_Entity& theArc) const; private: - size_t myNumberOfObjects; ///< number of previously mirrored objects + size_t myNumberOfObjects; ///< number of previously mirrored objects + double myMirrorLineLength; ///< length of mirror line (should be always greater than 0) }; #endif -- 2.39.2