From eee20f9f6787413a2d9e75352b89d278e0d0432b Mon Sep 17 00:00:00 2001 From: Mike Williams Date: Mon, 16 Aug 2021 12:25:58 -0400 Subject: [PATCH] Gerbview: reduce redundant file loading code --- gerbview/files.cpp | 79 ++++++----------------------- gerbview/tools/gerbview_control.cpp | 2 - 2 files changed, 15 insertions(+), 66 deletions(-) diff --git a/gerbview/files.cpp b/gerbview/files.cpp index 57fa6e9fbc..81b7f26fc7 100644 --- a/gerbview/files.cpp +++ b/gerbview/files.cpp @@ -192,7 +192,9 @@ bool GERBVIEW_FRAME::LoadGerberFiles( const wxString& aFullFileName ) bool isFirstFile = GetImagesList()->GetLoadedImageCount() == 0; - bool success = LoadListOfGerberAndDrillFiles( currentPath, filenamesList ); + // 0 is gerber files + std::vector fileTypesVec( filenamesList.Count(), 0 ); + bool success = LoadListOfGerberAndDrillFiles( currentPath, filenamesList, &fileTypesVec ); // Auto zoom is only applied if there is only one file loaded if( isFirstFile ) @@ -259,8 +261,7 @@ bool GERBVIEW_FRAME::LoadListOfGerberAndDrillFiles( const wxString& aPath, if( !progress && ( aFilenameList.GetCount() > 1 ) ) { - progress = std::make_unique( this, - _( "Loading Gerber files..." ), 1, + progress = std::make_unique( this, _( "Loading files..." ), 1, false ); progress->SetMaxProgress( aFilenameList.GetCount() - 1 ); progress->Report( wxString::Format( _("Loading %u/%zu %s..." ), @@ -303,7 +304,7 @@ bool GERBVIEW_FRAME::LoadListOfGerberAndDrillFiles( const wxString& aPath, { if( aFileType && ( *aFileType )[ii] == 1 ) { - if( LoadExcellonFiles( filename.GetFullPath() ) ) + if( Read_EXCELLON_File( filename.GetFullPath() ) ) { UpdateFileHistory( filename.GetFullPath(), &m_drillFileHistory ); @@ -404,71 +405,21 @@ bool GERBVIEW_FRAME::LoadExcellonFiles( const wxString& aFullFileName ) m_mruPath = currentPath; } - // Read Excellon drill files: each file is loaded on a new GerbView layer - bool success = true; - int layer = GetActiveLayer(); + // Set the busy cursor + wxBusyCursor wait; - // Manage errors when loading files - wxString msg; - WX_STRING_REPORTER reporter( &msg ); + bool isFirstFile = GetImagesList()->GetLoadedImageCount() == 0; - for( unsigned ii = 0; ii < filenamesList.GetCount(); ii++ ) + // 1 is drill files + std::vector fileTypesVec( filenamesList.Count(), 1 ); + bool success = LoadListOfGerberAndDrillFiles( currentPath, filenamesList, &fileTypesVec ); + + // Auto zoom is only applied if there is only one file loaded + if( isFirstFile ) { - filename = filenamesList[ii]; - - if( !filename.IsAbsolute() ) - filename.SetPath( currentPath ); - - m_lastFileName = filename.GetFullPath(); - - layer = getNextAvailableLayer(); - - if( layer == NO_AVAILABLE_LAYERS ) - { - success = false; - reporter.Report( MSG_NO_MORE_LAYER, RPT_SEVERITY_ERROR ); - - // Report the name of not loaded files: - while( ii < filenamesList.GetCount() ) - { - filename = filenamesList[ii++]; - wxString txt = wxString::Format( MSG_NOT_LOADED, filename.GetFullName() ); - reporter.Report( txt, RPT_SEVERITY_ERROR ); - } - break; - } - else - { - SetActiveLayer( layer, false ); - - if( Read_EXCELLON_File( filename.GetFullPath() ) ) - { - // Update the list of recent drill files. - UpdateFileHistory( filename.GetFullPath(), &m_drillFileHistory ); - } - else - { - wxString txt = wxString::Format( MSG_NOT_LOADED, filename.GetFullName() ); - reporter.Report( txt, RPT_SEVERITY_ERROR ); - } - } + Zoom_Automatique( false ); } - if( !success ) - { - HTML_MESSAGE_BOX mbox( this, _( "Errors" ) ); - mbox.ListSet( msg ); - mbox.ShowModal(); - } - - Zoom_Automatique( false ); - - // Synchronize layers tools with actual active layer: - ReFillLayerWidget(); - SetActiveLayer( GetActiveLayer() ); - m_LayersManager->UpdateLayerIcons(); - syncLayerBox(); - return success; } diff --git a/gerbview/tools/gerbview_control.cpp b/gerbview/tools/gerbview_control.cpp index 77a0e66235..7f5764edae 100644 --- a/gerbview/tools/gerbview_control.cpp +++ b/gerbview/tools/gerbview_control.cpp @@ -54,7 +54,6 @@ void GERBVIEW_CONTROL::Reset( RESET_REASON aReason ) int GERBVIEW_CONTROL::OpenGerber( const TOOL_EVENT& aEvent ) { m_frame->LoadGerberFiles( wxEmptyString ); - // loadListOfGerberAndDrillFiles() refreshes the canvas return 0; } @@ -63,7 +62,6 @@ int GERBVIEW_CONTROL::OpenGerber( const TOOL_EVENT& aEvent ) int GERBVIEW_CONTROL::OpenDrillFile( const TOOL_EVENT& aEvent ) { m_frame->LoadExcellonFiles( wxEmptyString ); - canvas()->Refresh(); return 0; }