From 4b11789f02524f43ecffdfce5cab72bed0606d35 Mon Sep 17 00:00:00 2001 From: tetektoza Date: Fri, 29 Aug 2025 16:52:43 +0200 Subject: [PATCH] Sketcher: Introduce Select All (Ctrl + A) (#23289) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Sketcher: Introduce Select All (Ctrl + A) As the title says, this allows selecting all geometries on the sketch with CTRL + A shortcut, plus also allows to select "Select All" option from Edit menu. * Sketcher: Use fmt instead of std::stringstream in selectAll * Sketcher: Fix typo in selectAll Co-authored-by: João Matos --------- Co-authored-by: João Matos --- src/Gui/CommandDoc.cpp | 21 ++++- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 91 ++++++++++++++++++++- 2 files changed, 108 insertions(+), 4 deletions(-) diff --git a/src/Gui/CommandDoc.cpp b/src/Gui/CommandDoc.cpp index c4acd82b69..7b378573aa 100644 --- a/src/Gui/CommandDoc.cpp +++ b/src/Gui/CommandDoc.cpp @@ -1299,16 +1299,31 @@ StdCmdSelectAll::StdCmdSelectAll() sWhatsThis = "Std_SelectAll"; sStatusTip = sToolTipText; sPixmap = "edit-select-all"; - //sAccel = "Ctrl+A"; // supersedes shortcuts for text edits + sAccel = "Ctrl+A"; // supersedes shortcuts for text edits + + // this cmd only alters selection, not doc or 3d view + eType = AlterSelection; } void StdCmdSelectAll::activated(int iMsg) { Q_UNUSED(iMsg); + + auto* activeDoc = Application::Instance->activeDocument(); + if (activeDoc) { + auto* editingVP = activeDoc->getInEdit(); + if (editingVP && editingVP->selectAll()) { + return; + } + } + + // fallback to doc level select SelectionSingleton& rSel = Selection(); App::Document* doc = App::GetApplication().getActiveDocument(); - std::vector objs = doc->getObjectsOfType(App::DocumentObject::getClassTypeId()); - rSel.setSelection(doc->getName(), objs); + if (doc) { + std::vector objs = doc->getObjectsOfType(App::DocumentObject::getClassTypeId()); + rSel.setSelection(doc->getName(), objs); + } } bool StdCmdSelectAll::isActive() diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 0dc4c5330c..f3e66b30d7 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -42,6 +42,8 @@ #include #endif +#include + #include #include #include @@ -2689,7 +2691,94 @@ void ViewProviderSketch::updateColor() bool ViewProviderSketch::selectAll() { - // TODO: eventually implement "select all" logic + // logic of this func has been stolen partly from doBoxSelection() + if (!isInEditMode()) { + return false; + } + + Sketcher::SketchObject* sketchObject = getSketchObject(); + if (!sketchObject) { + return false; + } + + Gui::Selection().clearSelection(); + + int intGeoCount = sketchObject->getHighestCurveIndex() + 1; + int extGeoCount = sketchObject->getExternalGeometryCount(); + + const std::vector geomlist = sketchObject->getCompleteGeometry(); + + int VertexId = -1; + int GeoId = 0; + + for (std::vector::const_iterator it = geomlist.begin(); + it != geomlist.end() - 2; // -2 to exclude H_Axis and V_Axis + ++it, ++GeoId) { + + if (GeoId >= intGeoCount) { + GeoId = -extGeoCount; + } + + if ((*it)->is()) { + VertexId++; + addSelection2(fmt::format("Vertex{}", VertexId + 1)); + } + else if ((*it)->is()) { + VertexId++; // start + addSelection2(fmt::format("Vertex{}", VertexId + 1)); + + VertexId++; // end + addSelection2(fmt::format("Vertex{}", VertexId + 1)); + + if (GeoId >= 0) { + addSelection2(fmt::format("Edge{}", GeoId + 1)); + } else { + addSelection2(fmt::format("ExternalEdge{}", -GeoId - 1)); + } + } + else if ((*it)->isDerivedFrom()) { + VertexId++; + addSelection2(fmt::format("Vertex{}", VertexId + 1)); + + if (GeoId >= 0) { + addSelection2(fmt::format("Edge{}", GeoId + 1)); + } else { + addSelection2(fmt::format("ExternalEdge{}", -GeoId - 1)); + } + } + else if ((*it)->isDerivedFrom()) { + if (auto arc = dynamic_cast(*it)) { + VertexId++; // start + addSelection2(fmt::format("Vertex{}", VertexId + 1)); + + VertexId++; // end + addSelection2(fmt::format("Vertex{}", VertexId + 1)); + + VertexId++; // center + addSelection2(fmt::format("Vertex{}", VertexId + 1)); + } else { + // for other curves, select available vertices + VertexId++; + addSelection2(fmt::format("Vertex{}", VertexId + 1)); + } + + if (GeoId >= 0) { + addSelection2(fmt::format("Edge{}", GeoId + 1)); + } else { + addSelection2(fmt::format("ExternalEdge{}", -GeoId - 1)); + } + } + } + + // select constraints too + const std::vector& constraints = sketchObject->Constraints.getValues(); + for (size_t i = 0; i < constraints.size(); ++i) { + addSelection2(fmt::format("Constraint{}", i + 1)); + } + + // get root point if they exist + addSelection2("RootPoint"); + return true; }