From 9ecb62c8f6b49dd144aaea7e5ea5b6a6e8790516 Mon Sep 17 00:00:00 2001 From: theo-vt Date: Sat, 14 Jun 2025 14:07:19 -0400 Subject: [PATCH] Sketcher: Fix autoscale issue with the origin (#21952) * Correctly handle geo ids < 0 in scale handler --- src/Mod/Sketcher/Gui/DrawSketchHandlerScale.h | 27 +++++++++---------- src/Mod/Sketcher/Gui/Utils.h | 3 ++- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerScale.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerScale.h index 9ef102712d..30292f6e78 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerScale.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerScale.h @@ -367,33 +367,29 @@ private: continue; } - int firstIndex = indexOfGeoId(listOfGeoIds, cstr->First); - int secondIndex = indexOfGeoId(listOfGeoIds, cstr->Second); - int thirdIndex = indexOfGeoId(listOfGeoIds, cstr->Third); - auto newConstr = std::unique_ptr(cstr->copy()); - newConstr->First = offsetGeoID(firstIndex, firstCurveCreated); + newConstr->First = offsetGeoID(newConstr->First, firstCurveCreated); if ((cstr->Type == Symmetric || cstr->Type == Tangent || cstr->Type == Perpendicular || cstr->Type == Angle) - && secondIndex != GeoEnum::GeoUndef && thirdIndex != GeoEnum::GeoUndef) { - newConstr->Second = offsetGeoID(secondIndex, firstCurveCreated); - newConstr->Third = offsetGeoID(thirdIndex, firstCurveCreated); + && cstr->Second != GeoEnum::GeoUndef && cstr->Third != GeoEnum::GeoUndef) { + newConstr->Second = offsetGeoID(cstr->Second, firstCurveCreated); + newConstr->Third = offsetGeoID(cstr->Third, firstCurveCreated); } else if ((cstr->Type == Coincident || cstr->Type == Tangent || cstr->Type == Symmetric || cstr->Type == Perpendicular || cstr->Type == Parallel || cstr->Type == Equal || cstr->Type == Angle || cstr->Type == PointOnObject || cstr->Type == InternalAlignment) - && secondIndex != GeoEnum::GeoUndef && thirdIndex == GeoEnum::GeoUndef) { - newConstr->Second = offsetGeoID(secondIndex, firstCurveCreated); + && cstr->Second != GeoEnum::GeoUndef && cstr->Third == GeoEnum::GeoUndef) { + newConstr->Second = offsetGeoID(cstr->Second, firstCurveCreated); } else if (cstr->Type == Radius || cstr->Type == Diameter) { newConstr->setValue(newConstr->getValue() * scaleFactor); } else if ((cstr->Type == Distance || cstr->Type == DistanceX || cstr->Type == DistanceY) - && secondIndex != GeoEnum::GeoUndef) { - newConstr->Second = offsetGeoID(secondIndex, firstCurveCreated); + && cstr->Second != GeoEnum::GeoUndef) { + newConstr->Second = offsetGeoID(cstr->Second, firstCurveCreated); newConstr->setValue(newConstr->getValue() * scaleFactor); } // (cstr->Type == Block || cstr->Type == Weight) @@ -428,9 +424,12 @@ private: // this assumes that a call to skipConstraint() has been // performed and that the constraint is valid within the context // of the scale operation - int offsetGeoID(int index, int firstCurveCreated) + int offsetGeoID(int id, int firstCurveCreated) { - return index < 0 ? index : index + firstCurveCreated; + if (id < 0) { // Covers external geometry, origin and undef + return id; + } + return indexOfGeoId(listOfGeoIds, id) + firstCurveCreated; } Base::Vector3d getScaledPoint(Base::Vector3d&& pointToScale, const Base::Vector2d& referencePoint, diff --git a/src/Mod/Sketcher/Gui/Utils.h b/src/Mod/Sketcher/Gui/Utils.h index 3bbfbe0618..178a1d789c 100644 --- a/src/Mod/Sketcher/Gui/Utils.h +++ b/src/Mod/Sketcher/Gui/Utils.h @@ -33,7 +33,6 @@ #include "ViewProviderSketchGeometryExtension.h" #include "GeometryCreationMode.h" - namespace App { class DocumentObject; @@ -209,6 +208,8 @@ std::string angleToDisplayFormat(double value, int digits); bool areCollinear(const Base::Vector2d& p1, const Base::Vector2d& p2, const Base::Vector2d& p3); +// Returns the index of the element in the vector, GeoUndef if the element is GeoUndef and -1 if not +// found int indexOfGeoId(const std::vector& vec, int elem); inline void scrollTo(QListWidget* list, int i, bool select)