From 51b99446679e7571b2939230cafbb4bac6dfe74b Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 10 Mar 2020 23:05:34 +0000 Subject: [PATCH] Fix pasting of items from board to Footprint Editor. In particular, map the netlist info to the orphaned item, and adjust the position of module graphic items to no longer be module-relative. Fixes https://gitlab.com/kicad/code/kicad/issues/4032 --- pcbnew/board_connected_item.h | 2 +- pcbnew/class_board.cpp | 4 ++-- pcbnew/netinfo.h | 3 +-- pcbnew/tools/pcbnew_control.cpp | 15 ++++++++++++--- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/pcbnew/board_connected_item.h b/pcbnew/board_connected_item.h index 89120af0f3..4e0d5c7396 100644 --- a/pcbnew/board_connected_item.h +++ b/pcbnew/board_connected_item.h @@ -89,7 +89,7 @@ public: */ void SetNet( NETINFO_ITEM* aNetInfo ) { - assert( aNetInfo->GetBoard() == GetBoard() ); + wxASSERT( aNetInfo->GetBoard() == GetBoard() || aNetInfo == NETINFO_LIST::OrphanedItem() ); m_netinfo = aNetInfo; } diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index b9b6f7e093..bbe20f896a 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -1771,14 +1771,14 @@ const std::vector BOARD::AllConnectedItems() void BOARD::ClearAllNetCodes() { - for ( BOARD_CONNECTED_ITEM* item : AllConnectedItems() ) + for( BOARD_CONNECTED_ITEM* item : AllConnectedItems() ) item->SetNetCode( 0 ); } void BOARD::MapNets( const BOARD* aDestBoard ) { - for ( BOARD_CONNECTED_ITEM* item : AllConnectedItems() ) + for( BOARD_CONNECTED_ITEM* item : AllConnectedItems() ) { NETINFO_ITEM* netInfo = aDestBoard->FindNet( item->GetNetname() ); diff --git a/pcbnew/netinfo.h b/pcbnew/netinfo.h index 263e03f88c..a7460e08b0 100644 --- a/pcbnew/netinfo.h +++ b/pcbnew/netinfo.h @@ -205,8 +205,7 @@ public: */ int GetClearance() { - wxASSERT( m_NetClass ); - return m_NetClass->GetClearance(); + return m_NetClass ? m_NetClass->GetClearance() : 0; } #endif diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index c75ce9d8f8..5e5da7ea21 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -628,11 +628,19 @@ int PCBNEW_CONTROL::Paste( const TOOL_EVENT& aEvent ) if( !clipItem ) return 0; - if( clipItem->Type() == PCB_T ) - static_cast( clipItem )->MapNets( m_frame->GetBoard() ); - bool editModules = m_editModules || frame()->IsType( FRAME_FOOTPRINT_EDITOR ); + if( clipItem->Type() == PCB_T ) + { + if( editModules ) + { + for( BOARD_CONNECTED_ITEM* item : static_cast( clipItem )->AllConnectedItems() ) + item->SetNet( NETINFO_LIST::OrphanedItem() ); + } + else + static_cast( clipItem )->MapNets( m_frame->GetBoard() ); + } + // The clipboard can contain two different things, an entire kicad_pcb // or a single module @@ -667,6 +675,7 @@ int PCBNEW_CONTROL::Paste( const TOOL_EVENT& aEvent ) for( auto item : clipModule->GraphicalItems() ) { + item->Move( clipModule->GetPosition() ); item->SetParent( editModule ); pastedItems.push_back( item ); }