kicad/pcbnew/plotgerb.cpp

832 lines
24 KiB
C++
Raw Normal View History

/*********************************************************/
/****Function to plot a board in GERBER RS274X format ****/
/*********************************************************/
/* Creates the output files, one per board layer:
* filenames are like xxxc.PHO and use the RS274X format
* Units = inches
* format 3.4, Leading zero omitted, Abs format
* format 3.4 uses the native pcbnew units (1/10000 inch).
*/
#include "fctsys.h"
#include "common.h"
#include "plot_common.h"
#include "confirm.h"
#include "pcbnew.h"
#include "pcbplot.h"
#include "trigo.h"
#include "appl_wxstruct.h"
/* Class to handle a D_CODE when plotting a board : */
#define FIRST_DCODE_VALUE 10 // D_CODE < 10 is a command, D_CODE >= 10 is a tool
class D_CODE
{
public:
D_CODE* m_Pnext, * m_Pback; /* for a linked list */
wxSize m_Size; /* horiz and Vert size*/
int m_Type; /* Type ( Line, rect , circulaire , ovale .. ); -1 = not used (free) descr */
int m_NumDcode; /* code number ( >= 10 ); 0 = not in use */
D_CODE()
{
m_Pnext = m_Pback = NULL;
m_Type = -1;
m_NumDcode = 0;
}
};
/* Variables locales : */
2008-03-22 05:55:06 +00:00
static int s_Last_D_code;
static float Gerb_scale_plot; // Coeff de conversion d'unites des traces
static D_CODE* s_DCodeList; // Pointeur sur la zone de stockage des D_CODES
wxString GerberFullFileName;
static double scale_x, scale_y; // echelles de convertion en X et Y (compte tenu
// des unites relatives du PCB et des traceurs
2008-03-22 05:55:06 +00:00
static bool ShowDcodeError = TRUE;
static void CloseFileGERBER( void );
static int Gen_D_CODE_File( FILE* penfile );
/* Routines Locales */
static void Init_ApertureList();
static void CloseFileGERBER();
static void Plot_1_CIRCLE_pad_GERBER( wxPoint pos, int diametre );
static void trace_1_pastille_OVALE_GERBER( wxPoint pos, wxSize size, int orient );
static void PlotRectangularPad_GERBER( wxPoint pos, wxSize size, int orient );
static D_CODE* get_D_code( int dx, int dy, int type, int drill );
static void trace_1_pad_TRAPEZE_GERBER( wxPoint pos, wxSize size, wxSize delta,
int orient, int modetrace );
/********************************************************************************/
2008-03-22 05:55:06 +00:00
void WinEDA_BasePcbFrame::Genere_GERBER( const wxString& FullFileName, int Layer,
bool PlotOriginIsAuxAxis )
/********************************************************************************/
/* Creates the output files, one per board layer:
* filenames are like xxxc.PHO and use the RS274X format
* Units = inches
* format 3.4, Leading zero omitted, Abs format
* format 3.4 uses the native pcbnew units (1/10000 inch).
*/
{
2008-03-22 05:55:06 +00:00
int tracevia = 1;
EraseMsgBox();
GerberFullFileName = FullFileName;
g_PlotOrient = 0;
if( Plot_Set_MIROIR )
g_PlotOrient |= PLOT_MIROIR;
/* Calculate scaling from pcbnew units (in 0.1 mil or 0.0001 inch) to gerber units */
Gerb_scale_plot = 1.0; /* for format 3.4 (4 digits for decimal format means 0.1 mil per gerber unit */
2009-02-26 00:37:04 +00:00
2008-03-22 05:55:06 +00:00
scale_x = Scale_X * Gerb_scale_plot;
scale_y = Scale_Y * Gerb_scale_plot;
2009-02-26 00:37:04 +00:00
2008-03-22 05:55:06 +00:00
g_PlotOffset.x = 0;
g_PlotOffset.y = 0;
2009-02-26 00:37:04 +00:00
2008-03-22 05:55:06 +00:00
if( PlotOriginIsAuxAxis )
g_PlotOffset = m_Auxiliary_Axis_Position;
g_Plot_PlotOutputFile = wxFopen( FullFileName, wxT( "wt" ) );
if( g_Plot_PlotOutputFile == NULL )
2008-03-22 05:55:06 +00:00
{
wxString msg = _( "unable to create file " ) + FullFileName;
DisplayError( this, msg );
return;
}
SetLocaleTo_C_standard();
2008-03-22 05:55:06 +00:00
InitPlotParametresGERBER( g_PlotOffset, scale_x, scale_y );
/* Clear the memory used for handle the D_CODE (aperture) list */
Init_ApertureList();
Affiche_1_Parametre( this, 0, _( "File" ), FullFileName, CYAN );
s_Last_D_code = 0;
Write_Header_GERBER( wxGetApp().GetAppName(), g_Plot_PlotOutputFile );
2008-03-22 05:55:06 +00:00
int layer_mask = g_TabOneLayerMask[Layer];
// Specify that the contents of the "Edges Pcb" layer are also to be
// plotted, unless the option of excluding that layer has been selected.
if( !g_Exclude_Edges_Pcb )
layer_mask |= EDGE_LAYER;
switch( Layer )
{
case FIRST_COPPER_LAYER:
case LAYER_N_2:
case LAYER_N_3:
case LAYER_N_4:
case LAYER_N_5:
case LAYER_N_6:
case LAYER_N_7:
case LAYER_N_8:
case LAYER_N_9:
case LAYER_N_10:
case LAYER_N_11:
case LAYER_N_12:
case LAYER_N_13:
case LAYER_N_14:
case LAYER_N_15:
case LAST_COPPER_LAYER:
Plot_Layer_GERBER( g_Plot_PlotOutputFile, layer_mask, 0, 1 );
2008-03-22 05:55:06 +00:00
break;
case SOLDERMASK_N_CU:
case SOLDERMASK_N_CMP: /* Trace du vernis epargne */
if( g_DrawViaOnMaskLayer )
tracevia = 1;
else
tracevia = 0;
Plot_Layer_GERBER( g_Plot_PlotOutputFile, layer_mask, g_DesignSettings.m_MaskMargin, tracevia );
2008-03-22 05:55:06 +00:00
break;
case SOLDERPASTE_N_CU:
case SOLDERPASTE_N_CMP: /* Trace du masque de pate de soudure */
Plot_Layer_GERBER( g_Plot_PlotOutputFile, layer_mask, 0, 0 );
2008-03-22 05:55:06 +00:00
break;
default:
Plot_Serigraphie( PLOT_FORMAT_GERBER, g_Plot_PlotOutputFile, layer_mask );
2008-03-22 05:55:06 +00:00
break;
}
CloseFileGERBER();
SetLocaleTo_Default();
}
/***********************************************************************/
2008-03-22 05:55:06 +00:00
void WinEDA_BasePcbFrame::Plot_Layer_GERBER( FILE* File, int masque_layer,
int garde, int tracevia )
/***********************************************************************/
/* Creates one GERBER file for a copper layer or a technical layer
* the silkscreen layers are plotted by Plot_Serigraphie() because they have special features
*/
{
2008-03-22 05:55:06 +00:00
wxPoint pos;
wxSize size;
wxString msg;
/* Draw items type Drawings Pcb matching with masque_layer: */
2009-02-26 00:37:04 +00:00
for( BOARD_ITEM* item = m_Pcb->m_Drawings; item; item = item->Next() )
2008-03-22 05:55:06 +00:00
{
2009-02-26 00:37:04 +00:00
switch( item->Type() )
2008-03-22 05:55:06 +00:00
{
case TYPE_DRAWSEGMENT:
2009-02-26 00:37:04 +00:00
PlotDrawSegment( (DRAWSEGMENT*) item, PLOT_FORMAT_GERBER,
2008-03-22 05:55:06 +00:00
masque_layer );
break;
case TYPE_TEXTE:
2009-02-26 00:37:04 +00:00
PlotTextePcb( (TEXTE_PCB*) item, PLOT_FORMAT_GERBER,
2008-03-22 05:55:06 +00:00
masque_layer );
break;
case TYPE_COTATION:
2009-02-26 00:37:04 +00:00
PlotCotation( (COTATION*) item, PLOT_FORMAT_GERBER,
2008-03-22 05:55:06 +00:00
masque_layer );
break;
case TYPE_MIRE:
2009-02-26 00:37:04 +00:00
PlotMirePcb( (MIREPCB*) item, PLOT_FORMAT_GERBER,
2008-03-22 05:55:06 +00:00
masque_layer );
break;
case TYPE_MARKER:
2008-03-22 05:55:06 +00:00
break;
default:
DisplayError( this, wxT( "Type Draw non gere" ) );
break;
}
}
2009-02-26 00:37:04 +00:00
/* Draw footprint shapes without pads (pads will plotted later) */
for( MODULE* module = m_Pcb->m_Modules; module; module = module->Next() )
2008-03-22 05:55:06 +00:00
{
2009-02-26 00:37:04 +00:00
for( BOARD_ITEM* item = module->m_Drawings; item; item = item->Next() )
2008-03-22 05:55:06 +00:00
{
2009-02-26 00:37:04 +00:00
switch( item->Type() )
2008-03-22 05:55:06 +00:00
{
case TYPE_EDGE_MODULE:
2009-02-26 00:37:04 +00:00
if( masque_layer & g_TabOneLayerMask[( (EDGE_MODULE*) item)->GetLayer()] )
Plot_1_EdgeModule( PLOT_FORMAT_GERBER, (EDGE_MODULE*) item );
2008-03-22 05:55:06 +00:00
break;
default:
break;
}
}
}
/* Plot footprint pads */
2009-02-26 00:37:04 +00:00
for( MODULE* module = m_Pcb->m_Modules; module; module = module->Next() )
2008-03-22 05:55:06 +00:00
{
2009-02-26 00:37:04 +00:00
for( D_PAD* pad = module->m_Pads; pad; pad = pad->Next() )
2008-03-22 05:55:06 +00:00
{
wxPoint shape_pos;
2009-02-26 00:37:04 +00:00
if( (pad->m_Masque_Layer & masque_layer) == 0 )
continue;
2009-02-26 00:37:04 +00:00
shape_pos = pad->ReturnShapePos();
2008-03-22 05:55:06 +00:00
pos = shape_pos;
2009-02-26 00:37:04 +00:00
size.x = pad->m_Size.x + 2 * garde;
size.y = pad->m_Size.y + 2 * garde;
2008-03-22 05:55:06 +00:00
/* Don't draw a null size item : */
if( size.x <= 0 || size.y <= 0 )
continue;
2009-02-26 00:37:04 +00:00
switch( pad->m_PadShape )
2008-03-22 05:55:06 +00:00
{
case PAD_CIRCLE:
Plot_1_CIRCLE_pad_GERBER( pos, size.x );
break;
case PAD_OVAL:
// Check whether the pad really has a circular shape instead
if( size.x == size.y )
Plot_1_CIRCLE_pad_GERBER( pos, size.x );
else
2009-02-26 00:37:04 +00:00
trace_1_pastille_OVALE_GERBER( pos, size, pad->m_Orient );
2008-03-22 05:55:06 +00:00
break;
case PAD_TRAPEZOID:
{
2009-02-26 00:37:04 +00:00
wxSize delta = pad->m_DeltaSize;
2008-03-22 05:55:06 +00:00
trace_1_pad_TRAPEZE_GERBER( pos, size,
2009-02-26 00:37:04 +00:00
delta, pad->m_Orient, FILLED );
2008-03-22 05:55:06 +00:00
}
break;
2008-03-22 05:55:06 +00:00
case PAD_RECT:
default:
2009-02-26 00:37:04 +00:00
PlotRectangularPad_GERBER( pos, size, pad->m_Orient );
2008-03-22 05:55:06 +00:00
break;
}
}
}
/* Plot vias : */
2008-03-22 05:55:06 +00:00
if( tracevia )
{
2009-02-26 00:37:04 +00:00
for( TRACK* track = m_Pcb->m_Track; track; track = track->Next() )
2008-03-22 05:55:06 +00:00
{
if( track->Type() != TYPE_VIA )
2008-03-22 05:55:06 +00:00
continue;
2009-02-26 00:37:04 +00:00
2008-03-22 05:55:06 +00:00
SEGVIA* Via = (SEGVIA*) track;
// vias not plotted if not on selected layer, but if layer
// == SOLDERMASK_LAYER_CU or SOLDERMASK_LAYER_CMP, vias are drawn,
// if they are on a external copper layer
int via_mask_layer = Via->ReturnMaskLayer();
2009-02-26 00:37:04 +00:00
2008-03-22 05:55:06 +00:00
if( via_mask_layer & CUIVRE_LAYER )
via_mask_layer |= SOLDERMASK_LAYER_CU;
2009-02-26 00:37:04 +00:00
2008-03-22 05:55:06 +00:00
if( via_mask_layer & CMP_LAYER )
via_mask_layer |= SOLDERMASK_LAYER_CMP;
2009-02-26 00:37:04 +00:00
2008-03-22 05:55:06 +00:00
if( ( via_mask_layer & masque_layer) == 0 )
continue;
pos = Via->m_Start;
size.x = size.y = Via->m_Width + 2 * garde;
2009-02-26 00:37:04 +00:00
2008-03-22 05:55:06 +00:00
/* Don't draw a null size item : */
if( size.x <= 0 )
continue;
2009-02-26 00:37:04 +00:00
2008-03-22 05:55:06 +00:00
Plot_1_CIRCLE_pad_GERBER( pos, size.x );
}
}
/* Plot tracks (not vias) : */
2009-02-26 00:37:04 +00:00
for( TRACK* track = m_Pcb->m_Track; track; track = track->Next() )
2008-03-22 05:55:06 +00:00
{
wxPoint end;
if( track->Type() == TYPE_VIA )
2008-03-22 05:55:06 +00:00
continue;
2009-02-26 00:37:04 +00:00
2008-03-22 05:55:06 +00:00
if( (g_TabOneLayerMask[track->GetLayer()] & masque_layer) == 0 )
continue;
size.x = size.y = track->m_Width;
pos = track->m_Start;
end = track->m_End;
SelectD_CODE_For_LineDraw( size.x );
2008-03-22 05:55:06 +00:00
PlotGERBERLine( pos, end, size.x );
}
/* Plot zones: */
2009-02-26 00:37:04 +00:00
for( TRACK* track = m_Pcb->m_Zone; track; track = track->Next() )
2008-03-22 05:55:06 +00:00
{
wxPoint end;
if( (g_TabOneLayerMask[track->GetLayer()] & masque_layer) == 0 )
continue;
size.x = size.y = track->m_Width;
pos = track->m_Start;
end = track->m_End;
SelectD_CODE_For_LineDraw( size.x );
2008-03-22 05:55:06 +00:00
PlotGERBERLine( pos, end, size.x );
}
/* Plot filled ares */
for( int ii = 0; ii < m_Pcb->GetAreaCount(); ii++ )
{
ZONE_CONTAINER* edge_zone = m_Pcb->GetArea( ii );
if( ( ( 1 << edge_zone->GetLayer() ) & masque_layer ) == 0 )
continue;
PlotFilledAreas( edge_zone, PLOT_FORMAT_GERBER );
}
}
/**********************************************************************/
2008-03-22 05:55:06 +00:00
void trace_1_pastille_OVALE_GERBER( wxPoint pos, wxSize size, int orient )
/**********************************************************************/
2008-01-05 17:30:56 +00:00
/* Trace 1 pastille PAD_OVAL en position pos_X,Y:
* dimensions dx, dy,
* orientation orient
* Pour une orientation verticale ou horizontale, la forme est flashee
* Pour une orientation quelconque la forme est tracee comme un segment
*/
{
2008-03-22 05:55:06 +00:00
D_CODE* dcode_ptr;
char cbuf[256];
2008-03-22 05:55:06 +00:00
int x0, y0, x1, y1, delta;
2008-03-22 05:55:06 +00:00
if( orient == 900 || orient == 2700 ) /* orient tournee de 90 deg */
EXCHG( size.x, size.y );
2008-03-22 05:55:06 +00:00
/* Trace de la forme flashee */
if( orient == 0 || orient == 900 || orient == 1800 || orient == 2700 )
2008-03-22 05:55:06 +00:00
{
UserToDeviceCoordinate( pos );
UserToDeviceSize( size );
dcode_ptr = get_D_code( size.x, size.y, GERB_OVALE, 0 );
if( dcode_ptr->m_NumDcode != s_Last_D_code )
{
sprintf( cbuf, "G54D%d*\n", dcode_ptr->m_NumDcode );
fputs( cbuf, g_Plot_PlotOutputFile );
2008-03-22 05:55:06 +00:00
s_Last_D_code = dcode_ptr->m_NumDcode;
}
sprintf( cbuf, "X%5.5dY%5.5dD03*\n", pos.x, pos.y );
fputs( cbuf, g_Plot_PlotOutputFile );
2008-03-22 05:55:06 +00:00
}
else /* Forme tracee comme un segment */
{
if( size.x > size.y )
{
EXCHG( size.x, size.y );
if( orient < 2700 )
orient += 900;
else
orient -= 2700;
}
/* la pastille est ramenee a une pastille ovale avec dy > dx */
delta = size.y - size.x;
x0 = 0;
y0 = -delta / 2;
x1 = 0;
y1 = delta / 2;
RotatePoint( &x0, &y0, orient );
RotatePoint( &x1, &y1, orient );
SelectD_CODE_For_LineDraw( size.x );
2008-03-22 05:55:06 +00:00
PlotGERBERLine( wxPoint( pos.x + x0, pos.y + y0 ),
wxPoint( pos.x + x1, pos.y + y1 ), size.x );
}
}
/******************************************************************/
2008-03-22 05:55:06 +00:00
void Plot_1_CIRCLE_pad_GERBER( wxPoint pos, int diametre )
/******************************************************************/
/* Plot a circular pad or via at the user position pos
*/
{
2008-03-22 05:55:06 +00:00
D_CODE* dcode_ptr;
char cbuf[256];
2008-03-22 05:55:06 +00:00
wxSize size( diametre, diametre );
2008-03-22 05:55:06 +00:00
UserToDeviceCoordinate( pos );
UserToDeviceSize( size );
dcode_ptr = get_D_code( size.x, size.x, GERB_CIRCLE, 0 );
if( dcode_ptr->m_NumDcode != s_Last_D_code )
{
sprintf( cbuf, "G54D%d*\n", dcode_ptr->m_NumDcode );
fputs( cbuf, g_Plot_PlotOutputFile );
2008-03-22 05:55:06 +00:00
s_Last_D_code = dcode_ptr->m_NumDcode;
}
sprintf( cbuf, "X%5.5dY%5.5dD03*\n", pos.x, pos.y );
fputs( cbuf, g_Plot_PlotOutputFile );
}
/**************************************************************************/
2008-03-22 05:55:06 +00:00
void PlotRectangularPad_GERBER( wxPoint pos, wxSize size, int orient )
/**************************************************************************/
/* Plot 1 rectangular pad
* donne par son centre, ses dimensions, et son orientation
* For a vertical or horizontal shape, the shape is an aperture (Dcode) and it is flashed
* For others orientations the shape is plotted as a polygon
*/
{
2008-03-22 05:55:06 +00:00
D_CODE* dcode_ptr;
char cbuf[256];
2008-03-22 05:55:06 +00:00
/* Trace de la forme flashee */
switch( orient )
{
case 900:
case 2700: /* la rotation de 90 ou 270 degres revient a permutter des dimensions */
EXCHG( size.x, size.y );
// Pass through
2008-03-22 05:55:06 +00:00
case 0:
case 1800:
UserToDeviceCoordinate( pos );
UserToDeviceSize( size );
dcode_ptr = get_D_code( size.x, size.y, GERB_RECT, 0 );
if( dcode_ptr->m_NumDcode != s_Last_D_code )
{
sprintf( cbuf, "G54D%d*\n", dcode_ptr->m_NumDcode );
fputs( cbuf, g_Plot_PlotOutputFile );
2008-03-22 05:55:06 +00:00
s_Last_D_code = dcode_ptr->m_NumDcode;
}
sprintf( cbuf, "X%5.5dY%5.5dD03*\n", pos.x, pos.y );
fputs( cbuf, g_Plot_PlotOutputFile );
2008-03-22 05:55:06 +00:00
break;
default: /* plot pad shape as polygon */
2008-03-22 05:55:06 +00:00
trace_1_pad_TRAPEZE_GERBER( pos, size, wxSize( 0, 0 ), orient, FILLED );
break;
}
}
/*****************************************************************/
2008-03-22 05:55:06 +00:00
void trace_1_contour_GERBER( wxPoint pos, wxSize size, wxSize delta,
int penwidth, int orient )
/*****************************************************************/
/* Trace 1 contour rectangulaire ou trapezoidal d'orientation quelconque
* donne par son centre,
* ses dimensions ,
* ses variations ,
* l'epaisseur du trait,
* et son orientation orient
*/
{
2008-03-22 05:55:06 +00:00
int ii;
wxPoint coord[4];
2008-03-22 05:55:06 +00:00
size.x /= 2;
size.y /= 2;
delta.x /= 2;
delta.y /= 2; /* demi dim dx et dy */
2008-03-22 05:55:06 +00:00
coord[0].x = pos.x - size.x - delta.y;
coord[0].y = pos.y + size.y + delta.x;
2008-03-22 05:55:06 +00:00
coord[1].x = pos.x - size.x + delta.y;
coord[1].y = pos.y - size.y - delta.x;
2008-03-22 05:55:06 +00:00
coord[2].x = pos.x + size.x - delta.y;
coord[2].y = pos.y - size.y + delta.x;
2008-03-22 05:55:06 +00:00
coord[3].x = pos.x + size.x + delta.y;
coord[3].y = pos.y + size.y - delta.x;
2008-03-22 05:55:06 +00:00
for( ii = 0; ii < 4; ii++ )
{
RotatePoint( &coord[ii].x, &coord[ii].y, pos.x, pos.y, orient );
}
SelectD_CODE_For_LineDraw( penwidth );
2008-03-22 05:55:06 +00:00
PlotGERBERLine( coord[0], coord[1], penwidth );
PlotGERBERLine( coord[1], coord[2], penwidth );
PlotGERBERLine( coord[2], coord[3], penwidth );
PlotGERBERLine( coord[3], coord[0], penwidth );
}
/*******************************************************************/
2008-03-22 05:55:06 +00:00
void trace_1_pad_TRAPEZE_GERBER( wxPoint pos, wxSize size, wxSize delta,
int orient, int modetrace )
/*******************************************************************/
/* Trace 1 pad trapezoidal donne par :
* son centre pos.x,pos.y
* ses dimensions size.x et size.y
* les variations delta.x et delta.y ( 1 des deux au moins doit etre nulle)
* son orientation orient en 0.1 degres
* le mode de trace (FILLED, SKETCH, FILAIRE)
*
* Le trace n'est fait que pour un trapeze, c.a.d que delta.x ou delta.y
* = 0.
*
* les notation des sommets sont ( vis a vis de la table tracante )
*
* " 0 ------------- 3 "
* " . . "
* " . O . "
* " . . "
* " 1 ---- 2 "
*
*
* exemple de Disposition pour delta.y > 0, delta.x = 0
* " 1 ---- 2 "
* " . . "
* " . O . "
* " . . "
* " 0 ------------- 3 "
*
*
* exemple de Disposition pour delta.y = 0, delta.x > 0
* " 0 "
* " . . "
* " . . "
* " . 3 "
* " . . "
* " . O . "
* " . . "
* " . 2 "
* " . . "
* " . . "
* " 1 "
*/
{
2008-03-22 05:55:06 +00:00
int ii, jj;
int dx, dy;
wxPoint polygon[4]; /* polygon corners */
2008-03-22 05:55:06 +00:00
int coord[8];
int ddx, ddy;
/* calcul des dimensions optimales du spot choisi = 1/4 plus petite dim */
dx = size.x - abs( delta.y );
dy = size.y - abs( delta.x );
dx = size.x / 2;
dy = size.y / 2;
ddx = delta.x / 2;
ddy = delta.y / 2;
polygon[0].x = -dx - ddy;
polygon[0].y = +dy + ddx;
polygon[1].x = -dx + ddy;
polygon[1].y = -dy - ddx;
polygon[2].x = +dx - ddy;
polygon[2].y = -dy + ddx;
polygon[3].x = +dx + ddy;
polygon[3].y = +dy - ddx;
2008-03-22 05:55:06 +00:00
/* Dessin du polygone et Remplissage eventuel de l'interieur */
for( ii = 0, jj = 0; ii < 4; ii++ )
{
RotatePoint( &polygon[ii].x, &polygon[ii].y, orient );
coord[jj] = polygon[ii].x += pos.x;
2008-03-22 05:55:06 +00:00
jj++;
coord[jj] = polygon[ii].y += pos.y;
2008-03-22 05:55:06 +00:00
jj++;
}
if( modetrace != FILLED )
{
int plotLine_width = (int) ( 10 * g_PlotLine_Width * Gerb_scale_plot );
SelectD_CODE_For_LineDraw( plotLine_width );
PlotGERBERLine( polygon[0], polygon[1], plotLine_width );
PlotGERBERLine( polygon[1], polygon[2], plotLine_width );
PlotGERBERLine( polygon[2], polygon[3], plotLine_width );
PlotGERBERLine( polygon[3], polygon[0], plotLine_width );
2008-03-22 05:55:06 +00:00
}
else
PlotFilledPolygon_GERBER( 4, coord );
}
/**********************************************************/
void SelectD_CODE_For_LineDraw( int aSize )
/**********************************************************/
/** Selects a D_Code nn to draw lines and writes G54Dnn to output file
* @param aSize = D_CODE diameter
*/
{
2008-03-22 05:55:06 +00:00
D_CODE* dcode_ptr;
dcode_ptr = get_D_code( aSize, aSize, GERB_LINE, 0 );
2008-03-22 05:55:06 +00:00
if( dcode_ptr->m_NumDcode != s_Last_D_code )
{
fprintf( g_Plot_PlotOutputFile, "G54D%d*\n", dcode_ptr->m_NumDcode );
2008-03-22 05:55:06 +00:00
s_Last_D_code = dcode_ptr->m_NumDcode;
}
}
/*******************************************************/
2008-03-22 05:55:06 +00:00
D_CODE* get_D_code( int dx, int dy, int type, int drill )
/*******************************************************/
/* Fonction Recherchant et Creant eventuellement la description
* du D_CODE du type et dimensions demandees
*/
{
2008-03-22 05:55:06 +00:00
D_CODE* ptr_tool, * last_dcode_ptr;
int num_new_D_code = FIRST_DCODE_VALUE;
ptr_tool = last_dcode_ptr = s_DCodeList;
while( ptr_tool && ptr_tool->m_Type >= 0 )
{
if( ( ptr_tool->m_Size.x == dx )
&& ( ptr_tool->m_Size.y == dy )
&& ( ptr_tool->m_Type == type ) )
return ptr_tool; /* D_code deja existant */
last_dcode_ptr = ptr_tool;
ptr_tool = ptr_tool->m_Pnext;
num_new_D_code++;
}
/* At this point, the requested D_CODE does not exist: It will be created */
if( ptr_tool == NULL ) /* We must create a new data */
{
ptr_tool = new D_CODE();
ptr_tool->m_NumDcode = num_new_D_code;
if( last_dcode_ptr )
{
ptr_tool->m_Pback = last_dcode_ptr;
last_dcode_ptr->m_Pnext = ptr_tool;
}
else
s_DCodeList = ptr_tool;
}
ptr_tool->m_Size.x = dx;
ptr_tool->m_Size.y = dy;
ptr_tool->m_Type = type;
return ptr_tool;
}
/***********************************/
static void Init_ApertureList()
/***********************************/
/* Init the memory to handle the aperture list:
* the member .m_Type is used by get_D_code() to handle the end of list:
* .m_Type < 0 is the first free aperture descr
*/
{
2008-03-22 05:55:06 +00:00
D_CODE* ptr_tool;
ptr_tool = s_DCodeList;
while( ptr_tool )
{
s_DCodeList->m_Type = -1;
ptr_tool = ptr_tool->m_Pnext;
}
ShowDcodeError = TRUE;
}
/******************************************************/
int Gen_D_CODE_File( FILE* penfile )
/******************************************************/
/* Genere la liste courante des D_CODES
* Retourne le nombre de D_Codes utilises
* Genere une sequence RS274X
*/
{
2008-03-22 05:55:06 +00:00
D_CODE* ptr_tool;
char cbuf[1024];
2008-03-22 05:55:06 +00:00
int nb_dcodes = 0;
/* Init : */
ptr_tool = s_DCodeList;
while( ptr_tool && ( ptr_tool->m_Type >= 0 ) )
{
float fscale = 0.0001f; // For 3.4 format
2008-03-22 05:55:06 +00:00
char* text;
sprintf( cbuf, "%%ADD%d", ptr_tool->m_NumDcode );
text = cbuf + strlen( cbuf );
switch( ptr_tool->m_Type )
{
case 1: // Circle (flash )
sprintf( text, "C,%f*%%\n", ptr_tool->m_Size.x * fscale );
break;
case 2: // PAD_RECT
sprintf( text, "R,%fX%f*%%\n", ptr_tool->m_Size.x * fscale,
ptr_tool->m_Size.y * fscale );
break;
case 3: // Circle ( lines )
sprintf( text, "C,%f*%%\n", ptr_tool->m_Size.x * fscale );
break;
case 4: // PAD_OVAL
sprintf( text, "O,%fX%f*%%\n", ptr_tool->m_Size.x * fscale,
ptr_tool->m_Size.y * fscale );
break;
default:
DisplayError( NULL, wxT( "Gen_D_CODE_File(): Dcode Type err" ) );
2008-03-22 05:55:06 +00:00
break;
}
fputs( cbuf, penfile );
ptr_tool = ptr_tool->m_Pnext;
nb_dcodes++;
}
return nb_dcodes;
}
/*****************************/
void CloseFileGERBER( void )
/****************************/
{
char line[1024];
wxString TmpFileName, msg;
FILE* tmpfile;
fputs( "M02*\n", g_Plot_PlotOutputFile );
fclose( g_Plot_PlotOutputFile );
// Reouverture g_Plot_PlotOutputFile pour ajout des Apertures
g_Plot_PlotOutputFile = wxFopen( GerberFullFileName, wxT( "rt" ) );
if( g_Plot_PlotOutputFile == NULL )
{
msg.Printf( _( "unable to reopen file <%s>" ), GerberFullFileName.GetData() );
DisplayError( NULL, msg );
return;
}
// Ouverture tmpfile
TmpFileName = GerberFullFileName + wxT( ".$$$" );
tmpfile = wxFopen( TmpFileName, wxT( "wt" ) );
if( tmpfile == NULL )
{
fclose( g_Plot_PlotOutputFile );
DisplayError( NULL, wxT( "CloseFileGERBER(): Can't Open tmp file" ) );
return;
}
// Placement des Apertures en RS274X
rewind( g_Plot_PlotOutputFile );
while( fgets( line, 1024, g_Plot_PlotOutputFile ) )
{
fputs( line, tmpfile );
if( strcmp( strtok( line, "\n\r" ), "G04 APERTURE LIST*" ) == 0 )
{
Gen_D_CODE_File( tmpfile );
fputs( "G04 APERTURE END LIST*\n", tmpfile );
}
}
fclose( tmpfile );
fclose( g_Plot_PlotOutputFile );
wxRemoveFile( GerberFullFileName );
wxRenameFile( TmpFileName, GerberFullFileName );
}