From 2db0ac4403e0951e76ec0a3cf4b070940faeccb7 Mon Sep 17 00:00:00 2001 From: theo-vt Date: Thu, 2 Oct 2025 23:21:32 -0400 Subject: [PATCH] Sketcher: Reassign virtual space flag to constraints after modifying them through a default DHS --- .../Sketcher/Gui/DrawSketchDefaultHandler.h | 36 +++++++++++++++++++ src/Mod/Sketcher/Gui/DrawSketchHandlerScale.h | 1 + 2 files changed, 37 insertions(+) diff --git a/src/Mod/Sketcher/Gui/DrawSketchDefaultHandler.h b/src/Mod/Sketcher/Gui/DrawSketchDefaultHandler.h index a1cd631128..84969a05b9 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchDefaultHandler.h +++ b/src/Mod/Sketcher/Gui/DrawSketchDefaultHandler.h @@ -1205,10 +1205,13 @@ protected: Sketcher::PythonConverter::Mode::OmitInternalGeometry) .c_str()); + size_t initialConstraintCount = sketchgui->getSketchObject()->Constraints.getSize(); auto shapeConstraints = toPointerVector(ShapeConstraints); Gui::Command::doCommand( Gui::Command::Doc, Sketcher::PythonConverter::convert(sketchObj, shapeConstraints).c_str()); + + reassignVirtualSpace(initialConstraintCount); } /** @brief Function to draw as an edit curve all the geometry in the ShapeGeometry vector.*/ @@ -1226,6 +1229,39 @@ protected: //@} +private: + // Reassign the correct virtual space index for the added constraints + void reassignVirtualSpace(size_t startIndex) + { + if (ShapeConstraints.empty()) { + return; + } + + std::stringstream stream; + bool hasConstraintsInVirtualSpace = false; + for (size_t i = 0; i < ShapeConstraints.size(); ++i) { + if (ShapeConstraints[i]->isInVirtualSpace) { + if (hasConstraintsInVirtualSpace) { + stream << ","; + } + stream << i + startIndex; + hasConstraintsInVirtualSpace = true; + } + } + if (!hasConstraintsInVirtualSpace) { + return; + } + + try { + Gui::cmdAppObjectArgs(sketchgui->getObject(), + "setVirtualSpace([%s], True)", + stream.str().c_str()); + } + catch (const Base::Exception& e) { + Base::Console().error("%s\n", e.what()); + } + } + protected: std::vector> sugConstraints; diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerScale.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerScale.h index 6c5f5d339b..8389192d2a 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerScale.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerScale.h @@ -341,6 +341,7 @@ private: return; } + listOfFacadeIds.clear(); for (auto& geoId : listOfGeoIds) { const Part::Geometry* pGeo = Obj->getGeometry(geoId); long facadeId;