Don't leak PCB_GROUP internals into BOARD_COMMIT.

(This also fixes a potential bug where the image
group's children didn't get the image as a parent.)
This commit is contained in:
Jeff Young 2025-04-21 18:24:30 +01:00
parent c1b1c689ad
commit 199a7a34ea
2 changed files with 16 additions and 11 deletions

View File

@ -751,16 +751,6 @@ void BOARD_COMMIT::Revert()
BOARD_ITEM* boardItemCopy = static_cast<BOARD_ITEM*>( entry.m_copy );
boardItem->SwapItemData( boardItemCopy );
if( PCB_GROUP* group = dynamic_cast<PCB_GROUP*>( boardItem ) )
{
group->RunOnChildren(
[&]( BOARD_ITEM* child )
{
child->SetParentGroup( group );
},
RECURSE_MODE::NO_RECURSE );
}
view->Add( boardItem );
connectivity->Add( boardItem );
itemsChanged.push_back( boardItem );

View File

@ -264,8 +264,23 @@ PCB_GROUP* PCB_GROUP::DeepDuplicate() const
void PCB_GROUP::swapData( BOARD_ITEM* aImage )
{
assert( aImage->Type() == PCB_GROUP_T );
PCB_GROUP* image = static_cast<PCB_GROUP*>( aImage );
std::swap( *( (PCB_GROUP*) this ), *( (PCB_GROUP*) aImage ) );
std::swap( *this, *image );
RunOnChildren(
[&]( BOARD_ITEM* child )
{
child->SetParentGroup( this );
},
RECURSE_MODE::NO_RECURSE );
image->RunOnChildren(
[&]( BOARD_ITEM* child )
{
child->SetParentGroup( image );
},
RECURSE_MODE::NO_RECURSE );
}