Commit 64f12ffe authored by dickelbeck's avatar dickelbeck

gerberview & pcbnew fixes

parent 5e448ec4
...@@ -4,6 +4,21 @@ Started 2007-June-11 ...@@ -4,6 +4,21 @@ Started 2007-June-11
Please add newer entries at the top, list the date and your name with Please add newer entries at the top, list the date and your name with
email address. email address.
2007-Sep-25 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================
+ pcbnew
* got rid of reference to global display options DisplayOpt.DisplayZones from
collectors.cpp so collectors.cpp can continue to be used in multiple future
(non-display related) general contexts.
* Moved TYPEZONE to end of AllBoardItems, added GENERAL_COLLECTOR::AllButZones to
provide support of DisplayOpt.DisplayZones.
* Added aHotKeyCode to PcbGeneralLocateAndDisplay()
+ gerbview
* viewer was getting stuck in a loop when loading a bad gerber file. Fixed
the bug, but line 223 through 225 of readgerb.cpp need review.
* beautified a few files with uncrustify, (any I had to look at).
2007-sept-25 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr> 2007-sept-25 UPDATE Jean-Pierre Charras <jean-pierre.charras@inpg.fr>
================================================================================ ================================================================================
+ pcbnew: + pcbnew:
......
/******************************************************/ /******************************************************/
/* Files.cp: Lecture / Sauvegarde des fichiers gerber */ /* Files.cp: Lecture / Sauvegarde des fichiers gerber */
/******************************************************/ /******************************************************/
#include "fctsys.h" #include "fctsys.h"
...@@ -12,215 +12,223 @@ ...@@ -12,215 +12,223 @@
/* Routines locales */ /* Routines locales */
static void LoadDCodeFile(WinEDA_GerberFrame * frame, const wxString & FullFileName, wxDC * DC); static void LoadDCodeFile( WinEDA_GerberFrame* frame, const wxString& FullFileName, wxDC* DC );
/********************************************************/ /********************************************************/
void WinEDA_GerberFrame::Files_io(wxCommandEvent& event) void WinEDA_GerberFrame::Files_io( wxCommandEvent& event )
/********************************************************/ /********************************************************/
/* Gestion generale des commandes de lecture de fichiers /* Gestion generale des commandes de lecture de fichiers
*/ */
{ {
int id = event.GetId(); int id = event.GetId();
wxClientDC dc(DrawPanel);
wxClientDC dc( DrawPanel );
DrawPanel->CursorOff(&dc);
DrawPanel->CursorOff( &dc );
switch (id)
{ switch( id )
case ID_MENU_LOAD_FILE: {
case ID_LOAD_FILE: case ID_MENU_LOAD_FILE:
if ( Clear_Pcb(&dc, TRUE) ) case ID_LOAD_FILE:
{ if( Clear_Pcb( &dc, TRUE ) )
LoadOneGerberFile(wxEmptyString, &dc, 0); {
} LoadOneGerberFile( wxEmptyString, &dc, 0 );
break; }
break;
case ID_MENU_INC_LAYER_AND_APPEND_FILE:
case ID_INC_LAYER_AND_APPEND_FILE: case ID_MENU_INC_LAYER_AND_APPEND_FILE:
{ case ID_INC_LAYER_AND_APPEND_FILE:
int layer = GetScreen()->m_Active_Layer; {
GetScreen()->m_Active_Layer++; int layer = GetScreen()->m_Active_Layer;
if( ! LoadOneGerberFile(wxEmptyString, &dc, 0) ) GetScreen()->m_Active_Layer++;
GetScreen()->m_Active_Layer = layer; if( !LoadOneGerberFile( wxEmptyString, &dc, 0 ) )
SetToolbars(); GetScreen()->m_Active_Layer = layer;
} SetToolbars();
break; }
break;
case ID_MENU_APPEND_FILE:
case ID_APPEND_FILE: case ID_MENU_APPEND_FILE:
LoadOneGerberFile(wxEmptyString, &dc, 0); case ID_APPEND_FILE:
break; LoadOneGerberFile( wxEmptyString, &dc, 0 );
break;
case ID_MENU_NEW_BOARD:
case ID_NEW_BOARD: case ID_MENU_NEW_BOARD:
Clear_Pcb(&dc, TRUE); case ID_NEW_BOARD:
Zoom_Automatique(FALSE); Clear_Pcb( &dc, TRUE );
GetScreen()->SetRefreshReq(); Zoom_Automatique( FALSE );
break; GetScreen()->SetRefreshReq();
break;
case ID_LOAD_FILE_1:
case ID_LOAD_FILE_2: case ID_LOAD_FILE_1:
case ID_LOAD_FILE_3: case ID_LOAD_FILE_2:
case ID_LOAD_FILE_4: case ID_LOAD_FILE_3:
case ID_LOAD_FILE_5: case ID_LOAD_FILE_4:
case ID_LOAD_FILE_6: case ID_LOAD_FILE_5:
case ID_LOAD_FILE_7: case ID_LOAD_FILE_6:
case ID_LOAD_FILE_8: case ID_LOAD_FILE_7:
case ID_LOAD_FILE_9: case ID_LOAD_FILE_8:
case ID_LOAD_FILE_10: case ID_LOAD_FILE_9:
if ( Clear_Pcb(&dc, TRUE) ) case ID_LOAD_FILE_10:
{ if( Clear_Pcb( &dc, TRUE ) )
LoadOneGerberFile( {
GetLastProject(id - ID_LOAD_FILE_1).GetData(), LoadOneGerberFile(
&dc, FALSE); GetLastProject( id - ID_LOAD_FILE_1 ).GetData(),
} &dc, FALSE );
break; }
break;
case ID_GERBVIEW_LOAD_DRILL_FILE:
DisplayError(this, _("Not yet available...")); case ID_GERBVIEW_LOAD_DRILL_FILE:
break; DisplayError( this, _( "Not yet available..." ) );
break;
case ID_GERBVIEW_LOAD_DCODE_FILE:
LoadDCodeFile(this, wxEmptyString, &dc); case ID_GERBVIEW_LOAD_DCODE_FILE:
break; LoadDCodeFile( this, wxEmptyString, &dc );
break;
case ID_SAVE_BOARD:
case ID_MENU_SAVE_BOARD: case ID_SAVE_BOARD:
SaveGerberFile(GetScreen()->m_FileName, &dc); case ID_MENU_SAVE_BOARD:
break; SaveGerberFile( GetScreen()->m_FileName, &dc );
break;
case ID_MENU_SAVE_BOARD_AS:
SaveGerberFile(wxEmptyString, &dc); case ID_MENU_SAVE_BOARD_AS:
break; SaveGerberFile( wxEmptyString, &dc );
break;
default:
DisplayError(this, wxT("File_io Internal Error") ); default:
break; DisplayError( this, wxT( "File_io Internal Error" ) );
} break;
}
DrawPanel->MouseToCursorSchema();
DrawPanel->CursorOn(&dc); DrawPanel->MouseToCursorSchema();
DrawPanel->CursorOn( &dc );
} }
/*******************************************************************************************/ /*******************************************************************************************/
int WinEDA_GerberFrame::LoadOneGerberFile(const wxString & FullFileName, int WinEDA_GerberFrame::LoadOneGerberFile( const wxString& FullFileName,
wxDC * DC, int mode) wxDC* DC, int mode )
/*******************************************************************************************/ /*******************************************************************************************/
/* /*
Lecture d'un fichier PCB, le nom etant dans PcbNameBuffer.s * Lecture d'un fichier PCB, le nom etant dans PcbNameBuffer.s
retourne: * retourne:
0 si fichier non lu ( annulation de commande ... ) * 0 si fichier non lu ( annulation de commande ... )
1 si OK * 1 si OK
*/ */
{ {
wxString filename = FullFileName; wxString filename = FullFileName;
wxString path = wxPathOnly(FullFileName); wxString path = wxPathOnly( FullFileName );
ActiveScreen = GetScreen(); ActiveScreen = GetScreen();
if( filename == wxEmptyString) if( filename == wxEmptyString )
{ {
wxString mask = wxT("*") + g_PhotoFilenameExt; wxString mask = wxT( "*" ) + g_PhotoFilenameExt;
mask += wxT(";*.gbr;*.gbx;*.lgr;*.ger");
filename = EDA_FileSelector(_("Gerber files:"), mask += wxT( ";*.gbr;*.gbx;*.lgr;*.ger" );
path, /* Chemin par defaut */
wxEmptyString, /* nom fichier par defaut */ filename = EDA_FileSelector( _( "Gerber files:" ),
g_PhotoFilenameExt, /* extension par defaut */ path, /* Chemin par defaut */
mask, /* Masque d'affichage */ wxEmptyString, /* nom fichier par defaut */
this, g_PhotoFilenameExt, /* extension par defaut */
0, mask, /* Masque d'affichage */
FALSE this,
); 0,
if ( filename == wxEmptyString ) return FALSE; FALSE
} );
if( filename == wxEmptyString )
GetScreen()->m_FileName = filename; return FALSE;
wxSetWorkingDirectory(path); }
ChangeFileNameExt(filename,g_PenFilenameExt);
GetScreen()->m_FileName = filename;
if ( Read_GERBER_File(DC, GetScreen()->m_FileName, filename) )
SetLastProject(GetScreen()->m_FileName); wxSetWorkingDirectory( path );
Zoom_Automatique(FALSE); ChangeFileNameExt( filename, g_PenFilenameExt );
GetScreen()->SetRefreshReq();
g_SaveTime = time(NULL); if( Read_GERBER_File( DC, GetScreen()->m_FileName, filename ) )
SetLastProject( GetScreen()->m_FileName );
return(1);
Zoom_Automatique( FALSE );
GetScreen()->SetRefreshReq();
g_SaveTime = time( NULL );
return 1;
} }
/**********************************************************************************************/ /**********************************************************************************************/
static void LoadDCodeFile(WinEDA_GerberFrame * frame, const wxString & FullFileName, wxDC * DC) static void LoadDCodeFile( WinEDA_GerberFrame* frame, const wxString& FullFileName, wxDC* DC )
/**********************************************************************************************/ /**********************************************************************************************/
/* /*
Lecture d'un fichier PCB, le nom etant dans PcbNameBuffer.s * Lecture d'un fichier PCB, le nom etant dans PcbNameBuffer.s
retourne: * retourne:
0 si fichier non lu ( annulation de commande ... ) * 0 si fichier non lu ( annulation de commande ... )
1 si OK * 1 si OK
*/ */
{ {
wxString filename = FullFileName; wxString filename = FullFileName;
ActiveScreen = frame->GetScreen(); ActiveScreen = frame->GetScreen();
if( filename == wxEmptyString) if( filename == wxEmptyString )
{ {
wxString penfilesmask( wxT("*") ); wxString penfilesmask( wxT( "*" ) );
penfilesmask += g_PenFilenameExt;
filename = frame->GetScreen()->m_FileName; penfilesmask += g_PenFilenameExt;
ChangeFileNameExt(filename,g_PenFilenameExt); filename = frame->GetScreen()->m_FileName;
filename = EDA_FileSelector(_("D codes files:"), ChangeFileNameExt( filename, g_PenFilenameExt );
wxEmptyString, /* Chemin par defaut */ filename = EDA_FileSelector( _( "D codes files:" ),
filename, /* nom fichier par defaut */ wxEmptyString, /* Chemin par defaut */
g_PenFilenameExt, /* extension par defaut */ filename, /* nom fichier par defaut */
penfilesmask, /* Masque d'affichage */ g_PenFilenameExt, /* extension par defaut */
frame, penfilesmask, /* Masque d'affichage */
0, frame,
TRUE 0,
); TRUE
if ( filename == wxEmptyString ) return; );
} if( filename == wxEmptyString )
return;
frame->Read_D_Code_File(filename); }
frame->CopyDCodesSizeToItems();
frame->GetScreen()->SetRefreshReq(); frame->Read_D_Code_File( filename );
frame->CopyDCodesSizeToItems();
frame->GetScreen()->SetRefreshReq();
} }
/*******************************************************************************/ /*******************************************************************************/
bool WinEDA_GerberFrame::SaveGerberFile(const wxString & FullFileName, wxDC * DC) bool WinEDA_GerberFrame::SaveGerberFile( const wxString& FullFileName, wxDC* DC )
/*******************************************************************************/ /*******************************************************************************/
/* Sauvegarde du fichier PCB en format ASCII /* Sauvegarde du fichier PCB en format ASCII
*/ */
{ {
wxString filename = FullFileName; wxString filename = FullFileName;
if( filename == wxEmptyString ) if( filename == wxEmptyString )
{ {
wxString mask( wxT("*")); wxString mask( wxT( "*" ) );
mask += g_PhotoFilenameExt;
filename = EDA_FileSelector(_("Gerber files:"), mask += g_PhotoFilenameExt;
wxEmptyString, /* Chemin par defaut */ filename = EDA_FileSelector( _( "Gerber files:" ),
GetScreen()->m_FileName, /* nom fichier par defaut */ wxEmptyString, /* Chemin par defaut */
g_PhotoFilenameExt, /* extension par defaut */ GetScreen()->m_FileName, /* nom fichier par defaut */
mask, /* Masque d'affichage */ g_PhotoFilenameExt, /* extension par defaut */
this, mask, /* Masque d'affichage */
wxFD_SAVE, this,
FALSE wxFD_SAVE,
); FALSE
if ( filename.IsEmpty() ) return FALSE; );
} if( filename.IsEmpty() )
return FALSE;
GetScreen()->m_FileName = filename; }
GetScreen()->m_FileName = filename;
// TODO // TODO
return TRUE; return TRUE;
} }
/********************************************************/ /********************************************************/
/**** Routine de lecture et visu d'un fichier GERBER ****/ /**** Routine de lecture et visu d'un fichier GERBER ****/
/********************************************************/ /********************************************************/
#include "fctsys.h" #include "fctsys.h"
...@@ -11,57 +11,57 @@ ...@@ -11,57 +11,57 @@
#include "protos.h" #include "protos.h"
/* Format Gerber : NOTES : /* Format Gerber : NOTES :
Fonctions preparatoires: * Fonctions preparatoires:
Gn = * Gn =
G01 interpolation lineaire ( trace de droites ) * G01 interpolation lineaire ( trace de droites )
G02,G20,G21 Interpolation circulaire , sens trigo < 0 * G02,G20,G21 Interpolation circulaire , sens trigo < 0
G03,G30,G31 Interpolation circulaire , sens trigo > 0 * G03,G30,G31 Interpolation circulaire , sens trigo > 0
G04 commentaire * G04 commentaire
G06 Interpolation parabolique * G06 Interpolation parabolique
G07 Interpolation cubique * G07 Interpolation cubique
G10 interpolation lineaire ( echelle 10x ) * G10 interpolation lineaire ( echelle 10x )
G11 interpolation lineaire ( echelle 0.1x ) * G11 interpolation lineaire ( echelle 0.1x )
G12 interpolation lineaire ( echelle 0.01x ) * G12 interpolation lineaire ( echelle 0.01x )
G52 plot symbole reference par Dnn code * G52 plot symbole reference par Dnn code
G53 plot symbole reference par Dnn ; symbole tourne de -90 degres * G53 plot symbole reference par Dnn ; symbole tourne de -90 degres
G54 Selection d'outil * G54 Selection d'outil
G55 Mode exposition photo * G55 Mode exposition photo
G56 plot symbole reference par Dnn A code * G56 plot symbole reference par Dnn A code
G57 affiche le symbole reference sur la console * G57 affiche le symbole reference sur la console
G58 plot et affiche le symbole reference sur la console * G58 plot et affiche le symbole reference sur la console
G60 interpolation lineaire ( echelle 100x ) * G60 interpolation lineaire ( echelle 100x )
G70 Unites = Inches * G70 Unites = Inches
G71 Unites = Millimetres * G71 Unites = Millimetres
G74 supprime interpolation circulaire sur 360 degre, revient a G01 * G74 supprime interpolation circulaire sur 360 degre, revient a G01
G75 Active interpolation circulaire sur 360 degre * G75 Active interpolation circulaire sur 360 degre
G90 Mode Coordonnees absolues * G90 Mode Coordonnees absolues
G91 Mode Coordonnees Relatives * G91 Mode Coordonnees Relatives
*
Coordonnees X,Y * Coordonnees X,Y
X,Y sont suivies de + ou - et de m+n chiffres (non separes) * X,Y sont suivies de + ou - et de m+n chiffres (non separes)
m = partie entiere * m = partie entiere
n = partie apres la virgule * n = partie apres la virgule
formats classiques : m = 2, n = 3 (format 2.3) * formats classiques : m = 2, n = 3 (format 2.3)
m = 3, n = 4 (format 3.4) * m = 3, n = 4 (format 3.4)
ex: * ex:
G__ X00345Y-06123 D__* * G__ X00345Y-06123 D__*
*
Outils et D_CODES * Outils et D_CODES
numero d'outil ( identification des formes ) * numero d'outil ( identification des formes )
1 a 99 (classique) * 1 a 99 (classique)
1 a 999 * 1 a 999
D_CODES: * D_CODES:
*
D01 ... D9 = codes d'action: * D01 ... D9 = codes d'action:
D01 = activation de lumiere (baisser de plume) lors du déplacement * D01 = activation de lumiere (baisser de plume) lors du déplacement
D02 = extinction de lumiere (lever de plume) lors du déplacement * D02 = extinction de lumiere (lever de plume) lors du déplacement
D03 = Flash * D03 = Flash
D09 = VAPE Flash * D09 = VAPE Flash
D51 = precede par G54 -> Select VAPE * D51 = precede par G54 -> Select VAPE
*
D10 ... D255 = Indentification d'outils ( d'ouvertures ) * D10 ... D255 = Indentification d'outils ( d'ouvertures )
Ne sont pas tj dans l'ordre ( voir tableau dans PCBPLOT.H) * Ne sont pas tj dans l'ordre ( voir tableau dans PCBPLOT.H)
*/ */
/* Variables locales : */ /* Variables locales : */
...@@ -69,208 +69,218 @@ Outils et D_CODES ...@@ -69,208 +69,218 @@ Outils et D_CODES
/* Routines Locales */ /* Routines Locales */
/* Routine de Lecture d'un fichier de D Codes. /* Routine de Lecture d'un fichier de D Codes.
Accepte format standard ou ALSPCB * Accepte format standard ou ALSPCB
un ';' demarre un commentaire. * un ';' demarre un commentaire.
*
Format Standard: * Format Standard:
tool, Horiz, Vert, drill, vitesse, acc. ,Type ; [DCODE (commentaire)] * tool, Horiz, Vert, drill, vitesse, acc. ,Type ; [DCODE (commentaire)]
ex: 1, 12, 12, 0, 0, 0, 3 ; D10 * ex: 1, 12, 12, 0, 0, 0, 3 ; D10
*
Format ALSPCB: * Format ALSPCB:
Ver , Hor , Type , Tool [,Drill] * Ver , Hor , Type , Tool [,Drill]
ex: 0.012, 0.012, L , D10 * ex: 0.012, 0.012, L , D10
*
Classe les caract en buf_tmp sous forme de tableau de structures D_CODE. * Classe les caract en buf_tmp sous forme de tableau de structures D_CODE.
Retourne: * Retourne:
< 0 si erreur: * < 0 si erreur:
-1 = Fichier non trouve * -1 = Fichier non trouve
-2 = Erreur lecture fichier * -2 = Erreur lecture fichier
Rang de D_code maxi lu ( nbr de dcodes ) * Rang de D_code maxi lu ( nbr de dcodes )
*
*
Representation interne: * Representation interne:
*
Les lignes sont représentées par des TRACKS standards * Les lignes sont représentées par des TRACKS standards
Les Flash sont représentées par des DRAWSEGMENTS * Les Flash sont représentées par des DRAWSEGMENTS
- ronds ou ovales: DRAWSEGMENTS * - ronds ou ovales: DRAWSEGMENTS
- rectangles: DRAWSEGMENTS * - rectangles: DRAWSEGMENTS
la reference aux D-CODES est placée dans le membre m_NetCode * la reference aux D-CODES est placée dans le membre m_NetCode
*/ */
/********************************************************/ /********************************************************/
bool WinEDA_GerberFrame::Read_GERBER_File(wxDC * DC, bool WinEDA_GerberFrame::Read_GERBER_File( wxDC* DC,
const wxString & GERBER_FullFileName, const wxString& GERBER_FullFileName,
const wxString & D_Code_FullFileName) const wxString& D_Code_FullFileName )
/********************************************************/ /********************************************************/
/* Lecture de 1 fichier gerber. /* Lecture de 1 fichier gerber.
Format * Format
Imperial * Imperial
Absolu * Absolu
fin de bloc = * * fin de bloc = *
CrLf apres chaque commande * CrLf apres chaque commande
G codes repetes * G codes repetes
*/ */
{ {
int G_commande = 0, D_commande = 0 ; /* Numero de commande G et D codes */ int G_commande = 0, D_commande = 0; /* Numero de commande G et D codes */
char Line[1024]; // Buffer des lignes du fichier gerber en cours char Line[1024]; // Buffer des lignes du fichier gerber en cours
wxString msg; wxString msg;
char * text; char* text;
int layer = GetScreen()->m_Active_Layer; int layer = GetScreen()->m_Active_Layer;
GERBER_Descr * gerber_layer; GERBER_Descr* gerber_layer;
wxPoint pos; wxPoint pos;
int error = 0; int error = 0;
if ( g_GERBER_Descr_List[layer] == NULL ) if( g_GERBER_Descr_List[layer] == NULL )
{ {
g_GERBER_Descr_List[layer] = new GERBER_Descr(layer); g_GERBER_Descr_List[layer] = new GERBER_Descr( layer );
} }
gerber_layer = g_GERBER_Descr_List[layer]; gerber_layer = g_GERBER_Descr_List[layer];
/* Mise a jour de l'echelle gerber : */
gerber_layer->ResetDefaultValues(); /* Mise a jour de l'echelle gerber : */
gerber_layer->ResetDefaultValues();
/* Lecture du fichier de Trace */
gerber_layer->m_Current_File = wxFopen(GERBER_FullFileName, wxT("rt") ); /* Lecture du fichier de Trace */
if (gerber_layer->m_Current_File == 0) gerber_layer->m_Current_File = wxFopen( GERBER_FullFileName, wxT( "rt" ) );
{ if( gerber_layer->m_Current_File == 0 )
msg = _("File ") + GERBER_FullFileName + _(" not found"); {
DisplayError(this, msg, 10); return FALSE; msg = _( "File " ) + GERBER_FullFileName + _( " not found" );
} DisplayError( this, msg, 10 );
return FALSE;
gerber_layer->m_FileName = GERBER_FullFileName; }
wxSetWorkingDirectory(wxPathOnly(GERBER_FullFileName)); gerber_layer->m_FileName = GERBER_FullFileName;
wxBusyCursor show_wait; wxSetWorkingDirectory( wxPathOnly( GERBER_FullFileName ) );
setlocale(LC_NUMERIC, "C");
wxBusyCursor show_wait;
while( TRUE ) setlocale( LC_NUMERIC, "C" );
{
if ( fgets(Line,255,gerber_layer->m_Current_File) == NULL ) // E.O.F while( TRUE )
{ {
if ( gerber_layer->m_FilesPtr == 0 ) break; if( fgets( Line, 255, gerber_layer->m_Current_File ) == NULL ) // E.O.F
fclose(gerber_layer->m_Current_File); {
gerber_layer->m_FilesPtr --; if( gerber_layer->m_FilesPtr == 0 )
gerber_layer->m_Current_File = break;
gerber_layer->m_FilesList[gerber_layer->m_FilesPtr];
continue; fclose( gerber_layer->m_Current_File );
}
text = StrPurge(Line); gerber_layer->m_FilesPtr--;
gerber_layer->m_Current_File =
while ( text && *text ) gerber_layer->m_FilesList[gerber_layer->m_FilesPtr];
{
switch( *text ) continue;
{ }
case ' ':
case '\r': text = StrPurge( Line );
case '\n':
text ++; while( text && *text )
break; {
switch( *text )
case '*': // End commande {
gerber_layer->m_CommandState = END_BLOCK; case ' ':
text ++; case '\r':
break; case '\n':
text++;
case 'M': // End file break;
gerber_layer->m_CommandState = CMD_IDLE;
while ( *text ) text ++; case '*': // End commande
break; gerber_layer->m_CommandState = END_BLOCK;
text++;
case 'G': /* Ligne type Gxx : commande */ break;
G_commande = gerber_layer->ReturnGCodeNumber(text);
gerber_layer->Execute_G_Command(text, G_commande); case 'M': // End file
break ; gerber_layer->m_CommandState = CMD_IDLE;
while( *text )
case 'D': /* Ligne type Dxx : Selection d'un outil ou commande si xx = 0..9*/ text++;
D_commande = gerber_layer->ReturnDCodeNumber(text); break;
gerber_layer->Execute_DCODE_Command(this, DC,
text, D_commande); case 'G': /* Ligne type Gxx : commande */
break ; G_commande = gerber_layer->ReturnGCodeNumber( text );
gerber_layer->Execute_G_Command( text, G_commande );
case 'X': break;
case 'Y': /* Commande de deplacement ou de Trace */
pos = gerber_layer->ReadXYCoord(text); case 'D': /* Ligne type Dxx : Selection d'un outil ou commande si xx = 0..9*/
if ( *text == '*' ) // command like X12550Y19250* D_commande = gerber_layer->ReturnDCodeNumber( text );
{ gerber_layer->Execute_DCODE_Command( this, DC,
gerber_layer->Execute_DCODE_Command(this, DC, text, text, D_commande );
gerber_layer->m_Last_Pen_Command); break;
}
break; case 'X':
case 'Y': /* Commande de deplacement ou de Trace */
case 'I': pos = gerber_layer->ReadXYCoord( text );
case 'J': /* Commande de deplacement ou de Trace */ if( *text == '*' ) // command like X12550Y19250*
pos = gerber_layer->ReadIJCoord(text); {
break; gerber_layer->Execute_DCODE_Command( this, DC, text,
gerber_layer->m_Last_Pen_Command );
case '%': }
if (gerber_layer->m_CommandState != ENTER_RS274X_CMD ) break;
{
gerber_layer->m_CommandState = ENTER_RS274X_CMD; case 'I':
gerber_layer->ReadRS274XCommand(this, DC, Line, text); case 'J': /* Commande de deplacement ou de Trace */
} pos = gerber_layer->ReadIJCoord( text );
else //Error break;
{
wxBell(); error++; case '%':
gerber_layer->m_CommandState = CMD_IDLE; if( gerber_layer->m_CommandState != ENTER_RS274X_CMD )
text++; {
} gerber_layer->m_CommandState = ENTER_RS274X_CMD;
break;
if( !gerber_layer->ReadRS274XCommand( this, DC, Line, text ) )
default: {
text ++; error++; error++;
break; }
} // end switch (*text) }
} // end while (text else //Error
} // end while (TRUE) {
wxBell();
if ( error ) error++;
{ gerber_layer->m_CommandState = CMD_IDLE;
msg.Printf( _("%d errors while reading Gerber file [%s]"), text++;
error, GERBER_FullFileName.GetData()); }
DisplayError(this, msg); break;
}
fclose(gerber_layer->m_Current_File) ; default:
text++;
setlocale(LC_NUMERIC, ""); error++;
break;
/* Init tableau des DCodes et Lecture fichier DCODES */ }
if ( !gerber_layer->m_As_DCode ) }
{ }
wxString DCodeFileName;
if( D_Code_FullFileName.IsEmpty()) if( error )
{ {
wxString mask; msg.Printf( _( "%d errors while reading Gerber file [%s]" ),
DCodeFileName = GERBER_FullFileName; error, GERBER_FullFileName.GetData() );
ChangeFileNameExt(DCodeFileName, g_PenFilenameExt); DisplayError( this, msg );
mask = wxT("*") + g_PenFilenameExt; }
DCodeFileName = EDA_FileSelector( _("D codes files:"), fclose( gerber_layer->m_Current_File );
wxEmptyString, /* Chemin par defaut */
DCodeFileName, /* nom fichier par defaut */ setlocale( LC_NUMERIC, "" );
g_PenFilenameExt, /* extension par defaut */
mask, /* Masque d'affichage */ /* Init tableau des DCodes et Lecture fichier DCODES */
this, if( !gerber_layer->m_As_DCode )
0, {
TRUE wxString DCodeFileName;
); if( D_Code_FullFileName.IsEmpty() )
} {
else DCodeFileName = D_Code_FullFileName; wxString mask;
DCodeFileName = GERBER_FullFileName;
if ( ! DCodeFileName.IsEmpty() ) ChangeFileNameExt( DCodeFileName, g_PenFilenameExt );
{ mask = wxT( "*" ) + g_PenFilenameExt;
Read_D_Code_File(DCodeFileName); DCodeFileName = EDA_FileSelector( _( "D codes files:" ),
CopyDCodesSizeToItems(); wxEmptyString, /* Chemin par defaut */
} DCodeFileName, /* nom fichier par defaut */
} g_PenFilenameExt, /* extension par defaut */
mask, /* Masque d'affichage */
return TRUE; this,
0,
TRUE
);
}
else
DCodeFileName = D_Code_FullFileName;
if( !DCodeFileName.IsEmpty() )
{
Read_D_Code_File( DCodeFileName );
CopyDCodesSizeToItems();
}
}
return TRUE;
} }
/********************************************************/ /********************************************************/
/* Routine de lecture d'un fichier GERBER format RS274X */ /* Routine de lecture d'un fichier GERBER format RS274X */
/********************************************************/ /********************************************************/
#include "fctsys.h" #include "fctsys.h"
...@@ -10,462 +10,521 @@ ...@@ -10,462 +10,521 @@
#include "protos.h" #include "protos.h"
#define IsNumber(x) ( ( ((x) >= '0') && ((x) <='9') ) ||\ #define IsNumber( x ) ( ( ( (x) >= '0' ) && ( (x) <='9' ) ) \
((x) == '-') || ((x) == '+') || ((x) == '.') || ((x) == ',')) || ( (x) == '-' ) || ( (x) == '+' ) || ( (x) == '.' ) || ( (x) == ',' ) )
#define CODE(x,y) ((x<<8) + (y)) #define CODE( x, y ) ( (x << 8) + (y) )
enum rs274x_parameters enum rs274x_parameters {
{ FORMAT_STATEMENT_COMMAND = CODE( 'F', 'S' ),
FORMAT_STATEMENT_COMMAND = CODE('F','S'), AXIS_SELECT = CODE( 'A', 'S' ),
AXIS_SELECT = CODE('A','S'), MIRROR_IMAGE = CODE( 'M', 'I' ),
MIRROR_IMAGE = CODE('M','I'), MODE_OF_UNITS = CODE( 'M', 'O' ),
MODE_OF_UNITS = CODE('M','O'), INCH = CODE( 'I', 'N' ),
INCH = CODE('I','N'), MILLIMETER = CODE( 'M', 'M' ),
MILLIMETER = CODE('M','M'), OFFSET = CODE( 'O', 'F' ),
OFFSET = CODE('O','F'), SCALE_FACTOR = CODE( 'S', 'F' ),
SCALE_FACTOR = CODE('S','F'),
IMAGE_NAME = CODE( 'I', 'N' ),
IMAGE_NAME = CODE('I','N'), IMAGE_JUSTIFY = CODE( 'I', 'J' ),
IMAGE_JUSTIFY = CODE('I','J'), IMAGE_OFFSET = CODE( 'I', 'O' ),
IMAGE_OFFSET = CODE('I','O'), IMAGE_POLARITY = CODE( 'I', 'P' ),
IMAGE_POLARITY = CODE('I','P'), IMAGE_ROTATION = CODE( 'I', 'R' ),
IMAGE_ROTATION = CODE('I','R'), PLOTTER_FILM = CODE( 'P', 'M' ),
PLOTTER_FILM = CODE('P','M'), INCLUDE_FILE = CODE( 'I', 'F' ),
INCLUDE_FILE = CODE('I','F'),
APERTURE_DESCR = CODE( 'A', 'D' ),
APERTURE_DESCR = CODE('A','D'), APERTURE_MACRO = CODE( 'A', 'M' ),
APERTURE_MACRO = CODE('A','M'), LAYER_NAME = CODE( 'L', 'N' ),
LAYER_NAME = CODE('L','N'), LAYER_POLARITY = CODE( 'L', 'P' ),
LAYER_POLARITY = CODE('L','P'), KNOCKOUT = CODE( 'K', 'O' ),
KNOCKOUT = CODE('K','O'), STEP_AND_REPEAT = CODE( 'S', 'P' ),
STEP_AND_REPEAT = CODE('S','P'), ROTATE = CODE( 'R', 'O' )
ROTATE = CODE('R','O')
}; };
/* Variables locales : */ /* Variables locales : */
/* Routines Locales */ /* Routines Locales */
static bool ReadApertureMacro( char * buff, char * &text, FILE *gerber_file); static bool ReadApertureMacro( char* buff, char*& text, FILE* gerber_file );
/* Lit 2 codes ascii du texte point par text /* Lit 2 codes ascii du texte point par text
retourne le code correspondant ou -1 si erreur * retourne le code correspondant ou -1 si erreur
*/ */
static int ReadXCommand(char * &text) static int ReadXCommand( char*& text )
{ {
int result; int result;
if ( text && *text ) if( text && *text )
{ {
result = (*text) << 8; text ++; result = (*text) << 8; text++;
} }
else return -1; else
if ( text && *text ) return -1;
{ if( text && *text )
result += (*text) & 255; text ++; {
} result += (*text) & 255; text++;
else return -1; }
return result; else
return -1;
return result;
} }
/********************************/ /********************************/
static int ReadInt(char * &text) static int ReadInt( char*& text )
/********************************/ /********************************/
{ {
int nb = 0; int nb = 0;
while ( text && *text == ' ' ) text++; // Skip blanks before number while( text && *text == ' ' )
text++;
while ( text && *text)
{ // Skip blanks before number
if ( (*text >= '0') && (*text <='9') )
{ while( text && *text )
nb *= 10; nb += *text & 0x0F; {
text++; if( (*text >= '0') && (*text <='9') )
} {
else break; nb *= 10; nb += *text & 0x0F;
} text++;
return nb; }
else
break;
}
return nb;
} }
/************************************/ /************************************/
static double ReadDouble(char * &text) static double ReadDouble( char*& text )
/************************************/ /************************************/
{ {
double nb = 0.0; double nb = 0.0;
char buf[256], * ptchar; char buf[256], * ptchar;
ptchar = buf; ptchar = buf;
while ( text && *text == ' ' ) text++; // Skip blanks before number while( text && *text == ' ' )
while ( text && *text) text++;
{
if ( IsNumber(*text) ) // Skip blanks before number
{ while( text && *text )
* ptchar = * text; {
text++; ptchar ++; if( IsNumber( *text ) )
} {
else break; *ptchar = *text;
} text++; ptchar++;
*ptchar = 0; }
else
nb = atof(buf); break;
return nb; }
*ptchar = 0;
nb = atof( buf );
return nb;
} }
/****************************************************************************/ /****************************************************************************/
bool GERBER_Descr::ReadRS274XCommand(WinEDA_GerberFrame * frame, wxDC * DC, bool GERBER_Descr::ReadRS274XCommand( WinEDA_GerberFrame* frame, wxDC* DC,
char * buff, char * &text) char* buff, char*& text )
/****************************************************************************/ /****************************************************************************/
/* Lit toutes les commandes RS274X jusqu'a trouver de code de fin % /* Lit toutes les commandes RS274X jusqu'a trouver de code de fin %
appelle ExecuteRS274XCommand() pour chaque commande trouve * appelle ExecuteRS274XCommand() pour chaque commande trouve
*/ */
{ {
int code_command; bool ok = true;
bool eof = FALSE; int code_command;
text++; text++;
do for(;;)
{ {
while ( *text ) while( *text )
{ {
switch( *text ) switch( *text )
{ {
case '%': // End commande case '%': // End commande
text ++; text++;
m_CommandState = CMD_IDLE; m_CommandState = CMD_IDLE;
return TRUE; goto exit; // success completion
case ' ': case ' ':
case '\r': case '\r':
case '\n': case '\n':
text++; text++;
break; break;
case '*': case '*':
text++; text++;
break; break;
default: default:
code_command = ReadXCommand ( text ); code_command = ReadXCommand( text );
ExecuteRS274XCommand(code_command, ok = ExecuteRS274XCommand( code_command, buff, text );
buff, text); if( !ok )
break; goto exit;
} break;
} }
// End of current line }
if ( fgets(buff,255,m_Current_File) == NULL ) eof = TRUE;
text = buff; // End of current line
} while( !eof ); if( fgets( buff, 255, m_Current_File ) == NULL )
{
return FALSE; ok = false;
break;
}
text = buff;
}
exit:
return ok;
} }
/*******************************************************************************/ /*******************************************************************************/
bool GERBER_Descr::ExecuteRS274XCommand(int command, char * buff, char * &text) bool GERBER_Descr::ExecuteRS274XCommand( int command, char* buff, char*& text )
/*******************************************************************************/ /*******************************************************************************/
/* Execute 1 commande RS274X /* Execute 1 commande RS274X
*/ */
{ {
int code; int code;
int xy_seq_len, xy_seq_char; int xy_seq_len, xy_seq_char;
char ctmp; char ctmp;
bool ok = TRUE; bool ok = TRUE;
D_CODE * dcode; D_CODE* dcode;
char Line[1024]; char Line[1024];
wxString msg; wxString msg;
double fcoord; double fcoord;
double conv_scale = m_GerbMetric ? PCB_INTERNAL_UNIT/25.4 : PCB_INTERNAL_UNIT; double conv_scale = m_GerbMetric ? PCB_INTERNAL_UNIT / 25.4 : PCB_INTERNAL_UNIT;
switch( command ) switch( command )
{ {
case FORMAT_STATEMENT_COMMAND: case FORMAT_STATEMENT_COMMAND:
xy_seq_len = 2; xy_seq_len = 2;
while ( *text != '*' )
{ while( *text != '*' )
switch ( *text ) {
{ switch( *text )
case ' ': {
text++; case ' ':
break; text++;
case'L': // No Leading 0 break;
m_NoTrailingZeros = FALSE;
text ++; case 'L': // No Leading 0
break; m_NoTrailingZeros = FALSE;
case'T': // No trailing 0 text++;
m_NoTrailingZeros = TRUE; break;
text ++;
break; case 'T': // No trailing 0
case 'A': // Absolute coord m_NoTrailingZeros = TRUE;
m_Relative = FALSE; text++; text++;
break; break;
case 'I': // Absolute coord
m_Relative = TRUE; text++; case 'A': // Absolute coord
break; m_Relative = FALSE; text++;
case 'N': // Sequence code (followed by the number of digits for the X,Y command break;
text++;
xy_seq_char = * text; text++; case 'I': // Absolute coord
if ( (xy_seq_char >= '0') && (xy_seq_char <= '9') ) m_Relative = TRUE; text++;
xy_seq_len = - '0'; break;
break;
case 'N': // Sequence code (followed by the number of digits for the X,Y command
case 'X': text++;
case 'Y': // Valeurs transmises :2 (really xy_seq_len : FIX ME) digits xy_seq_char = *text; text++;
code = *(text ++); ctmp = *(text++) - '0'; if( (xy_seq_char >= '0') && (xy_seq_char <= '9') )
if ( code == 'X' ) xy_seq_len = -'0';
{ break;
m_FmtScale.x = * text - '0'; // = nb chiffres apres la virgule
m_FmtLen.x = ctmp + m_FmtScale.x; // = nb total de chiffres case 'X':
} case 'Y': // Valeurs transmises :2 (really xy_seq_len : FIX ME) digits
else { code = *(text++); ctmp = *(text++) - '0';
m_FmtScale.y = * text - '0'; if( code == 'X' )
m_FmtLen.y = ctmp + m_FmtScale.y; {
} m_FmtScale.x = *text - '0'; // = nb chiffres apres la virgule
text++; m_FmtLen.x = ctmp + m_FmtScale.x; // = nb total de chiffres
break; }
else
case'*': {
break; m_FmtScale.y = *text - '0';
m_FmtLen.y = ctmp + m_FmtScale.y;
default: }
GetEndOfBlock( buff, text, m_Current_File ); text++;
ok = FALSE; break;
break;
} case '*':
} break;
break;
default:
case AXIS_SELECT: GetEndOfBlock( buff, text, m_Current_File );
case MIRROR_IMAGE: ok = FALSE;
ok = FALSE; break;
break; }
}
case MODE_OF_UNITS:
code = ReadXCommand ( text ); break;
if ( code == INCH ) m_GerbMetric = FALSE;
else if ( code == MILLIMETER ) m_GerbMetric = TRUE; case AXIS_SELECT:
conv_scale = m_GerbMetric ? PCB_INTERNAL_UNIT/25.4 : PCB_INTERNAL_UNIT; case MIRROR_IMAGE:
break; ok = FALSE;
break;
case OFFSET: // command: OFAnnBnn (nn = float number)
m_Offset.x = m_Offset.y = 0; case MODE_OF_UNITS:
while ( *text != '*' ) code = ReadXCommand( text );
{ if( code == INCH )
switch ( *text ) m_GerbMetric = FALSE;
{ else if( code == MILLIMETER )
case'A': // A axis offset in current unit (inch ou mm) m_GerbMetric = TRUE;
text ++; conv_scale = m_GerbMetric ? PCB_INTERNAL_UNIT / 25.4 : PCB_INTERNAL_UNIT;
fcoord = ReadDouble(text); break;
m_Offset.x = (int) round(fcoord * conv_scale);
break; case OFFSET: // command: OFAnnBnn (nn = float number)
m_Offset.x = m_Offset.y = 0;
case'B': // B axis offset in current unit (inch ou mm) while( *text != '*' )
text ++; {
fcoord = ReadDouble(text); switch( *text )
m_Offset.y = (int) round(fcoord * conv_scale); {
break; case 'A': // A axis offset in current unit (inch ou mm)
} text++;
} fcoord = ReadDouble( text );
break; m_Offset.x = (int) round( fcoord * conv_scale );
break;
case SCALE_FACTOR:
case IMAGE_JUSTIFY: case 'B': // B axis offset in current unit (inch ou mm)
case IMAGE_ROTATION : text++;
case IMAGE_OFFSET: fcoord = ReadDouble( text );
case PLOTTER_FILM: m_Offset.y = (int) round( fcoord * conv_scale );
case LAYER_NAME: break;
case KNOCKOUT: }
case STEP_AND_REPEAT: }
case ROTATE:
msg.Printf(_("Command <%c%c> ignored by Gerbview"), break;
(command>>8) & 0xFF, command & 0xFF);
if ( g_DebugLevel > 0 )wxMessageBox(msg); case SCALE_FACTOR:
break; case IMAGE_JUSTIFY:
case IMAGE_ROTATION:
case IMAGE_NAME: case IMAGE_OFFSET:
m_Name.Empty(); case PLOTTER_FILM:
while ( *text != '*' ) case LAYER_NAME:
{ case KNOCKOUT:
m_Name.Append(*text); text++; case STEP_AND_REPEAT:
} case ROTATE:
break; msg.Printf( _( "Command <%c%c> ignored by Gerbview" ),
(command >> 8) & 0xFF, command & 0xFF );
case IMAGE_POLARITY: if( g_DebugLevel > 0 )
if ( strnicmp(text, "NEG", 3 ) == 0 ) m_ImageNegative = TRUE; wxMessageBox( msg );
else m_ImageNegative = FALSE; break;
break;
case IMAGE_NAME:
case LAYER_POLARITY: m_Name.Empty();
if ( * text == 'C' ) m_LayerNegative = TRUE; while( *text != '*' )
else m_LayerNegative = FALSE; {
break; m_Name.Append( *text ); text++;
}
case APERTURE_MACRO:
ReadApertureMacro( buff, text, m_Current_File ); break;
break;
case IMAGE_POLARITY:
case INCLUDE_FILE: if( strnicmp( text, "NEG", 3 ) == 0 )
if ( m_FilesPtr >= 10 ) m_ImageNegative = TRUE;
{ else
ok = FALSE; m_ImageNegative = FALSE;
DisplayError(NULL, _("Too many include files!!") ); break;
break;
} case LAYER_POLARITY:
strcpy(Line, text); if( *text == 'C' )
strtok(Line,"*%%\n\r"); m_LayerNegative = TRUE;
m_FilesList[m_FilesPtr] = m_Current_File; else
m_Current_File = fopen(Line,"rt"); m_LayerNegative = FALSE;
if (m_Current_File == 0) break;
{
wxString msg; case APERTURE_MACRO:
msg.Printf( wxT("fichier <%s> non trouve"),Line); ReadApertureMacro( buff, text, m_Current_File );
DisplayError(NULL, msg, 10); break;
ok = FALSE;
m_Current_File = m_FilesList[m_FilesPtr]; case INCLUDE_FILE:
break; if( m_FilesPtr >= 10 )
} {
m_FilesPtr ++; ok = FALSE;
break; DisplayError( NULL, _( "Too many include files!!" ) );
break;
case APERTURE_DESCR: }
if ( *text != 'D' ) strcpy( Line, text );
{ strtok( Line, "*%%\n\r" );
ok = FALSE; break; m_FilesList[m_FilesPtr] = m_Current_File;
} m_Current_File = fopen( Line, "rt" );
m_As_DCode = TRUE; if( m_Current_File == 0 )
text++; {
code = ReadInt(text); wxString msg;
ctmp = *text; msg.Printf( wxT( "fichier <%s> non trouve" ), Line );
dcode = ReturnToolDescr(m_Layer, code); DisplayError( NULL, msg, 10 );
if ( dcode == NULL ) break; ok = FALSE;
if ( text[1] == ',' ) // Tool usuel (C,R,O,P) m_Current_File = m_FilesList[m_FilesPtr];
{ break;
text += 2; // text pointe size ( 1er modifier) }
dcode->m_Size.x = dcode->m_Size.y = m_FilesPtr++;
(int) round(ReadDouble(text) * conv_scale); break;
switch (ctmp )
{ case APERTURE_DESCR:
case 'C': // Circle if( *text != 'D' )
dcode->m_Shape = GERB_CIRCLE; {
while ( * text == ' ' ) text++; ok = FALSE; break;
if ( * text == 'X' ) }
{ m_As_DCode = TRUE;
text++; text++;
dcode->m_Drill.x = dcode->m_Drill.y = code = ReadInt( text );
(int) round(ReadDouble(text) * conv_scale); ctmp = *text;
dcode->m_DrillShape = 1; dcode = ReturnToolDescr( m_Layer, code );
} if( dcode == NULL )
while ( * text == ' ' ) text++; break;
if ( * text == 'X' ) if( text[1] == ',' ) // Tool usuel (C,R,O,P)
{ {
text++; text += 2; // text pointe size ( 1er modifier)
dcode->m_Drill.y = dcode->m_Size.x = dcode->m_Size.y =
(int) round(ReadDouble(text) * conv_scale); (int) round( ReadDouble( text ) * conv_scale );
dcode->m_DrillShape = 2;
} switch( ctmp )
dcode->m_Defined = TRUE; {
break; case 'C': // Circle
dcode->m_Shape = GERB_CIRCLE;
case 'O': // ovale while( *text == ' ' )
case 'R': // rect text++;
dcode->m_Shape = (ctmp == 'O') ? GERB_OVALE : GERB_RECT;
while ( * text == ' ' ) text++; if( *text == 'X' )
if ( * text == 'X' ) {
{ text++;
text++; dcode->m_Drill.x = dcode->m_Drill.y =
dcode->m_Size.y = (int) round( ReadDouble( text ) * conv_scale );
(int) round(ReadDouble(text) * conv_scale); dcode->m_DrillShape = 1;
} }
while ( * text == ' ' ) text++; while( *text == ' ' )
if ( * text == 'X' ) text++;
{
text++; if( *text == 'X' )
dcode->m_Drill.x = dcode->m_Drill.y = {
(int) round(ReadDouble(text) * conv_scale); text++;
dcode->m_DrillShape = 1; dcode->m_Drill.y =
} (int) round( ReadDouble( text ) * conv_scale );
while ( * text == ' ' ) text++; dcode->m_DrillShape = 2;
if ( * text == 'Y' ) }
{ dcode->m_Defined = TRUE;
text++; break;
dcode->m_Drill.y =
(int) round(ReadDouble(text) * conv_scale); case 'O': // ovale
dcode->m_DrillShape = 2; case 'R': // rect
} dcode->m_Shape = (ctmp == 'O') ? GERB_OVALE : GERB_RECT;
dcode->m_Defined = TRUE; while( *text == ' ' )
break; text++;
case 'P': // Polygone if( *text == 'X' )
{
text++;
dcode->m_Size.y =
(int) round( ReadDouble( text ) * conv_scale );
}
while( *text == ' ' )
text++;
if( *text == 'X' )
{
text++;
dcode->m_Drill.x = dcode->m_Drill.y =
(int) round( ReadDouble( text ) * conv_scale );
dcode->m_DrillShape = 1;
}
while( *text == ' ' )
text++;
if( *text == 'Y' )
{
text++;
dcode->m_Drill.y =
(int) round( ReadDouble( text ) * conv_scale );
dcode->m_DrillShape = 2;
}
dcode->m_Defined = TRUE;
break;
case 'P': // Polygone
// A modifier: temporairement la forme ronde est utilise // A modifier: temporairement la forme ronde est utilise
dcode->m_Shape = GERB_CIRCLE; dcode->m_Shape = GERB_CIRCLE;
dcode->m_Defined = TRUE; dcode->m_Defined = TRUE;
break; break;
} }
} }
break; break;
default: default:
ok = FALSE; ok = FALSE;
break; break;
} }
GetEndOfBlock( buff, text, m_Current_File ); ok = GetEndOfBlock( buff, text, m_Current_File );
return ok;
return ok;
} }
/*****************************************************************/ /*****************************************************************/
bool GetEndOfBlock( char * buff, char * &text, FILE *gerber_file) bool GetEndOfBlock( char* buff, char*& text, FILE* gerber_file )
/*****************************************************************/ /*****************************************************************/
{ {
bool eof = FALSE; for(;;)
{
do { while( (text < buff + 255) && *text )
while ( (text < buff+255) && *text ) {
{ if( *text == '*' )
if ( *text == '*' ) return TRUE; return TRUE;
if ( *text == '%' ) return TRUE; if( *text == '%' )
text ++; return TRUE;
} text++;
if ( fgets(buff,255,gerber_file) == NULL ) eof = TRUE; }
text = buff;
} while( ! eof); if( fgets( buff, 255, gerber_file ) == NULL )
break;
return FALSE;
text = buff;
}
return FALSE;
} }
/*******************************************************************/ /*******************************************************************/
bool ReadApertureMacro( char * buff, char * &text, FILE *gerber_file) bool ReadApertureMacro( char* buff, char*& text, FILE* gerber_file )
/*******************************************************************/ /*******************************************************************/
{ {
wxString macro_name; wxString macro_name;
int macro_type = 0; int macro_type = 0;
// Read macro name // Read macro name
while ( (text < buff+255) && *text ) while( (text < buff + 255) && *text )
{ {
if ( *text == '*' ) break; if( *text == '*' )
macro_name.Append(*text); break;
text ++; macro_name.Append( *text );
} text++;
}
if ( g_DebugLevel > 0 ) wxMessageBox(macro_name, wxT("macro name"));
text = buff; if( g_DebugLevel > 0 )
fgets(buff,255,gerber_file); wxMessageBox( macro_name, wxT( "macro name" ) );
text = buff;
// Read parameters fgets( buff, 255, gerber_file );
macro_type = ReadInt(text);
// Read parameters
while ( (text < buff+255) && *text ) macro_type = ReadInt( text );
{
if ( *text == '*' ) return TRUE; while( (text < buff + 255) && *text )
text ++; {
} if( *text == '*' )
return FALSE; return TRUE;
text++;
}
return FALSE;
} }
...@@ -112,11 +112,11 @@ public: ...@@ -112,11 +112,11 @@ public:
/** /**
* Function Remove * Function Remove
* removes the item at item_position (first position is 0); * removes the item at item_position (first position is 0);
* @param item_position index. * @param ndx The index into the list.
*/ */
void Remove( unsigned int item_position ) void Remove( int ndx )
{ {
m_List.erase( m_List.begin() + item_position ); m_List.erase( m_List.begin() + (unsigned) ndx );
} }
/** /**
......
...@@ -400,8 +400,12 @@ public: ...@@ -400,8 +400,12 @@ public:
* a popup menu is shown which allows the user to pick which item he/she is * a popup menu is shown which allows the user to pick which item he/she is
* interested in. Once an item is chosen, then it is make the "current item" * interested in. Once an item is chosen, then it is make the "current item"
* and the status window is updated to reflect this. * and the status window is updated to reflect this.
*
* @param aHotKeyCode The hotkey which relates to the caller and determines the
* type of search to be performed. If zero, then the mouse tools will be
* tested instead.
*/ */
BOARD_ITEM* PcbGeneralLocateAndDisplay(); BOARD_ITEM* PcbGeneralLocateAndDisplay( int aHotKeyCode = 0 );
BOARD_ITEM* Locate( int typeloc, int LayerSearch ); BOARD_ITEM* Locate( int typeloc, int LayerSearch );
void ProcessItemSelection( wxCommandEvent& event ); void ProcessItemSelection( wxCommandEvent& event );
......
...@@ -38,10 +38,10 @@ const KICAD_T GENERAL_COLLECTOR::AllBoardItems[] = { ...@@ -38,10 +38,10 @@ const KICAD_T GENERAL_COLLECTOR::AllBoardItems[] = {
TYPECOTATION, TYPECOTATION,
TYPEVIA, TYPEVIA,
TYPETRACK, TYPETRACK,
TYPEZONE,
TYPEPAD, TYPEPAD,
TYPETEXTEMODULE, TYPETEXTEMODULE,
TYPEMODULE, TYPEMODULE,
TYPEZONE,
EOT EOT
}; };
...@@ -52,13 +52,24 @@ const KICAD_T GENERAL_COLLECTOR::PrimaryItems[] = { ...@@ -52,13 +52,24 @@ const KICAD_T GENERAL_COLLECTOR::PrimaryItems[] = {
TYPECOTATION, TYPECOTATION,
TYPEVIA, TYPEVIA,
TYPETRACK, TYPETRACK,
// TYPEPAD, TYPEPAD and TYPETEXTEMODULE are handled in a subsearch
// TYPETEXTEMODULE,
TYPEMODULE, TYPEMODULE,
EOT EOT
}; };
const KICAD_T GENERAL_COLLECTOR::AllButZones[] = {
TYPETEXTE,
TYPEDRAWSEGMENT,
TYPECOTATION,
TYPEVIA,
TYPETRACK,
TYPEPAD,
TYPETEXTEMODULE,
TYPEMODULE,
EOT
};
const KICAD_T GENERAL_COLLECTOR::ModuleItems[] = { const KICAD_T GENERAL_COLLECTOR::ModuleItems[] = {
TYPEMODULE, TYPEMODULE,
EOT EOT
...@@ -95,7 +106,6 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_BaseStruct* testItem, const void* ...@@ -95,7 +106,6 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_BaseStruct* testItem, const void*
{ {
BOARD_ITEM* item = (BOARD_ITEM*) testItem; BOARD_ITEM* item = (BOARD_ITEM*) testItem;
MODULE* module = NULL; MODULE* module = NULL;
bool skip_item = false;
#if 0 // debugging #if 0 // debugging
static int breakhere = 0; static int breakhere = 0;
...@@ -173,7 +183,6 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_BaseStruct* testItem, const void* ...@@ -173,7 +183,6 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_BaseStruct* testItem, const void*
case TYPETRACK: case TYPETRACK:
break; break;
case TYPEZONE: case TYPEZONE:
if( ! DisplayOpt.DisplayZones ) skip_item = true;
break; break;
case TYPETEXTE: case TYPETEXTE:
break; break;
...@@ -183,20 +192,18 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_BaseStruct* testItem, const void* ...@@ -183,20 +192,18 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_BaseStruct* testItem, const void*
break; break;
case TYPETEXTEMODULE: case TYPETEXTEMODULE:
module = (MODULE*) item->GetParent();
if( m_Guide->IgnoreMTextsMarkedNoShow() && ((TEXTE_MODULE*)item)->m_NoShow )
goto exit;
if( module )
{ {
module = (MODULE*) item->GetParent(); if( m_Guide->IgnoreMTextsOnCopper() && module->GetLayer()==LAYER_CUIVRE_N )
if( m_Guide->IgnoreMTextsMarkedNoShow() && ((TEXTE_MODULE*)item)->m_NoShow )
goto exit; goto exit;
if( module ) if( m_Guide->IgnoreMTextsOnCmp() && module->GetLayer()==LAYER_CMP_N )
{ goto exit;
if( m_Guide->IgnoreMTextsOnCopper() && module->GetLayer()==LAYER_CUIVRE_N )
goto exit;
if( m_Guide->IgnoreMTextsOnCmp() && module->GetLayer()==LAYER_CMP_N )
goto exit;
}
} }
break; break;
...@@ -234,7 +241,7 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_BaseStruct* testItem, const void* ...@@ -234,7 +241,7 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_BaseStruct* testItem, const void*
{ {
if( item->HitTest( m_RefPos ) ) if( item->HitTest( m_RefPos ) )
{ {
if ( ! skip_item ) Append( item ); Append( item );
goto exit; goto exit;
} }
} }
...@@ -261,7 +268,7 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_BaseStruct* testItem, const void* ...@@ -261,7 +268,7 @@ SEARCH_RESULT GENERAL_COLLECTOR::Inspect( EDA_BaseStruct* testItem, const void*
{ {
if( item->HitTest( m_RefPos ) ) if( item->HitTest( m_RefPos ) )
{ {
if ( ! skip_item ) Append2nd( item ); Append2nd( item );
goto exit; goto exit;
} }
} }
......
...@@ -146,6 +146,7 @@ public: ...@@ -146,6 +146,7 @@ public:
* @return bool - ture if should ignore MODULEs on component layer. * @return bool - ture if should ignore MODULEs on component layer.
*/ */
virtual bool IgnoreModulesOnCmp() const = 0; virtual bool IgnoreModulesOnCmp() const = 0;
/** /**
* Function UseHitTesting * Function UseHitTesting
...@@ -201,6 +202,12 @@ public: ...@@ -201,6 +202,12 @@ public:
static const KICAD_T AllBoardItems[]; static const KICAD_T AllBoardItems[];
/**
* A scan list for all editable board items, except zones
*/
static const KICAD_T AllButZones[];
/** /**
* A scan list for all primary board items, omitting items which are subordinate to * A scan list for all primary board items, omitting items which are subordinate to
* a MODULE, such as D_PAD and TEXTEMODULE. * a MODULE, such as D_PAD and TEXTEMODULE.
......
...@@ -153,9 +153,9 @@ static BOARD_ITEM* AllAreModulesAndReturnSmallestIfSo( GENERAL_COLLECTOR* aColle ...@@ -153,9 +153,9 @@ static BOARD_ITEM* AllAreModulesAndReturnSmallestIfSo( GENERAL_COLLECTOR* aColle
} }
/*************************************************************/ /****************************************************************************/
BOARD_ITEM* WinEDA_BasePcbFrame::PcbGeneralLocateAndDisplay() BOARD_ITEM* WinEDA_BasePcbFrame::PcbGeneralLocateAndDisplay( int aHotKeyCode )
/*************************************************************/ /****************************************************************************/
{ {
BOARD_ITEM* item; BOARD_ITEM* item;
...@@ -166,7 +166,11 @@ BOARD_ITEM* WinEDA_BasePcbFrame::PcbGeneralLocateAndDisplay() ...@@ -166,7 +166,11 @@ BOARD_ITEM* WinEDA_BasePcbFrame::PcbGeneralLocateAndDisplay()
const KICAD_T* scanList; const KICAD_T* scanList;
if( m_ID_current_state == 0 ) if( aHotKeyCode )
{
// switch here
}
else if( m_ID_current_state == 0 )
{ {
switch( m_HTOOL_current_state ) switch( m_HTOOL_current_state )
{ {
...@@ -175,7 +179,9 @@ BOARD_ITEM* WinEDA_BasePcbFrame::PcbGeneralLocateAndDisplay() ...@@ -175,7 +179,9 @@ BOARD_ITEM* WinEDA_BasePcbFrame::PcbGeneralLocateAndDisplay()
break; break;
default: default:
scanList = GENERAL_COLLECTOR::AllBoardItems; scanList = DisplayOpt.DisplayZones ?
GENERAL_COLLECTOR::AllBoardItems :
GENERAL_COLLECTOR::AllButZones;
break; break;
} }
} }
...@@ -196,26 +202,32 @@ BOARD_ITEM* WinEDA_BasePcbFrame::PcbGeneralLocateAndDisplay() ...@@ -196,26 +202,32 @@ BOARD_ITEM* WinEDA_BasePcbFrame::PcbGeneralLocateAndDisplay()
break; break;
default: default:
scanList = GENERAL_COLLECTOR::AllBoardItems; scanList = DisplayOpt.DisplayZones ?
GENERAL_COLLECTOR::AllBoardItems :
GENERAL_COLLECTOR::AllButZones;
} }
} }
m_Collector->Collect( m_Pcb, scanList, GetScreen()->RefPos( true ), guide ); m_Collector->Collect( m_Pcb, scanList, GetScreen()->RefPos( true ), guide );
/* debugging: print out the collected items, showing their priority order too. #if 0
* for( unsigned i=0; i<m_Collector->GetCount(); ++i ) // debugging: print out the collected items, showing their priority order too.
* (*m_Collector)[i]->Show( 0, std::cout ); for( unsigned i=0; i<m_Collector->GetCount(); ++i )
*/ (*m_Collector)[i]->Show( 0, std::cout );
#endif
/* Remove redundancies: most of time, zones are found twice, /* Remove redundancies: most of time, zones are found twice,
* because zones are filled twice ( once by by horizontal and once by vertical segments ) * because zones are filled twice ( once by by horizontal and once by vertical segments )
*/ */
unsigned long timestampzone = 0; unsigned long timestampzone = 0;
for( unsigned int ii = 0; ii < m_Collector->GetCount(); ii++ )
int limit = m_Collector->GetCount();
for( int ii = 0; ii < limit; ii++ )
{ {
item = (*m_Collector)[ii]; item = (*m_Collector)[ii];
if( item->Type() != TYPEZONE ) if( item->Type() != TYPEZONE )
continue; continue;
/* Found a TYPE ZONE */ /* Found a TYPE ZONE */
if( item->m_TimeStamp == timestampzone ) // Remove it, redundant, zone already found if( item->m_TimeStamp == timestampzone ) // Remove it, redundant, zone already found
{ {
...@@ -282,14 +294,6 @@ BOARD_ITEM* WinEDA_BasePcbFrame::PcbGeneralLocateAndDisplay() ...@@ -282,14 +294,6 @@ BOARD_ITEM* WinEDA_BasePcbFrame::PcbGeneralLocateAndDisplay()
} }
return item; return item;
/* old way:
*
* item = Locate( CURSEUR_OFF_GRILLE, GetScreen()->m_Active_Layer );
* if( item == NULL )
* item = Locate( CURSEUR_OFF_GRILLE, -1 );
* return item;
*/
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment