diff --git a/pcbnew/class_drawsegment.cpp b/pcbnew/class_drawsegment.cpp index 8b1c833192..33060cde05 100644 --- a/pcbnew/class_drawsegment.cpp +++ b/pcbnew/class_drawsegment.cpp @@ -995,7 +995,17 @@ int DRAWSEGMENT::GetPointCount() const void DRAWSEGMENT::SwapData( BOARD_ITEM* aImage ) { - assert( aImage->Type() == PCB_LINE_T ); + DRAWSEGMENT* image = dynamic_cast( aImage ); + assert( image ); - std::swap( *((DRAWSEGMENT*) this), *((DRAWSEGMENT*) aImage) ); + std::swap( m_Width, image->m_Width ); + std::swap( m_Start, image->m_Start ); + std::swap( m_End, image->m_End ); + std::swap( m_Shape, image->m_Shape ); + std::swap( m_Type, image->m_Type ); + std::swap( m_Angle, image->m_Angle ); + std::swap( m_BezierC1, image->m_BezierC1 ); + std::swap( m_BezierC2, image->m_BezierC2 ); + std::swap( m_BezierPoints, image->m_BezierPoints ); + std::swap( m_Poly, image->m_Poly ); } diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index 404cc89aab..91278730de 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -601,52 +602,109 @@ int PCBNEW_CONTROL::Paste( const TOOL_EVENT& aEvent ) { case PCB_T: { + BOARD* clipBoard = (BOARD*) clipItem; + if( editModules ) { - wxLogDebug( wxT( "attempting to paste a pcb in the footprint editor\n") ); - return 0; + MODULE* editModule = board()->GetFirstModule(); + std::vector pastedItems; + + for( MODULE* clipModule : clipBoard->Modules() ) + { + clipModule->SetParent( board() ); + + for( auto pad : clipModule->Pads() ) + { + pad->SetParent( editModule ); + pastedItems.push_back( pad ); + } + + clipModule->Pads().clear(); + + for( auto item : clipModule->GraphicalItems() ) + { + item->SetParent( editModule ); + pastedItems.push_back( item ); + } + + clipModule->GraphicalItems().clear(); + } + + for( BOARD_ITEM* clipDrawItem : clipBoard->Drawings() ) + { + if( clipDrawItem->Type() == PCB_LINE_T ) + { + DRAWSEGMENT* clipDrawSeg = (DRAWSEGMENT*) clipDrawItem; + + // Convert to PCB_MODULE_EDGE_T + EDGE_MODULE* pastedDrawSeg = new EDGE_MODULE( editModule ); + static_cast( pastedDrawSeg )->SwapData( clipDrawSeg ); + pastedDrawSeg->SetLocalCoord(); + + pastedItems.push_back( pastedDrawSeg ); + } + else if( clipDrawItem->Type() == PCB_TEXT_T ) + { + TEXTE_PCB* clipTextItem = (TEXTE_PCB*) clipDrawItem; + + // Convert to PCB_MODULE_TEXT_T + TEXTE_MODULE* pastedTextItem = new TEXTE_MODULE( editModule ); + static_cast( pastedTextItem )->SwapText( *clipTextItem ); + static_cast( pastedTextItem )->SwapEffects( *clipTextItem ); + + pastedItems.push_back( pastedTextItem ); + } + } + + delete clipBoard; + + placeBoardItems( pastedItems, true, true ); + } + else + { + placeBoardItems( clipBoard, true ); + + m_frame->Compile_Ratsnest( true ); + m_frame->GetBoard()->BuildConnectivity(); } - placeBoardItems( static_cast( clipItem ), true ); - - m_frame->Compile_Ratsnest( true ); - m_frame->GetBoard()->BuildConnectivity(); break; } case PCB_MODULE_T: { - std::vector items; - - clipItem->SetParent( board() ); + MODULE* clipModule = (MODULE*) clipItem; + std::vector pastedItems; if( editModules ) { - auto oldModule = static_cast( clipItem ); - auto newModule = board()->GetFirstModule(); + MODULE* editModule = board()->GetFirstModule(); - for( auto pad : oldModule->Pads() ) + for( auto pad : clipModule->Pads() ) { - pad->SetParent( newModule ); - items.push_back( pad ); + pad->SetParent( editModule ); + pastedItems.push_back( pad ); } - oldModule->Pads().clear(); + clipModule->Pads().clear(); - for( auto item : oldModule->GraphicalItems() ) + for( auto item : clipModule->GraphicalItems() ) { - item->SetParent( newModule ); - items.push_back( item ); + item->SetParent( editModule ); + pastedItems.push_back( item ); } - oldModule->GraphicalItems().clear(); + clipModule->GraphicalItems().clear(); + + delete clipModule; } else { - items.push_back( clipItem ); + clipModule->SetParent( board() ); + pastedItems.push_back( clipModule ); } - placeBoardItems( items, true, true ); + placeBoardItems( pastedItems, true, true ); break; }