From 147c839857fe1889be4590281190151b7f279cca Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 1 Feb 2021 16:39:26 +0000 Subject: [PATCH] Allow drag-select of fields. Fixes https://gitlab.com/kicad/code/kicad/issues/6662 --- eeschema/tools/ee_selection_tool.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/eeschema/tools/ee_selection_tool.cpp b/eeschema/tools/ee_selection_tool.cpp index 05df061153..05fdb56e12 100644 --- a/eeschema/tools/ee_selection_tool.cpp +++ b/eeschema/tools/ee_selection_tool.cpp @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include @@ -1105,13 +1106,15 @@ bool EE_SELECTION_TOOL::selectMultiple() // Mark items within the selection box as selected std::vector selectedItems; - std::vector sheetPins; + std::vector children; // Filter the view items based on the selection box BOX2I selectionBox = area.ViewBBox(); view->Query( selectionBox, selectedItems ); // Get the list of selected items - // Sheet pins aren't in the view; add them by hand + // Some children aren't in the view; add them by hand. + // DO NOT add them directly to selectedItems. If we add enough to cause the vector + // to grow it will re-allocate and invalidate the top-level for-loop iterator. for( KIGFX::VIEW::LAYER_ITEM_PAIR& pair : selectedItems ) { SCH_SHEET* sheet = dynamic_cast( pair.first ); @@ -1121,11 +1124,21 @@ bool EE_SELECTION_TOOL::selectMultiple() int layer = pair.second; for( SCH_SHEET_PIN* pin : sheet->GetPins() ) - sheetPins.emplace_back( KIGFX::VIEW::LAYER_ITEM_PAIR( pin, layer ) ); + children.emplace_back( KIGFX::VIEW::LAYER_ITEM_PAIR( pin, layer ) ); + } + + SCH_COMPONENT* symbol = dynamic_cast( pair.first ); + + if( symbol ) + { + int layer = pair.second; + + for( SCH_FIELD& field : symbol->GetFields() ) + children.emplace_back( KIGFX::VIEW::LAYER_ITEM_PAIR( &field, layer ) ); } } - selectedItems.insert( selectedItems.end(), sheetPins.begin(), sheetPins.end() ); + selectedItems.insert( selectedItems.end(), children.begin(), children.end() ); int height = area.GetEnd().y - area.GetOrigin().y;