2011-09-26 20:32:56 +00:00
|
|
|
/**
|
|
|
|
* @file gerbview/files.cpp
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
2012-02-16 20:03:33 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Jean-Pierre Charras, jaen-pierre.charras@gipsa-lab.inpg.com
|
|
|
|
* Copyright (C) 2004-2012 KiCad Developers, see change_log.txt for contributors.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <fctsys.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <class_drawpanel.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <gestfich.h>
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <gerbview.h>
|
|
|
|
#include <gerbview_id.h>
|
|
|
|
#include <class_gerbview_layer_widget.h>
|
2012-02-16 20:03:33 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
|
2011-03-17 19:14:45 +00:00
|
|
|
void GERBVIEW_FRAME::OnGbrFileHistory( wxCommandEvent& event )
|
2009-01-17 20:31:19 +00:00
|
|
|
{
|
|
|
|
wxString fn;
|
|
|
|
|
2011-03-17 19:14:45 +00:00
|
|
|
fn = GetFileFromHistory( event.GetId(), _( "Gerber files" ) );
|
2009-01-17 20:31:19 +00:00
|
|
|
|
2011-03-17 19:14:45 +00:00
|
|
|
if( !fn.IsEmpty() )
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-26 20:32:56 +00:00
|
|
|
|
2011-03-17 19:14:45 +00:00
|
|
|
void GERBVIEW_FRAME::OnDrlFileHistory( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
wxString fn;
|
|
|
|
|
|
|
|
fn = GetFileFromHistory( event.GetId(), _( "Drill files" ), &m_drillFileHistory );
|
|
|
|
|
|
|
|
if( !fn.IsEmpty() )
|
|
|
|
{
|
|
|
|
Erase_Current_Layer( false );
|
|
|
|
LoadExcellonFiles( fn );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-25 15:10:01 +00:00
|
|
|
|
2009-11-09 14:00:22 +00:00
|
|
|
/* File commands. */
|
2011-03-12 09:50:21 +00:00
|
|
|
void GERBVIEW_FRAME::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:
|
|
|
|
Erase_Current_Layer( false );
|
2010-12-15 20:15:24 +00:00
|
|
|
LoadGerberFiles( wxEmptyString );
|
2007-09-25 15:10:01 +00:00
|
|
|
break;
|
|
|
|
|
2011-03-17 19:14:45 +00:00
|
|
|
case ID_GERBVIEW_ERASE_ALL:
|
2009-11-23 17:24:33 +00:00
|
|
|
Clear_Pcb( true );
|
|
|
|
Zoom_Automatique( false );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->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:
|
2011-03-16 20:51:20 +00:00
|
|
|
LoadExcellonFiles( wxEmptyString );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->Refresh();
|
2007-09-25 15:10:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ID_GERBVIEW_LOAD_DCODE_FILE:
|
2011-03-13 18:03:43 +00:00
|
|
|
LoadDCodeFile( wxEmptyString );
|
2011-12-22 13:28:11 +00:00
|
|
|
m_canvas->Refresh();
|
2007-09-25 15:10:01 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2011-03-13 18:03:43 +00:00
|
|
|
wxFAIL_MSG( wxT( "File_io: unexpected command id" ) );
|
2007-09-25 15:10:01 +00:00
|
|
|
break;
|
|
|
|
}
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-12 09:50:21 +00:00
|
|
|
bool GERBVIEW_FRAME::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
|
|
|
|
2011-03-02 15:24:39 +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
|
|
|
|
2011-03-02 15:24:39 +00:00
|
|
|
dlg.GetPaths( filenamesList );
|
2010-12-15 20:15:24 +00:00
|
|
|
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
|
|
|
|
2011-09-30 18:15:37 +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();
|
2011-01-20 16:34:57 +00:00
|
|
|
|
2010-12-15 20:15:24 +00:00
|
|
|
for( unsigned ii = 0; ii < filenamesList.GetCount(); ii++ )
|
|
|
|
{
|
|
|
|
wxFileName filename = filenamesList[ii];
|
2011-03-02 15:24:39 +00:00
|
|
|
|
|
|
|
if( !filename.IsAbsolute() )
|
|
|
|
filename.SetPath( currentPath );
|
|
|
|
|
2011-01-20 16:34:57 +00:00
|
|
|
GetScreen()->SetFileName( filename.GetFullPath() );
|
2010-12-15 20:15:24 +00:00
|
|
|
|
2010-12-17 20:34:29 +00:00
|
|
|
setActiveLayer( layer, false );
|
2011-01-20 16:34:57 +00:00
|
|
|
|
2011-03-02 15:24:39 +00:00
|
|
|
if( Read_GERBER_File( filename.GetFullPath(), filename.GetFullPath() ) )
|
2010-12-15 20:15:24 +00:00
|
|
|
{
|
2011-03-17 19:14:45 +00:00
|
|
|
UpdateFileHistory( GetScreen()->GetFileName() );
|
2011-03-02 15:24:39 +00:00
|
|
|
|
|
|
|
layer = getNextAvailableLayer( layer );
|
|
|
|
|
|
|
|
if( layer == NO_AVAILABLE_LAYERS )
|
|
|
|
{
|
|
|
|
wxString msg = wxT( "No more empty layers are available. The remaining gerber " );
|
|
|
|
msg += wxT( "files will not be loaded." );
|
|
|
|
wxMessageBox( msg );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
setActiveLayer( layer, false );
|
2010-12-15 20:15:24 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-25 15:10:01 +00:00
|
|
|
|
2011-03-01 18:45:21 +00:00
|
|
|
Zoom_Automatique( false );
|
2007-09-25 15:10:01 +00:00
|
|
|
|
2010-12-17 20:34:29 +00:00
|
|
|
// Synchronize layers tools with actual active layer:
|
2011-03-02 15:24:39 +00:00
|
|
|
setActiveLayer( getActiveLayer() );
|
2011-04-05 17:49:14 +00:00
|
|
|
m_LayersManager->UpdateLayerIcons();
|
2011-03-16 20:51:20 +00:00
|
|
|
syncLayerBox();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GERBVIEW_FRAME::LoadExcellonFiles( const wxString& aFullFileName )
|
|
|
|
{
|
|
|
|
wxString filetypes;
|
|
|
|
wxArrayString filenamesList;
|
|
|
|
wxFileName filename = aFullFileName;
|
|
|
|
wxString currentPath;
|
|
|
|
|
|
|
|
if( !filename.IsOk() )
|
|
|
|
{
|
2012-02-16 20:03:33 +00:00
|
|
|
filetypes = wxGetTranslation( DrillFileWildcard );
|
2011-03-16 20:51:20 +00:00
|
|
|
filetypes << wxT("|");
|
|
|
|
/* All filetypes */
|
2012-02-16 20:03:33 +00:00
|
|
|
filetypes += wxGetTranslation( AllFilesWildcard );
|
2011-03-16 20:51:20 +00:00
|
|
|
|
|
|
|
/* Use the current working directory if the file name path does not exist. */
|
|
|
|
if( filename.DirExists() )
|
|
|
|
currentPath = filename.GetPath();
|
|
|
|
else
|
|
|
|
currentPath = wxGetCwd();
|
|
|
|
|
|
|
|
wxFileDialog dlg( this,
|
|
|
|
_( "Open Drill File" ),
|
|
|
|
currentPath,
|
|
|
|
filename.GetFullName(),
|
|
|
|
filetypes,
|
|
|
|
wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE | wxFD_CHANGE_DIR );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
dlg.GetPaths( filenamesList );
|
|
|
|
currentPath = wxGetCwd();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxFileName filename = aFullFileName;
|
|
|
|
filenamesList.Add( aFullFileName );
|
|
|
|
currentPath = filename.GetPath();
|
|
|
|
}
|
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
// Read gerber files: each file is loaded on a new GerbView layer
|
2011-03-16 20:51:20 +00:00
|
|
|
int layer = getActiveLayer();
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < filenamesList.GetCount(); ii++ )
|
|
|
|
{
|
|
|
|
wxFileName filename = filenamesList[ii];
|
|
|
|
|
|
|
|
if( !filename.IsAbsolute() )
|
|
|
|
filename.SetPath( currentPath );
|
|
|
|
|
|
|
|
GetScreen()->SetFileName( filename.GetFullPath() );
|
|
|
|
|
|
|
|
setActiveLayer( layer, false );
|
|
|
|
|
|
|
|
if( Read_EXCELLON_File( filename.GetFullPath() ) )
|
|
|
|
{
|
2011-03-17 19:14:45 +00:00
|
|
|
// Update the list of recentdrill files.
|
|
|
|
UpdateFileHistory( filename.GetFullPath(), &m_drillFileHistory );
|
|
|
|
|
2011-03-16 20:51:20 +00:00
|
|
|
layer = getNextAvailableLayer( layer );
|
|
|
|
|
|
|
|
if( layer == NO_AVAILABLE_LAYERS )
|
|
|
|
{
|
|
|
|
wxString msg = wxT( "No more empty layers are available. The remaining gerber " );
|
|
|
|
msg += wxT( "files will not be loaded." );
|
|
|
|
wxMessageBox( msg );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
setActiveLayer( layer, false );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Zoom_Automatique( false );
|
|
|
|
|
|
|
|
// Synchronize layers tools with actual active layer:
|
|
|
|
setActiveLayer( getActiveLayer() );
|
2011-04-05 17:49:14 +00:00
|
|
|
m_LayersManager->UpdateLayerIcons();
|
2010-12-17 20:34:29 +00:00
|
|
|
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
|
|
|
|
2011-03-13 18:03:43 +00:00
|
|
|
bool GERBVIEW_FRAME::LoadDCodeFile( const wxString& aFullFileName )
|
2007-05-06 16:03:28 +00:00
|
|
|
{
|
2009-11-09 14:00:22 +00:00
|
|
|
wxString wildcard;
|
2011-03-13 18:03:43 +00:00
|
|
|
wxFileName fn = aFullFileName;
|
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
|
|
|
{
|
2011-03-12 09:50:21 +00:00
|
|
|
wildcard = _( "Gerber DCODE files" );
|
2011-03-13 18:03:43 +00:00
|
|
|
wildcard += wxT(" ") + AllFilesWildcard;
|
|
|
|
fn = GetScreen()->GetFileName();
|
|
|
|
wxFileDialog dlg( this, _( "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 )
|
2011-03-13 18:03:43 +00:00
|
|
|
return false;
|
2009-04-05 20:49:15 +00:00
|
|
|
|
|
|
|
fn = dlg.GetPath();
|
2007-09-25 15:10:01 +00:00
|
|
|
}
|
|
|
|
|
2011-03-13 18:03:43 +00:00
|
|
|
ReadDCodeDefinitionFile( fn.GetFullPath() );
|
|
|
|
CopyDCodesSizeToItems();
|
|
|
|
return true;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|