From 9dacd4abb77710e09e74109b53e070980c9a12a3 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 20 Feb 2021 18:09:09 +0000 Subject: [PATCH] Don't allow footprint children in groups outside their footprint. Fixes https://gitlab.com/kicad/code/kicad/issues/7625 --- pcbnew/plugins/kicad/pcb_parser.cpp | 21 +++++++++++++- pcbnew/tools/group_tool.cpp | 43 +++++++++++++++++++++++++---- 2 files changed, 58 insertions(+), 6 deletions(-) diff --git a/pcbnew/plugins/kicad/pcb_parser.cpp b/pcbnew/plugins/kicad/pcb_parser.cpp index fd6a48b200..3631a4e732 100644 --- a/pcbnew/plugins/kicad/pcb_parser.cpp +++ b/pcbnew/plugins/kicad/pcb_parser.cpp @@ -808,7 +808,26 @@ void PCB_PARSER::resolveGroups( BOARD_ITEM* aParent ) item = getItem( aUuid ); if( item && item->Type() != NOT_USED ) - group->AddItem( item ); + { + switch( item->Type() ) + { + // We used to allow fp items in non-footprint groups. It was a mistake. + case PCB_FP_TEXT_T: + case PCB_FP_SHAPE_T: + case PCB_FP_ZONE_T: + if( item->GetParent() == group->GetParent() ) + group->AddItem( item ); + + break; + + // This is the deleted item singleton, which means we didn't find the uuid. + case NOT_USED: + break; + + default: + group->AddItem( item ); + } + } } } diff --git a/pcbnew/tools/group_tool.cpp b/pcbnew/tools/group_tool.cpp index b7d63955cd..f71d95b682 100644 --- a/pcbnew/tools/group_tool.cpp +++ b/pcbnew/tools/group_tool.cpp @@ -211,13 +211,46 @@ int GROUP_TOOL::PickNewMember( const TOOL_EVENT& aEvent ) int GROUP_TOOL::Group( const TOOL_EVENT& aEvent ) { - PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool(); - const PCB_SELECTION& selection = selTool->GetSelection(); - BOARD* board = getModel(); - PCB_GROUP* group = nullptr; + PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool(); + PCB_SELECTION selection; + + if( m_isFootprintEditor ) + { + selection = selTool->RequestSelection( + []( const VECTOR2I& , GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* ) + { + } ); + } + else + { + selection = selTool->RequestSelection( + []( const VECTOR2I& , GENERAL_COLLECTOR& aCollector, PCB_SELECTION_TOOL* ) + { + // Iterate from the back so we don't have to worry about removals. + for( int i = aCollector.GetCount() - 1; i >= 0; --i ) + { + BOARD_ITEM* item = aCollector[ i ]; + + switch( item->Type() ) + { + case PCB_FP_TEXT_T: + case PCB_FP_SHAPE_T: + case PCB_FP_ZONE_T: + aCollector.Remove( item ); + break; + + default: + break; + } + } + } ); + } if( selection.Empty() ) - m_toolMgr->RunAction( PCB_ACTIONS::selectionCursor, true ); + return 0; + + BOARD* board = getModel(); + PCB_GROUP* group = nullptr; if( m_isFootprintEditor ) {