From 6bed2e663e6ce55c959906f3957ddcedf53bc903 Mon Sep 17 00:00:00 2001 From: tetektoza Date: Mon, 3 Nov 2025 00:00:53 +0100 Subject: [PATCH] Sketcher: Clear selection on selected geometry when hiding When a geometry element is selected and then hidden using the visibility checkbox in the Elements panel, it remains in the selection. Subsequently, if another geometry element is selected and deleted, both the visible element AND the hidden element are deleted. Root cause of that is basically that `changeLayer()` functions change the geometry's visual layer, but never clear the geometry from `Gui::Selection()`. So, this patch adds the handling to collect every sub-element name of the hidden geometry and then formats it and calls remove selection on the geometry during layer change transaction. --- src/Mod/Sketcher/Gui/TaskSketcherElements.cpp | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp b/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp index 9ee7c0b3e4..052075c3c6 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp @@ -34,6 +34,8 @@ #include #include +#include + #include #include #include @@ -646,6 +648,11 @@ void ElementView::changeLayer(ElementItem* item, int layer) return; } + const int geoid = item->ElementNbr; + const int startingVertex = item->StartingVertex; + const int midVertex = item->MidVertex; + const int endVertex = item->EndVertex; + doc->openTransaction("Geometry Layer Change"); auto sketchObject = item->getSketchObject(); @@ -653,8 +660,6 @@ void ElementView::changeLayer(ElementItem* item, int layer) auto geometry = sketchObject->Geometry.getValues(); auto newGeometry(geometry); - auto geoid = item->ElementNbr; - // currently only internal geometry can be changed from one layer to another if (geoid >= 0) { auto currentLayer = getSafeGeomLayerId(geometry[geoid]); @@ -677,6 +682,28 @@ void ElementView::changeLayer(ElementItem* item, int layer) } doc->commitTransaction(); + + if (layer == static_cast(ElementItem::Layer::Hidden) && geoid >= 0) { + const std::string docName = sketchObject->getDocument()->getName(); + const std::string objName = sketchObject->getNameInDocument(); + + auto deselect = [&](const std::string& name) { + const std::string convertedName = sketchObject->convertSubName(name); + Gui::Selection().rmvSelection(docName.c_str(), objName.c_str(), convertedName.c_str()); + }; + + deselect(fmt::format("Edge{}", geoid + 1)); + + if (startingVertex >= 0) { + deselect(fmt::format("Vertex{}", startingVertex + 1)); + } + if (midVertex >= 0) { + deselect(fmt::format("Vertex{}", midVertex + 1)); + } + if (endVertex >= 0) { + deselect(fmt::format("Vertex{}", endVertex + 1)); + } + } } void ElementView::contextMenuEvent(QContextMenuEvent* event)