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
This commit is contained in:
Jeff Young 2024-03-29 15:58:19 +00:00
parent 42552d2e78
commit 2c21ef1ed0
2 changed files with 15 additions and 8 deletions

View File

@ -788,9 +788,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,15 +432,25 @@ 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 );
connectivity->Remove( item );
parent->Remove( item );
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 ) )
@ -453,8 +463,8 @@ 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 );
parent->Add( item );
update_item_change_state( item, ITEM_CHANGE_TYPE::CHANGED );
break;
}