From 259e41be2db2a221bd221242ce0bce9d17be4da3 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Mon, 28 Nov 2022 09:10:02 -0800 Subject: [PATCH] Don't add non-groupable items to the group Things like markers and netinfo should never get added to the group, even if we are inside the group while adding the items Fixes https://gitlab.com/kicad/code/kicad/issues/13026 --- include/pcb_group.h | 7 +++++++ pcbnew/board_commit.cpp | 5 ++++- pcbnew/pcb_group.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/include/pcb_group.h b/include/pcb_group.h index 7050378be4..4efedd369a 100644 --- a/include/pcb_group.h +++ b/include/pcb_group.h @@ -222,6 +222,13 @@ public: */ void RunOnDescendants( const std::function& aFunction ) const; + /** + * Check if the proposed type can be added to a group + * @param aType KICAD_T type to check + * @return true if the type can belong to a group, false otherwise + */ + static bool IsGroupableType( KICAD_T aType ); + protected: ///< @copydoc BOARD_ITEM::swapData void swapData( BOARD_ITEM* aImage ) override; diff --git a/pcbnew/board_commit.cpp b/pcbnew/board_commit.cpp index e0f5918282..5d0ea59563 100644 --- a/pcbnew/board_commit.cpp +++ b/pcbnew/board_commit.cpp @@ -246,8 +246,11 @@ void BOARD_COMMIT::Push( const wxString& aMessage, int aCommitFlags ) { case CHT_ADD: { - if( selTool && selTool->GetEnteredGroup() && !boardItem->GetParentGroup() ) + if( selTool && selTool->GetEnteredGroup() && !boardItem->GetParentGroup() + && PCB_GROUP::IsGroupableType( boardItem->Type() ) ) + { selTool->GetEnteredGroup()->AddItem( boardItem ); + } if( m_isFootprintEditor ) { diff --git a/pcbnew/pcb_group.cpp b/pcbnew/pcb_group.cpp index afbe5e988d..55ca9e11c1 100644 --- a/pcbnew/pcb_group.cpp +++ b/pcbnew/pcb_group.cpp @@ -32,14 +32,55 @@ #include #include +#include + PCB_GROUP::PCB_GROUP( BOARD_ITEM* aParent ) : BOARD_ITEM( aParent, PCB_GROUP_T ) { } +bool PCB_GROUP::IsGroupableType( KICAD_T aType ) +{ + switch ( aType ) + { + case PCB_FOOTPRINT_T: + case PCB_PAD_T: + case PCB_SHAPE_T: + case PCB_BITMAP_T: + case PCB_TEXT_T: + case PCB_TEXTBOX_T: + case PCB_FP_TEXT_T: + case PCB_FP_TEXTBOX_T: + case PCB_FP_SHAPE_T: + case PCB_FP_DIM_ALIGNED_T: + case PCB_FP_DIM_LEADER_T: + case PCB_FP_DIM_CENTER_T: + case PCB_FP_DIM_RADIAL_T: + case PCB_FP_DIM_ORTHOGONAL_T: + case PCB_FP_ZONE_T: + case PCB_TRACE_T: + case PCB_VIA_T: + case PCB_ARC_T: + case PCB_DIMENSION_T: + case PCB_DIM_ALIGNED_T: + case PCB_DIM_LEADER_T: + case PCB_DIM_CENTER_T: + case PCB_DIM_RADIAL_T: + case PCB_DIM_ORTHOGONAL_T: + case PCB_ZONE_T: + return true; + default: + return false; + } +} + + bool PCB_GROUP::AddItem( BOARD_ITEM* aItem ) { + wxCHECK_MSG( IsGroupableType( aItem->Type() ), false, + wxT( "Invalid item type added to group: " ) + aItem->GetTypeDesc() ); + // Items can only be in one group at a time if( aItem->GetParentGroup() ) aItem->GetParentGroup()->RemoveItem( aItem );