From 64d25752d49c5325ecba301500e52d9f158f650c Mon Sep 17 00:00:00 2001 From: tetektoza Date: Thu, 27 Nov 2025 19:11:51 +0100 Subject: [PATCH] Sketcher: Use constraint index instead of geoId as key in expr storage `SketcherTransformationExpressionHelper` was using `geoId` as the map key for storing expressions during geometry transformations. This is incorrect since single geometry may have multiple constraints with different expressions. So, using `geoId` as the key causes `std::map` overwrites, resulting in only the last expression being preserved per geometry. So this patch changes key to be a constraint index, and adds `ConstraintExpressionInfo` struct to store both expression and `geoId`. Co-authored-by: PaddleStroke --- .../Gui/SketcherTransformationExpressionHelper.cpp | 13 +++++++------ .../Gui/SketcherTransformationExpressionHelper.h | 10 ++++++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Mod/Sketcher/Gui/SketcherTransformationExpressionHelper.cpp b/src/Mod/Sketcher/Gui/SketcherTransformationExpressionHelper.cpp index f6224dc6b8..5a859810f8 100644 --- a/src/Mod/Sketcher/Gui/SketcherTransformationExpressionHelper.cpp +++ b/src/Mod/Sketcher/Gui/SketcherTransformationExpressionHelper.cpp @@ -54,10 +54,11 @@ void SketcherTransformationExpressionHelper::storeOriginalExpressions( = sketchObject->getExpression(spath); if (expr_info.expression) { - // map expression to geoid as a key - originalExpressions[geoId] = std::shared_ptr( - expr_info.expression->copy() - ); + // map expression to constraint index as a key, storing both expression and geoId + ConstraintExpressionInfo info; + info.expression = std::shared_ptr(expr_info.expression->copy()); + info.geoId = geoId; + originalExpressions[static_cast(i)] = info; } } } @@ -91,7 +92,7 @@ void SketcherTransformationExpressionHelper::copyExpressionsToNewConstraints( // try to find and apply a matching expression for this constraint bool expressionApplied = false; for (const auto& exprPair : originalExpressions) { - int originalGeoId = exprPair.first; + int originalGeoId = exprPair.second.geoId; int originalIndex = indexOfGeoId(listOfGeoIds, originalGeoId); if (originalIndex >= 0) { @@ -101,7 +102,7 @@ void SketcherTransformationExpressionHelper::copyExpressionsToNewConstraints( originalIndex, params, secondNumberOfCopies, - exprPair.second, + exprPair.second.expression, sketchObj ); diff --git a/src/Mod/Sketcher/Gui/SketcherTransformationExpressionHelper.h b/src/Mod/Sketcher/Gui/SketcherTransformationExpressionHelper.h index e8d39d5050..8118f5036f 100644 --- a/src/Mod/Sketcher/Gui/SketcherTransformationExpressionHelper.h +++ b/src/Mod/Sketcher/Gui/SketcherTransformationExpressionHelper.h @@ -84,6 +84,12 @@ private: int numberOfCopiesToMake; }; + struct ConstraintExpressionInfo + { + std::shared_ptr expression; + int geoId; // the geoId from listOfGeoIds that this constraint references + }; + /// calculate parameters needed for copy operations CopyCalculationParams calculateCopyParams( Sketcher::SketchObject* sketchObject, @@ -106,8 +112,8 @@ private: /// check if a constraint references the specified geometry ID bool constraintReferencesGeometry(const Sketcher::Constraint* cstr, int geoId) const; - // original geo id to expression mapping - std::map> originalExpressions; + // original constraint index to expression and geoId mapping + std::map originalExpressions; }; } // namespace SketcherGui