2011-09-20 13:57:40 +00:00
|
|
|
/**
|
|
|
|
* @file common_plotGERBER_functions.cpp
|
|
|
|
* @brief Common GERBER plot routines.
|
|
|
|
*/
|
2008-12-23 07:37:39 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <gr_basic.h>
|
|
|
|
#include <trigo.h>
|
|
|
|
#include <wxstruct.h>
|
|
|
|
#include <base_struct.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <plot_common.h>
|
|
|
|
#include <macros.h>
|
|
|
|
#include <kicad_string.h>
|
2008-12-23 07:37:39 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <build_version.h>
|
2010-01-05 08:48:49 +00:00
|
|
|
|
2008-12-23 07:37:39 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
void GERBER_PLOTTER::SetViewport( const wxPoint& aOffset, double aIusPerDecimil,
|
|
|
|
double aScale, bool aMirror )
|
2008-12-23 07:37:39 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
wxASSERT( !outputFile );
|
2010-12-11 18:40:39 +00:00
|
|
|
wxASSERT( aMirror == false );
|
|
|
|
plotMirror = false;
|
2012-05-03 18:37:56 +00:00
|
|
|
plotOffset = aOffset;
|
2009-06-28 18:13:55 +00:00
|
|
|
wxASSERT( aScale == 1 );
|
2012-05-03 18:37:56 +00:00
|
|
|
plotScale = 1;
|
2012-08-29 20:13:47 +00:00
|
|
|
m_IUsPerDecimil = aIusPerDecimil;
|
2012-05-03 18:37:56 +00:00
|
|
|
iuPerDeviceUnit = 1.0 / aIusPerDecimil;
|
|
|
|
/* We don't handle the filmbox, and it's more useful to keep the
|
|
|
|
* origin at the origin */
|
|
|
|
paperSize.x = 0;
|
|
|
|
paperSize.y = 0;
|
|
|
|
SetDefaultLineWidth( 100 * aIusPerDecimil ); // Arbitrary default
|
2008-12-23 07:37:39 +00:00
|
|
|
}
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
/**
|
|
|
|
* Emit a D-Code record, using proper conversions
|
2012-10-13 18:54:33 +00:00
|
|
|
* to format a leading zero omitted gerber coordinate
|
2012-05-03 18:37:56 +00:00
|
|
|
* (for 4 decimal positions, see header generation in start_plot
|
|
|
|
*/
|
|
|
|
void GERBER_PLOTTER::emitDcode( const DPOINT& pt, int dcode )
|
|
|
|
{
|
|
|
|
|
2012-10-13 18:54:33 +00:00
|
|
|
fprintf( outputFile, "X%dY%dD%02d*\n",
|
2012-05-03 18:37:56 +00:00
|
|
|
int( pt.x ), int( pt.y ), dcode );
|
|
|
|
}
|
2008-12-23 07:37:39 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function start_plot
|
2008-12-23 07:37:39 +00:00
|
|
|
* Write GERBER header to file
|
|
|
|
* initialize global variable g_Plot_PlotOutputFile
|
|
|
|
*/
|
2012-10-13 18:54:33 +00:00
|
|
|
bool GERBER_PLOTTER::StartPlot()
|
2008-12-23 07:37:39 +00:00
|
|
|
{
|
2012-10-13 18:54:33 +00:00
|
|
|
wxASSERT( outputFile );
|
|
|
|
|
|
|
|
finalFile = outputFile; // the actual gerber file will be created later
|
2010-03-31 16:59:32 +00:00
|
|
|
|
|
|
|
// Create a temporary filename to store gerber file
|
2011-09-20 13:57:40 +00:00
|
|
|
// note tmpfile() does not work under Vista and W7 in user mode
|
2010-03-31 16:59:32 +00:00
|
|
|
m_workFilename = filename + wxT(".tmp");
|
2012-05-03 18:37:56 +00:00
|
|
|
workFile = wxFopen( m_workFilename, wxT( "wt" ));
|
|
|
|
outputFile = workFile;
|
|
|
|
wxASSERT( outputFile );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
if( outputFile == NULL )
|
2010-03-31 16:59:32 +00:00
|
|
|
return false;
|
|
|
|
|
2013-10-04 08:42:09 +00:00
|
|
|
/* 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 );
|
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
wxString Title = creator + wxT( " " ) + GetBuildVersion();
|
2012-05-03 18:37:56 +00:00
|
|
|
fprintf( outputFile, "G04 (created by %s) date %s*\n",
|
2011-11-08 16:37:25 +00:00
|
|
|
TO_UTF8( Title ), TO_UTF8( DateAndTime() ) );
|
2008-12-23 07:37:39 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
/* Mass parameter: unit = INCHES */
|
|
|
|
fputs( "%MOIN*%\n", outputFile );
|
2008-12-23 07:37:39 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
/* Specify linear interpol (G01), unit = INCH (G70), abs format (G90) */
|
|
|
|
fputs( "G01*\nG70*\nG90*\n", outputFile );
|
|
|
|
fputs( "G04 APERTURE LIST*\n", outputFile );
|
2009-06-28 16:50:42 +00:00
|
|
|
/* Select the default aperture */
|
2012-05-03 18:37:56 +00:00
|
|
|
SetCurrentLineWidth( -1 );
|
2010-03-31 16:59:32 +00:00
|
|
|
|
|
|
|
return true;
|
2008-12-23 07:37:39 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
bool GERBER_PLOTTER::EndPlot()
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
|
|
|
char line[1024];
|
|
|
|
wxString msg;
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
wxASSERT( outputFile );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
/* Outfile is actually a temporary file i.e. workFile */
|
|
|
|
fputs( "M02*\n", outputFile );
|
|
|
|
fflush( outputFile );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
fclose( workFile );
|
|
|
|
workFile = wxFopen( m_workFilename, wxT( "rt" ));
|
|
|
|
wxASSERT( workFile );
|
|
|
|
outputFile = finalFile;
|
2008-12-23 07:37:39 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
// Placement of apertures in RS274X
|
2012-05-03 18:37:56 +00:00
|
|
|
while( fgets( line, 1024, workFile ) )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
fputs( line, outputFile );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
if( strcmp( strtok( line, "\n\r" ), "G04 APERTURE LIST*" ) == 0 )
|
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
writeApertureList();
|
|
|
|
fputs( "G04 APERTURE END LIST*\n", outputFile );
|
2009-06-28 18:13:55 +00:00
|
|
|
}
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
fclose( workFile );
|
|
|
|
fclose( finalFile );
|
2010-03-31 16:59:32 +00:00
|
|
|
::wxRemoveFile( m_workFilename );
|
2012-05-03 18:37:56 +00:00
|
|
|
outputFile = 0;
|
2010-03-31 16:59:32 +00:00
|
|
|
|
|
|
|
return true;
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
void GERBER_PLOTTER::SetDefaultLineWidth( int width )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
defaultPenWidth = width;
|
|
|
|
currentAperture = apertures.end();
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
void GERBER_PLOTTER::SetCurrentLineWidth( int width )
|
2008-12-23 07:37:39 +00:00
|
|
|
{
|
2009-06-28 16:50:42 +00:00
|
|
|
int pen_width;
|
|
|
|
|
|
|
|
if( width > 0 )
|
|
|
|
pen_width = width;
|
|
|
|
else
|
2012-05-03 18:37:56 +00:00
|
|
|
pen_width = defaultPenWidth;
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
selectAperture( wxSize( pen_width, pen_width ), APERTURE::Plotting );
|
|
|
|
currentPenWidth = pen_width;
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
std::vector<APERTURE>::iterator GERBER_PLOTTER::getAperture( const wxSize& size,
|
|
|
|
APERTURE::APERTURE_TYPE type )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
|
|
|
int last_D_code = 9;
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
// Search an existing aperture
|
2009-08-29 10:20:48 +00:00
|
|
|
std::vector<APERTURE>::iterator tool = apertures.begin();
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
while( tool != apertures.end() )
|
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
last_D_code = tool->DCode;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
if( (tool->Type == type) && (tool->Size == size) )
|
2009-06-28 18:13:55 +00:00
|
|
|
return tool;
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
tool++;
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
// Allocate a new aperture
|
2009-08-29 10:20:48 +00:00
|
|
|
APERTURE new_tool;
|
2012-05-03 18:37:56 +00:00
|
|
|
new_tool.Size = size;
|
|
|
|
new_tool.Type = type;
|
|
|
|
new_tool.DCode = last_D_code + 1;
|
2009-06-28 18:13:55 +00:00
|
|
|
apertures.push_back( new_tool );
|
|
|
|
return apertures.end() - 1;
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
void GERBER_PLOTTER::selectAperture( const wxSize& size,
|
|
|
|
APERTURE::APERTURE_TYPE type )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
wxASSERT( outputFile );
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
if( ( currentAperture == apertures.end() )
|
|
|
|
|| ( currentAperture->Type != type )
|
|
|
|
|| ( currentAperture->Size != size ) )
|
2009-06-28 18:13:55 +00:00
|
|
|
{
|
2013-05-06 17:47:01 +00:00
|
|
|
// Pick an existing aperture or create a new one
|
2012-05-03 18:37:56 +00:00
|
|
|
currentAperture = getAperture( size, type );
|
|
|
|
fprintf( outputFile, "G54D%d*\n", currentAperture->DCode );
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
/**
|
|
|
|
* Generate the table of D codes
|
2009-06-28 16:50:42 +00:00
|
|
|
*/
|
2012-05-03 18:37:56 +00:00
|
|
|
void GERBER_PLOTTER::writeApertureList()
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
wxASSERT( outputFile );
|
2009-06-28 16:50:42 +00:00
|
|
|
char cbuf[1024];
|
|
|
|
|
2013-05-06 17:47:01 +00:00
|
|
|
// Init
|
2009-08-29 10:20:48 +00:00
|
|
|
for( std::vector<APERTURE>::iterator tool = apertures.begin();
|
2009-06-28 18:13:55 +00:00
|
|
|
tool != apertures.end(); tool++ )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
const double fscale = 0.0001f * plotScale
|
2013-05-06 17:47:01 +00:00
|
|
|
* iuPerDeviceUnit ;
|
2012-05-03 18:37:56 +00:00
|
|
|
char* text = cbuf + sprintf( cbuf, "%%ADD%d", tool->DCode );
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2013-05-06 17:47:01 +00:00
|
|
|
/* Please note: the Gerber specs for mass parameters say that
|
|
|
|
exponential syntax is *not* allowed and the decimal point should
|
|
|
|
also be always inserted. So the %g format is ruled out, but %f is fine
|
|
|
|
(the # modifier forces the decimal point). Sadly the %f formatter
|
|
|
|
can't remove trailing zeros but thats not a problem, since nothing
|
|
|
|
forbid it (the file is only slightly longer) */
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
switch( tool->Type )
|
2009-06-28 18:13:55 +00:00
|
|
|
{
|
2009-08-29 10:20:48 +00:00
|
|
|
case APERTURE::Circle:
|
2013-05-06 17:47:01 +00:00
|
|
|
sprintf( text, "C,%#f*%%\n", tool->Size.x * fscale );
|
2009-06-28 18:13:55 +00:00
|
|
|
break;
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2009-08-29 10:20:48 +00:00
|
|
|
case APERTURE::Rect:
|
2013-05-06 17:47:01 +00:00
|
|
|
sprintf( text, "R,%#fX%#f*%%\n",
|
2012-05-03 18:37:56 +00:00
|
|
|
tool->Size.x * fscale,
|
|
|
|
tool->Size.y * fscale );
|
2009-06-28 18:13:55 +00:00
|
|
|
break;
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2009-08-29 10:20:48 +00:00
|
|
|
case APERTURE::Plotting:
|
2013-05-06 17:47:01 +00:00
|
|
|
sprintf( text, "C,%#f*%%\n", tool->Size.x * fscale );
|
2009-06-28 18:13:55 +00:00
|
|
|
break;
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2009-08-29 10:20:48 +00:00
|
|
|
case APERTURE::Oval:
|
2013-05-06 17:47:01 +00:00
|
|
|
sprintf( text, "O,%#fX%#f*%%\n",
|
2012-10-13 18:54:33 +00:00
|
|
|
tool->Size.x * fscale,
|
2012-05-03 18:37:56 +00:00
|
|
|
tool->Size.y * fscale );
|
2009-06-28 18:13:55 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
fputs( cbuf, outputFile );
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
void GERBER_PLOTTER::PenTo( const wxPoint& aPos, char plume )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
wxASSERT( outputFile );
|
|
|
|
DPOINT pos_dev = userToDeviceCoordinates( aPos );
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
switch( plume )
|
|
|
|
{
|
|
|
|
case 'Z':
|
|
|
|
break;
|
2008-12-23 07:37:39 +00:00
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
case 'U':
|
2012-05-03 18:37:56 +00:00
|
|
|
emitDcode( pos_dev, 2 );
|
2009-06-28 18:13:55 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'D':
|
2012-05-03 18:37:56 +00:00
|
|
|
emitDcode( pos_dev, 1 );
|
2009-06-28 18:13:55 +00:00
|
|
|
}
|
2008-12-23 07:37:39 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
penState = plume;
|
2008-12-23 07:37:39 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2012-10-13 18:54:33 +00:00
|
|
|
void GERBER_PLOTTER::Rect( const wxPoint& p1, const wxPoint& p2, FILL_T fill,
|
2012-05-03 18:37:56 +00:00
|
|
|
int width )
|
2008-12-23 07:37:39 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
std::vector< wxPoint > cornerList;
|
2011-04-20 08:13:21 +00:00
|
|
|
|
|
|
|
// Build corners list
|
|
|
|
cornerList.push_back( p1 );
|
|
|
|
wxPoint corner(p1.x, p2.y);
|
|
|
|
cornerList.push_back( corner );
|
|
|
|
cornerList.push_back( p2 );
|
|
|
|
corner.x = p2.x;
|
|
|
|
corner.y = p1.y;
|
|
|
|
cornerList.push_back( corner );
|
|
|
|
cornerList.push_back( p1 );
|
|
|
|
|
|
|
|
PlotPoly( cornerList, fill, width );
|
2008-12-23 07:37:39 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2012-07-15 17:28:52 +00:00
|
|
|
void GERBER_PLOTTER::Circle( const wxPoint& aCenter, int aDiameter, FILL_T aFill,
|
|
|
|
int aWidth )
|
2008-12-23 07:37:39 +00:00
|
|
|
{
|
2012-07-15 17:28:52 +00:00
|
|
|
Arc( aCenter, 0, 3600, aDiameter / 2, aFill, aWidth );
|
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2013-05-05 07:17:48 +00:00
|
|
|
void GERBER_PLOTTER::Arc( const wxPoint& aCenter, double aStAngle, double aEndAngle,
|
2012-07-15 17:28:52 +00:00
|
|
|
int aRadius, FILL_T aFill, int aWidth )
|
|
|
|
{
|
|
|
|
wxASSERT( outputFile );
|
|
|
|
wxPoint start, end;
|
2013-05-02 18:06:58 +00:00
|
|
|
start.x = aCenter.x + KiROUND( cosdecideg( aRadius, aStAngle ) );
|
|
|
|
start.y = aCenter.y - KiROUND( sindecideg( aRadius, aStAngle ) );
|
2012-05-03 18:37:56 +00:00
|
|
|
SetCurrentLineWidth( aWidth );
|
|
|
|
MoveTo( start );
|
2013-05-02 18:06:58 +00:00
|
|
|
end.x = aCenter.x + KiROUND( cosdecideg( aRadius, aEndAngle ) );
|
|
|
|
end.y = aCenter.y - KiROUND( sindecideg( aRadius, aEndAngle ) );
|
2012-07-15 17:28:52 +00:00
|
|
|
DPOINT devEnd = userToDeviceCoordinates( end );
|
2012-07-18 19:32:47 +00:00
|
|
|
DPOINT devCenter = userToDeviceCoordinates( aCenter )
|
|
|
|
- userToDeviceCoordinates( start );
|
2012-07-15 17:28:52 +00:00
|
|
|
fprintf( outputFile, "G75*\n" ); // Multiquadrant mode
|
|
|
|
|
|
|
|
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.
|
2008-12-23 07:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
/**
|
|
|
|
* Gerber polygon: they can (and *should*) be filled with the
|
|
|
|
* appropriate G36/G37 sequence (raster fills are deprecated)
|
2009-06-28 18:13:55 +00:00
|
|
|
*/
|
2012-10-13 18:54:33 +00:00
|
|
|
void GERBER_PLOTTER::PlotPoly( const std::vector< wxPoint >& aCornerList,
|
2012-05-03 18:37:56 +00:00
|
|
|
FILL_T aFill, int aWidth )
|
2008-12-23 07:37:39 +00:00
|
|
|
{
|
2011-04-20 08:13:21 +00:00
|
|
|
if( aCornerList.size() <= 1 )
|
|
|
|
return;
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
SetCurrentLineWidth( aWidth );
|
2009-06-28 18:13:55 +00:00
|
|
|
|
|
|
|
if( aFill )
|
2012-05-03 18:37:56 +00:00
|
|
|
fputs( "G36*\n", outputFile );
|
2011-04-20 08:13:21 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
MoveTo( aCornerList[0] );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2011-04-20 08:13:21 +00:00
|
|
|
for( unsigned ii = 1; ii < aCornerList.size(); ii++ )
|
2008-12-23 07:37:39 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
LineTo( aCornerList[ii] );
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
2009-06-28 18:13:55 +00:00
|
|
|
|
|
|
|
if( aFill )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
FinishTo( aCornerList[0] );
|
|
|
|
fputs( "G37*\n", outputFile );
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
PenFinish();
|
2008-12-23 07:37:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
/**
|
|
|
|
* Filled circular flashes are stored as apertures
|
2009-06-28 16:50:42 +00:00
|
|
|
*/
|
2012-10-13 18:54:33 +00:00
|
|
|
void GERBER_PLOTTER::FlashPadCircle( const wxPoint& pos, int diametre,
|
2012-05-03 18:37:56 +00:00
|
|
|
EDA_DRAW_MODE_T trace_mode )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
wxASSERT( outputFile );
|
2009-06-28 18:13:55 +00:00
|
|
|
wxSize size( diametre, diametre );
|
2008-12-23 07:37:39 +00:00
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
switch( trace_mode )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2012-01-03 17:14:17 +00:00
|
|
|
case LINE:
|
2009-06-28 16:50:42 +00:00
|
|
|
case SKETCH:
|
2012-05-03 18:37:56 +00:00
|
|
|
SetCurrentLineWidth( -1 );
|
|
|
|
Circle( pos, diametre - currentPenWidth, NO_FILL );
|
2009-06-28 18:13:55 +00:00
|
|
|
break;
|
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
case FILLED:
|
2012-05-03 18:37:56 +00:00
|
|
|
DPOINT pos_dev = userToDeviceCoordinates( pos );
|
|
|
|
selectAperture( size, APERTURE::Circle );
|
|
|
|
emitDcode( pos_dev, 3 );
|
2009-06-28 18:13:55 +00:00
|
|
|
break;
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
/**
|
|
|
|
* Filled oval flashes are handled as aperture in the 90 degree positions only
|
2009-11-23 15:16:50 +00:00
|
|
|
*/
|
2013-05-05 07:17:48 +00:00
|
|
|
void GERBER_PLOTTER::FlashPadOval( const wxPoint& pos, const wxSize& aSize, double orient,
|
2012-05-03 18:37:56 +00:00
|
|
|
EDA_DRAW_MODE_T trace_mode )
|
2008-12-23 07:37:39 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
wxASSERT( outputFile );
|
2009-06-28 18:13:55 +00:00
|
|
|
int x0, y0, x1, y1, delta;
|
2012-05-03 18:37:56 +00:00
|
|
|
wxSize size( aSize );
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
/* Plot a flashed shape. */
|
2009-06-28 18:13:55 +00:00
|
|
|
if( ( orient == 0 || orient == 900 || orient == 1800 || orient == 2700 )
|
|
|
|
&& trace_mode == FILLED )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2009-11-23 15:16:50 +00:00
|
|
|
if( orient == 900 || orient == 2700 ) /* orientation turned 90 deg. */
|
2009-06-28 18:13:55 +00:00
|
|
|
EXCHG( size.x, size.y );
|
2012-10-13 18:54:33 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
DPOINT pos_dev = userToDeviceCoordinates( pos );
|
|
|
|
selectAperture( size, APERTURE::Oval );
|
|
|
|
emitDcode( pos_dev, 3 );
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
2009-11-23 15:16:50 +00:00
|
|
|
else /* Plot pad as a segment. */
|
2008-12-23 07:37:39 +00:00
|
|
|
{
|
2009-06-28 18:13:55 +00:00
|
|
|
if( size.x > size.y )
|
|
|
|
{
|
|
|
|
EXCHG( size.x, size.y );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
if( orient < 2700 )
|
|
|
|
orient += 900;
|
|
|
|
else
|
|
|
|
orient -= 2700;
|
|
|
|
}
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
if( trace_mode == FILLED )
|
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
/* XXX to do: use an aperture macro to declare the rotated pad */
|
2009-11-23 15:16:50 +00:00
|
|
|
/* The pad is reduced to an oval with dy > dx */
|
2009-06-28 18:13:55 +00:00
|
|
|
delta = size.y - size.x;
|
|
|
|
x0 = 0;
|
|
|
|
y0 = -delta / 2;
|
|
|
|
x1 = 0;
|
|
|
|
y1 = delta / 2;
|
|
|
|
RotatePoint( &x0, &y0, orient );
|
|
|
|
RotatePoint( &x1, &y1, orient );
|
2012-05-03 18:37:56 +00:00
|
|
|
ThickSegment( wxPoint( pos.x + x0, pos.y + y0 ),
|
2009-06-28 18:13:55 +00:00
|
|
|
wxPoint( pos.x + x1, pos.y + y1 ),
|
|
|
|
size.x, trace_mode );
|
|
|
|
}
|
|
|
|
else
|
2011-09-20 13:57:40 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
sketchOval( pos, size, orient, -1 );
|
2011-09-20 13:57:40 +00:00
|
|
|
}
|
2008-12-23 07:37:39 +00:00
|
|
|
}
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
/**
|
|
|
|
* Filled rect flashes are handled as aperture in the 90 degree positions only
|
2009-11-23 15:16:50 +00:00
|
|
|
*/
|
2012-05-03 18:37:56 +00:00
|
|
|
void GERBER_PLOTTER::FlashPadRect( const wxPoint& pos, const wxSize& aSize,
|
2013-05-05 07:17:48 +00:00
|
|
|
double orient, EDA_DRAW_MODE_T trace_mode )
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2012-05-03 18:37:56 +00:00
|
|
|
wxASSERT( outputFile );
|
|
|
|
wxSize size( aSize );
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2013-05-01 17:32:36 +00:00
|
|
|
// Plot as an aperture flash
|
|
|
|
switch( int( orient ) )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
|
|
|
case 900:
|
2013-05-01 17:32:36 +00:00
|
|
|
case 2700: // rotation of 90 degrees or 270 swaps sizes
|
2012-05-03 18:37:56 +00:00
|
|
|
EXCHG( size.x, size.y );
|
2008-12-23 07:37:39 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
// Pass through
|
2009-06-28 16:50:42 +00:00
|
|
|
case 0:
|
|
|
|
case 1800:
|
2012-05-03 18:37:56 +00:00
|
|
|
switch( trace_mode )
|
|
|
|
{
|
|
|
|
case LINE:
|
|
|
|
case SKETCH:
|
|
|
|
SetCurrentLineWidth( -1 );
|
|
|
|
Rect( wxPoint( pos.x - (size.x - currentPenWidth) / 2,
|
|
|
|
pos.y - (size.y - currentPenWidth) / 2 ),
|
|
|
|
wxPoint( pos.x + (size.x - currentPenWidth) / 2,
|
|
|
|
pos.y + (size.y - currentPenWidth) / 2 ),
|
|
|
|
NO_FILL );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FILLED:
|
|
|
|
DPOINT pos_dev = userToDeviceCoordinates( pos );
|
|
|
|
selectAperture( size, APERTURE::Rect );
|
|
|
|
emitDcode( pos_dev, 3 );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-10-13 18:54:33 +00:00
|
|
|
default: // plot pad shape as polygon
|
2012-05-03 18:37:56 +00:00
|
|
|
{
|
2012-10-13 18:54:33 +00:00
|
|
|
// XXX to do: use an aperture macro to declare the rotated pad
|
2012-05-03 18:37:56 +00:00
|
|
|
wxPoint coord[4];
|
|
|
|
// coord[0] is assumed the lower left
|
|
|
|
// coord[1] is assumed the upper left
|
|
|
|
// coord[2] is assumed the upper right
|
|
|
|
// coord[3] is assumed the lower right
|
|
|
|
|
|
|
|
/* Trace the outline. */
|
|
|
|
coord[0].x = -size.x/2; // lower left
|
|
|
|
coord[0].y = size.y/2;
|
|
|
|
coord[1].x = -size.x/2; // upper left
|
|
|
|
coord[1].y = -size.y/2;
|
|
|
|
coord[2].x = size.x/2; // upper right
|
|
|
|
coord[2].y = -size.y/2;
|
|
|
|
coord[3].x = size.x/2; // lower right
|
|
|
|
coord[3].y = size.y/2;
|
|
|
|
|
|
|
|
FlashPadTrapez( pos, coord, orient, trace_mode );
|
|
|
|
}
|
|
|
|
break;
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
2008-12-23 07:37:39 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
/**
|
|
|
|
* Trapezoidal pad at the moment are *never* handled as aperture, since
|
|
|
|
* they require aperture macros
|
2009-06-28 16:50:42 +00:00
|
|
|
*/
|
2012-05-03 18:37:56 +00:00
|
|
|
void GERBER_PLOTTER::FlashPadTrapez( const wxPoint& aPadPos, const wxPoint* aCorners,
|
2013-05-05 07:17:48 +00:00
|
|
|
double aPadOrient, EDA_DRAW_MODE_T aTrace_Mode )
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2012-10-13 18:54:33 +00:00
|
|
|
// XXX to do: use an aperture macro to declare the pad
|
2011-04-20 08:13:21 +00:00
|
|
|
// polygon corners list
|
2012-05-03 18:37:56 +00:00
|
|
|
std::vector< wxPoint > cornerList;
|
2010-09-13 11:51:09 +00:00
|
|
|
|
|
|
|
for( int ii = 0; ii < 4; ii++ )
|
2011-04-20 08:13:21 +00:00
|
|
|
cornerList.push_back( aCorners[ii] );
|
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
// Draw the polygon and fill the interior as required
|
2011-04-20 08:13:21 +00:00
|
|
|
for( unsigned ii = 0; ii < 4; ii++ )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2011-04-20 08:13:21 +00:00
|
|
|
RotatePoint( &cornerList[ii], aPadOrient );
|
|
|
|
cornerList[ii] += aPadPos;
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2010-09-13 11:51:09 +00:00
|
|
|
// Close the polygon
|
2011-04-20 08:13:21 +00:00
|
|
|
cornerList.push_back( cornerList[0] );
|
2008-12-23 07:37:39 +00:00
|
|
|
|
2012-05-03 18:37:56 +00:00
|
|
|
SetCurrentLineWidth( -1 );
|
2011-04-20 08:13:21 +00:00
|
|
|
PlotPoly( cornerList, aTrace_Mode==FILLED ? FILLED_SHAPE : NO_FILL );
|
2009-06-28 18:13:55 +00:00
|
|
|
}
|
2010-12-06 22:05:12 +00:00
|
|
|
|
2012-10-13 18:54:33 +00:00
|
|
|
/**
|
2012-05-03 18:37:56 +00:00
|
|
|
* Change the plot polarity and begin a new layer
|
|
|
|
* Used to 'scratch off' silk screen away from solder mask
|
|
|
|
*/
|
2010-12-06 22:05:12 +00:00
|
|
|
void GERBER_PLOTTER::SetLayerPolarity( bool aPositive )
|
|
|
|
{
|
|
|
|
if( aPositive )
|
2012-05-03 18:37:56 +00:00
|
|
|
fprintf( outputFile, "%%LPD*%%\n" );
|
2010-12-06 22:05:12 +00:00
|
|
|
else
|
2012-05-03 18:37:56 +00:00
|
|
|
fprintf( outputFile, "%%LPC*%%\n" );
|
2010-12-06 22:05:12 +00:00
|
|
|
}
|
2012-05-03 18:37:56 +00:00
|
|
|
|