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.
This commit is contained in:
tetektoza
2025-10-28 23:51:02 +01:00
committed by Kacper Donat
parent 1f78dac7b5
commit ced9c0dd4f

View File

@@ -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;