@ -23,10 +23,23 @@ void GERBER_PLOTTER::SetViewport( const wxPoint& aOffset, double aIusPerDecimil,
wxASSERT ( aMirror = = false ) ;
m_plotMirror = false ;
plotOffset = aOffset ;
wxASSERT ( aScale = = 1 ) ;
plotScale = 1 ;
wxASSERT ( aScale = = 1 ) ; // aScale parameter is not used in Gerber
plotScale = 1 ; // Plot scale is *always* 1.0
m_gerberUnitInch = false ; // Currently fixed, but could be an option
// number of digits after the point (number of digits of the mantissa
// Be carefull: the coordinates are stored in an integer
// so 6 digits (inches) or 5 digits (mm) is the best value
// to avoid truncations and overflow
m_gerberUnitFmt = m_gerberUnitInch ? 6 : 5 ;
m_IUsPerDecimil = aIusPerDecimil ;
iuPerDeviceUnit = 1.0 / aIusPerDecimil ;
iuPerDeviceUnit = pow ( 10.0 , m_gerberUnitFmt ) / ( aIusPerDecimil * 10000.0 ) ;
if ( ! m_gerberUnitInch )
iuPerDeviceUnit * = 25.4 ; // gerber output in mm
/* We don't handle the filmbox, and it's more useful to keep the
* origin at the origin */
paperSize . x = 0 ;
@ -67,25 +80,38 @@ bool GERBER_PLOTTER::StartPlot()
if ( outputFile = = NULL )
return false ;
if ( ! attribFunction . IsEmpty ( ) )
if ( ! m_ attribFunction. IsEmpty ( ) )
{
fputs ( " %TF.GerberVersion,J1*% \n " , outputFile ) ;
fprintf ( outputFile , " %%TF.FileFunction,%s*%% \n " , TO_UTF8 ( attribFunction ) ) ;
fprintf ( outputFile , " %%TF.FileFunction,%s*%% \n " ,
TO_UTF8 ( m_ attribFunction ) ) ;
}
/* Set coordinate format to 3.4 absolute, leading zero omitted */
fputs ( " %FSLAX34Y34*% \n " , outputFile ) ;
fputs ( " G04 Gerber Fmt 3.4, Leading zero omitted, Abs format* \n " , outputFile ) ;
// Set coordinate format to 3.6 or 4.5 absolute, leading zero omitted
// the number of digits for the integer part of coordintes is needed
// in gerber format, but is not very important when omitting leading zeros
// It is fixed here to 3 (inch) or 4 (mm), but is not actually used
int leadingDigitCount = m_gerberUnitInch ? 3 : 4 ;
fprintf ( outputFile , " %%FSLAX%d%dY%d%d*%% \n " ,
leadingDigitCount , m_gerberUnitFmt ,
leadingDigitCount , m_gerberUnitFmt ) ;
fprintf ( outputFile ,
" G04 Gerber Fmt %d.%d, Leading zero omitted, Abs format (unit %s)* \n " ,
leadingDigitCount , m_gerberUnitFmt ,
m_gerberUnitInch ? " inch " : " mm " ) ;
wxString Title = creator + wxT ( " " ) + GetBuildVersion ( ) ;
fprintf ( outputFile , " G04 (created by %s) date %s* \n " ,
TO_UTF8 ( Title ) , TO_UTF8 ( DateAndTime ( ) ) ) ;
/* Mass parameter: unit = INCHES */
fputs ( " %MOIN*% \n " , outputFile ) ;
/* Mass parameter: unit = INCHES/MM */
if ( m_gerberUnitInch )
fputs ( " %MOIN*% \n " , outputFile ) ;
else
fputs ( " %MOMM*% \n " , outputFile ) ;
/* Specify linear interpol (G01), unit = INCH (G70), abs format (G90) */
fputs ( " G01* \n G70* \n G90* \n " , outputFile ) ;
/* Specify linear interpol (G01) */
fputs ( " G01* \n " , outputFile ) ;
fputs ( " G04 APERTURE LIST* \n " , outputFile ) ;
/* Select the default aperture */
SetCurrentLineWidth ( - 1 ) ;
@ -191,7 +217,7 @@ void GERBER_PLOTTER::selectAperture( const wxSize& size,
{
// Pick an existing aperture or create a new one
currentAperture = getAperture ( size , type ) ;
fprintf ( outputFile , " G54 D%d*\n " , currentAperture - > DCode ) ;
fprintf ( outputFile , " D%d* \n " , currentAperture - > DCode ) ;
}
}
@ -208,8 +234,13 @@ void GERBER_PLOTTER::writeApertureList()
for ( std : : vector < APERTURE > : : iterator tool = apertures . begin ( ) ;
tool ! = apertures . end ( ) ; tool + + )
{
const double fscale = 0.0001f * plotScale
* iuPerDeviceUnit ;
// apertude sizes are in inch or mm, regardless the
// coordinates format
double fscale = 0.0001 * plotScale / m_IUsPerDecimil ; // inches
if ( ! m_gerberUnitInch )
fscale * = 25.4 ; // size in mm
char * text = cbuf + sprintf ( cbuf , " %%ADD%d " , tool - > DCode ) ;
/* Please note: the Gerber specs for mass parameters say that