diff --git a/pcbnew/router/pns_kicad_iface.cpp b/pcbnew/router/pns_kicad_iface.cpp index b4a2e9b835..ac949e9830 100644 --- a/pcbnew/router/pns_kicad_iface.cpp +++ b/pcbnew/router/pns_kicad_iface.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -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( m_tool ); } diff --git a/pcbnew/router/pns_kicad_iface.h b/pcbnew/router/pns_kicad_iface.h index a32615241a..0210ab01fe 100644 --- a/pcbnew/router/pns_kicad_iface.h +++ b/pcbnew/router/pns_kicad_iface.h @@ -23,6 +23,8 @@ #define __PNS_KICAD_IFACE_H #include +#include +#include #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 m_hiddenItems; + std::unordered_map m_itemGroups; + std::unordered_map> m_replacementMap; + PCB_TOOL_BASE* m_tool; std::unique_ptr m_commit; int m_commitFlags;