diff --git a/src/Mod/Sketcher/App/SketchAnalysis.cpp b/src/Mod/Sketcher/App/SketchAnalysis.cpp index ad00af681f..402dc8f563 100644 --- a/src/Mod/Sketcher/App/SketchAnalysis.cpp +++ b/src/Mod/Sketcher/App/SketchAnalysis.cpp @@ -591,56 +591,17 @@ int SketchAnalysis::detectMissingVerticalHorizontalConstraints(double anglepreci return verthorizConstraints.size(); } -void SketchAnalysis::makeMissingVerticalHorizontal(bool onebyone) +void SketchAnalysis::makeMissingVerticalHorizontal() { - int status, dofs; - std::vector constr; + makeConstraints(verthorizConstraints); +} - for (std::vector::iterator it = verthorizConstraints.begin(); - it != verthorizConstraints.end(); - ++it) { - Sketcher::Constraint* c = new Sketcher::Constraint(); - c->Type = it->Type; - c->First = it->First; - c->Second = it->Second; - c->FirstPos = it->FirstPos; - c->SecondPos = it->SecondPos; - - if (onebyone) { - // addConstraint() creates a clone - sketch->addConstraint(c); - delete c; - - solvesketch(status, dofs, true); - - if (status == -2) { // redundant constraints - sketch->autoRemoveRedundants(false); - - solvesketch(status, dofs, false); - } - - if (status) { - THROWMT(Base::RuntimeError, - QT_TRANSLATE_NOOP("Exceptions", - "Autoconstrain error: Unsolvable sketch while applying " - "vertical/horizontal constraints.")); - } - } - else { - constr.push_back(c); - } - } - - if (!onebyone) { - sketch->addConstraints(constr); - } - - verthorizConstraints.clear(); - - for (std::vector::iterator it = constr.begin(); it != constr.end(); - ++it) { - delete *it; - } +void SketchAnalysis::makeMissingVerticalHorizontalOneByOne() +{ + makeConstraintsOneByOne(verthorizConstraints, + QT_TRANSLATE_NOOP("Exceptions", + "Autoconstrain error: Unsolvable sketch while " + "applying vertical/horizontal constraints.")); } bool SketchAnalysis::checkVertical(Base::Vector3d dir, double angleprecision) diff --git a/src/Mod/Sketcher/App/SketchAnalysis.h b/src/Mod/Sketcher/App/SketchAnalysis.h index d06355fc5c..3664a3db98 100644 --- a/src/Mod/Sketcher/App/SketchAnalysis.h +++ b/src/Mod/Sketcher/App/SketchAnalysis.h @@ -116,7 +116,8 @@ public: verthorizConstraints = cl; } /// Vertical/Horizontal constraints simple routine Make step (see constructor) - void makeMissingVerticalHorizontal(bool onebyone = false); + void makeMissingVerticalHorizontal(); + void makeMissingVerticalHorizontalOneByOne(); /// Equality constraints simple routine Detect step (see constructor) int detectMissingEqualityConstraints(double precision); diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index e322b40b9c..f4a14ddce3 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -9833,8 +9833,10 @@ void SketchObject::makeMissingPointOnPointCoincident(bool onebyone) void SketchObject::makeMissingVerticalHorizontal(bool onebyone) { - if (analyser) - analyser->makeMissingVerticalHorizontal(onebyone); + if (analyser) { + onebyone ? analyser->makeMissingVerticalHorizontalOneByOne() + : analyser->makeMissingVerticalHorizontal(); + } } void SketchObject::makeMissingEquality(bool onebyone)