← Back to team overview

kicad-developers team mailing list archive

Re: patch to fix bug in DXF plot

 

----- Original Message -----

> From: Wayne Stambaugh <stambaughw@xxxxxxxxxxx>
> To: kicad-developers@xxxxxxxxxxxxxxxxxxx
> Cc: 
> Sent: Thursday, December 19, 2013 8:52 AM
> Subject: Re: [Kicad-developers] patch to fix bug in DXF plot
> 
> On 12/17/2013 5:03 AM, Cirilo Bernardo wrote:
> 
>>  Hi folks,
>> 
>>   There is a bug in DXF plot which changes the included angle of arcs. To 
> demonstrate the bug:
>> 
>>  1. in the edge cutout layer, create a rectangle with rounded corners and 
> plot the layer to DXF. Since KiCad will write a PCB file with all angles = +90, 
> everything is OK.
>> 
>>  2. Delete the cutout layer and import the DXF. At this point everything 
> should look OK.
>> 
>>  3. Plot the dxf again; this time things go bad because the DXF importer 
> marked some angles as -90 in Step 2.
>> 
>>  4. Import the bad DXF (or view it with MCAD software).
>> 
>>  I have only fixed the bug in BRDITEMS_PLOTTER::PlotDrawSegment and only for 
> DXF plotting. I did not create tests to check if the problem exists with other 
> types of plotting routines (it is possible others are affected, but not 
> necessarily so) and I did not investigate problems with exporting an Arc in 
> BRDITEMS_PLOTTER::Plot_1_EdgeModule.
>> 
>>  Cheers,
>>  Cirilo
> 
> Your patch does not work for the attached board edge cuts layer so I am
> reluctant to commit it.  It may work for your case but it may have
> broken another corner case.  Don't feel bad, the current DXF plot does
> not plot this board correctly either.  I've known about this problem for
> a while but have been too lazy to fix it.  There is some oddness in the
> way the DXF defines arcs that I am not completely familiar with.  If you
> can get the attached board to plot correctly without breaking all of the
> other DXF arc plotting, you'll get a hardy pat on back and your patch
> committed. :)  Also, your editor is leaving trailing white space which
> is a violation of the coding policy.
> 
> What I really would like to see is converting our DXF plotting over to
> use the dxflib that JP recently added to the project.  It seems like a
> much more complete solution which could give us better results in terms
> of layer and color support.  Arcs with width would be nice too.  Maybe
> you could become the guru of DXF plotting.
> 
> Thanks,
> 
> Wayne
> 
> 


After more experimentation with DXF, I'm confident I've got it right this time.  I also patched the rendering of module outlines. The previous suggested patch was indeed incorrect and some items would render fine while others were wrong.

- Cirilo
=== modified file 'pcbnew/plot_brditems_plotter.cpp'
--- pcbnew/plot_brditems_plotter.cpp	2013-12-05 12:24:27 +0000
+++ pcbnew/plot_brditems_plotter.cpp	2013-12-19 07:38:11 +0000
@@ -402,6 +402,15 @@
 
         double endAngle = startAngle + aEdge->GetAngle();
 
+        if ( GetFormat() == PLOT_FORMAT_DXF )
+        {
+            if( aEdge->GetAngle() < 0 )
+                std::swap( startAngle, endAngle );
+
+            if( m_layerMask & ( SILKSCREEN_LAYER_BACK | DRAW_LAYER | COMMENT_LAYER ) )
+                std::swap( startAngle, endAngle );
+        }
+
         if ( ( GetFormat() == PLOT_FORMAT_DXF ) &&
              ( m_layerMask & ( SILKSCREEN_LAYER_BACK | DRAW_LAYER | COMMENT_LAYER ) ) )
             m_plotter->ThickArc( pos, -startAngle, -endAngle, radius, thickness, GetMode() );
@@ -615,6 +624,13 @@
         radius = KiROUND( GetLineLength( end, start ) );
         StAngle  = ArcTangente( end.y - start.y, end.x - start.x );
         EndAngle = StAngle + aSeg->GetAngle();
+
+        if ( GetFormat() == PLOT_FORMAT_DXF )
+        {
+            if( aSeg->GetAngle() < 0 )
+                std::swap( StAngle, EndAngle );
+        }
+
         m_plotter->ThickArc( start, -EndAngle, -StAngle, radius, thickness, GetMode() );
         break;
 


References