From db407a1c0be6311b1abe3a8dce575a82ceb85b87 Mon Sep 17 00:00:00 2001 From: Mike Williams Date: Mon, 16 Aug 2021 13:38:04 -0400 Subject: [PATCH] Gerbview: clean up loading files to prepare for more autodetection --- gerbview/files.cpp | 52 +++++++++++++++++++++++++----------- gerbview/gerbview_frame.h | 9 +++---- gerbview/job_file_reader.cpp | 4 ++- 3 files changed, 44 insertions(+), 21 deletions(-) diff --git a/gerbview/files.cpp b/gerbview/files.cpp index 81b7f26fc7..720eb78ee9 100644 --- a/gerbview/files.cpp +++ b/gerbview/files.cpp @@ -22,6 +22,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +#include #include #include #include @@ -206,10 +207,13 @@ bool GERBVIEW_FRAME::LoadGerberFiles( const wxString& aFullFileName ) } -bool GERBVIEW_FRAME::LoadListOfGerberAndDrillFiles( const wxString& aPath, - const wxArrayString& aFilenameList, - const std::vector* aFileType ) +bool GERBVIEW_FRAME::LoadListOfGerberAndDrillFiles( const wxString& aPath, + const wxArrayString& aFilenameList, + std::vector* aFileType ) { + wxCHECK_MSG( aFilenameList.Count() == aFileType->size(), false, + "Mismatch in file names and file types count" ); + wxFileName filename; // Read gerber files: each file is loaded on a new GerbView layer @@ -302,8 +306,33 @@ bool GERBVIEW_FRAME::LoadListOfGerberAndDrillFiles( const wxString& aPath, try { - if( aFileType && ( *aFileType )[ii] == 1 ) + // 2 = Autodetect + if( ( *aFileType )[ii] == 2 ) { + if( EXCELLON_IMAGE::TestFileIsExcellon( filename.GetFullPath() ) ) + ( *aFileType )[ii] = 1; + else if( GERBER_FILE_IMAGE::TestFileIsRS274( filename.GetFullPath() ) ) + ( *aFileType )[ii] = 0; + } + + switch( ( *aFileType )[ii] ) + { + case 0: + + if( Read_GERBER_File( filename.GetFullPath() ) ) + { + UpdateFileHistory( filename.GetFullPath() ); + + if( firstLoadedLayer == NO_AVAILABLE_LAYERS ) + { + firstLoadedLayer = layer; + } + } + + break; + + case 1: + if( Read_EXCELLON_File( filename.GetFullPath() ) ) { UpdateFileHistory( filename.GetFullPath(), &m_drillFileHistory ); @@ -314,18 +343,11 @@ bool GERBVIEW_FRAME::LoadListOfGerberAndDrillFiles( const wxString& aPath, firstLoadedLayer = layer; } } - } - else - { - if( Read_GERBER_File( filename.GetFullPath() ) ) - { - UpdateFileHistory( filename.GetFullPath() ); - if( firstLoadedLayer == NO_AVAILABLE_LAYERS ) - { - firstLoadedLayer = layer; - } - } + break; + default: + wxString txt = wxString::Format( MSG_NOT_LOADED, filename.GetFullName() ); + reporter.Report( txt, RPT_SEVERITY_ERROR ); } } catch( const std::bad_alloc& ) diff --git a/gerbview/gerbview_frame.h b/gerbview/gerbview_frame.h index 4734d11bfa..8cbbbce600 100644 --- a/gerbview/gerbview_frame.h +++ b/gerbview/gerbview_frame.h @@ -67,13 +67,12 @@ public: * * @param aPath is the base path for the filenames if they are relative * @param aFilenameList is a list of filenames to load - * @param aFileType is a list of type of files to load (0 = Gerber, 1 = NC drill) - * if nullptr, files are expected Gerber type. + * @param aFileType is a list of type of files to load (0 = Gerber, 1 = NC drill, 2 Autodetect) + * Successfully autodetected files will have their type changed * @return true if every file loaded successfully */ - bool LoadListOfGerberAndDrillFiles( const wxString& aPath, - const wxArrayString& aFilenameList, - const std::vector* aFileType = nullptr ); + bool LoadListOfGerberAndDrillFiles( const wxString& aPath, const wxArrayString& aFilenameList, + std::vector* aFileType ); // Virtual basic functions: void ReCreateHToolbar() override; diff --git a/gerbview/job_file_reader.cpp b/gerbview/job_file_reader.cpp index 2c2baafb0d..9575bf79cf 100644 --- a/gerbview/job_file_reader.cpp +++ b/gerbview/job_file_reader.cpp @@ -226,7 +226,9 @@ bool GERBVIEW_FRAME::LoadGerberJobFile( const wxString& aFullFileName ) wxArrayString& gbrfiles = gbjReader.GetGerberFiles(); - success = LoadListOfGerberAndDrillFiles( currentPath, gbrfiles ); + // 0 = Gerber file type + std::vector fileTypesVec( gbrfiles.Count(), 0 ); + success = LoadListOfGerberAndDrillFiles( currentPath, gbrfiles, &fileTypesVec ); Zoom_Automatique( false ); }