This patch fixes the issue mentioned here: https://forum.kicad.info/t/import-dxf-with-arcs-from-freecad-into-kicad/7074/6
There is no bug report on the launchpad issue tracker. The problem occurs when a DXF file uses a Polyline rather than a LWPolyline. I essentially copied my code for ::addLWPolyline into ::addPolyline and made a few trivial changes so that it would compile. This is an oversight on my part when I improved support for LWPolyline; I didn't check that Polyline would have shared the same problem of replacing arcs with line segments. I have only tested on the example DXF file provided in the page linked above; all of the other DXF files which I have use LWPolyline so this issue is never seen. - Cirilo
From 8b97ac8ecc55659bcf132b09511058c9795d28be Mon Sep 17 00:00:00 2001 From: Cirilo Bernardo <[email protected]> Date: Fri, 26 May 2017 01:44:46 +0000 Subject: [PATCH 1/2] Fixed line width bug for non-mm DXF units --- pcbnew/import_dxf/dxf2brd_items.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/pcbnew/import_dxf/dxf2brd_items.cpp b/pcbnew/import_dxf/dxf2brd_items.cpp index dfd8272c9..0bba71106 100644 --- a/pcbnew/import_dxf/dxf2brd_items.cpp +++ b/pcbnew/import_dxf/dxf2brd_items.cpp @@ -120,7 +120,8 @@ void DXF2BRD_CONVERTER::addLine( const DRW_Line& aData ) segm->SetStart( start ); wxPoint end( mapX( aData.secPoint.x ), mapY( aData.secPoint.y ) ); segm->SetEnd( end ); - segm->SetWidth( mapDim( aData.thickness == 0 ? m_defaultThickness : aData.thickness ) ); + segm->SetWidth( mapDim( aData.thickness == 0 ? m_defaultThickness / m_DXF2mm + : aData.thickness ) ); m_newItemsList.push_back( segm ); } @@ -153,7 +154,7 @@ void DXF2BRD_CONVERTER::addPolyline(const DRW_Polyline& aData ) segm->SetStart( segment_startpoint ); wxPoint segment_endpoint( mapX( vertex->basePoint.x ), mapY( vertex->basePoint.y ) ); segm->SetEnd( segment_endpoint ); - segm->SetWidth( mapDim( aData.thickness == 0 ? m_defaultThickness + segm->SetWidth( mapDim( aData.thickness == 0 ? m_defaultThickness / m_DXF2mm : aData.thickness ) ); m_newItemsList.push_back( segm ); segment_startpoint = segment_endpoint; @@ -169,7 +170,7 @@ void DXF2BRD_CONVERTER::addPolyline(const DRW_Polyline& aData ) closing_segm->SetLayer( ToLAYER_ID( m_brdLayer ) ); closing_segm->SetStart( segment_startpoint ); closing_segm->SetEnd( polyline_startpoint ); - closing_segm->SetWidth( mapDim( aData.thickness == 0 ? m_defaultThickness + closing_segm->SetWidth( mapDim( aData.thickness == 0 ? m_defaultThickness / m_DXF2mm : aData.thickness ) ); m_newItemsList.push_back( closing_segm ); } @@ -186,7 +187,7 @@ void DXF2BRD_CONVERTER::addLWPolyline(const DRW_LWPolyline& aData ) wxRealPoint seg_start; wxRealPoint poly_start; double bulge = 0.0; - int lineWidth = mapDim( aData.thickness == 0 ? m_defaultThickness + int lineWidth = mapDim( aData.thickness == 0 ? m_defaultThickness / m_DXF2mm : aData.thickness ); for( unsigned ii = 0; ii < aData.vertlist.size(); ii++ ) @@ -235,7 +236,8 @@ void DXF2BRD_CONVERTER::addCircle( const DRW_Circle& aData ) segm->SetCenter( center ); wxPoint circle_start( mapX( aData.basePoint.x + aData.radious ), mapY( aData.basePoint.y ) ); segm->SetArcStart( circle_start ); - segm->SetWidth( mapDim( aData.thickness == 0 ? m_defaultThickness : aData.thickness ) ); + segm->SetWidth( mapDim( aData.thickness == 0 ? m_defaultThickness / m_DXF2mm + : aData.thickness ) ); m_newItemsList.push_back( segm ); } @@ -274,7 +276,8 @@ void DXF2BRD_CONVERTER::addArc( const DRW_Arc& data ) segm->SetAngle( angle ); - segm->SetWidth( mapDim( data.thickness == 0 ? m_defaultThickness : data.thickness ) ); + segm->SetWidth( mapDim( data.thickness == 0 ? m_defaultThickness / m_DXF2mm + : data.thickness ) ); m_newItemsList.push_back( segm ); } @@ -384,7 +387,8 @@ void DXF2BRD_CONVERTER::addText( const DRW_Text& aData ) // The 0.8 factor gives a better height/width ratio with our font textItem->SetTextWidth( mapDim( aData.height * 0.8 ) ); textItem->SetTextHeight( mapDim( aData.height ) ); - textItem->SetThickness( mapDim( aData.thickness == 0 ? m_defaultThickness : aData.thickness ) ); + textItem->SetThickness( mapDim( aData.thickness == 0 ? m_defaultThickness / m_DXF2mm + : aData.thickness ) ); textItem->SetText( text ); m_newItemsList.push_back( static_cast< BOARD_ITEM* >( brdItem ) ); @@ -446,7 +450,8 @@ void DXF2BRD_CONVERTER::addMText( const DRW_MText& aData ) // The 0.8 factor gives a better height/width ratio with our font textItem->SetTextWidth( mapDim( aData.height * 0.8 ) ); textItem->SetTextHeight( mapDim( aData.height ) ); - textItem->SetThickness( mapDim( aData.thickness == 0 ? m_defaultThickness : aData.thickness ) ); + textItem->SetThickness( mapDim( aData.thickness == 0 ? m_defaultThickness / m_DXF2mm + : aData.thickness ) ); textItem->SetText( text ); // Initialize text justifications: -- 2.11.0 From ce74e16c234d961e2d057e8787406fe2c8f4e11f Mon Sep 17 00:00:00 2001 From: Cirilo Bernardo <[email protected]> Date: Sun, 1 Oct 2017 08:53:40 +0000 Subject: [PATCH 2/2] DXF: fix import of Polyline with bulge --- pcbnew/import_dxf/dxf2brd_items.cpp | 61 ++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/pcbnew/import_dxf/dxf2brd_items.cpp b/pcbnew/import_dxf/dxf2brd_items.cpp index 0bba71106..c24bbd62e 100644 --- a/pcbnew/import_dxf/dxf2brd_items.cpp +++ b/pcbnew/import_dxf/dxf2brd_items.cpp @@ -127,12 +127,18 @@ void DXF2BRD_CONVERTER::addLine( const DRW_Line& aData ) void DXF2BRD_CONVERTER::addPolyline(const DRW_Polyline& aData ) { - // Currently, Pcbnew does not know polylines, for boards. - // So we have to convert a polyline to a set of segments. - // Obviously, the z coordinate is ignored + // Convert DXF Polylines into a series of KiCad Lines and Arcs. + // A Polyline (as opposed to a LWPolyline) may be a 3D line or + // even a 3D Mesh. The only type of Polyline which is guaranteed + // to import correctly is a 2D Polyline in X and Y, which is what + // we assume of all Polylines. The width used is the width of the + // Polyline; per-vertex line widths, if present, are ignored. - wxPoint polyline_startpoint; - wxPoint segment_startpoint; + wxRealPoint seg_start; + wxRealPoint poly_start; + double bulge = 0.0; + int lineWidth = mapDim( aData.thickness == 0 ? m_defaultThickness / m_DXF2mm + : aData.thickness ); for( unsigned ii = 0; ii < aData.vertlist.size(); ii++ ) { @@ -140,39 +146,32 @@ void DXF2BRD_CONVERTER::addPolyline(const DRW_Polyline& aData ) if( ii == 0 ) { - segment_startpoint.x = mapX( vertex->basePoint.x ); - segment_startpoint.y = mapY( vertex->basePoint.y ); - polyline_startpoint = segment_startpoint; + seg_start.x = m_xOffset + vertex->basePoint.x * m_DXF2mm; + seg_start.y = m_yOffset - vertex->basePoint.y * m_DXF2mm; + bulge = vertex->bulge; + poly_start = seg_start; continue; } - DRAWSEGMENT* segm = ( m_useModuleItems ) ? - static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) : - new DRAWSEGMENT; - - segm->SetLayer( ToLAYER_ID( m_brdLayer ) ); - segm->SetStart( segment_startpoint ); - wxPoint segment_endpoint( mapX( vertex->basePoint.x ), mapY( vertex->basePoint.y ) ); - segm->SetEnd( segment_endpoint ); - segm->SetWidth( mapDim( aData.thickness == 0 ? m_defaultThickness / m_DXF2mm - : aData.thickness ) ); - m_newItemsList.push_back( segm ); - segment_startpoint = segment_endpoint; + wxRealPoint seg_end( m_xOffset + vertex->basePoint.x * m_DXF2mm, + m_yOffset - vertex->basePoint.y * m_DXF2mm ); + + if( std::abs( bulge ) < MIN_BULGE ) + insertLine( seg_start, seg_end, lineWidth ); + else + insertArc( seg_start, seg_end, bulge, lineWidth ); + + bulge = vertex->bulge; + seg_start = seg_end; } - // Polyline flags bit 0 indicates closed (1) or open (0) polyline + // LWPolyline flags bit 0 indicates closed (1) or open (0) polyline if( aData.flags & 1 ) { - DRAWSEGMENT* closing_segm = ( m_useModuleItems ) ? - static_cast< DRAWSEGMENT* >( new EDGE_MODULE( NULL ) ) : - new DRAWSEGMENT; - - closing_segm->SetLayer( ToLAYER_ID( m_brdLayer ) ); - closing_segm->SetStart( segment_startpoint ); - closing_segm->SetEnd( polyline_startpoint ); - closing_segm->SetWidth( mapDim( aData.thickness == 0 ? m_defaultThickness / m_DXF2mm - : aData.thickness ) ); - m_newItemsList.push_back( closing_segm ); + if( std::abs( bulge ) < MIN_BULGE ) + insertLine( seg_start, poly_start, lineWidth ); + else + insertArc( seg_start, poly_start, bulge, lineWidth ); } } -- 2.11.0
_______________________________________________ Mailing list: https://launchpad.net/~kicad-developers Post to : [email protected] Unsubscribe : https://launchpad.net/~kicad-developers More help : https://help.launchpad.net/ListHelp

