Maintain group membership when shoving

Keep track of the original group membership and assign this to the newly
created element as well

Fixes https://gitlab.com/kicad/code/kicad/-/issues/20862
This commit is contained in:
Seth Hillbrand 2025-08-26 10:33:36 -07:00
parent 9c577a4f4c
commit 2db8c6eca0
2 changed files with 35 additions and 0 deletions

View File

@ -35,6 +35,7 @@
#include <pcb_table.h>
#include <pcb_tablecell.h>
#include <board_commit.h>
#include <eda_group.h>
#include <layer_ids.h>
#include <kidialog.h>
#include <tools/pcb_tool_base.h>
@ -1989,6 +1990,9 @@ void PNS_KICAD_IFACE::RemoveItem( PNS::ITEM* aItem )
if( parent )
{
if( EDA_GROUP* group = parent->GetParentGroup() )
m_itemGroups[parent] = group;
m_commit->Remove( parent );
}
}
@ -2183,6 +2187,15 @@ BOARD_CONNECTED_ITEM* PNS_KICAD_IFACE::createBoardItem( PNS::ITEM* aItem )
newNetInfo->SetNetClass( m_board->GetDesignSettings().m_NetSettings->GetDefaultNetclass() );
}
if( newBoardItem )
{
if( BOARD_ITEM* src = aItem->GetSourceItem() )
{
if( m_itemGroups.contains( src ) )
m_replacementMap[src].push_back( newBoardItem );
}
}
return newBoardItem;
}
@ -2224,6 +2237,21 @@ void PNS_KICAD_IFACE::Commit()
m_fpOffsets.clear();
for( const auto& [ src, items ] : m_replacementMap )
{
if( auto it = m_itemGroups.find( src ); it != m_itemGroups.end() )
{
EDA_GROUP* group = it->second;
m_commit->Modify( group->AsEdaItem(), nullptr, RECURSE_MODE::NO_RECURSE );
for( BOARD_ITEM* bi : items )
group->AddItem( bi );
}
}
m_itemGroups.clear();
m_replacementMap.clear();
m_commit->Push( _( "Routing" ), m_commitFlags );
m_commit = std::make_unique<BOARD_COMMIT>( m_tool );
}

View File

@ -23,6 +23,8 @@
#define __PNS_KICAD_IFACE_H
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include "pns_router.h"
@ -38,6 +40,8 @@ class FOOTPRINT;
class PAD;
class EDA_TEXT;
class LENGTH_DELAY_CALCULATION_ITEM;
class BOARD_ITEM;
class EDA_GROUP;
namespace PNS
{
@ -176,6 +180,9 @@ protected:
KIGFX::VIEW_GROUP* m_previewItems;
std::unordered_set<BOARD_ITEM*> m_hiddenItems;
std::unordered_map<BOARD_ITEM*, EDA_GROUP*> m_itemGroups;
std::unordered_map<BOARD_ITEM*, std::vector<BOARD_ITEM*>> m_replacementMap;
PCB_TOOL_BASE* m_tool;
std::unique_ptr<BOARD_COMMIT> m_commit;
int m_commitFlags;