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
|
|
|
|
|
|
|
#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"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "kicad_string.h"
|
2008-12-23 07:37:39 +00:00
|
|
|
|
2010-01-05 08:48:49 +00:00
|
|
|
#include "build_version.h"
|
|
|
|
|
2008-12-23 07:37:39 +00:00
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function set_viewport
|
2009-06-28 18:13:55 +00:00
|
|
|
* Set the plot offset for the current plotting
|
|
|
|
* @param aOffset = plot offset
|
|
|
|
* @param aScale = coordinate scale (scale coefficient for coordinates)
|
2010-12-14 15:56:30 +00:00
|
|
|
* @param aMirror - Mirror plot if true.
|
2008-12-23 07:37:39 +00:00
|
|
|
*/
|
2010-12-11 18:40:39 +00:00
|
|
|
void GERBER_PLOTTER::set_viewport( wxPoint aOffset, double aScale, bool aMirror )
|
2008-12-23 07:37:39 +00:00
|
|
|
{
|
2009-06-28 18:13:55 +00:00
|
|
|
wxASSERT( !output_file );
|
2010-12-11 18:40:39 +00:00
|
|
|
wxASSERT( aMirror == false );
|
|
|
|
plotMirror = false;
|
|
|
|
plot_offset = aOffset;
|
2009-06-28 18:13:55 +00:00
|
|
|
wxASSERT( aScale == 1 );
|
|
|
|
plot_scale = 1;
|
2009-06-28 16:50:42 +00:00
|
|
|
device_scale = 1;
|
2009-11-23 15:16:50 +00:00
|
|
|
set_default_line_width( 100 ); /* line thickness in 1 / 1000 inch */
|
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
|
|
|
|
* @param aFile: an opened file to write to
|
|
|
|
*/
|
2010-03-31 16:59:32 +00:00
|
|
|
bool GERBER_PLOTTER::start_plot( FILE* aFile )
|
2008-12-23 07:37:39 +00:00
|
|
|
{
|
2009-06-28 18:13:55 +00:00
|
|
|
wxASSERT( !output_file );
|
|
|
|
final_file = aFile;
|
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");
|
|
|
|
work_file = wxFopen( m_workFilename, wxT( "wt" ));
|
2009-06-28 16:50:42 +00:00
|
|
|
output_file = work_file;
|
2010-03-31 16:59:32 +00:00
|
|
|
wxASSERT( output_file );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2010-03-31 16:59:32 +00:00
|
|
|
if( output_file == NULL )
|
|
|
|
return false;
|
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
wxString Title = creator + wxT( " " ) + GetBuildVersion();
|
2011-11-08 16:37:25 +00:00
|
|
|
fprintf( output_file, "G04 (created by %s) date %s*\n",
|
|
|
|
TO_UTF8( Title ), TO_UTF8( DateAndTime() ) );
|
2008-12-23 07:37:39 +00:00
|
|
|
|
|
|
|
// Specify linear interpol (G01), unit = INCH (G70), abs format (G90):
|
2009-06-28 16:50:42 +00:00
|
|
|
fputs( "G01*\nG70*\nG90*\n", output_file );
|
|
|
|
fputs( "%MOIN*%\n", output_file ); // set unites = INCHES
|
2008-12-23 07:37:39 +00:00
|
|
|
|
|
|
|
/* Set gerber format to 3.4 */
|
|
|
|
fputs( "G04 Gerber Fmt 3.4, Leading zero omitted, Abs format*\n%FSLAX34Y34*%\n",
|
2009-06-28 18:13:55 +00:00
|
|
|
output_file );
|
2008-12-23 07:37:39 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
fputs( "G04 APERTURE LIST*\n", output_file );
|
|
|
|
/* Select the default aperture */
|
2009-06-28 18:13:55 +00:00
|
|
|
set_current_line_width( -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
|
|
|
|
2010-03-31 16:59:32 +00:00
|
|
|
bool GERBER_PLOTTER::end_plot()
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
|
|
|
char line[1024];
|
|
|
|
wxString msg;
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
wxASSERT( output_file );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
/* Outfile is actually a temporary file! */
|
|
|
|
fputs( "M02*\n", output_file );
|
2009-06-28 18:13:55 +00:00
|
|
|
fflush( output_file );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2010-03-31 16:59:32 +00:00
|
|
|
// rewind( work_file ); // work_file == output_file !!!
|
|
|
|
fclose( work_file );
|
|
|
|
work_file = wxFopen( m_workFilename, wxT( "rt" ));
|
|
|
|
wxASSERT( work_file );
|
2009-06-28 16:50:42 +00:00
|
|
|
output_file = final_file;
|
2008-12-23 07:37:39 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
// Placement of apertures in RS274X
|
2009-06-28 16:50:42 +00:00
|
|
|
while( fgets( line, 1024, work_file ) )
|
|
|
|
{
|
2009-06-28 18:13:55 +00:00
|
|
|
fputs( line, output_file );
|
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 )
|
|
|
|
{
|
|
|
|
write_aperture_list();
|
|
|
|
fputs( "G04 APERTURE END LIST*\n", output_file );
|
|
|
|
}
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose( work_file );
|
|
|
|
fclose( final_file );
|
2010-03-31 16:59:32 +00:00
|
|
|
::wxRemoveFile( m_workFilename );
|
2009-06-28 16:50:42 +00:00
|
|
|
output_file = 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
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
/* Set the default line width (in 1/1000 inch) for the current plotting
|
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
void GERBER_PLOTTER::set_default_line_width( int width )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2009-11-23 15:16:50 +00:00
|
|
|
default_pen_width = width;
|
2009-06-28 18:13:55 +00:00
|
|
|
current_aperture = apertures.end();
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
/* Set the Current line width (in 1/1000 inch) for the next plot
|
2008-12-23 07:37:39 +00:00
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
void GERBER_PLOTTER::set_current_line_width( 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
|
|
|
|
pen_width = default_pen_width;
|
|
|
|
|
2009-08-29 10:20:48 +00:00
|
|
|
select_aperture( wxSize( pen_width, pen_width ), APERTURE::Plotting );
|
2009-06-28 16:50:42 +00:00
|
|
|
current_pen_width = pen_width;
|
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2009-08-29 10:20:48 +00:00
|
|
|
std::vector<APERTURE>::iterator GERBER_PLOTTER::get_aperture( const wxSize& size,
|
2009-11-23 15:16:50 +00:00
|
|
|
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() )
|
|
|
|
{
|
|
|
|
last_D_code = tool->D_code;
|
2011-09-20 13:57:40 +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;
|
2009-06-28 18:13:55 +00:00
|
|
|
new_tool.size = size;
|
|
|
|
new_tool.type = type;
|
|
|
|
new_tool.D_code = last_D_code + 1;
|
|
|
|
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
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
void GERBER_PLOTTER::select_aperture( const wxSize& size,
|
|
|
|
APERTURE::Aperture_Type type )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2009-06-28 18:13:55 +00:00
|
|
|
wxASSERT( output_file );
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
if( ( current_aperture == apertures.end() )
|
2009-11-23 15:16:50 +00:00
|
|
|
|| ( current_aperture->type != type )
|
|
|
|
|| ( current_aperture->size != size ) )
|
2009-06-28 18:13:55 +00:00
|
|
|
{
|
|
|
|
/* Pick an existing aperture or create a new one */
|
|
|
|
current_aperture = get_aperture( size, type );
|
|
|
|
fprintf( output_file, "G54D%d*\n", current_aperture->D_code );
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
/*Generate list of D_CODES.
|
|
|
|
* Returns the number of D_Codes generated in RS274X format.
|
2009-06-28 16:50:42 +00:00
|
|
|
*/
|
2009-11-23 15:16:50 +00:00
|
|
|
void GERBER_PLOTTER::write_aperture_list()
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2009-06-28 18:13:55 +00:00
|
|
|
wxASSERT( output_file );
|
2009-06-28 16:50:42 +00:00
|
|
|
char cbuf[1024];
|
|
|
|
|
|
|
|
/* 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
|
|
|
{
|
2009-06-28 18:13:55 +00:00
|
|
|
const float fscale = 0.0001f * plot_scale; // For 3.4 format
|
|
|
|
char* text;
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
text = cbuf + sprintf( cbuf, "%%ADD%d", tool->D_code );
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
switch( tool->type )
|
|
|
|
{
|
2009-08-29 10:20:48 +00:00
|
|
|
case APERTURE::Circle:
|
2009-06-28 18:13:55 +00:00
|
|
|
sprintf( text, "C,%f*%%\n", tool->size.x * fscale );
|
|
|
|
break;
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2009-08-29 10:20:48 +00:00
|
|
|
case APERTURE::Rect:
|
2009-06-28 18:13:55 +00:00
|
|
|
sprintf( text, "R,%fX%f*%%\n", tool->size.x * fscale,
|
|
|
|
tool->size.y * fscale );
|
|
|
|
break;
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2009-08-29 10:20:48 +00:00
|
|
|
case APERTURE::Plotting:
|
2009-06-28 18:13:55 +00:00
|
|
|
sprintf( text, "C,%f*%%\n", tool->size.x * fscale );
|
|
|
|
break;
|
2009-06-28 16:50:42 +00:00
|
|
|
|
2009-08-29 10:20:48 +00:00
|
|
|
case APERTURE::Oval:
|
2011-09-20 13:57:40 +00:00
|
|
|
sprintf( text, "O,%fX%f*%%\n", 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-06-28 18:13:55 +00:00
|
|
|
fputs( cbuf, output_file );
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2009-08-29 10:20:48 +00:00
|
|
|
void GERBER_PLOTTER::pen_to( wxPoint aPos, char plume )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2009-06-28 18:13:55 +00:00
|
|
|
wxASSERT( output_file );
|
2009-06-28 16:50:42 +00:00
|
|
|
user_to_device_coordinates( aPos );
|
|
|
|
|
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':
|
|
|
|
fprintf( output_file, "X%5.5dY%5.5dD02*\n", aPos.x, aPos.y );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'D':
|
|
|
|
fprintf( output_file, "X%5.5dY%5.5dD01*\n", aPos.x, aPos.y );
|
|
|
|
}
|
2008-12-23 07:37:39 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
pen_state = plume;
|
2008-12-23 07:37:39 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2009-08-29 10:20:48 +00:00
|
|
|
void GERBER_PLOTTER::rect( wxPoint p1, wxPoint p2, FILL_T fill, int width )
|
2008-12-23 07:37:39 +00:00
|
|
|
{
|
2011-04-20 08:13:21 +00:00
|
|
|
static std::vector< wxPoint > cornerList;
|
|
|
|
cornerList.clear();
|
|
|
|
|
|
|
|
// 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
|
|
|
|
2010-11-12 16:36:43 +00:00
|
|
|
/**
|
|
|
|
* Function circle
|
2008-12-23 07:37:39 +00:00
|
|
|
* writes a non filled circle to output file
|
|
|
|
* Plot one circle as segments (6 to 16 depending on its radius
|
2009-11-23 15:16:50 +00:00
|
|
|
* @param aCentre = center coordinates
|
2009-06-28 18:13:55 +00:00
|
|
|
* @param aDiameter = diameter of the circle
|
2010-12-29 17:47:32 +00:00
|
|
|
* @param aFill = plot option (NO_FILL, FILLED_SHAPE, FILLED_WITH_BG_BODYCOLOR)
|
|
|
|
* not used here: circles are always not filled the gerber. Filled circles are flashed
|
2009-06-28 16:50:42 +00:00
|
|
|
* @param aWidth = line width
|
2009-06-28 18:13:55 +00:00
|
|
|
*/
|
2011-09-20 13:57:40 +00:00
|
|
|
void GERBER_PLOTTER::circle( wxPoint aCentre, int aDiameter, FILL_T aFill, int aWidth )
|
2008-12-23 07:37:39 +00:00
|
|
|
{
|
2009-06-28 18:13:55 +00:00
|
|
|
wxASSERT( output_file );
|
|
|
|
wxPoint start, end;
|
|
|
|
double radius = aDiameter / 2;
|
2011-09-20 13:57:40 +00:00
|
|
|
const int delta = 3600 / 32; /* increment (in 0.1 degrees) to draw circles */
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2009-10-26 19:00:46 +00:00
|
|
|
start.x = aCentre.x + wxRound( radius );
|
2009-06-28 18:13:55 +00:00
|
|
|
start.y = aCentre.y;
|
|
|
|
set_current_line_width( aWidth );
|
|
|
|
move_to( start );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
for( int ii = delta; ii < 3600; ii += delta )
|
2008-12-23 07:37:39 +00:00
|
|
|
{
|
2011-09-20 13:57:40 +00:00
|
|
|
end.x = aCentre.x + (int) ( radius * cos( DEG2RAD( (double)ii / 10.0 ) ) );
|
|
|
|
end.y = aCentre.y + (int) ( radius * sin( DEG2RAD( (double)ii / 10.0 ) ) );
|
2009-06-28 18:13:55 +00:00
|
|
|
line_to( end );
|
2008-12-23 07:37:39 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
finish_to( start );
|
2008-12-23 07:37:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-06-06 06:51:42 +00:00
|
|
|
/*
|
2011-04-20 08:13:21 +00:00
|
|
|
* Function PlotPoly
|
|
|
|
* writes a filled or not filled polyline to output file
|
2011-06-07 15:29:01 +00:00
|
|
|
* @param aCornerList = buffer of corners coordinates
|
|
|
|
* @param aFill = plot option (NO_FILL, FILLED_SHAPE, FILLED_WITH_BG_BODYCOLOR)
|
|
|
|
* @param aWidth = Width of the line to plot.
|
2009-06-28 18:13:55 +00:00
|
|
|
*/
|
2011-04-20 08:13:21 +00:00
|
|
|
void GERBER_PLOTTER::PlotPoly( std::vector< wxPoint >& aCornerList, 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;
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
set_current_line_width( aWidth );
|
|
|
|
|
|
|
|
if( aFill )
|
|
|
|
fputs( "G36*\n", output_file );
|
2011-04-20 08:13:21 +00:00
|
|
|
|
|
|
|
move_to( 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
|
|
|
{
|
2011-04-20 08:13:21 +00:00
|
|
|
line_to( 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
|
|
|
{
|
2011-04-20 08:13:21 +00:00
|
|
|
finish_to( aCornerList[0] );
|
2009-06-28 18:13:55 +00:00
|
|
|
fputs( "G37*\n", output_file );
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-06-28 18:13:55 +00:00
|
|
|
pen_finish();
|
2008-12-23 07:37:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-31 14:59:20 +00:00
|
|
|
/*
|
|
|
|
* Function PlotImage
|
|
|
|
* Only Postscript plotters can plot bitmaps
|
|
|
|
* for plotters that cannot plot a bitmap, a rectangle is plotted
|
|
|
|
* For GERBER_PLOTTER, draws a rectangle
|
|
|
|
* param aImage = the bitmap
|
|
|
|
* param aPos = position of the center of the bitmap
|
|
|
|
* param aScaleFactor = the scale factor to apply to the bitmap size
|
|
|
|
* (this is not the plot scale factor)
|
|
|
|
*/
|
|
|
|
void GERBER_PLOTTER::PlotImage( wxImage & aImage, wxPoint aPos, double aScaleFactor )
|
|
|
|
{
|
|
|
|
wxSize size;
|
|
|
|
size.x = aImage.GetWidth();
|
|
|
|
size.y = aImage.GetHeight();
|
|
|
|
|
|
|
|
size.x = wxRound( size.x * aScaleFactor );
|
|
|
|
size.y = wxRound( size.y * aScaleFactor );
|
|
|
|
|
|
|
|
wxPoint start = aPos;
|
|
|
|
start.x -= size.x / 2;
|
|
|
|
start.y -= size.y / 2;
|
|
|
|
|
|
|
|
wxPoint end = start;
|
|
|
|
end.x += size.x;
|
|
|
|
end.y += size.y;
|
|
|
|
|
|
|
|
rect( start, end, NO_FILL );
|
|
|
|
|
|
|
|
}
|
2009-06-28 18:13:55 +00:00
|
|
|
|
|
|
|
/* Function flash_pad_circle
|
|
|
|
* Plot a circular pad or via at the user position pos
|
2009-06-28 16:50:42 +00:00
|
|
|
*/
|
2011-09-20 13:57:40 +00:00
|
|
|
void GERBER_PLOTTER::flash_pad_circle( wxPoint pos, int diametre, GRTraceMode trace_mode )
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2009-06-28 18:13:55 +00:00
|
|
|
wxASSERT( output_file );
|
|
|
|
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
|
|
|
{
|
|
|
|
case FILAIRE:
|
|
|
|
case SKETCH:
|
2009-06-28 18:13:55 +00:00
|
|
|
set_current_line_width( -1 );
|
|
|
|
circle( pos, diametre - current_pen_width, NO_FILL );
|
|
|
|
break;
|
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
case FILLED:
|
2009-06-28 18:13:55 +00:00
|
|
|
user_to_device_coordinates( pos );
|
2009-08-29 10:20:48 +00:00
|
|
|
select_aperture( size, APERTURE::Circle );
|
2009-06-28 18:13:55 +00:00
|
|
|
fprintf( output_file, "X%5.5dY%5.5dD03*\n", pos.x, pos.y );
|
|
|
|
break;
|
2009-06-28 16:50:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
/* Plot oval pad at position pos:
|
|
|
|
* Dimensions dx, dy,
|
|
|
|
* Orient Orient
|
|
|
|
* For a vertical or horizontal orientation, the shape is flashed
|
|
|
|
* For any orientation the shape is drawn as a segment
|
|
|
|
*/
|
2009-08-29 10:20:48 +00:00
|
|
|
void GERBER_PLOTTER::flash_pad_oval( wxPoint pos, wxSize size, int orient,
|
2009-06-28 18:13:55 +00:00
|
|
|
GRTraceMode trace_mode )
|
2008-12-23 07:37:39 +00:00
|
|
|
{
|
2009-06-28 18:13:55 +00:00
|
|
|
wxASSERT( output_file );
|
|
|
|
int x0, y0, x1, y1, delta;
|
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 );
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
user_to_device_coordinates( pos );
|
2009-08-29 10:20:48 +00:00
|
|
|
select_aperture( size, APERTURE::Oval );
|
2009-06-28 18:13:55 +00:00
|
|
|
fprintf( output_file, "X%5.5dY%5.5dD03*\n", pos.x, pos.y );
|
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 )
|
|
|
|
{
|
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 );
|
|
|
|
thick_segment( wxPoint( pos.x + x0, pos.y + y0 ),
|
|
|
|
wxPoint( pos.x + x1, pos.y + y1 ),
|
|
|
|
size.x, trace_mode );
|
|
|
|
}
|
|
|
|
else
|
2011-09-20 13:57:40 +00:00
|
|
|
{
|
2009-06-28 18:13:55 +00:00
|
|
|
sketch_oval( 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
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
/* Plot rectangular pad.
|
|
|
|
* Gives its center, size, and orientation
|
|
|
|
* For a vertical or horizontal shape, the shape is an aperture (Dcode) and
|
|
|
|
* it is flashed.
|
|
|
|
* For others shape the direction is plotted as a polygon.
|
|
|
|
*/
|
2009-08-29 10:20:48 +00:00
|
|
|
void GERBER_PLOTTER::flash_pad_rect( wxPoint pos, wxSize size,
|
2009-06-28 18:13:55 +00:00
|
|
|
int orient, GRTraceMode trace_mode )
|
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2009-06-28 18:13:55 +00:00
|
|
|
wxASSERT( output_file );
|
2009-11-23 15:16:50 +00:00
|
|
|
|
|
|
|
/* Plot as flashed. */
|
2009-06-28 16:50:42 +00:00
|
|
|
switch( orient )
|
|
|
|
{
|
|
|
|
case 900:
|
2009-11-23 15:16:50 +00:00
|
|
|
case 2700: /* rotation of 90 degrees or 270 returns dimensions */
|
2009-06-28 16:50:42 +00:00
|
|
|
EXCHG( size.x, size.y );
|
2008-12-23 07:37:39 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
// Pass through
|
|
|
|
case 0:
|
|
|
|
case 1800:
|
2009-06-28 18:13:55 +00:00
|
|
|
switch( trace_mode )
|
|
|
|
{
|
|
|
|
case FILAIRE:
|
|
|
|
case SKETCH:
|
|
|
|
set_current_line_width( -1 );
|
|
|
|
rect( wxPoint( pos.x - (size.x - current_pen_width) / 2,
|
|
|
|
pos.y - (size.y - current_pen_width) / 2 ),
|
|
|
|
wxPoint( pos.x + (size.x - current_pen_width) / 2,
|
|
|
|
pos.y + (size.y - current_pen_width) / 2 ),
|
|
|
|
NO_FILL );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FILLED:
|
|
|
|
user_to_device_coordinates( pos );
|
2009-08-29 10:20:48 +00:00
|
|
|
select_aperture( size, APERTURE::Rect );
|
2009-06-28 18:13:55 +00:00
|
|
|
fprintf( output_file, "X%5.5dY%5.5dD03*\n", pos.x, pos.y );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2009-06-28 16:50:42 +00:00
|
|
|
|
|
|
|
default: /* plot pad shape as polygon */
|
2010-09-13 11:51:09 +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. */
|
2010-10-12 16:01:07 +00:00
|
|
|
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;
|
2010-09-13 11:51:09 +00:00
|
|
|
|
|
|
|
flash_pad_trapez( pos, coord, orient, trace_mode );
|
|
|
|
}
|
2009-06-28 16:50:42 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-12-23 07:37:39 +00:00
|
|
|
}
|
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
|
2009-11-23 15:16:50 +00:00
|
|
|
/* Plot trapezoidal pad.
|
2010-09-13 11:51:09 +00:00
|
|
|
* aPadPos is pad position, aCorners the corners positions of the basic shape
|
|
|
|
* Orientation aPadOrient in 0.1 degrees
|
|
|
|
* Plot mode = FILLED or SKETCH
|
2009-06-28 16:50:42 +00:00
|
|
|
*/
|
2010-09-13 11:51:09 +00:00
|
|
|
void GERBER_PLOTTER::flash_pad_trapez( wxPoint aPadPos, wxPoint aCorners[4],
|
2011-09-20 13:57:40 +00:00
|
|
|
int aPadOrient, GRTraceMode aTrace_Mode )
|
2009-11-23 15:16:50 +00:00
|
|
|
|
2009-06-28 16:50:42 +00:00
|
|
|
{
|
2011-04-20 08:13:21 +00:00
|
|
|
// polygon corners list
|
|
|
|
static std::vector< wxPoint > cornerList;
|
|
|
|
cornerList.clear();
|
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] );
|
|
|
|
|
|
|
|
/* Draw the polygon and fill the interior as required. */
|
|
|
|
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
|
|
|
|
2009-06-28 18:13:55 +00:00
|
|
|
set_current_line_width( -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
|
|
|
|
2011-09-20 13:57:40 +00:00
|
|
|
|
2010-12-06 22:05:12 +00:00
|
|
|
void GERBER_PLOTTER::SetLayerPolarity( bool aPositive )
|
|
|
|
{
|
|
|
|
if( aPositive )
|
|
|
|
fprintf( output_file, "%%LPD*%%\n" );
|
|
|
|
else
|
|
|
|
fprintf( output_file, "%%LPC*%%\n" );
|
|
|
|
}
|