From 6fca6cfd9e2f3af02634b403bcf9c8e1e05ee137 Mon Sep 17 00:00:00 2001 From: theo-vt Date: Fri, 13 Feb 2026 16:34:46 -0500 Subject: [PATCH] Sketcher.scale: scale constraint with the right index (#27188) (cherry picked from commit 9cbef0c5ce4697f511770cc223acee93e65a171d) --- src/Mod/Sketcher/Gui/DrawSketchHandlerScale.h | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerScale.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerScale.h index 65318244ed..a6add8afd9 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerScale.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerScale.h @@ -133,6 +133,7 @@ public: if (deleteOriginal) { deleteOriginalGeos(); } + int initialConstraintCount = sketchgui->getSketchObject()->Constraints.getSize(); commandAddShapeGeometryAndConstraints(); @@ -140,7 +141,7 @@ public: reassignFacadeIds(); } - scaleLabels(); + scaleLabels(initialConstraintCount); Gui::Command::commitCommand(); } catch (const Base::Exception& e) { @@ -345,22 +346,24 @@ private: Base::Console().error("%s\n", e.what()); } } - void scaleLabels() + void scaleLabels(int constraintIndexOffset) { SketchObject* sketch = sketchgui->getSketchObject(); for (auto toScale : listOfLabelsToScale) { - sketch->setLabelDistance(toScale.constrId, toScale.distance * scaleFactor); + int constrId = toScale.constrId + constraintIndexOffset; - // Label position or radii and diameters represent an angle, so + sketch->setLabelDistance(constrId, toScale.distance * static_cast(scaleFactor)); + + // Label position or radii anddiameters represent an angle, so // they should not be scaled - Sketcher::ConstraintType type = sketch->Constraints[toScale.constrId]->Type; + Sketcher::ConstraintType type = sketch->Constraints[constrId]->Type; if (type == Sketcher::ConstraintType::Radius || type == Sketcher::ConstraintType::Diameter) { - sketch->setLabelPosition(toScale.constrId, toScale.position); + sketch->setLabelPosition(constrId, toScale.position); } else { - sketch->setLabelPosition(toScale.constrId, toScale.position * scaleFactor); + sketch->setLabelPosition(constrId, toScale.position * static_cast(scaleFactor)); } } } @@ -494,9 +497,8 @@ private: } const std::vector& vals = Obj->Constraints.getValues(); - - for (size_t i = 0; i < vals.size(); ++i) { - auto cstr = vals[i]; + int cstrIndex = 0; + for (auto cstr : vals) { if (skipConstraint(cstr)) { continue; } @@ -510,7 +512,7 @@ private: if (firstIndex != GeoEnum::GeoUndef) { listOfLabelsToScale.push_back( LabelToScale { - .constrId = static_cast(i), + .constrId = cstrIndex, .position = cstr->LabelPosition, .distance = cstr->LabelDistance } @@ -569,6 +571,7 @@ private: } ShapeConstraints.push_back(std::move(newConstr)); + cstrIndex++; } } }