From 4b0cd7f034e568aab97a243d68db22bcc420bff4 Mon Sep 17 00:00:00 2001 From: theo-vt Date: Mon, 29 Dec 2025 15:38:12 -0500 Subject: [PATCH] Sketcher.scale: Scale label of modified constraints (#26442) * Sketcher.scale: Scale label of modified constraints * Sketcher.scale: Narrowing conversion on constraint index --- src/Mod/Sketcher/Gui/DrawSketchHandlerScale.h | 41 ++++++++++++++++++- src/Mod/Sketcher/Gui/EditDatumDialog.cpp | 15 ------- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerScale.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerScale.h index d5a35b9459..de5ed68696 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerScale.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerScale.h @@ -140,6 +140,7 @@ public: reassignFacadeIds(); } + scaleLabels(); Gui::Command::commitCommand(); } catch (const Base::Exception& e) { @@ -273,7 +274,15 @@ private: } private: + struct LabelToScale + { + int constrId; + float position; + float distance; + }; + std::vector listOfGeoIds; + std::vector listOfLabelsToScale; std::vector listOfFacadeIds; Base::Vector2d referencePoint, startPoint, endPoint; bool deleteOriginal; @@ -336,6 +345,25 @@ private: Base::Console().error("%s\n", e.what()); } } + void scaleLabels() + { + SketchObject* sketch = sketchgui->getSketchObject(); + + for (auto toScale : listOfLabelsToScale) { + sketch->setLabelDistance(toScale.constrId, toScale.distance * scaleFactor); + + // Label position or radii and diameters represent an angle, so + // they should not be scaled + Sketcher::ConstraintType type = sketch->Constraints[toScale.constrId]->Type; + if (type == Sketcher::ConstraintType::Radius + || type == Sketcher::ConstraintType::Diameter) { + sketch->setLabelPosition(toScale.constrId, toScale.position); + } + else { + sketch->setLabelPosition(toScale.constrId, toScale.position * scaleFactor); + } + } + } void createShape(bool onlyeditoutline) override { @@ -467,7 +495,8 @@ private: const std::vector& vals = Obj->Constraints.getValues(); - for (auto& cstr : vals) { + for (size_t i = 0; i < vals.size(); ++i) { + auto cstr = vals[i]; if (skipConstraint(cstr)) { continue; } @@ -478,6 +507,16 @@ private: auto newConstr = std::unique_ptr(cstr->copy()); + if (firstIndex != GeoEnum::GeoUndef) { + listOfLabelsToScale.push_back( + LabelToScale { + .constrId = static_cast(i), + .position = cstr->LabelPosition, + .distance = cstr->LabelDistance + } + ); + } + if ((cstr->Type == Symmetric || cstr->Type == Tangent || cstr->Type == Perpendicular || cstr->Type == Angle) && firstIndex != GeoEnum::GeoUndef && secondIndex != GeoEnum::GeoUndef diff --git a/src/Mod/Sketcher/Gui/EditDatumDialog.cpp b/src/Mod/Sketcher/Gui/EditDatumDialog.cpp index 6228a47dcb..63e2aa57b0 100644 --- a/src/Mod/Sketcher/Gui/EditDatumDialog.cpp +++ b/src/Mod/Sketcher/Gui/EditDatumDialog.cpp @@ -436,26 +436,11 @@ void EditDatumDialog::performAutoScale(double newDatum) double oldDatum = sketch->getDatum(ConstrNbr); double scaleFactor = newDatum / oldDatum; - float initLabelDistance = sketch->Constraints[ConstrNbr]->LabelDistance; - float initLabelPosition = sketch->Constraints[ConstrNbr]->LabelPosition; centerScale(scaleFactor); // Some constraints cannot be scaled so the actual datum constraint // might change index ConstrNbr = sketch->getSingleScaleDefiningConstraint(); - - sketch->setLabelDistance(ConstrNbr, initLabelDistance * scaleFactor); - - // Label position or radii and diameters represent an angle, so - // they should not be scaled - Sketcher::ConstraintType type = sketch->Constraints[ConstrNbr]->Type; - if (type == Sketcher::ConstraintType::Radius - || type == Sketcher::ConstraintType::Diameter) { - sketch->setLabelPosition(ConstrNbr, initLabelPosition); - } - else { - sketch->setLabelPosition(ConstrNbr, initLabelPosition * scaleFactor); - } } catch (const Base::Exception& e) { Base::Console().error("Exception performing autoscale: %s\n", e.what());