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
|
2019-04-01 16:46:11 +00:00
|
|
|
* Copyright (C) 2004-2019 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>
|
2017-01-26 09:45:28 +00:00
|
|
|
#include <reporter.h>
|
2017-01-26 12:16:49 +00:00
|
|
|
#include <html_messagebox.h>
|
2014-06-27 17:07:42 +00:00
|
|
|
#include <gerbview_frame.h>
|
2012-01-23 04:33:36 +00:00
|
|
|
#include <gerbview_id.h>
|
2018-01-29 12:26:58 +00:00
|
|
|
#include <gerber_file_image.h>
|
2018-02-21 02:58:53 +00:00
|
|
|
#include <gerber_file_image_list.h>
|
2018-11-26 11:49:13 +00:00
|
|
|
#include <excellon_image.h>
|
2018-01-29 12:26:58 +00:00
|
|
|
#include <gerbview_layer_widget.h>
|
2012-02-16 20:03:33 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2018-02-21 02:58:53 +00:00
|
|
|
#include <widgets/progress_reporter.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
|
|
|
|
2019-04-10 13:40:01 +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 )
|
|
|
|
{
|
2019-04-10 13:40:01 +00:00
|
|
|
wxString filename = GetFileFromHistory( event.GetId(), _( "Job files" ), &m_jobFileHistory );
|
2017-08-19 16:28:11 +00:00
|
|
|
|
|
|
|
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:
|
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 );
|
2019-05-30 12:25:08 +00:00
|
|
|
GetGalCanvas()->Refresh();
|
2010-10-17 16:42:06 +00:00
|
|
|
ClearMsgPanel();
|
2007-09-25 15:10:01 +00:00
|
|
|
break;
|
|
|
|
|
2018-10-08 09:51:13 +00:00
|
|
|
case ID_GERBVIEW_RELOAD_ALL:
|
|
|
|
{
|
|
|
|
// Store filenames
|
2018-11-26 11:49:13 +00:00
|
|
|
wxArrayString listOfGerberFiles;
|
|
|
|
std::vector<int> fileType;
|
|
|
|
|
2018-10-08 09:51:13 +00:00
|
|
|
for( unsigned i = 0; i < GetImagesList()->ImagesMaxCount(); i++ )
|
|
|
|
{
|
2018-11-26 11:49:13 +00:00
|
|
|
if( GetImagesList()->GetGbrImage( i ) == nullptr )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if( !GetImagesList()->GetGbrImage( i )->m_InUse )
|
|
|
|
continue;
|
|
|
|
|
2019-04-10 13:40:01 +00:00
|
|
|
auto* drill_file = dynamic_cast<EXCELLON_IMAGE*>( GetImagesList()->GetGbrImage( i ) );
|
2018-11-26 11:49:13 +00:00
|
|
|
|
|
|
|
if( drill_file )
|
|
|
|
fileType.push_back( 1 );
|
|
|
|
else
|
|
|
|
fileType.push_back( 0 );
|
|
|
|
|
|
|
|
listOfGerberFiles.Add( GetImagesList()->GetGbrImage( i )->m_FileName );
|
2018-10-08 09:51:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Clear all layers
|
|
|
|
Clear_DrawLayers( false );
|
|
|
|
Zoom_Automatique( false );
|
2019-05-30 12:25:08 +00:00
|
|
|
GetGalCanvas()->Refresh();
|
2018-10-08 09:51:13 +00:00
|
|
|
ClearMsgPanel();
|
|
|
|
|
|
|
|
// Load the layers from stored paths
|
|
|
|
wxBusyCursor wait;
|
2018-11-26 11:49:13 +00:00
|
|
|
loadListOfGerberAndDrillFiles( wxEmptyString, listOfGerberFiles, &fileType );
|
2018-10-08 09:51:13 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2007-09-25 15:10:01 +00:00
|
|
|
case ID_GERBVIEW_LOAD_DRILL_FILE:
|
2011-03-16 20:51:20 +00:00
|
|
|
LoadExcellonFiles( wxEmptyString );
|
2019-05-30 12:25:08 +00:00
|
|
|
GetGalCanvas()->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 );
|
2019-05-30 12:25:08 +00:00
|
|
|
GetGalCanvas()->Refresh();
|
2017-01-26 09:45:28 +00:00
|
|
|
break;
|
|
|
|
|
2017-08-19 16:28:11 +00:00
|
|
|
case ID_GERBVIEW_LOAD_JOB_FILE:
|
|
|
|
LoadGerberJobFile( wxEmptyString );
|
2019-05-30 12:25:08 +00:00
|
|
|
GetGalCanvas()->Refresh();
|
2017-08-19 16:28:11 +00:00
|
|
|
break;
|
|
|
|
|
2007-09-25 15:10:01 +00:00
|
|
|
default:
|
2018-12-07 10:25:30 +00:00
|
|
|
wxFAIL_MSG( "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
|
|
|
{
|
2019-04-01 16:46:11 +00:00
|
|
|
static int lastGerberFileWildcard = 0;
|
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
|
2019-01-08 11:57:39 +00:00
|
|
|
filetypes += AllFilesWildcard();
|
2009-11-09 14:00:22 +00:00
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2018-02-27 22:30:50 +00:00
|
|
|
wxFileDialog dlg( this, _( "Open Gerber File(s)" ),
|
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 );
|
2019-04-01 16:46:11 +00:00
|
|
|
dlg.SetFilterIndex( lastGerberFileWildcard );
|
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
|
|
|
|
2019-04-01 16:46:11 +00:00
|
|
|
lastGerberFileWildcard = dlg.GetFilterIndex();
|
2011-03-02 15:24:39 +00:00
|
|
|
dlg.GetPaths( filenamesList );
|
2018-02-19 13:48:05 +00:00
|
|
|
m_mruPath = currentPath = dlg.GetDirectory();
|
2010-12-15 20:15:24 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
filenamesList.Add( aFullFileName );
|
2018-02-19 13:48:05 +00:00
|
|
|
m_mruPath = currentPath = filename.GetPath();
|
2009-04-05 20:49:15 +00:00
|
|
|
}
|
2007-09-25 15:10:01 +00:00
|
|
|
|
2018-02-28 01:59:47 +00:00
|
|
|
Erase_Current_DrawLayer( false );
|
|
|
|
|
2017-09-25 01:12:58 +00:00
|
|
|
// Set the busy cursor
|
|
|
|
wxBusyCursor wait;
|
|
|
|
|
2018-11-26 11:49:13 +00:00
|
|
|
return loadListOfGerberAndDrillFiles( currentPath, filenamesList );
|
2018-02-21 02:58:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-26 11:49:13 +00:00
|
|
|
bool GERBVIEW_FRAME::loadListOfGerberAndDrillFiles( const wxString& aPath,
|
|
|
|
const wxArrayString& aFilenameList,
|
|
|
|
const std::vector<int>* aFileType )
|
2018-02-21 02:58:53 +00:00
|
|
|
{
|
|
|
|
wxFileName filename;
|
|
|
|
|
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();
|
2019-04-10 13:40:01 +00:00
|
|
|
LSET visibility = GetVisibleLayers();
|
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 );
|
|
|
|
|
2018-02-21 02:58:53 +00:00
|
|
|
// Show progress dialog after 1 second of loading
|
|
|
|
static const long long progressShowDelay = 1000;
|
|
|
|
|
|
|
|
auto startTime = wxGetUTCTimeMillis();
|
|
|
|
std::unique_ptr<WX_PROGRESS_REPORTER> progress = nullptr;
|
|
|
|
|
|
|
|
for( unsigned ii = 0; ii < aFilenameList.GetCount(); ii++ )
|
2010-12-15 20:15:24 +00:00
|
|
|
{
|
2019-03-24 16:32:57 +00:00
|
|
|
filename = aFilenameList[ii];
|
|
|
|
|
|
|
|
if( !filename.IsAbsolute() )
|
|
|
|
filename.SetPath( aPath );
|
|
|
|
|
|
|
|
// Check for non existing files, to avoid creating broken or useless data
|
|
|
|
// and report all in one error list:
|
|
|
|
if( !filename.FileExists() )
|
|
|
|
{
|
|
|
|
wxString warning;
|
|
|
|
warning << "<b>" << _( "File not found:" ) << "</b><br>"
|
|
|
|
<< filename.GetFullPath() << "<br>";
|
|
|
|
reporter.Report( warning, REPORTER::RPT_WARNING );
|
|
|
|
success = false;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-02-21 02:58:53 +00:00
|
|
|
if( !progress && wxGetUTCTimeMillis() - startTime > progressShowDelay )
|
|
|
|
{
|
|
|
|
progress = std::make_unique<WX_PROGRESS_REPORTER>( this,
|
|
|
|
_( "Loading Gerber files..." ), 1, false );
|
|
|
|
progress->SetMaxProgress( aFilenameList.GetCount() - 1 );
|
|
|
|
progress->Report( _("Loading Gerber files..." ) );
|
|
|
|
}
|
|
|
|
else if( progress )
|
|
|
|
{
|
|
|
|
progress->KeepRefreshing();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2019-04-10 13:40:01 +00:00
|
|
|
visibility[ layer ] = true;
|
2018-02-28 02:33:41 +00:00
|
|
|
|
2018-11-26 11:49:13 +00:00
|
|
|
if( aFileType && (*aFileType)[ii] == 1 )
|
2010-12-15 20:15:24 +00:00
|
|
|
{
|
2018-11-26 11:49:13 +00:00
|
|
|
LoadExcellonFiles( filename.GetFullPath() );
|
|
|
|
layer = GetActiveLayer(); // Loading NC drill file changes the active layer
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( Read_GERBER_File( filename.GetFullPath() ) )
|
2011-03-02 15:24:39 +00:00
|
|
|
{
|
2018-11-26 11:49:13 +00:00
|
|
|
UpdateFileHistory( m_lastFileName );
|
2017-01-26 12:16:49 +00:00
|
|
|
|
2018-11-26 11:49:13 +00:00
|
|
|
layer = getNextAvailableLayer( layer );
|
|
|
|
|
|
|
|
if( layer == NO_AVAILABLE_LAYERS && ii < aFilenameList.GetCount()-1 )
|
2017-01-26 12:16:49 +00:00
|
|
|
{
|
2018-11-26 11:49:13 +00:00
|
|
|
success = false;
|
|
|
|
reporter.Report( MSG_NO_MORE_LAYER, REPORTER::RPT_ERROR );
|
|
|
|
|
|
|
|
// Report the name of not loaded files:
|
|
|
|
ii += 1;
|
|
|
|
while( ii < aFilenameList.GetCount() )
|
|
|
|
{
|
|
|
|
filename = aFilenameList[ii++];
|
2019-04-10 13:40:01 +00:00
|
|
|
wxString txt = wxString::Format( MSG_NOT_LOADED, filename.GetFullName() );
|
2018-11-26 11:49:13 +00:00
|
|
|
reporter.Report( txt, REPORTER::RPT_ERROR );
|
|
|
|
}
|
|
|
|
break;
|
2017-01-26 12:16:49 +00:00
|
|
|
}
|
2011-03-02 15:24:39 +00:00
|
|
|
|
2018-11-26 11:49:13 +00:00
|
|
|
SetActiveLayer( layer, false );
|
|
|
|
}
|
2010-12-15 20:15:24 +00:00
|
|
|
}
|
2018-02-21 02:58:53 +00:00
|
|
|
|
|
|
|
if( progress )
|
|
|
|
progress->AdvanceProgress();
|
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 )
|
|
|
|
{
|
2018-02-21 02:58:53 +00:00
|
|
|
wxSafeYield(); // Allows slice of time to redraw the screen
|
|
|
|
// to refresh widgets, before displaying messages
|
2017-01-26 12:16:49 +00:00
|
|
|
HTML_MESSAGE_BOX mbox( this, _( "Errors" ) );
|
|
|
|
mbox.ListSet( msg );
|
|
|
|
mbox.ShowModal();
|
|
|
|
}
|
|
|
|
|
2018-02-28 02:33:41 +00:00
|
|
|
SetVisibleLayers( visibility );
|
|
|
|
|
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();
|
2018-03-15 01:51:58 +00:00
|
|
|
|
|
|
|
// TODO: it would be nice if we could set the active layer to one of the
|
|
|
|
// ones that was just loaded, but to maintain the previous user experience
|
|
|
|
// we need to set it to a blank layer in case they load another file.
|
|
|
|
// We can't start with the next available layer when loading files because
|
|
|
|
// some users expect the behavior of overwriting the active layer on load.
|
|
|
|
SetActiveLayer( getNextAvailableLayer( layer ), true );
|
|
|
|
|
2011-04-05 17:49:14 +00:00
|
|
|
m_LayersManager->UpdateLayerIcons();
|
2018-02-21 02:58:53 +00:00
|
|
|
syncLayerBox( true );
|
|
|
|
|
2018-03-04 04:43:16 +00:00
|
|
|
GetGalCanvas()->Refresh();
|
|
|
|
|
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 */
|
2019-01-08 11:57:39 +00:00
|
|
|
filetypes += 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
|
|
|
|
2018-11-26 09:55:36 +00:00
|
|
|
wxFileDialog dlg( this, _( "Open NC (Excellon) Drill File(s)" ),
|
2017-01-26 17:15:46 +00:00
|
|
|
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.
|
2018-11-26 11:49:13 +00:00
|
|
|
UpdateFileHistory( filename.GetFullPath(), &m_drillFileHistory );
|
2011-03-17 19:14:45 +00:00
|
|
|
|
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++];
|
2019-04-10 13:40:01 +00:00
|
|
|
wxString txt = wxString::Format( MSG_NOT_LOADED, filename.GetFullName() );
|
2017-01-26 12:16:49 +00:00
|
|
|
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.
|
2018-04-08 10:28:59 +00:00
|
|
|
// Gerber files ext is usually "gbr", but can be also another 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;
|
|
|
|
}
|