← Back to team overview

kicad-developers team mailing list archive

Re: patch to fix bug in DXF plot

 

Le 18/12/2013 22:52, Wayne Stambaugh a écrit :
> 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

Can you try this very basic patch ?
Thanks.


-- 
Jean-Pierre CHARRAS
=== modifié fichier common/common_plotDXF_functions.cpp
--- common/common_plotDXF_functions.cpp	2013-12-06 18:31:15 +0000
+++ common/common_plotDXF_functions.cpp	2013-12-19 08:04:05 +0000
@@ -386,7 +386,7 @@
     }
 }

-/** Plot an arc in DXF format
+/* Plot an arc in DXF format
  * Filling is not supported
  */
 void DXF_PLOTTER::Arc( const wxPoint& centre, double StAngle, double EndAngle, int radius,
@@ -397,6 +397,14 @@
     if( radius <= 0 )
         return;

+    // In DXF, arcs are drawn CCW.
+    // In Kicad, arcs are CW or CCW
+    // If StAngle > EndAngle, it is CW. So transform it to CCW
+    if( StAngle > EndAngle )
+    {
+        EXCHG( StAngle, EndAngle );
+    }
+
     DPOINT centre_dev = userToDeviceCoordinates( centre );
     double radius_dev = userToDeviceSize( radius );

@@ -425,6 +433,7 @@
         EXCHG( size.x, size.y );
         orient = AddAngles( orient, 900 );
     }
+
     sketchOval( pos, size, orient, -1 );
 }



Follow ups

References