From 18695751e81b7b46fae5c882e4e2c1dca96d90b7 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 27 Sep 2016 13:35:03 +0200 Subject: [PATCH] Fixed a footprint editor crash on DXF import Fixes: lp:1627422 * https://bugs.launchpad.net/kicad/+bug/1627422 --- pcbnew/tools/drawing_tool.cpp | 48 +++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index f84f7923a5..746041b6f7 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -605,28 +605,60 @@ int DRAWING_TOOL::PlaceDXF( const TOOL_EVENT& aEvent ) { // Modules use different types for the same things, // so we need to convert imported items to appropriate classes. - BOARD_ITEM* converted = NULL; + BOARD_ITEM* converted; switch( item->Type() ) { case PCB_TEXT_T: - converted = new TEXTE_MODULE( (MODULE*) parent ); - - // Copy coordinates, layer, etc. - *static_cast( converted ) = *static_cast( item ); + { + TEXTE_PCB* text = static_cast( item ); + TEXTE_MODULE* textMod = new TEXTE_MODULE( (MODULE*) parent ); + // Assignment operator also copies the item PCB_TEXT_T type, + // so it cannot be added to a module which handles PCB_MODULE_TEXT_T + textMod->SetPosition( text->GetPosition() ); + textMod->SetText( text->GetText() ); + textMod->SetSize( text->GetSize() ); + textMod->SetThickness( text->GetThickness() ); + textMod->SetOrientation( text->GetOrientation() ); + textMod->SetTextPosition( text->GetTextPosition() ); + textMod->SetSize( text->GetSize() ); + textMod->SetMirrored( text->IsMirrored() ); + textMod->SetAttributes( text->GetAttributes() ); + textMod->SetItalic( text->IsItalic() ); + textMod->SetBold( text->IsBold() ); + textMod->SetHorizJustify( text->GetHorizJustify() ); + textMod->SetVertJustify( text->GetVertJustify() ); + textMod->SetMultilineAllowed( text->IsMultilineAllowed() ); + converted = textMod; break; + } case PCB_LINE_T: - converted = new EDGE_MODULE( (MODULE*) parent ); - // Copy coordinates, layer, etc. - *static_cast( converted ) = *static_cast( item ); + { + DRAWSEGMENT* seg = static_cast( item ); + EDGE_MODULE* modSeg = new EDGE_MODULE( (MODULE*) parent ); + + // Assignment operator also copies the item PCB_LINE_T type, + // so it cannot be added to a module which handles PCB_MODULE_EDGE_T + modSeg->SetWidth( seg->GetWidth() ); + modSeg->SetStart( seg->GetStart() ); + modSeg->SetEnd( seg->GetEnd() ); + modSeg->SetShape( seg->GetShape() ); + modSeg->SetType( seg->GetType() ); + modSeg->SetBezControl1( seg->GetBezControl1() ); + modSeg->SetBezControl2( seg->GetBezControl2() ); + modSeg->SetBezierPoints( seg->GetBezierPoints() ); + modSeg->SetPolyPoints( seg->GetPolyPoints() ); + converted = modSeg; break; + } default: assert( false ); break; } + converted->SetLayer( item->GetLayer() ); delete item; item = converted; }