From 41f539dbafa52a62978602b634cb60f1a62fbc61 Mon Sep 17 00:00:00 2001 From: theo-vt Date: Fri, 18 Jul 2025 10:58:30 -0400 Subject: [PATCH] Sketcher: Only autoscale if the datum being edited is the scale defining datum (#22419) --- src/Mod/Sketcher/App/SketchObject.cpp | 16 ++++++++-------- src/Mod/Sketcher/App/SketchObject.h | 4 +++- src/Mod/Sketcher/Gui/EditDatumDialog.cpp | 9 ++++++++- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 421eff14f0..bc9148dd39 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -7600,21 +7600,21 @@ int SketchObject::getGeoIdFromCompleteGeometryIndex(int completeGeometryIndex) c else return (completeGeometryIndex - completeGeometryCount); } -bool SketchObject::hasSingleScaleDefiningConstraint() const +int SketchObject::getSingleScaleDefiningConstraint() const { const std::vector& vals = this->Constraints.getValues(); - bool foundOne = false; - for (auto val : vals) { + int found = -1; + for (size_t i = 0; i < vals.size(); ++i) { // An angle does not define scale - if (val->isDimensional() && val->Type != Angle) { - if (foundOne) { - return false; + if (vals[i]->isDimensional() && vals[i]->Type != Angle) { + if (found != -1) { // More than one scale defining constraint + return -1; } - foundOne = true; + found = i; } } - return foundOne; + return found; } std::unique_ptr SketchObject::getGeometryFacade(int GeoId) const diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index 9958ba94ef..4a595871a8 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -272,7 +272,9 @@ public: int getGeoIdFromCompleteGeometryIndex(int completeGeometryIndex) const; - bool hasSingleScaleDefiningConstraint() const; + // Returns the index of the scale defining constraint if + // there is only one and -1 otherwise + int getSingleScaleDefiningConstraint() const; /// returns non zero if the sketch contains conflicting constraints int hasConflicts() const; diff --git a/src/Mod/Sketcher/Gui/EditDatumDialog.cpp b/src/Mod/Sketcher/Gui/EditDatumDialog.cpp index 27e3258ce9..a5418a276d 100644 --- a/src/Mod/Sketcher/Gui/EditDatumDialog.cpp +++ b/src/Mod/Sketcher/Gui/EditDatumDialog.cpp @@ -409,8 +409,15 @@ void EditDatumDialog::performAutoScale(double newDatum) || (autoScaleMode == static_cast(SketcherGui::AutoScaleMode::WhenNoScaleFeatureIsVisible) && !hasVisualFeature(sketch, nullptr, Gui::Application::Instance->activeDocument()))) - && sketch->getExternalGeometryCount() <= 2 && sketch->hasSingleScaleDefiningConstraint()) { + && sketch->getExternalGeometryCount() <= 2) { try { + // Handle the case where multiple datum constraints are present but only one is scale + // defining e.g. a bunch of angle constraints and a single length constraint + int scaleDefiningConstraint = sketch->getSingleScaleDefiningConstraint(); + if (scaleDefiningConstraint != ConstrNbr) { + return; + } + double oldDatum = sketch->getDatum(ConstrNbr); double scaleFactor = newDatum / oldDatum; float initLabelDistance = sketch->Constraints[ConstrNbr]->LabelDistance;