Make sure group children get added to board.

Also fixes a bug where you could import on to an invisible
layer (we now auto-show the layer if you do that).

Fixes https://gitlab.com/kicad/code/kicad/-/issues/16642
This commit is contained in:
Jeff Young 2024-01-18 14:00:30 +00:00
parent 84c6451787
commit 57315dd625
1 changed files with 21 additions and 13 deletions

View File

@ -1504,14 +1504,14 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent )
std::vector<BOARD_ITEM*> selectedItems; // the group, or newItems if no group
PCB_SELECTION preview;
BOARD_COMMIT commit( m_frame );
PCB_GROUP* group = nullptr;
PICKED_ITEMS_LIST groupUndoList;
PCB_LAYER_ID layer = F_Cu;
PCB_GROUP* group = dlg.ShouldGroupItems() ? new PCB_GROUP( m_frame->GetModel() )
: nullptr;
if( group )
if( dlg.ShouldGroupItems() )
{
group = new PCB_GROUP( m_frame->GetModel() );
newItems.push_back( group );
selectedItems.push_back( group );
preview.Add( group );
@ -1542,21 +1542,29 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent )
BOARD_ITEM* item = dynamic_cast<BOARD_ITEM*>( ptr.release() );
wxCHECK2( item, continue );
newItems.push_back( item );
if( group )
{
group->AddItem( item );
groupUndoList.PushItem( ITEM_PICKER( nullptr, item, UNDO_REDO::REGROUP ) );
}
else
{
newItems.push_back( item );
selectedItems.push_back( item );
}
groupUndoList.PushItem( ITEM_PICKER( nullptr, item, UNDO_REDO::REGROUP ) );
layer = item->GetLayer();
preview.Add( item );
}
// Clear the current selection then select the drawings so that edit tools work on them
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear );
EDA_ITEMS selItems( selectedItems.begin(), selectedItems.end() );
m_toolMgr->RunAction<EDA_ITEMS*>( PCB_ACTIONS::selectItems, &selItems );
if( !dlg.IsPlacementInteractive() )
{
for( BOARD_ITEM* item : newItems )
@ -1570,14 +1578,14 @@ int DRAWING_TOOL::PlaceImportedGraphics( const TOOL_EVENT& aEvent )
return 0;
}
if( !m_view->IsLayerVisible( layer ) )
{
m_frame->GetAppearancePanel()->SetLayerVisible( layer, true );
m_frame->GetCanvas()->Refresh();
}
m_view->Add( &preview );
// Clear the current selection then select the drawings so that edit tools work on them
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear );
EDA_ITEMS selItems( selectedItems.begin(), selectedItems.end() );
m_toolMgr->RunAction<EDA_ITEMS*>( PCB_ACTIONS::selectItems, &selItems );
m_frame->PushTool( aEvent );
auto setCursor =