From 3b0466f3e8f81bcc756f16f96dfbd77ab4665fda Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 6 Oct 2022 21:02:29 +0300 Subject: [PATCH] Fix selection and entering in nested groups. Fixes https://gitlab.com/kicad/code/kicad/issues/12586 (cherry picked from commit 0fea6f5ac37565ec88d2c4f4c12001951c2a4dab) --- include/pcb_group.h | 4 ++-- pcbnew/pcb_group.cpp | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/pcb_group.h b/include/pcb_group.h index d7cffd9072..51f0102892 100644 --- a/include/pcb_group.h +++ b/include/pcb_group.h @@ -92,11 +92,11 @@ public: void RemoveAll(); /* - * Search for highest level group containing item. + * Search for highest level group inside of aScope, containing item. * * @param aScope restricts the search to groups within the group scope. * @param isFootprintEditor true if we should stop promoting at the footprint level - * @return group containing item, if it exists, otherwise, NULL + * @return group inside of aScope, containing item, if exists, otherwise, nullptr */ static PCB_GROUP* TopLevelGroup( BOARD_ITEM* aItem, PCB_GROUP* aScope, bool isFootprintEditor ); diff --git a/pcbnew/pcb_group.cpp b/pcbnew/pcb_group.cpp index 4f5665ec37..66242dd929 100644 --- a/pcbnew/pcb_group.cpp +++ b/pcbnew/pcb_group.cpp @@ -70,7 +70,8 @@ void PCB_GROUP::RemoveAll() } -PCB_GROUP* getTopLevelGroup( BOARD_ITEM* aItem, PCB_GROUP* aScope, bool isFootprintEditor ) +/// 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; @@ -86,6 +87,9 @@ PCB_GROUP* getTopLevelGroup( BOARD_ITEM* aItem, PCB_GROUP* aScope, bool isFootpr group = aItem->GetParentGroup(); } + if( group == aScope ) + return nullptr; + while( group && group->GetParentGroup() && group->GetParentGroup() != aScope ) { if( group->GetParent()->Type() == PCB_FOOTPRINT_T && isFootprintEditor ) @@ -97,19 +101,21 @@ PCB_GROUP* getTopLevelGroup( BOARD_ITEM* aItem, PCB_GROUP* aScope, bool isFootpr return group; } + PCB_GROUP* PCB_GROUP::TopLevelGroup( BOARD_ITEM* aItem, PCB_GROUP* aScope, bool isFootprintEditor ) { - PCB_GROUP* candidate = getTopLevelGroup( aItem, aScope, isFootprintEditor ); - - return candidate == aScope ? nullptr : candidate; + return getNestedGroup( aItem, aScope, isFootprintEditor ); } bool PCB_GROUP::WithinScope( BOARD_ITEM* aItem, PCB_GROUP* aScope, bool isFootprintEditor ) { - PCB_GROUP* candidate = getTopLevelGroup( aItem, aScope, isFootprintEditor ); + if( aItem->GetParentGroup() && aItem->GetParentGroup() == aScope ) + return true; - return candidate == aScope; + PCB_GROUP* nested = getNestedGroup( aItem, aScope, isFootprintEditor ); + + return nested && nested->GetParentGroup() && nested->GetParentGroup() == aScope; }