Fix footprint undo for new UUID caches.

The footprint's children get swapped by the parent's std::swap
call, so they need to get removed/added to their parent around
the swap.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/17592

(cherry picked from commit 2c21ef1ed0)
This commit is contained in:
Jeff Young 2024-03-29 15:58:19 +00:00
parent 524d431438
commit 09985988e7
2 changed files with 13 additions and 6 deletions

View File

@ -791,9 +791,6 @@ void FOOTPRINT::Remove( BOARD_ITEM* aBoardItem, REMOVE_MODE aMode )
{
PCB_FIELD* field = static_cast<PCB_FIELD*>( aBoardItem );
// Only user text can be removed this way.
wxCHECK_RET( !field->IsMandatoryField(),
wxT( "Please report this bug: Invalid remove operation on required text" ) );
for( auto it = m_fields.begin(); it != m_fields.end(); ++it )
{
if( *it == aBoardItem )

View File

@ -432,7 +432,17 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList )
{
case UNDO_REDO::CHANGED: /* Exchange old and new data for each item */
{
BOARD_ITEM* item = (BOARD_ITEM*) eda_item;
BOARD_ITEM* item = (BOARD_ITEM*) eda_item;
BOARD_ITEM_CONTAINER* parent = GetBoard();
if( item->GetParentFootprint() )
{
// We need the current item and it's parent, which may be different from what
// was stored if we're multiple frames up the undo stack.
item = GetBoard()->GetItem( item->m_Uuid );
parent = item->GetParentFootprint();
}
BOARD_ITEM* image = (BOARD_ITEM*) aList->GetPickedItemLink( ii );
view->Remove( item );
@ -440,7 +450,7 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList )
item->SwapItemData( image );
eda_item->ClearFlags( UR_TRANSIENT );
item->ClearFlags( UR_TRANSIENT );
image->SetFlags( UR_TRANSIENT );
if( PCB_GROUP* group = dynamic_cast<PCB_GROUP*>( item ) )
@ -454,7 +464,7 @@ void PCB_BASE_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList )
view->Add( item );
view->Hide( item, false );
connectivity->Add( item );
update_item_change_state( eda_item, ITEM_CHANGE_TYPE::CHANGED );
update_item_change_state( item, ITEM_CHANGE_TYPE::CHANGED );
break;
}