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

(cherry picked from commit 2db8c6eca0)
This commit is contained in:
Seth Hillbrand
2025-09-17 10:33:36 -07:00
parent f13c9cbd49
commit d6ef6252a2
2 changed files with 36 additions and 0 deletions
+28
View File
@@ -34,6 +34,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>
@@ -1973,6 +1974,9 @@ void PNS_KICAD_IFACE::RemoveItem( PNS::ITEM* aItem )
if( parent )
{
if( PCB_GROUP* group = parent->GetParentGroup() )
m_itemGroups[parent] = group;
m_commit->Remove( parent );
}
}
@@ -2165,6 +2169,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;
}
@@ -2206,6 +2219,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() )
{
PCB_GROUP* group = it->second;
m_commit->Modify( group );
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 );
}
+8
View File
@@ -23,6 +23,8 @@
#define __PNS_KICAD_IFACE_H
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include "pns_router.h"
@@ -37,6 +39,9 @@ class PCB_TOOL_BASE;
class FOOTPRINT;
class PAD;
class EDA_TEXT;
class LENGTH_DELAY_CALCULATION_ITEM;
class BOARD_ITEM;
class EDA_GROUP;
namespace PNS
{
@@ -163,6 +168,9 @@ protected:
KIGFX::VIEW_GROUP* m_previewItems;
std::unordered_set<BOARD_ITEM*> m_hiddenItems;
std::unordered_map<BOARD_ITEM*, PCB_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;