diff --git a/pcbnew/router/pns_kicad_iface.cpp b/pcbnew/router/pns_kicad_iface.cpp index 576fe99ca6..4bac47ca53 100644 --- a/pcbnew/router/pns_kicad_iface.cpp +++ b/pcbnew/router/pns_kicad_iface.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -1321,6 +1322,15 @@ void PNS_KICAD_IFACE::RemoveItem( PNS::ITEM* aItem ) { BOARD_CONNECTED_ITEM* parent = aItem->Parent(); + if ( aItem->OfKind(PNS::ITEM::SOLID_T) ) + { + auto pad = static_cast( parent ); + auto pos = static_cast( aItem )->Pos(); + + m_moduleOffsets[ pad ].p_old = pos; + return; + } + if( parent ) { m_commit->Remove( parent ); @@ -1380,6 +1390,15 @@ void PNS_KICAD_IFACE::AddItem( PNS::ITEM* aItem ) break; } + case PNS::ITEM::SOLID_T: + { + auto pad = static_cast( aItem->Parent() ); + auto pos = static_cast( aItem )->Pos(); + + m_moduleOffsets[ pad ].p_new = pos; + return; + } + default: break; } @@ -1397,8 +1416,29 @@ void PNS_KICAD_IFACE::AddItem( PNS::ITEM* aItem ) void PNS_KICAD_IFACE::Commit() { + std::set processedMods; + EraseView(); - m_commit->Push( _( "Added a track" ) ); + + for( auto mo : m_moduleOffsets ) + { + auto offset = mo.second.p_new - mo.second.p_old; + auto mod = mo.first->GetParent(); + + VECTOR2I p_orig = mod->GetPosition(); + VECTOR2I p_new = p_orig + offset; + + if( processedMods.find( mod ) != processedMods.end() ) + continue; + + processedMods.insert( mod ); + m_commit->Modify( mod ); + mod->SetPosition( wxPoint( p_new.x, p_new.y )); + } + + m_moduleOffsets.clear(); + + m_commit->Push( _( "Interactive Router" ) ); m_commit = std::make_unique( m_tool ); } diff --git a/pcbnew/router/pns_kicad_iface.h b/pcbnew/router/pns_kicad_iface.h index a5cf0780d7..7b3f727e52 100644 --- a/pcbnew/router/pns_kicad_iface.h +++ b/pcbnew/router/pns_kicad_iface.h @@ -33,6 +33,8 @@ class BOARD; class BOARD_COMMIT; class PCB_DISPLAY_OPTIONS; class PCB_TOOL_BASE; +class MODULE; +class D_PAD; namespace KIGFX { @@ -103,6 +105,11 @@ public: void UpdateNet( int aNetCode ) override; private: + struct OFFSET { + VECTOR2I p_old, p_new; + }; + + std::map m_moduleOffsets; KIGFX::VIEW* m_view; KIGFX::VIEW_GROUP* m_previewItems; std::unordered_set m_hiddenItems;