From ced9c0dd4fbeb9c3c433388201092ba4069efcb9 Mon Sep 17 00:00:00 2001 From: tetektoza Date: Tue, 28 Oct 2025 23:51:02 +0100 Subject: [PATCH] Sketcher: Remember cursor angle for Rectangle OVPs after OVP is set As the title says. Currently user is able to change geometry if OVP is set on labels. This is because `doEnforceControlParameters` reads mouse position every mouse move and calculates angle from it, resulting in a new angle every time mouse is moved. So, this patch basically reads the position before it was set, and once it is set, locks the position of the mouse and calculates angle from it which will be maintained until user cleans the OVP or makes a new primitive. --- .../Sketcher/Gui/DrawSketchHandlerRectangle.h | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerRectangle.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerRectangle.h index 679007857d..90c94b9452 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerRectangle.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerRectangle.h @@ -104,6 +104,8 @@ public: , constructionPointThreeId(Sketcher::GeoEnum::GeoUndef) , centerPointId(Sketcher::GeoEnum::GeoUndef) , side(0) + , lengthSign(0) + , widthSign(0) {} ~DrawSketchHandlerRectangle() override = default; @@ -815,6 +817,8 @@ private: void onReset() override { thickness = 0.; + lengthSign = 0; + widthSign = 0; toolWidgetManager.resetControls(); } @@ -827,6 +831,10 @@ private: int firstCurve, constructionPointOneId, constructionPointTwoId, constructionPointThreeId, centerPointId, side; + // Sign tracking for OVP lock fix (issue #23459) + // These store the direction sign when OVP is first set to prevent sign flipping + int lengthSign, widthSign; + void createShape(bool onlyeditoutline) override { ShapeGeometry.clear(); @@ -1987,12 +1995,16 @@ void DSHRectangleControllerBase::doEnforceControlParameters(Base::Vector2d& onSk if (fabs(length) < Precision::Confusion() && onViewParameters[OnViewParameter::Third]->hasFinishedEditing) { unsetOnViewParameter(onViewParameters[OnViewParameter::Third].get()); + handler->lengthSign = 0; return; } if (handler->constructionMethod() == ConstructionMethod::Diagonal) { - int sign = (onSketchPos.x - handler->corner1.x) >= 0 ? 1 : -1; - onSketchPos.x = handler->corner1.x + sign * length; + if (handler->lengthSign == 0) { + handler->lengthSign = + (onSketchPos.x - handler->corner1.x) >= 0 ? 1 : -1; + } + onSketchPos.x = handler->corner1.x + handler->lengthSign * length; } else { onSketchPos.x = handler->center.x + length / 2; @@ -2003,12 +2015,15 @@ void DSHRectangleControllerBase::doEnforceControlParameters(Base::Vector2d& onSk if (fabs(width) < Precision::Confusion() && onViewParameters[OnViewParameter::Fourth]->hasFinishedEditing) { unsetOnViewParameter(onViewParameters[OnViewParameter::Fourth].get()); + handler->widthSign = 0; return; } if (handler->constructionMethod() == ConstructionMethod::Diagonal) { - int sign = (onSketchPos.y - handler->corner1.y) >= 0 ? 1 : -1; - onSketchPos.y = handler->corner1.y + sign * width; + if (handler->widthSign == 0) { + handler->widthSign = (onSketchPos.y - handler->corner1.y) >= 0 ? 1 : -1; + } + onSketchPos.y = handler->corner1.y + handler->widthSign * width; } else { onSketchPos.y = handler->center.y + width / 2;