From 5a6c088bd9311aaf5dc967f1cc6782ff94722b5c Mon Sep 17 00:00:00 2001 From: Marco Mattila Date: Sun, 15 Jul 2012 20:28:52 +0300 Subject: [PATCH] Use circular interpolation for circles and arcs in pcbnew gerber plots. --- common/common_plotGERBER_functions.cpp | 40 +++++++++++++++----------- include/plot_common.h | 2 ++ 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/common/common_plotGERBER_functions.cpp b/common/common_plotGERBER_functions.cpp index 05a0202605..c1995d623b 100644 --- a/common/common_plotGERBER_functions.cpp +++ b/common/common_plotGERBER_functions.cpp @@ -274,27 +274,35 @@ void GERBER_PLOTTER::Rect( const wxPoint& p1, const wxPoint& p2, FILL_T fill, } -void GERBER_PLOTTER::Circle( const wxPoint& aCentre, int aDiameter, FILL_T aFill, - int aWidth ) +void GERBER_PLOTTER::Circle( const wxPoint& aCenter, int aDiameter, FILL_T aFill, + int aWidth ) +{ + Arc( aCenter, 0, 3600, aDiameter / 2, aFill, aWidth ); +} + + +void GERBER_PLOTTER::Arc( const wxPoint& aCenter, int aStAngle, int aEndAngle, + int aRadius, FILL_T aFill, int aWidth ) { wxASSERT( outputFile ); - wxPoint start, end; - double radius = aDiameter / 2; - const int delta = 3600 / 32; /* increment (in 0.1 degrees) to draw circles */ - - start.x = aCentre.x + KiROUND( radius ); - start.y = aCentre.y; + wxPoint start, end; + start.x = aCenter.x + KiROUND( aRadius*cos( DEG2RAD( aStAngle/10.0 ) ) ); + start.y = aCenter.y - KiROUND( aRadius*sin( DEG2RAD( aStAngle/10.0 ) ) ); SetCurrentLineWidth( aWidth ); MoveTo( start ); + end.x = aCenter.x + KiROUND( aRadius*cos( DEG2RAD( aEndAngle/10.0 ) ) ); + end.y = aCenter.y - KiROUND( aRadius*sin( DEG2RAD( aEndAngle/10.0 ) ) ); + DPOINT devEnd = userToDeviceCoordinates( end ); + DPOINT devCenter = userToDeviceCoordinates( aCenter - start ); + fprintf( outputFile, "G75*\n" ); // Multiquadrant mode - for( int ii = delta; ii < 3600; ii += delta ) - { - end.x = aCentre.x + (int) ( radius * cos( DEG2RAD( ii / 10.0 ) ) ); - end.y = aCentre.y + (int) ( radius * sin( DEG2RAD( ii / 10.0 ) ) ); - LineTo( end ); - } - - FinishTo( start ); + if( aStAngle < aEndAngle ) + fprintf( outputFile, "G03" ); + else + fprintf( outputFile, "G02" ); + fprintf( outputFile, "X%dY%dI%dJ%dD01*\n", int( devEnd.x ), int( devEnd.y ), + int( devCenter.x ), int( devCenter.y ) ); + fprintf( outputFile, "G74*\nG01*\n" ); // Back to single quadrant and linear interp. } diff --git a/include/plot_common.h b/include/plot_common.h index dd5ff393f3..662226a6a7 100644 --- a/include/plot_common.h +++ b/include/plot_common.h @@ -679,6 +679,8 @@ public: int width = -1 ); virtual void Circle( const wxPoint& pos, int diametre, FILL_T fill, int width = -1 ); + virtual void Arc( const wxPoint& aCenter, int aStAngle, int aEndAngle, int aRadius, + FILL_T aFill, int aWidth = -1 ); virtual void PlotPoly( const std::vector< wxPoint >& aCornerList, FILL_T aFill, int aWidth = -1);