From 152252c6858e849b08f154f24dd2aa2865b22ad4 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 14 Oct 2022 17:22:09 +0300 Subject: [PATCH] Fix selecting pads of footprints in groups. (cherry picked from commit 67985510a8cc1ddb3898e722f49ad26c394554f7) --- pcbnew/pcb_group.cpp | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/pcbnew/pcb_group.cpp b/pcbnew/pcb_group.cpp index 66242dd929..5d87e82528 100644 --- a/pcbnew/pcb_group.cpp +++ b/pcbnew/pcb_group.cpp @@ -70,22 +70,23 @@ void PCB_GROUP::RemoveAll() } +/* + * @return if not in the footprint editor and aItem is in a footprint, returns the + * footprint's parent group. Otherwise, returns the aItem's parent group. + */ +PCB_GROUP* getClosestGroup( BOARD_ITEM* aItem, bool isFootprintEditor ) +{ + if( !isFootprintEditor && aItem->GetParent() && aItem->GetParent()->Type() == PCB_FOOTPRINT_T ) + return aItem->GetParent()->GetParentGroup(); + else + return aItem->GetParentGroup(); +} + + /// Returns the top level group inside the aScope group, or nullptr PCB_GROUP* getNestedGroup( BOARD_ITEM* aItem, PCB_GROUP* aScope, bool isFootprintEditor ) { - PCB_GROUP* group = nullptr; - - if( isFootprintEditor ) - { - group = aItem->GetParentGroup(); - } - else - { - if( aItem->GetParent() && aItem->GetParent()->Type() == PCB_FOOTPRINT_T ) - group = aItem->GetParent()->GetParentGroup(); - else - group = aItem->GetParentGroup(); - } + PCB_GROUP* group = getClosestGroup( aItem, isFootprintEditor ); if( group == aScope ) return nullptr; @@ -110,7 +111,9 @@ PCB_GROUP* PCB_GROUP::TopLevelGroup( BOARD_ITEM* aItem, PCB_GROUP* aScope, bool bool PCB_GROUP::WithinScope( BOARD_ITEM* aItem, PCB_GROUP* aScope, bool isFootprintEditor ) { - if( aItem->GetParentGroup() && aItem->GetParentGroup() == aScope ) + PCB_GROUP* group = getClosestGroup( aItem, isFootprintEditor ); + + if( group && group == aScope ) return true; PCB_GROUP* nested = getNestedGroup( aItem, aScope, isFootprintEditor );