2009-11-09 14:00:22 +00:00
|
|
|
/*************/
|
|
|
|
/* files.cpp */
|
|
|
|
/*************/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
#include "fctsys.h"
|
|
|
|
#include "common.h"
|
2009-02-04 15:25:03 +00:00
|
|
|
#include "class_drawpanel.h"
|
|
|
|
#include "confirm.h"
|
|
|
|
#include "gestfich.h"
|
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
#include "gerbview.h"
|
|
|
|
|
2009-11-09 14:00:22 +00:00
|
|
|
static void LoadDCodeFile( WinEDA_GerberFrame* frame,
|
2009-11-21 20:44:19 +00:00
|
|
|
const wxString& FullFileName );
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
2010-10-17 16:42:06 +00:00
|
|
|
/* Load a Gerber file selected from history list on current layer
|
2010-10-05 19:54:27 +00:00
|
|
|
* Previous data is deleted
|
|
|
|
*/
|
2009-01-17 20:31:19 +00:00
|
|
|
void WinEDA_GerberFrame::OnFileHistory( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
wxString fn;
|
|
|
|
|
|
|
|
fn = GetFileFromHistory( event.GetId(), _( "Printed circuit board" ) );
|
|
|
|
|
2010-02-04 11:03:31 +00:00
|
|
|
if( fn != wxEmptyString )
|
2009-01-17 20:31:19 +00:00
|
|
|
{
|
2010-02-04 11:03:31 +00:00
|
|
|
Erase_Current_Layer( false );
|
2010-12-15 20:15:24 +00:00
|
|
|
LoadGerberFiles( fn );
|
2009-01-17 20:31:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-25 15:10:01 +00:00
|
|
|
|
2009-11-09 14:00:22 +00:00
|
|
|
/* File commands. */
|
|
|
|
void WinEDA_GerberFrame::Files_io( wxCommandEvent& event )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-11-09 14:00:22 +00:00
|
|
|
int id = event.GetId();
|
2007-09-25 15:10:01 +00:00
|
|
|
|
|
|
|
switch( id )
|
|
|
|
{
|
2010-02-04 11:03:31 +00:00
|
|
|
case wxID_FILE:
|
2010-05-17 20:35:46 +00:00
|
|
|
{
|
2010-02-04 11:03:31 +00:00
|
|
|
Erase_Current_Layer( false );
|
2010-12-15 20:15:24 +00:00
|
|
|
LoadGerberFiles( wxEmptyString );
|
2007-09-25 15:10:01 +00:00
|
|
|
break;
|
2010-05-17 20:35:46 +00:00
|
|
|
}
|
2007-09-25 15:10:01 +00:00
|
|
|
|
|
|
|
case ID_MENU_INC_LAYER_AND_APPEND_FILE:
|
|
|
|
case ID_INC_LAYER_AND_APPEND_FILE:
|
2009-11-09 14:00:22 +00:00
|
|
|
{
|
2010-02-04 09:08:08 +00:00
|
|
|
int origLayer = getActiveLayer();
|
|
|
|
if( origLayer < NB_LAYERS )
|
|
|
|
{
|
|
|
|
setActiveLayer(origLayer+1);
|
2010-10-05 19:54:27 +00:00
|
|
|
Erase_Current_Layer( false );
|
2010-12-15 20:15:24 +00:00
|
|
|
if( !LoadGerberFiles( wxEmptyString ) )
|
2010-02-04 09:08:08 +00:00
|
|
|
setActiveLayer(origLayer);
|
|
|
|
SetToolbars();
|
|
|
|
}
|
|
|
|
else
|
2010-05-17 20:35:46 +00:00
|
|
|
{
|
|
|
|
wxString msg;
|
2010-06-19 10:58:50 +00:00
|
|
|
msg.Printf( _( "GerbView only supports a maximum of %d layers. You must first \
|
2010-05-17 20:35:46 +00:00
|
|
|
delete an existing layer to load any new layers." ), NB_LAYERS );
|
|
|
|
wxMessageBox( msg );
|
|
|
|
}
|
2009-11-09 14:00:22 +00:00
|
|
|
}
|
|
|
|
break;
|
2007-09-25 15:10:01 +00:00
|
|
|
|
|
|
|
case ID_NEW_BOARD:
|
2009-11-23 17:24:33 +00:00
|
|
|
Clear_Pcb( true );
|
|
|
|
Zoom_Automatique( false );
|
2010-01-13 13:43:36 +00:00
|
|
|
DrawPanel->Refresh();
|
2010-10-17 16:42:06 +00:00
|
|
|
ClearMsgPanel();
|
2007-09-25 15:10:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_GERBVIEW_LOAD_DRILL_FILE:
|
|
|
|
DisplayError( this, _( "Not yet available..." ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_GERBVIEW_LOAD_DCODE_FILE:
|
2009-11-21 20:44:19 +00:00
|
|
|
LoadDCodeFile( this, wxEmptyString );
|
2007-09-25 15:10:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
DisplayError( this, wxT( "File_io Internal Error" ) );
|
|
|
|
break;
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-15 20:15:24 +00:00
|
|
|
bool WinEDA_GerberFrame::LoadGerberFiles( const wxString& aFullFileName )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-11-09 14:00:22 +00:00
|
|
|
wxString filetypes;
|
2010-12-15 20:15:24 +00:00
|
|
|
wxArrayString filenamesList;
|
2010-05-17 20:35:46 +00:00
|
|
|
wxFileName filename = aFullFileName;
|
2010-12-15 20:15:24 +00:00
|
|
|
wxString currentPath;
|
2007-09-25 15:10:01 +00:00
|
|
|
|
|
|
|
ActiveScreen = GetScreen();
|
2009-04-05 20:49:15 +00:00
|
|
|
|
2010-12-15 20:15:24 +00:00
|
|
|
if( ! filename.IsOk() )
|
2007-09-25 15:10:01 +00:00
|
|
|
{
|
2009-12-30 18:06:12 +00:00
|
|
|
/* Standard gerber filetypes
|
|
|
|
* (See http://en.wikipedia.org/wiki/Gerber_File)
|
|
|
|
* the .pho extension is the default used in Pcbnew
|
2010-10-17 16:42:06 +00:00
|
|
|
* However there are a lot of other extensions used for gerber files
|
|
|
|
* Because the first letter is usually g, we accept g* as extension
|
|
|
|
* (Mainly internal copper layers do not have specific extention,
|
|
|
|
* and filenames are like *.g1, *.g2 *.gb1 ...).
|
2009-12-30 18:06:12 +00:00
|
|
|
*/
|
2010-10-17 16:42:06 +00:00
|
|
|
filetypes = _( "Gerber files (.g* .lgr .pho)" );
|
2009-12-30 18:06:12 +00:00
|
|
|
filetypes << wxT("|");
|
2010-10-17 16:42:06 +00:00
|
|
|
filetypes += wxT("*.g*;*.G*;*.lgr;*.LGR;*.pho;*.PHO" );
|
2009-12-30 18:06:12 +00:00
|
|
|
filetypes << wxT("|");
|
2009-11-09 14:00:22 +00:00
|
|
|
|
|
|
|
/* Special gerber filetypes */
|
|
|
|
filetypes += _( "Top layer (*.GTL)|*.GTL;*.gtl|" );
|
|
|
|
filetypes += _( "Bottom layer (*.GBL)|*.GBL;*.gbl|" );
|
|
|
|
filetypes += _( "Bottom solder resist (*.GBS)|*.GBS;*.gbs|" );
|
|
|
|
filetypes += _( "Top solder resist (*.GTS)|*.GTS;*.gts|" );
|
|
|
|
filetypes += _( "Bottom overlay (*.GBO)|*.GBO;*.gbo|" );
|
|
|
|
filetypes += _( "Top overlay (*.GTO)|*.GTO;*.gto|" );
|
|
|
|
filetypes += _( "Bottom paste (*.GBP)|*.GBP;*.gbp|" );
|
|
|
|
filetypes += _( "Top paste (*.GTP)|*.GTP;*.gtp|" );
|
|
|
|
filetypes += _( "Keep-out layer (*.GKO)|*.GKO;*.gko|" );
|
|
|
|
filetypes += _( "Mechanical layers (*.GMx)|*.GM1;*.gm1;*.GM2;*.gm2;*.GM3;*.gm3|" );
|
|
|
|
filetypes += _( "Top Pad Master (*.GPT)|*.GPT;*.gpt|" );
|
|
|
|
filetypes += _( "Bottom Pad Master (*.GPB)|*.GPB;*.gpb|" );
|
|
|
|
|
|
|
|
/* All filetypes */
|
|
|
|
filetypes += AllFilesWildcard;
|
|
|
|
|
2010-05-17 20:35:46 +00:00
|
|
|
/* Use the current working directory if the file name path does not exist. */
|
|
|
|
if( filename.DirExists() )
|
2010-12-15 20:15:24 +00:00
|
|
|
currentPath = filename.GetPath();
|
|
|
|
else
|
|
|
|
currentPath = wxGetCwd();
|
2009-05-28 20:46:16 +00:00
|
|
|
|
|
|
|
wxFileDialog dlg( this,
|
|
|
|
_( "Open Gerber File" ),
|
2010-12-15 20:15:24 +00:00
|
|
|
currentPath,
|
2009-05-28 20:46:16 +00:00
|
|
|
filename.GetFullName(),
|
|
|
|
filetypes,
|
2010-12-15 20:15:24 +00:00
|
|
|
wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE | wxFD_CHANGE_DIR );
|
2008-02-23 01:26:21 +00:00
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return false;
|
2008-02-23 01:26:21 +00:00
|
|
|
|
2010-12-15 20:15:24 +00:00
|
|
|
dlg.GetFilenames( filenamesList );
|
|
|
|
currentPath = wxGetCwd();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxFileName filename = aFullFileName;
|
|
|
|
filenamesList.Add( aFullFileName );
|
|
|
|
currentPath = filename.GetPath();
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2007-09-25 15:10:01 +00:00
|
|
|
|
2010-12-15 20:15:24 +00:00
|
|
|
// Read gerber files: each file is loaded on a new gerbview layer
|
2010-12-17 20:34:29 +00:00
|
|
|
int layer = getActiveLayer();
|
2010-12-15 20:15:24 +00:00
|
|
|
for( unsigned ii = 0; ii < filenamesList.GetCount(); ii++ )
|
|
|
|
{
|
|
|
|
wxFileName filename = filenamesList[ii];
|
|
|
|
filename.SetPath( currentPath );
|
|
|
|
GetScreen()->m_FileName = filename.GetFullPath();
|
|
|
|
filename.SetExt( g_PenFilenameExt );
|
|
|
|
|
2010-12-17 20:34:29 +00:00
|
|
|
setActiveLayer( layer, false );
|
2010-12-15 20:15:24 +00:00
|
|
|
if( Read_GERBER_File( GetScreen()->m_FileName, filename.GetFullPath() ) )
|
|
|
|
{
|
|
|
|
SetLastProject( GetScreen()->m_FileName );
|
2010-12-17 20:34:29 +00:00
|
|
|
layer++;
|
|
|
|
if( layer >= NB_LAYERS )
|
|
|
|
layer = 0;
|
2010-12-15 20:15:24 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-25 15:10:01 +00:00
|
|
|
|
2009-11-23 17:24:33 +00:00
|
|
|
Zoom_Automatique( false );
|
2007-09-25 15:10:01 +00:00
|
|
|
GetScreen()->SetRefreshReq();
|
|
|
|
g_SaveTime = time( NULL );
|
|
|
|
|
2010-12-17 20:34:29 +00:00
|
|
|
// Synchronize layers tools with actual active layer:
|
|
|
|
setActiveLayer(getActiveLayer());
|
|
|
|
syncLayerBox();
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
return true;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
2007-09-25 15:10:01 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
/*
|
2010-02-04 11:03:31 +00:00
|
|
|
* Read a DCode file (not used with RX274X files , just with RS274D old files).
|
|
|
|
* Note: there is no standard for DCode file.
|
|
|
|
* Just read a file format created by early versions of Pcbnew.
|
2009-11-09 14:00:22 +00:00
|
|
|
* Returns:
|
|
|
|
* 0 if file not read (cancellation of order ...)
|
|
|
|
* 1 if OK
|
2007-09-25 15:10:01 +00:00
|
|
|
*/
|
2009-11-09 14:00:22 +00:00
|
|
|
static void LoadDCodeFile( WinEDA_GerberFrame* frame,
|
2009-11-21 20:44:19 +00:00
|
|
|
const wxString& FullFileName )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-11-09 14:00:22 +00:00
|
|
|
wxString wildcard;
|
2009-04-05 20:49:15 +00:00
|
|
|
wxFileName fn = FullFileName;
|
2007-09-25 15:10:01 +00:00
|
|
|
|
|
|
|
ActiveScreen = frame->GetScreen();
|
|
|
|
|
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
|
|
|
wildcard.Printf( _( "Gerber DCODE files (%s)|*.%s" ),
|
2009-11-09 14:00:22 +00:00
|
|
|
GetChars( g_PenFilenameExt ),
|
|
|
|
GetChars( g_PenFilenameExt ) );
|
2009-04-05 20:49:15 +00:00
|
|
|
wildcard += AllFilesWildcard;
|
|
|
|
fn = frame->GetScreen()->m_FileName;
|
|
|
|
fn.SetExt( g_PenFilenameExt );
|
2009-11-09 14:00:22 +00:00
|
|
|
wxFileDialog dlg( (wxWindow*) frame, _( "Load GERBER DCODE File" ),
|
2009-04-05 20:49:15 +00:00
|
|
|
fn.GetPath(), fn.GetFullName(), wildcard,
|
|
|
|
wxFD_OPEN | wxFD_FILE_MUST_EXIST );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
2007-09-25 15:10:01 +00:00
|
|
|
return;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
fn = dlg.GetPath();
|
2007-09-25 15:10:01 +00:00
|
|
|
}
|
|
|
|
|
2009-04-05 20:49:15 +00:00
|
|
|
frame->Read_D_Code_File( fn.GetFullPath() );
|
2007-09-25 15:10:01 +00:00
|
|
|
frame->CopyDCodesSizeToItems();
|
|
|
|
frame->GetScreen()->SetRefreshReq();
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|