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.
|
|
|
|
*
|
2017-01-26 17:15:46 +00:00
|
|
|
* Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
|
|
|
|
* Copyright (C) 2004-2017 KiCad Developers, see AUTHORS.txt for contributors.
|
2012-02-16 20:03:33 +00:00
|
|
|
*
|
|
|
|
* 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>
|
2017-01-26 09:45:28 +00:00
|
|
|
#include <wx/fs_zip.h>
|
|
|
|
#include <wx/wfstream.h>
|
|
|
|
#include <wx/zipstrm.h>
|
|
|
|
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <common.h>
|
|
|
|
#include <class_drawpanel.h>
|
2017-01-26 09:45:28 +00:00
|
|
|
#include <reporter.h>
|
2017-01-26 12:16:49 +00:00
|
|
|
#include <html_messagebox.h>
|
2009-02-04 15:25:03 +00:00
|
|
|
|
2014-06-27 17:07:42 +00:00
|
|
|
#include <gerbview_frame.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <gerbview_id.h>
|
2017-03-31 08:55:13 +00:00
|
|
|
#include <class_gerber_file_image.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#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
|
|
|
|
2017-01-26 17:15:46 +00:00
|
|
|
// HTML Messages used more than one time:
|
|
|
|
#define MSG_NO_MORE_LAYER\
|
|
|
|
_( "<b>No more available free graphic layer</b> in Gerbview to load files" )
|
|
|
|
#define MSG_NOT_LOADED _( "\n<b>Not loaded:</b> <i>%s</i>" )
|
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
|
|
|
{
|
2014-07-14 18:59:41 +00:00
|
|
|
Erase_Current_DrawLayer( 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() )
|
|
|
|
{
|
2014-07-14 18:59:41 +00:00
|
|
|
Erase_Current_DrawLayer( false );
|
2011-03-17 19:14:45 +00:00
|
|
|
LoadExcellonFiles( fn );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-19 16:28:11 +00:00
|
|
|
|
2017-01-26 09:45:28 +00:00
|
|
|
void GERBVIEW_FRAME::OnZipFileHistory( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
wxString filename;
|
|
|
|
filename = GetFileFromHistory( event.GetId(), _( "Zip files" ), &m_zipFileHistory );
|
|
|
|
|
|
|
|
if( !filename.IsEmpty() )
|
|
|
|
{
|
|
|
|
Erase_Current_DrawLayer( false );
|
|
|
|
LoadZipArchiveFile( filename );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-09-25 15:10:01 +00:00
|
|
|
|
2017-08-19 16:28:11 +00:00
|
|
|
void GERBVIEW_FRAME::OnJobFileHistory( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
wxString filename;
|
|
|
|
filename = GetFileFromHistory( event.GetId(), _( "Job files" ), &m_jobFileHistory );
|
|
|
|
|
|
|
|
if( !filename.IsEmpty() )
|
|
|
|
{
|
|
|
|
LoadGerberJobFile( filename );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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:
|
2014-07-14 18:59:41 +00:00
|
|
|
Erase_Current_DrawLayer( 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:
|
2014-12-03 16:22:06 +00:00
|
|
|
Clear_DrawLayers( false );
|
2009-11-23 17:24:33 +00:00
|
|
|
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;
|
|
|
|
|
2017-01-26 09:45:28 +00:00
|
|
|
case ID_GERBVIEW_LOAD_ZIP_ARCHIVE_FILE:
|
|
|
|
LoadZipArchiveFile( wxEmptyString );
|
|
|
|
m_canvas->Refresh();
|
|
|
|
break;
|
|
|
|
|
2017-08-19 16:28:11 +00:00
|
|
|
case ID_GERBVIEW_LOAD_JOB_FILE:
|
|
|
|
LoadGerberJobFile( wxEmptyString );
|
|
|
|
m_canvas->Refresh();
|
|
|
|
break;
|
|
|
|
|
2007-09-25 15:10:01 +00:00
|
|
|
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)
|
2014-06-30 10:00:21 +00:00
|
|
|
* the .gbr (.pho in legacy files) 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
|
2015-09-25 19:38:09 +00:00
|
|
|
* (Mainly internal copper layers do not have specific extension,
|
2010-10-17 16:42:06 +00:00
|
|
|
* and filenames are like *.g1, *.g2 *.gb1 ...).
|
2016-09-07 08:28:16 +00:00
|
|
|
* Now (2014) Ucamco (the company which manages the Gerber format) encourages
|
2014-06-30 10:00:21 +00:00
|
|
|
* use of .gbr only and the Gerber X2 file format.
|
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("|");
|
2014-06-30 10:00:21 +00:00
|
|
|
filetypes += wxT("*.g*;*.G*;*.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|" );
|
|
|
|
|
2016-09-07 08:28:16 +00:00
|
|
|
// All filetypes
|
2009-11-09 14:00:22 +00:00
|
|
|
filetypes += AllFilesWildcard;
|
|
|
|
|
2016-09-07 08:28:16 +00:00
|
|
|
// Use the current working directory if the file name path does not exist.
|
2010-05-17 20:35:46 +00:00
|
|
|
if( filename.DirExists() )
|
2010-12-15 20:15:24 +00:00
|
|
|
currentPath = filename.GetPath();
|
|
|
|
else
|
2016-09-07 08:28:16 +00:00
|
|
|
{
|
2015-09-25 19:38:09 +00:00
|
|
|
currentPath = m_mruPath;
|
2009-05-28 20:46:16 +00:00
|
|
|
|
2016-09-07 08:28:16 +00:00
|
|
|
// On wxWidgets 3.1 (bug?) the path in wxFileDialog is ignored when
|
|
|
|
// finishing by the dir separator. Remove it if any:
|
|
|
|
if( currentPath.EndsWith( '\\' ) || currentPath.EndsWith( '/' ) )
|
|
|
|
currentPath.RemoveLast();
|
|
|
|
}
|
|
|
|
|
|
|
|
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 );
|
2015-09-25 19:38:09 +00:00
|
|
|
|
|
|
|
// @todo Take a closer look at the CWD switching here. The current working directory
|
|
|
|
// gets changed by wxFileDialog because the wxFD_CHANGE_DIR flag is set. Is this the
|
|
|
|
// appropriate behavior? The current working directory is not returned to the previous
|
|
|
|
// value so this may be an issue elsewhere.
|
2010-12-15 20:15:24 +00:00
|
|
|
currentPath = wxGetCwd();
|
2015-09-25 19:38:09 +00:00
|
|
|
m_mruPath = currentPath;
|
2010-12-15 20:15:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
filenamesList.Add( aFullFileName );
|
|
|
|
currentPath = filename.GetPath();
|
2015-09-25 19:38:09 +00:00
|
|
|
m_mruPath = currentPath;
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2007-09-25 15:10:01 +00:00
|
|
|
|
2017-09-25 01:12:58 +00:00
|
|
|
// Set the busy cursor
|
|
|
|
wxBusyCursor wait;
|
|
|
|
|
2011-09-30 18:15:37 +00:00
|
|
|
// Read gerber files: each file is loaded on a new GerbView layer
|
2017-01-26 12:16:49 +00:00
|
|
|
bool success = true;
|
2017-09-17 22:43:20 +00:00
|
|
|
int layer = GetActiveLayer();
|
2011-01-20 16:34:57 +00:00
|
|
|
|
2017-01-26 12:16:49 +00:00
|
|
|
// Manage errors when loading files
|
|
|
|
wxString msg;
|
|
|
|
WX_STRING_REPORTER reporter( &msg );
|
|
|
|
|
2010-12-15 20:15:24 +00:00
|
|
|
for( unsigned ii = 0; ii < filenamesList.GetCount(); ii++ )
|
|
|
|
{
|
2016-04-29 11:10:31 +00:00
|
|
|
filename = filenamesList[ii];
|
2011-03-02 15:24:39 +00:00
|
|
|
|
|
|
|
if( !filename.IsAbsolute() )
|
|
|
|
filename.SetPath( currentPath );
|
|
|
|
|
2012-08-29 16:59:50 +00:00
|
|
|
m_lastFileName = filename.GetFullPath();
|
2010-12-15 20:15:24 +00:00
|
|
|
|
2017-09-17 22:43:20 +00:00
|
|
|
SetActiveLayer( layer, false );
|
2011-01-20 16:34:57 +00:00
|
|
|
|
2016-05-25 09:45:55 +00:00
|
|
|
if( Read_GERBER_File( filename.GetFullPath() ) )
|
2010-12-15 20:15:24 +00:00
|
|
|
{
|
2012-08-29 16:59:50 +00:00
|
|
|
UpdateFileHistory( m_lastFileName );
|
2011-03-02 15:24:39 +00:00
|
|
|
|
|
|
|
layer = getNextAvailableLayer( layer );
|
|
|
|
|
2017-01-26 12:16:49 +00:00
|
|
|
if( layer == NO_AVAILABLE_LAYERS && ii < filenamesList.GetCount()-1 )
|
2011-03-02 15:24:39 +00:00
|
|
|
{
|
2017-01-26 12:16:49 +00:00
|
|
|
success = false;
|
2017-01-26 17:15:46 +00:00
|
|
|
reporter.Report( MSG_NO_MORE_LAYER, REPORTER::RPT_ERROR );
|
2017-01-26 12:16:49 +00:00
|
|
|
|
|
|
|
// Report the name of not loaded files:
|
|
|
|
ii += 1;
|
|
|
|
while( ii < filenamesList.GetCount() )
|
|
|
|
{
|
|
|
|
filename = filenamesList[ii++];
|
|
|
|
wxString txt;
|
2017-01-26 17:15:46 +00:00
|
|
|
txt.Printf( MSG_NOT_LOADED,
|
2017-01-26 12:16:49 +00:00
|
|
|
GetChars( filename.GetFullName() ) );
|
|
|
|
reporter.Report( txt, REPORTER::RPT_ERROR );
|
|
|
|
}
|
2011-03-02 15:24:39 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-09-17 22:43:20 +00:00
|
|
|
SetActiveLayer( layer, false );
|
2010-12-15 20:15:24 +00:00
|
|
|
}
|
|
|
|
}
|
2007-09-25 15:10:01 +00:00
|
|
|
|
2017-01-26 12:16:49 +00:00
|
|
|
if( !success )
|
|
|
|
{
|
|
|
|
HTML_MESSAGE_BOX mbox( this, _( "Errors" ) );
|
|
|
|
mbox.ListSet( msg );
|
|
|
|
mbox.ShowModal();
|
|
|
|
}
|
|
|
|
|
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:
|
2014-11-22 11:52:57 +00:00
|
|
|
ReFillLayerWidget();
|
2017-09-17 22:43:20 +00:00
|
|
|
SetActiveLayer( GetActiveLayer() );
|
2011-04-05 17:49:14 +00:00
|
|
|
m_LayersManager->UpdateLayerIcons();
|
2011-03-16 20:51:20 +00:00
|
|
|
syncLayerBox();
|
2017-01-26 12:16:49 +00:00
|
|
|
return success;
|
2011-03-16 20:51:20 +00:00
|
|
|
}
|
|
|
|
|
2015-09-25 19:38:09 +00:00
|
|
|
|
2011-03-16 20:51:20 +00:00
|
|
|
bool GERBVIEW_FRAME::LoadExcellonFiles( const wxString& aFullFileName )
|
|
|
|
{
|
|
|
|
wxString filetypes;
|
|
|
|
wxArrayString filenamesList;
|
|
|
|
wxFileName filename = aFullFileName;
|
|
|
|
wxString currentPath;
|
|
|
|
|
|
|
|
if( !filename.IsOk() )
|
|
|
|
{
|
2017-11-12 00:31:38 +00:00
|
|
|
filetypes = DrillFileWildcard();
|
|
|
|
filetypes << wxT( "|" );
|
|
|
|
|
2011-03-16 20:51:20 +00:00
|
|
|
/* 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
|
2015-09-25 19:38:09 +00:00
|
|
|
currentPath = m_mruPath;
|
2011-03-16 20:51:20 +00:00
|
|
|
|
2017-01-26 17:15:46 +00:00
|
|
|
wxFileDialog dlg( this, _( "Open Drill File" ),
|
|
|
|
currentPath, filename.GetFullName(), filetypes,
|
2011-03-16 20:51:20 +00:00
|
|
|
wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE | wxFD_CHANGE_DIR );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
dlg.GetPaths( filenamesList );
|
|
|
|
currentPath = wxGetCwd();
|
2015-09-25 19:38:09 +00:00
|
|
|
m_mruPath = currentPath;
|
2011-03-16 20:51:20 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
filenamesList.Add( aFullFileName );
|
|
|
|
currentPath = filename.GetPath();
|
2015-09-25 19:38:09 +00:00
|
|
|
m_mruPath = currentPath;
|
2011-03-16 20:51:20 +00:00
|
|
|
}
|
|
|
|
|
2017-01-26 12:16:49 +00:00
|
|
|
// Read Excellon drill files: each file is loaded on a new GerbView layer
|
|
|
|
bool success = true;
|
2017-09-17 22:43:20 +00:00
|
|
|
int layer = GetActiveLayer();
|
2011-03-16 20:51:20 +00:00
|
|
|
|
2017-01-26 12:16:49 +00:00
|
|
|
// Manage errors when loading files
|
|
|
|
wxString msg;
|
|
|
|
WX_STRING_REPORTER reporter( &msg );
|
|
|
|
|
2011-03-16 20:51:20 +00:00
|
|
|
for( unsigned ii = 0; ii < filenamesList.GetCount(); ii++ )
|
|
|
|
{
|
2016-04-29 11:10:31 +00:00
|
|
|
filename = filenamesList[ii];
|
2011-03-16 20:51:20 +00:00
|
|
|
|
|
|
|
if( !filename.IsAbsolute() )
|
|
|
|
filename.SetPath( currentPath );
|
|
|
|
|
2012-08-29 16:59:50 +00:00
|
|
|
m_lastFileName = filename.GetFullPath();
|
2011-03-16 20:51:20 +00:00
|
|
|
|
2017-09-17 22:43:20 +00:00
|
|
|
SetActiveLayer( layer, false );
|
2011-03-16 20:51:20 +00:00
|
|
|
|
|
|
|
if( Read_EXCELLON_File( filename.GetFullPath() ) )
|
|
|
|
{
|
2015-09-25 19:38:09 +00:00
|
|
|
// Update the list of recent drill files.
|
2011-03-17 19:14:45 +00:00
|
|
|
UpdateFileHistory( filename.GetFullPath(), &m_drillFileHistory );
|
|
|
|
|
2011-03-16 20:51:20 +00:00
|
|
|
layer = getNextAvailableLayer( layer );
|
|
|
|
|
2017-01-26 12:16:49 +00:00
|
|
|
if( layer == NO_AVAILABLE_LAYERS && ii < filenamesList.GetCount()-1 )
|
2011-03-16 20:51:20 +00:00
|
|
|
{
|
2017-01-26 12:16:49 +00:00
|
|
|
success = false;
|
2017-01-26 17:15:46 +00:00
|
|
|
reporter.Report( MSG_NO_MORE_LAYER, REPORTER::RPT_ERROR );
|
2017-01-26 12:16:49 +00:00
|
|
|
|
|
|
|
// Report the name of not loaded files:
|
|
|
|
ii += 1;
|
|
|
|
while( ii < filenamesList.GetCount() )
|
|
|
|
{
|
|
|
|
filename = filenamesList[ii++];
|
|
|
|
wxString txt;
|
2017-01-26 17:15:46 +00:00
|
|
|
txt.Printf( MSG_NOT_LOADED,
|
2017-01-26 12:16:49 +00:00
|
|
|
GetChars( filename.GetFullName() ) );
|
|
|
|
reporter.Report( txt, REPORTER::RPT_ERROR );
|
|
|
|
}
|
2011-03-16 20:51:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-09-17 22:43:20 +00:00
|
|
|
SetActiveLayer( layer, false );
|
2011-03-16 20:51:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-26 12:16:49 +00:00
|
|
|
if( !success )
|
|
|
|
{
|
|
|
|
HTML_MESSAGE_BOX mbox( this, _( "Errors" ) );
|
|
|
|
mbox.ListSet( msg );
|
|
|
|
mbox.ShowModal();
|
|
|
|
}
|
|
|
|
|
2011-03-16 20:51:20 +00:00
|
|
|
Zoom_Automatique( false );
|
|
|
|
|
|
|
|
// Synchronize layers tools with actual active layer:
|
2014-11-22 11:52:57 +00:00
|
|
|
ReFillLayerWidget();
|
2017-09-17 22:43:20 +00:00
|
|
|
SetActiveLayer( GetActiveLayer() );
|
2011-04-05 17:49:14 +00:00
|
|
|
m_LayersManager->UpdateLayerIcons();
|
2010-12-17 20:34:29 +00:00
|
|
|
syncLayerBox();
|
|
|
|
|
2017-01-26 12:16:49 +00:00
|
|
|
return success;
|
2007-05-06 16:03:28 +00:00
|
|
|
}
|
2017-01-26 09:45:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool GERBVIEW_FRAME::unarchiveFiles( const wxString& aFullFileName, REPORTER* aReporter )
|
|
|
|
{
|
2017-03-31 08:55:13 +00:00
|
|
|
wxString msg;
|
2017-01-26 09:45:28 +00:00
|
|
|
|
2017-03-31 08:55:13 +00:00
|
|
|
// Extract the path of aFullFileName. We use it to store temporary files
|
2017-01-26 09:45:28 +00:00
|
|
|
wxFileName fn( aFullFileName );
|
|
|
|
wxString unzipDir = fn.GetPath();
|
|
|
|
|
2017-03-31 08:55:13 +00:00
|
|
|
wxFFileInputStream zipFile( aFullFileName );
|
2017-01-26 09:45:28 +00:00
|
|
|
|
2017-03-31 08:55:13 +00:00
|
|
|
if( !zipFile.IsOk() )
|
2017-01-26 09:45:28 +00:00
|
|
|
{
|
2017-03-31 08:55:13 +00:00
|
|
|
if( aReporter )
|
2017-01-26 09:45:28 +00:00
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Zip file \"%s\" cannot be opened" ), GetChars( aFullFileName ) );
|
2017-03-31 08:55:13 +00:00
|
|
|
aReporter->Report( msg, REPORTER::RPT_ERROR );
|
2017-01-26 09:45:28 +00:00
|
|
|
}
|
|
|
|
|
2017-03-31 08:55:13 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-01-26 09:45:28 +00:00
|
|
|
|
2017-03-31 08:55:13 +00:00
|
|
|
// Update the list of recent zip files.
|
|
|
|
UpdateFileHistory( aFullFileName, &m_zipFileHistory );
|
2017-01-26 09:45:28 +00:00
|
|
|
|
2017-03-31 08:55:13 +00:00
|
|
|
// The unzipped file in only a temporary file. Give it a filename
|
|
|
|
// which cannot conflict with an usual filename.
|
|
|
|
// TODO: make Read_GERBER_File() and Read_EXCELLON_File() able to
|
|
|
|
// accept a stream, and avoid using a temp file.
|
|
|
|
wxFileName temp_fn( "$tempfile.tmp" );
|
|
|
|
temp_fn.MakeAbsolute( unzipDir );
|
|
|
|
wxString unzipped_tempfile = temp_fn.GetFullPath();
|
2017-01-26 09:45:28 +00:00
|
|
|
|
|
|
|
|
2017-03-31 08:55:13 +00:00
|
|
|
bool success = true;
|
|
|
|
wxZipInputStream zipArchive( zipFile );
|
|
|
|
wxZipEntry* entry;
|
|
|
|
bool reported_no_more_layer = false;
|
|
|
|
|
|
|
|
while( ( entry = zipArchive.GetNextEntry() ) )
|
|
|
|
{
|
|
|
|
wxString fname = entry->GetName();
|
|
|
|
wxFileName uzfn = fname;
|
|
|
|
wxString curr_ext = uzfn.GetExt().Lower();
|
2017-01-26 09:45:28 +00:00
|
|
|
|
2017-01-26 17:15:46 +00:00
|
|
|
// The archive contains Gerber and/or Excellon drill files. Use the right loader.
|
|
|
|
// However it can contain a few other files (reports, pdf files...),
|
|
|
|
// which will be skipped.
|
|
|
|
// Gerber files ext is usually "gbr", but can be also an other value, starting by "g"
|
2017-01-26 10:36:01 +00:00
|
|
|
// old gerber files ext from kicad is .pho
|
2017-01-26 09:45:28 +00:00
|
|
|
// drill files do not have a well defined ext
|
2017-01-26 17:15:46 +00:00
|
|
|
// It is .drl in kicad, but .txt in Altium for instance
|
|
|
|
// Allows only .drl for drill files.
|
2017-03-31 08:55:13 +00:00
|
|
|
if( curr_ext[0] != 'g' && curr_ext != "pho" && curr_ext != "drl" )
|
2017-01-26 09:45:28 +00:00
|
|
|
{
|
|
|
|
if( aReporter )
|
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "Info: skip file <i>\"%s\"</i> (unknown type)\n" ),
|
2017-03-31 08:55:13 +00:00
|
|
|
GetChars( entry->GetName() ) );
|
2017-01-26 17:15:46 +00:00
|
|
|
aReporter->Report( msg, REPORTER::RPT_WARNING );
|
2017-01-26 09:45:28 +00:00
|
|
|
}
|
2017-03-31 08:55:13 +00:00
|
|
|
|
|
|
|
continue;
|
2017-01-26 09:45:28 +00:00
|
|
|
}
|
|
|
|
|
2017-09-17 22:43:20 +00:00
|
|
|
int layer = GetActiveLayer();
|
2017-01-26 09:45:28 +00:00
|
|
|
|
2017-03-31 08:55:13 +00:00
|
|
|
if( layer == NO_AVAILABLE_LAYERS )
|
2017-01-26 17:15:46 +00:00
|
|
|
{
|
|
|
|
success = false;
|
|
|
|
|
|
|
|
if( aReporter )
|
|
|
|
{
|
2017-03-31 08:55:13 +00:00
|
|
|
if( !reported_no_more_layer )
|
|
|
|
aReporter->Report( MSG_NO_MORE_LAYER, REPORTER::RPT_ERROR );
|
|
|
|
|
|
|
|
reported_no_more_layer = true;
|
|
|
|
|
|
|
|
// Report the name of not loaded files:
|
|
|
|
msg.Printf( MSG_NOT_LOADED, GetChars( entry->GetName() ) );
|
2017-01-26 17:15:46 +00:00
|
|
|
aReporter->Report( msg, REPORTER::RPT_ERROR );
|
|
|
|
}
|
|
|
|
|
2017-03-31 08:55:13 +00:00
|
|
|
delete entry;
|
|
|
|
continue;
|
|
|
|
}
|
2017-01-26 09:45:28 +00:00
|
|
|
|
2017-03-31 08:55:13 +00:00
|
|
|
// Create the unzipped temporary file:
|
2017-01-26 09:45:28 +00:00
|
|
|
{
|
2017-03-31 08:55:13 +00:00
|
|
|
wxFFileOutputStream temporary_ofile( unzipped_tempfile );
|
|
|
|
|
|
|
|
if( temporary_ofile.Ok() )
|
|
|
|
temporary_ofile.Write( zipArchive );
|
|
|
|
else
|
2017-01-26 09:45:28 +00:00
|
|
|
{
|
2017-03-31 08:55:13 +00:00
|
|
|
success = false;
|
2017-01-26 10:36:01 +00:00
|
|
|
|
2017-03-31 08:55:13 +00:00
|
|
|
if( aReporter )
|
2017-01-26 10:36:01 +00:00
|
|
|
{
|
2017-12-15 11:37:46 +00:00
|
|
|
msg.Printf( _( "<b>Unable to create temporary file \"%s\"</b>\n"),
|
2017-03-31 08:55:13 +00:00
|
|
|
GetChars( unzipped_tempfile ) );
|
|
|
|
aReporter->Report( msg, REPORTER::RPT_ERROR );
|
2017-01-26 10:36:01 +00:00
|
|
|
}
|
2017-01-26 09:45:28 +00:00
|
|
|
}
|
2017-03-31 08:55:13 +00:00
|
|
|
}
|
2017-01-26 09:45:28 +00:00
|
|
|
|
2017-03-31 08:55:13 +00:00
|
|
|
bool read_ok = true;
|
|
|
|
|
|
|
|
if( curr_ext[0] == 'g' || curr_ext == "pho" )
|
|
|
|
{
|
|
|
|
// Read gerber files: each file is loaded on a new GerbView layer
|
|
|
|
read_ok = Read_GERBER_File( unzipped_tempfile );
|
|
|
|
}
|
|
|
|
else // if( curr_ext == "drl" )
|
|
|
|
{
|
|
|
|
read_ok = Read_EXCELLON_File( unzipped_tempfile );
|
|
|
|
}
|
|
|
|
|
|
|
|
delete entry;
|
|
|
|
|
|
|
|
// The unzipped file is only a temporary file, delete it.
|
|
|
|
wxRemoveFile( unzipped_tempfile );
|
|
|
|
|
|
|
|
if( !read_ok )
|
|
|
|
{
|
|
|
|
success = false;
|
|
|
|
|
|
|
|
if( aReporter )
|
|
|
|
{
|
|
|
|
msg.Printf( _("<b>unzipped file %s read error</b>\n"),
|
|
|
|
GetChars( unzipped_tempfile ) );
|
|
|
|
aReporter->Report( msg, REPORTER::RPT_ERROR );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GERBER_FILE_IMAGE* gerber_image = GetGbrImage( layer );
|
2017-05-29 18:47:21 +00:00
|
|
|
|
|
|
|
if( gerber_image )
|
|
|
|
gerber_image->m_FileName = fname;
|
2017-03-31 08:55:13 +00:00
|
|
|
|
|
|
|
layer = getNextAvailableLayer( layer );
|
2017-09-17 22:43:20 +00:00
|
|
|
SetActiveLayer( layer, false );
|
2017-01-26 17:15:46 +00:00
|
|
|
}
|
2017-01-26 09:45:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool GERBVIEW_FRAME::LoadZipArchiveFile( const wxString& aFullFileName )
|
|
|
|
{
|
|
|
|
#define ZipFileExtension "zip"
|
2017-11-12 00:31:38 +00:00
|
|
|
|
2017-01-26 09:45:28 +00:00
|
|
|
wxFileName filename = aFullFileName;
|
|
|
|
wxString currentPath;
|
|
|
|
|
|
|
|
if( !filename.IsOk() )
|
|
|
|
{
|
|
|
|
// Use the current working directory if the file name path does not exist.
|
|
|
|
if( filename.DirExists() )
|
|
|
|
currentPath = filename.GetPath();
|
|
|
|
else
|
|
|
|
currentPath = m_mruPath;
|
|
|
|
|
|
|
|
wxFileDialog dlg( this,
|
|
|
|
_( "Open Zip File" ),
|
|
|
|
currentPath,
|
|
|
|
filename.GetFullName(),
|
2017-11-12 00:31:38 +00:00
|
|
|
ZipFileWildcard(),
|
2017-01-26 09:45:28 +00:00
|
|
|
wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
filename = dlg.GetPath();
|
|
|
|
currentPath = wxGetCwd();
|
|
|
|
m_mruPath = currentPath;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
currentPath = filename.GetPath();
|
|
|
|
m_mruPath = currentPath;
|
|
|
|
}
|
|
|
|
|
2017-01-26 17:15:46 +00:00
|
|
|
wxString msg;
|
|
|
|
WX_STRING_REPORTER reporter( &msg );
|
2017-01-26 09:45:28 +00:00
|
|
|
|
2017-01-26 17:15:46 +00:00
|
|
|
if( filename.IsOk() )
|
|
|
|
unarchiveFiles( filename.GetFullPath(), &reporter );
|
2017-01-26 09:45:28 +00:00
|
|
|
|
|
|
|
Zoom_Automatique( false );
|
|
|
|
|
|
|
|
// Synchronize layers tools with actual active layer:
|
|
|
|
ReFillLayerWidget();
|
2017-09-17 22:43:20 +00:00
|
|
|
SetActiveLayer( GetActiveLayer() );
|
2017-01-26 09:45:28 +00:00
|
|
|
m_LayersManager->UpdateLayerIcons();
|
|
|
|
syncLayerBox();
|
|
|
|
|
2017-01-26 17:15:46 +00:00
|
|
|
if( !msg.IsEmpty() )
|
|
|
|
{
|
|
|
|
wxSafeYield(); // Allows slice of time to redraw the screen
|
|
|
|
// to refresh widgets, before displaying messages
|
|
|
|
HTML_MESSAGE_BOX mbox( this, _( "Messages" ) );
|
|
|
|
mbox.ListSet( msg );
|
|
|
|
mbox.ShowModal();
|
|
|
|
}
|
|
|
|
|
2017-01-26 09:45:28 +00:00
|
|
|
return true;
|
|
|
|
}
|