From a534f24fb64f6798c237ed81d4ae7feefafda0e1 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Thu, 8 Oct 2020 11:26:16 +0100 Subject: [PATCH] Repair deleting of groups in modedit. --- pcbnew/tools/edit_tool.cpp | 47 ++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 8f803761a1..5f0296f7af 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -1095,21 +1095,12 @@ int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent ) // As we are about to remove items, they have to be removed from the selection first m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); - PCBNEW_SELECTION removed; - for( EDA_ITEM* item : selectionCopy ) { - PCB_GROUP* group = static_cast( item )->GetParentGroup(); + PCB_GROUP* parentGroup = static_cast( item )->GetParentGroup(); - if( group ) - group->RemoveItem( static_cast( item ) ); - - if( m_editModules ) - { - m_commit->Remove( item ); - removed.Add( item ); - continue; - } + if( parentGroup ) + parentGroup->RemoveItem( static_cast( item ) ); switch( item->Type() ) { @@ -1120,7 +1111,7 @@ int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent ) if( text->GetType() == FP_TEXT::TEXT_is_DIVERS ) { - m_commit->Modify( text ); + m_commit->Modify( parent ); getView()->Remove( text ); parent->Remove( text ); } @@ -1193,25 +1184,41 @@ int EDIT_TOOL::Remove( const TOOL_EVENT& aEvent ) // Remove the entire zone otherwise m_commit->Remove( item ); - removed.Add( item ); } break; case PCB_GROUP_T: + { + PCB_GROUP* group = static_cast( item ); + + if( m_editModules ) + { + MODULE* parent = static_cast( item->GetParent() ); + + m_commit->Modify( parent ); + getView()->Remove( group ); + parent->Remove( group ); + + group->RunOnDescendants( [&]( BOARD_ITEM* bItem ) + { + getView()->Remove( bItem ); + parent->Remove( bItem ); + }); + } + else { m_commit->Remove( item ); - removed.Add( item ); - static_cast( item )->RunOnDescendants( [&]( BOARD_ITEM* bItem ) - { - m_commit->Remove( bItem ); - }); + group->RunOnDescendants( [&]( BOARD_ITEM* bItem ) + { + m_commit->Remove( bItem ); + }); } + } break; default: m_commit->Remove( item ); - removed.Add( item ); break; } }