← Back to team overview

kicad-developers team mailing list archive

Re: PATCH: Fix default line widths for non-mm units in DXF import

 

Attached is the corresponding patch for the STABLE branch.

- Cirilo


On Fri, May 26, 2017 at 2:10 AM, Cirilo Bernardo
<cirilo.bernardo@xxxxxxxxx> wrote:
> In the DXF importer a default line width of 0.1 is used when no line width
> is specified in the file. That's all fine when the file specifies mm as the
> unit of length but we have a conversion problem if we use any other unit.
> Historically this is due to KiCad assuming that DXF files were all in some
> specific unit (I can't recall now if it was inch or mm). When I worked on
> the DXF importer to use the unit specified in the file (only defaulting to mm
> if no unit was specified) I missed this issue with line width conversions.
>
> To demonstrate the bug: create a DXF outline in a unit other than mm -
> I recommend using inches since that demonstrates the problem nicely
> while leaving the outline recognizable.  Do not assign a line width to
> the glyphs, otherwise kicad will correctly process the assigned width.
> Since kicad assigns a default line width of 0.1, the resulting line widths
> will be 25.4mm/inch * 0.1 = 2.54mm wide.
>
> Re: STABLE RELEASE: A similar fix will be required for the stable
> release; I don't know if this patch will apply since the file has been
> touched a number of times since the stable branch. Fortunately
> there are not many lines that need to be changed and they all
> follow the same formula. This bug was originally reported for the
> stable branch (4.0.6) here:
>
> https://forum.kicad.info/t/importing-dxf-to-pcb-new-creating-illegible-blobs/6548
>
> [OT] Incidentally, on one occasion a user was complaining about his DXF
> import going wrong. The problem in that case was that no unit length was
> specified in the DXF file so KiCad assumed mm when the design was done
> with inches. Is this issue (a) not worth worrying about, or (b) should be
> fixed by adding a "default DXF unit length (if none specified)" drop-down
> box in the DXF import dialog?
>
> - Cirilo
From 5d49fe207b6eccccdbafa9e91c04d3bce510169b Mon Sep 17 00:00:00 2001
From: Cirilo Bernardo <cirilo.bernardo@xxxxxxxxx>
Date: Mon, 29 May 2017 06:28:53 +0000
Subject: [PATCH] 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 524f0e981..a48f591f0 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->SetWidth( mapDim( aData.height * 0.8 ) );
     textItem->SetHeight( 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->SetWidth( mapDim( aData.height * 0.8 ) );
     textItem->SetHeight( 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


Follow ups

References