From b4221b72f9c829b918a9747ac4df9c5c281a2500 Mon Sep 17 00:00:00 2001 From: PaddleStroke Date: Mon, 10 Mar 2025 12:49:17 +0100 Subject: [PATCH] Sketcher: DSH: add OVP constraints before AutoConstraints. --- .../Sketcher/Gui/DrawSketchDefaultHandler.h | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Mod/Sketcher/Gui/DrawSketchDefaultHandler.h b/src/Mod/Sketcher/Gui/DrawSketchDefaultHandler.h index 3bb0e96ee8..48a5345220 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchDefaultHandler.h +++ b/src/Mod/Sketcher/Gui/DrawSketchDefaultHandler.h @@ -491,10 +491,10 @@ protected: executeCommands(); if (sugConstraints.size() > 0) { - generateAutoConstraints(); - beforeCreateAutoConstraints(); + generateAutoConstraints(); + createAutoConstraints(); } } @@ -988,13 +988,20 @@ protected: // redundants anymore } - // This is an awful situation. It should not be possible if the DSH works properly. It is - // just a safeguard. + // This can happen if OVP generated constraints and autoconstraints are conflicting + // For instance : https://github.com/FreeCAD/FreeCAD/issues/17722 if (sketchobject->getLastHasConflicts()) { - THROWM(Base::RuntimeError, - QT_TRANSLATE_NOOP( - "Notifications", - "Autoconstraints cause conflicting constraints - Please report!") "\n"); + auto lastsketchconstraintindex = sketchobject->Constraints.getSize() - 1; + + auto conflicting = sketchobject->getLastConflicting(); + + for (int index = conflicting.size() - 1; index >= 0; index--) { + int conflictingIndex = conflicting[index] - 1; + if (conflictingIndex > lastsketchconstraintindex) { + int removeindex = conflictingIndex - lastsketchconstraintindex - 1; + AutoConstraints.erase(std::next(AutoConstraints.begin(), removeindex)); + } + } } }