2007-09-25 15:10:01 +00:00
|
|
|
|
/********************************************************/
|
|
|
|
|
/**** Routine de lecture et visu d'un fichier GERBER ****/
|
|
|
|
|
/********************************************************/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
|
#include "confirm.h"
|
|
|
|
|
#include "kicad_string.h"
|
|
|
|
|
#include "gestfich.h"
|
2007-06-05 12:10:51 +00:00
|
|
|
|
#include "gerbview.h"
|
|
|
|
|
#include "pcbplot.h"
|
|
|
|
|
#include "protos.h"
|
|
|
|
|
|
|
|
|
|
/* Format Gerber : NOTES :
|
2007-09-25 15:10:01 +00:00
|
|
|
|
* Fonctions preparatoires:
|
|
|
|
|
* Gn =
|
|
|
|
|
* G01 interpolation lineaire ( trace de droites )
|
|
|
|
|
* G02,G20,G21 Interpolation circulaire , sens trigo < 0
|
|
|
|
|
* G03,G30,G31 Interpolation circulaire , sens trigo > 0
|
|
|
|
|
* G04 commentaire
|
|
|
|
|
* G06 Interpolation parabolique
|
|
|
|
|
* G07 Interpolation cubique
|
|
|
|
|
* G10 interpolation lineaire ( echelle 10x )
|
|
|
|
|
* G11 interpolation lineaire ( echelle 0.1x )
|
|
|
|
|
* G12 interpolation lineaire ( echelle 0.01x )
|
|
|
|
|
* G52 plot symbole reference par Dnn code
|
|
|
|
|
* G53 plot symbole reference par Dnn ; symbole tourne de -90 degres
|
|
|
|
|
* G54 Selection d'outil
|
|
|
|
|
* G55 Mode exposition photo
|
|
|
|
|
* G56 plot symbole reference par Dnn A code
|
|
|
|
|
* G57 affiche le symbole reference sur la console
|
|
|
|
|
* G58 plot et affiche le symbole reference sur la console
|
|
|
|
|
* G60 interpolation lineaire ( echelle 100x )
|
|
|
|
|
* G70 Unites = Inches
|
|
|
|
|
* G71 Unites = Millimetres
|
|
|
|
|
* G74 supprime interpolation circulaire sur 360 degre, revient a G01
|
|
|
|
|
* G75 Active interpolation circulaire sur 360 degre
|
|
|
|
|
* G90 Mode Coordonnees absolues
|
|
|
|
|
* G91 Mode Coordonnees Relatives
|
2007-11-02 09:58:42 +00:00
|
|
|
|
*
|
2007-09-25 15:10:01 +00:00
|
|
|
|
* Coordonnees X,Y
|
|
|
|
|
* X,Y sont suivies de + ou - et de m+n chiffres (non separes)
|
|
|
|
|
* m = partie entiere
|
|
|
|
|
* n = partie apres la virgule
|
|
|
|
|
* formats classiques : m = 2, n = 3 (format 2.3)
|
|
|
|
|
* m = 3, n = 4 (format 3.4)
|
|
|
|
|
* ex:
|
|
|
|
|
* G__ X00345Y-06123 D__*
|
2007-11-02 09:58:42 +00:00
|
|
|
|
*
|
2007-09-25 15:10:01 +00:00
|
|
|
|
* Outils et D_CODES
|
|
|
|
|
* numero d'outil ( identification des formes )
|
|
|
|
|
* 1 a 99 (classique)
|
|
|
|
|
* 1 a 999
|
|
|
|
|
* D_CODES:
|
2007-11-02 09:58:42 +00:00
|
|
|
|
*
|
2007-09-25 15:10:01 +00:00
|
|
|
|
* D01 ... D9 = codes d'action:
|
2008-02-12 21:12:46 +00:00
|
|
|
|
* D01 = activation de lumiere (baisser de plume) lors du d<EFBFBD>placement
|
|
|
|
|
* D02 = extinction de lumiere (lever de plume) lors du d<EFBFBD>placement
|
2007-09-25 15:10:01 +00:00
|
|
|
|
* D03 = Flash
|
|
|
|
|
* D09 = VAPE Flash
|
|
|
|
|
* D51 = precede par G54 -> Select VAPE
|
2007-11-02 09:58:42 +00:00
|
|
|
|
*
|
2007-09-25 15:10:01 +00:00
|
|
|
|
* D10 ... D255 = Indentification d'outils ( d'ouvertures )
|
|
|
|
|
* Ne sont pas tj dans l'ordre ( voir tableau dans PCBPLOT.H)
|
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Variables locales : */
|
|
|
|
|
|
|
|
|
|
/* Routines Locales */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Routine de Lecture d'un fichier de D Codes.
|
2007-09-25 15:10:01 +00:00
|
|
|
|
* Accepte format standard ou ALSPCB
|
|
|
|
|
* un ';' demarre un commentaire.
|
2007-11-02 09:58:42 +00:00
|
|
|
|
*
|
2007-09-25 15:10:01 +00:00
|
|
|
|
* Format Standard:
|
|
|
|
|
* tool, Horiz, Vert, drill, vitesse, acc. ,Type ; [DCODE (commentaire)]
|
|
|
|
|
* ex: 1, 12, 12, 0, 0, 0, 3 ; D10
|
2007-11-02 09:58:42 +00:00
|
|
|
|
*
|
2007-09-25 15:10:01 +00:00
|
|
|
|
* Format ALSPCB:
|
|
|
|
|
* Ver , Hor , Type , Tool [,Drill]
|
|
|
|
|
* ex: 0.012, 0.012, L , D10
|
2007-11-02 09:58:42 +00:00
|
|
|
|
*
|
2007-09-25 15:10:01 +00:00
|
|
|
|
* Classe les caract en buf_tmp sous forme de tableau de structures D_CODE.
|
|
|
|
|
* Retourne:
|
|
|
|
|
* < 0 si erreur:
|
|
|
|
|
* -1 = Fichier non trouve
|
|
|
|
|
* -2 = Erreur lecture fichier
|
|
|
|
|
* Rang de D_code maxi lu ( nbr de dcodes )
|
2007-11-02 09:58:42 +00:00
|
|
|
|
*
|
|
|
|
|
*
|
2007-09-25 15:10:01 +00:00
|
|
|
|
* Representation interne:
|
2007-11-02 09:58:42 +00:00
|
|
|
|
*
|
2008-02-12 21:12:46 +00:00
|
|
|
|
* Les lignes sont repr<EFBFBD>sent<EFBFBD>es par des TRACKS standards
|
|
|
|
|
* Les Flash sont repr<EFBFBD>sent<EFBFBD>es par des DRAWSEGMENTS
|
2007-09-25 15:10:01 +00:00
|
|
|
|
* - ronds ou ovales: DRAWSEGMENTS
|
|
|
|
|
* - rectangles: DRAWSEGMENTS
|
2008-02-12 21:12:46 +00:00
|
|
|
|
* la reference aux D-CODES est plac<EFBFBD>e dans le membre GetNet()
|
2007-09-25 15:10:01 +00:00
|
|
|
|
*/
|
2007-06-05 12:10:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/********************************************************/
|
2007-09-25 15:10:01 +00:00
|
|
|
|
bool WinEDA_GerberFrame::Read_GERBER_File( wxDC* DC,
|
|
|
|
|
const wxString& GERBER_FullFileName,
|
|
|
|
|
const wxString& D_Code_FullFileName )
|
2007-06-05 12:10:51 +00:00
|
|
|
|
/********************************************************/
|
|
|
|
|
|
2007-11-02 09:58:42 +00:00
|
|
|
|
/* Read a gerber file (RS274D or RS274X format).
|
|
|
|
|
* Normal format:
|
2007-09-25 15:10:01 +00:00
|
|
|
|
* Imperial
|
2007-11-02 09:58:42 +00:00
|
|
|
|
* Absolute
|
|
|
|
|
* end of block = *
|
|
|
|
|
* CrLf after each command
|
2007-09-25 15:10:01 +00:00
|
|
|
|
* G codes repetes
|
2007-06-05 12:10:51 +00:00
|
|
|
|
*/
|
|
|
|
|
{
|
2007-11-02 09:58:42 +00:00
|
|
|
|
int G_commande = 0,
|
2008-11-07 07:55:28 +00:00
|
|
|
|
D_commande = 0; /* command number for G et D commands (like G04 or D02) */
|
|
|
|
|
|
2008-11-08 06:44:07 +00:00
|
|
|
|
char line[GERBER_BUFZ];
|
2008-11-07 07:55:28 +00:00
|
|
|
|
|
2007-09-25 15:10:01 +00:00
|
|
|
|
wxString msg;
|
|
|
|
|
char* text;
|
2007-11-02 09:58:42 +00:00
|
|
|
|
int layer; /* current layer used in gerbview */
|
2008-11-08 06:44:07 +00:00
|
|
|
|
GERBER* gerber;
|
2007-09-25 15:10:01 +00:00
|
|
|
|
wxPoint pos;
|
|
|
|
|
int error = 0;
|
|
|
|
|
|
2008-04-17 16:25:29 +00:00
|
|
|
|
layer = GetScreen()->m_Active_Layer;
|
2007-09-25 15:10:01 +00:00
|
|
|
|
|
2008-11-08 06:44:07 +00:00
|
|
|
|
if( g_GERBER_List[layer] == NULL )
|
2007-09-25 15:10:01 +00:00
|
|
|
|
{
|
2008-11-08 06:44:07 +00:00
|
|
|
|
g_GERBER_List[layer] = new GERBER( layer );
|
2007-09-25 15:10:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-11-08 06:44:07 +00:00
|
|
|
|
gerber = g_GERBER_List[layer];
|
2007-11-02 09:58:42 +00:00
|
|
|
|
|
|
|
|
|
/* Set the gerber scale: */
|
2008-11-08 06:44:07 +00:00
|
|
|
|
gerber->ResetDefaultValues();
|
2007-09-25 15:10:01 +00:00
|
|
|
|
|
2007-11-02 09:58:42 +00:00
|
|
|
|
/* Read the gerber file */
|
2008-11-08 06:44:07 +00:00
|
|
|
|
gerber->m_Current_File = wxFopen( GERBER_FullFileName, wxT( "rt" ) );
|
|
|
|
|
if( gerber->m_Current_File == 0 )
|
2007-09-25 15:10:01 +00:00
|
|
|
|
{
|
|
|
|
|
msg = _( "File " ) + GERBER_FullFileName + _( " not found" );
|
2007-11-02 09:58:42 +00:00
|
|
|
|
DisplayError( this, msg, 10 );
|
2007-09-25 15:10:01 +00:00
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-08 06:44:07 +00:00
|
|
|
|
gerber->m_FileName = GERBER_FullFileName;
|
2007-09-25 15:10:01 +00:00
|
|
|
|
|
2008-02-23 01:26:21 +00:00
|
|
|
|
wxString path = wxPathOnly( GERBER_FullFileName );
|
|
|
|
|
if( path != wxEmptyString )
|
|
|
|
|
wxSetWorkingDirectory( path );
|
2007-09-25 15:10:01 +00:00
|
|
|
|
|
|
|
|
|
wxBusyCursor show_wait;
|
2008-06-06 16:39:45 +00:00
|
|
|
|
SetLocaleTo_C_standard( );
|
2007-09-25 15:10:01 +00:00
|
|
|
|
|
|
|
|
|
while( TRUE )
|
|
|
|
|
{
|
2008-11-08 06:44:07 +00:00
|
|
|
|
if( fgets( line, sizeof(line), gerber->m_Current_File ) == NULL ) // E.O.F
|
2007-09-25 15:10:01 +00:00
|
|
|
|
{
|
2008-11-08 06:44:07 +00:00
|
|
|
|
if( gerber->m_FilesPtr == 0 )
|
2007-09-25 15:10:01 +00:00
|
|
|
|
break;
|
2007-11-02 09:58:42 +00:00
|
|
|
|
|
2008-11-08 06:44:07 +00:00
|
|
|
|
fclose( gerber->m_Current_File );
|
2007-11-02 09:58:42 +00:00
|
|
|
|
|
2008-11-08 06:44:07 +00:00
|
|
|
|
gerber->m_FilesPtr--;
|
|
|
|
|
gerber->m_Current_File =
|
|
|
|
|
gerber->m_FilesList[gerber->m_FilesPtr];
|
2007-11-02 09:58:42 +00:00
|
|
|
|
|
2007-09-25 15:10:01 +00:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2007-11-02 09:58:42 +00:00
|
|
|
|
|
2008-11-08 06:44:07 +00:00
|
|
|
|
text = StrPurge( line );
|
2007-09-25 15:10:01 +00:00
|
|
|
|
|
|
|
|
|
while( text && *text )
|
|
|
|
|
{
|
|
|
|
|
switch( *text )
|
|
|
|
|
{
|
|
|
|
|
case ' ':
|
|
|
|
|
case '\r':
|
|
|
|
|
case '\n':
|
|
|
|
|
text++;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '*': // End commande
|
2008-11-08 06:44:07 +00:00
|
|
|
|
gerber->m_CommandState = END_BLOCK;
|
2007-09-25 15:10:01 +00:00
|
|
|
|
text++;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'M': // End file
|
2008-11-08 06:44:07 +00:00
|
|
|
|
gerber->m_CommandState = CMD_IDLE;
|
2007-09-25 15:10:01 +00:00
|
|
|
|
while( *text )
|
|
|
|
|
text++;
|
2007-11-02 09:58:42 +00:00
|
|
|
|
|
2007-09-25 15:10:01 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2007-11-02 09:58:42 +00:00
|
|
|
|
case 'G': /* Line type Gxx : command */
|
2008-11-08 06:44:07 +00:00
|
|
|
|
G_commande = gerber->ReturnGCodeNumber( text );
|
|
|
|
|
gerber->Execute_G_Command( text, G_commande );
|
2007-09-25 15:10:01 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2007-11-02 09:58:42 +00:00
|
|
|
|
case 'D': /* Line type Dxx : Tool selection (xx > 0) or command if xx = 0..9*/
|
2008-11-08 06:44:07 +00:00
|
|
|
|
D_commande = gerber->ReturnDCodeNumber( text );
|
2009-04-29 17:09:00 +00:00
|
|
|
|
gerber->Execute_DCODE_Command( this, DC, text, D_commande );
|
2007-09-25 15:10:01 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'X':
|
2007-11-02 09:58:42 +00:00
|
|
|
|
case 'Y': /* Move or draw command */
|
2008-11-08 06:44:07 +00:00
|
|
|
|
pos = gerber->ReadXYCoord( text );
|
2007-09-25 15:10:01 +00:00
|
|
|
|
if( *text == '*' ) // command like X12550Y19250*
|
|
|
|
|
{
|
2008-11-08 06:44:07 +00:00
|
|
|
|
gerber->Execute_DCODE_Command( this, DC, text,
|
2009-04-29 17:09:00 +00:00
|
|
|
|
gerber->m_Last_Pen_Command );
|
2007-09-25 15:10:01 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'I':
|
2007-11-02 09:58:42 +00:00
|
|
|
|
case 'J': /* Auxiliary Move command */
|
2008-11-08 06:44:07 +00:00
|
|
|
|
pos = gerber->ReadIJCoord( text );
|
2007-09-25 15:10:01 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case '%':
|
2008-11-08 06:44:07 +00:00
|
|
|
|
if( gerber->m_CommandState != ENTER_RS274X_CMD )
|
2007-09-25 15:10:01 +00:00
|
|
|
|
{
|
2008-11-08 06:44:07 +00:00
|
|
|
|
gerber->m_CommandState = ENTER_RS274X_CMD;
|
2007-11-02 09:58:42 +00:00
|
|
|
|
|
2008-11-08 06:44:07 +00:00
|
|
|
|
if( !gerber->ReadRS274XCommand( this, DC, line, text ) )
|
2007-09-25 15:10:01 +00:00
|
|
|
|
{
|
|
|
|
|
error++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else //Error
|
|
|
|
|
{
|
|
|
|
|
error++;
|
2008-11-08 06:44:07 +00:00
|
|
|
|
gerber->m_CommandState = CMD_IDLE;
|
2007-09-25 15:10:01 +00:00
|
|
|
|
text++;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2007-11-02 09:58:42 +00:00
|
|
|
|
text++;
|
2007-09-25 15:10:01 +00:00
|
|
|
|
error++;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if( error )
|
|
|
|
|
{
|
|
|
|
|
msg.Printf( _( "%d errors while reading Gerber file [%s]" ),
|
2009-04-05 20:49:15 +00:00
|
|
|
|
error, GERBER_FullFileName.GetData() );
|
2007-09-25 15:10:01 +00:00
|
|
|
|
DisplayError( this, msg );
|
|
|
|
|
}
|
2008-11-08 06:44:07 +00:00
|
|
|
|
fclose( gerber->m_Current_File );
|
2007-09-25 15:10:01 +00:00
|
|
|
|
|
2008-06-06 16:39:45 +00:00
|
|
|
|
SetLocaleTo_Default( );
|
2007-09-25 15:10:01 +00:00
|
|
|
|
|
2007-11-02 09:58:42 +00:00
|
|
|
|
/* Init DCodes list and perhaps read a DCODES file,
|
|
|
|
|
* if the gerber file is only a RS274D file (without any aperture information)
|
|
|
|
|
*/
|
2008-11-09 02:57:42 +00:00
|
|
|
|
if( !gerber->m_Has_DCode )
|
2007-09-25 15:10:01 +00:00
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
|
wxFileName fn;
|
|
|
|
|
|
2007-09-25 15:10:01 +00:00
|
|
|
|
if( D_Code_FullFileName.IsEmpty() )
|
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
|
wxString wildcard;
|
|
|
|
|
|
|
|
|
|
fn = GERBER_FullFileName;
|
|
|
|
|
fn.SetExt( g_PenFilenameExt );
|
|
|
|
|
wildcard.Printf( _( "Gerber DCODE files (%s)|*.%s" ),
|
|
|
|
|
g_PenFilenameExt.c_str(), g_PenFilenameExt.c_str());
|
|
|
|
|
wildcard += AllFilesWildcard;
|
|
|
|
|
|
|
|
|
|
wxFileDialog dlg( this, _( "Load GERBER DCODE File" ),
|
|
|
|
|
wxEmptyString, fn.GetFullName(), wildcard,
|
|
|
|
|
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
|
2007-09-25 15:10:01 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
2009-04-05 20:49:15 +00:00
|
|
|
|
fn = D_Code_FullFileName;
|
2007-09-25 15:10:01 +00:00
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
if( fn.IsOk() )
|
2007-09-25 15:10:01 +00:00
|
|
|
|
{
|
2009-04-05 20:49:15 +00:00
|
|
|
|
Read_D_Code_File( fn.GetFullPath() );
|
2007-09-25 15:10:01 +00:00
|
|
|
|
CopyDCodesSizeToItems();
|
|
|
|
|
}
|
2009-04-05 20:49:15 +00:00
|
|
|
|
else
|
|
|
|
|
return false;
|
2007-09-25 15:10:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
|
return true;
|
2007-06-05 12:10:51 +00:00
|
|
|
|
}
|