Add progress reporting for GerbView file loading
This commit is contained in:
parent
fad0452c0e
commit
0c9d11c180
|
@ -100,7 +100,7 @@ bool PROGRESS_REPORTER::KeepRefreshing( bool aWait )
|
||||||
|
|
||||||
|
|
||||||
WX_PROGRESS_REPORTER::WX_PROGRESS_REPORTER( wxWindow* aParent, const wxString& aTitle,
|
WX_PROGRESS_REPORTER::WX_PROGRESS_REPORTER( wxWindow* aParent, const wxString& aTitle,
|
||||||
int aNumPhases ) :
|
int aNumPhases, bool aCanAbort ) :
|
||||||
PROGRESS_REPORTER( aNumPhases ),
|
PROGRESS_REPORTER( aNumPhases ),
|
||||||
wxProgressDialog( aTitle, wxT( "" ), 1, aParent,
|
wxProgressDialog( aTitle, wxT( "" ), 1, aParent,
|
||||||
// wxPD_APP_MODAL | // Don't use; messes up OSX when called from
|
// wxPD_APP_MODAL | // Don't use; messes up OSX when called from
|
||||||
|
@ -108,7 +108,7 @@ WX_PROGRESS_REPORTER::WX_PROGRESS_REPORTER( wxWindow* aParent, const wxString& a
|
||||||
wxPD_AUTO_HIDE | // *MUST* use; otherwise wxWidgets will spin
|
wxPD_AUTO_HIDE | // *MUST* use; otherwise wxWidgets will spin
|
||||||
// up another event loop on completion which
|
// up another event loop on completion which
|
||||||
// causes all sorts of grief
|
// causes all sorts of grief
|
||||||
wxPD_CAN_ABORT |
|
( aCanAbort ? wxPD_CAN_ABORT : 0 ) |
|
||||||
wxPD_ELAPSED_TIME )
|
wxPD_ELAPSED_TIME )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,8 +39,10 @@
|
||||||
#include <gerbview_frame.h>
|
#include <gerbview_frame.h>
|
||||||
#include <gerbview_id.h>
|
#include <gerbview_id.h>
|
||||||
#include <gerber_file_image.h>
|
#include <gerber_file_image.h>
|
||||||
|
#include <gerber_file_image_list.h>
|
||||||
#include <gerbview_layer_widget.h>
|
#include <gerbview_layer_widget.h>
|
||||||
#include <wildcards_and_files_ext.h>
|
#include <wildcards_and_files_ext.h>
|
||||||
|
#include <widgets/progress_reporter.h>
|
||||||
|
|
||||||
// HTML Messages used more than one time:
|
// HTML Messages used more than one time:
|
||||||
#define MSG_NO_MORE_LAYER\
|
#define MSG_NO_MORE_LAYER\
|
||||||
|
@ -216,6 +218,15 @@ bool GERBVIEW_FRAME::LoadGerberFiles( const wxString& aFullFileName )
|
||||||
// Set the busy cursor
|
// Set the busy cursor
|
||||||
wxBusyCursor wait;
|
wxBusyCursor wait;
|
||||||
|
|
||||||
|
return loadListOfGerberFiles( currentPath, filenamesList );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool GERBVIEW_FRAME::loadListOfGerberFiles( const wxString& aPath,
|
||||||
|
const wxArrayString& aFilenameList )
|
||||||
|
{
|
||||||
|
wxFileName filename;
|
||||||
|
|
||||||
// Read gerber files: each file is loaded on a new GerbView layer
|
// Read gerber files: each file is loaded on a new GerbView layer
|
||||||
bool success = true;
|
bool success = true;
|
||||||
int layer = GetActiveLayer();
|
int layer = GetActiveLayer();
|
||||||
|
@ -224,12 +235,30 @@ bool GERBVIEW_FRAME::LoadGerberFiles( const wxString& aFullFileName )
|
||||||
wxString msg;
|
wxString msg;
|
||||||
WX_STRING_REPORTER reporter( &msg );
|
WX_STRING_REPORTER reporter( &msg );
|
||||||
|
|
||||||
for( unsigned ii = 0; ii < filenamesList.GetCount(); ii++ )
|
// 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++ )
|
||||||
{
|
{
|
||||||
filename = filenamesList[ii];
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
filename = aFilenameList[ii];
|
||||||
|
|
||||||
if( !filename.IsAbsolute() )
|
if( !filename.IsAbsolute() )
|
||||||
filename.SetPath( currentPath );
|
filename.SetPath( aPath );
|
||||||
|
|
||||||
m_lastFileName = filename.GetFullPath();
|
m_lastFileName = filename.GetFullPath();
|
||||||
|
|
||||||
|
@ -241,16 +270,16 @@ bool GERBVIEW_FRAME::LoadGerberFiles( const wxString& aFullFileName )
|
||||||
|
|
||||||
layer = getNextAvailableLayer( layer );
|
layer = getNextAvailableLayer( layer );
|
||||||
|
|
||||||
if( layer == NO_AVAILABLE_LAYERS && ii < filenamesList.GetCount()-1 )
|
if( layer == NO_AVAILABLE_LAYERS && ii < aFilenameList.GetCount()-1 )
|
||||||
{
|
{
|
||||||
success = false;
|
success = false;
|
||||||
reporter.Report( MSG_NO_MORE_LAYER, REPORTER::RPT_ERROR );
|
reporter.Report( MSG_NO_MORE_LAYER, REPORTER::RPT_ERROR );
|
||||||
|
|
||||||
// Report the name of not loaded files:
|
// Report the name of not loaded files:
|
||||||
ii += 1;
|
ii += 1;
|
||||||
while( ii < filenamesList.GetCount() )
|
while( ii < aFilenameList.GetCount() )
|
||||||
{
|
{
|
||||||
filename = filenamesList[ii++];
|
filename = aFilenameList[ii++];
|
||||||
wxString txt;
|
wxString txt;
|
||||||
txt.Printf( MSG_NOT_LOADED,
|
txt.Printf( MSG_NOT_LOADED,
|
||||||
GetChars( filename.GetFullName() ) );
|
GetChars( filename.GetFullName() ) );
|
||||||
|
@ -261,10 +290,15 @@ bool GERBVIEW_FRAME::LoadGerberFiles( const wxString& aFullFileName )
|
||||||
|
|
||||||
SetActiveLayer( layer, false );
|
SetActiveLayer( layer, false );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if( progress )
|
||||||
|
progress->AdvanceProgress();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !success )
|
if( !success )
|
||||||
{
|
{
|
||||||
|
wxSafeYield(); // Allows slice of time to redraw the screen
|
||||||
|
// to refresh widgets, before displaying messages
|
||||||
HTML_MESSAGE_BOX mbox( this, _( "Errors" ) );
|
HTML_MESSAGE_BOX mbox( this, _( "Errors" ) );
|
||||||
mbox.ListSet( msg );
|
mbox.ListSet( msg );
|
||||||
mbox.ShowModal();
|
mbox.ShowModal();
|
||||||
|
@ -272,11 +306,14 @@ bool GERBVIEW_FRAME::LoadGerberFiles( const wxString& aFullFileName )
|
||||||
|
|
||||||
Zoom_Automatique( false );
|
Zoom_Automatique( false );
|
||||||
|
|
||||||
|
GetImagesList()->SortImagesByZOrder();
|
||||||
|
|
||||||
// Synchronize layers tools with actual active layer:
|
// Synchronize layers tools with actual active layer:
|
||||||
ReFillLayerWidget();
|
ReFillLayerWidget();
|
||||||
SetActiveLayer( GetActiveLayer() );
|
SetActiveLayer( GetActiveLayer() );
|
||||||
m_LayersManager->UpdateLayerIcons();
|
m_LayersManager->UpdateLayerIcons();
|
||||||
syncLayerBox();
|
syncLayerBox( true );
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -216,6 +216,15 @@ private:
|
||||||
/// Updates the GAL with display settings changes
|
/// Updates the GAL with display settings changes
|
||||||
void applyDisplaySettingsToGAL();
|
void applyDisplaySettingsToGAL();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loads a list of Gerber files and updates the view based on them
|
||||||
|
* @param aPath is the base path for the filenames if they are relative
|
||||||
|
* @param aFilenameList is a list of filenames to load
|
||||||
|
* @return true if every file loaded successfully
|
||||||
|
*/
|
||||||
|
bool loadListOfGerberFiles( const wxString& aPath,
|
||||||
|
const wxArrayString& aFilenameList );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent );
|
GERBVIEW_FRAME( KIWAY* aKiway, wxWindow* aParent );
|
||||||
~GERBVIEW_FRAME();
|
~GERBVIEW_FRAME();
|
||||||
|
|
|
@ -144,6 +144,7 @@ bool GERBVIEW_FRAME::LoadGerberJobFile( const wxString& aFullFileName )
|
||||||
{
|
{
|
||||||
wxFileName filename = aFullFileName;
|
wxFileName filename = aFullFileName;
|
||||||
wxString currentPath;
|
wxString currentPath;
|
||||||
|
bool success = true;
|
||||||
|
|
||||||
if( !filename.IsOk() )
|
if( !filename.IsOk() )
|
||||||
{
|
{
|
||||||
|
@ -189,41 +190,7 @@ bool GERBVIEW_FRAME::LoadGerberJobFile( const wxString& aFullFileName )
|
||||||
|
|
||||||
wxArrayString& gbrfiles = gbjReader.GetGerberFiles();
|
wxArrayString& gbrfiles = gbjReader.GetGerberFiles();
|
||||||
|
|
||||||
wxFileName gbr_fn = filename;
|
success = loadListOfGerberFiles( currentPath, gbrfiles );
|
||||||
bool read_ok;
|
|
||||||
int layer = 0;
|
|
||||||
SetActiveLayer( layer, false );
|
|
||||||
|
|
||||||
for( unsigned ii = 0; ii < gbrfiles.GetCount(); ii++ )
|
|
||||||
{
|
|
||||||
gbr_fn.SetFullName( gbrfiles[ii] );
|
|
||||||
|
|
||||||
if( gbr_fn.FileExists() )
|
|
||||||
{
|
|
||||||
//LoadGerberFiles( gbr_fn.GetFullPath() );
|
|
||||||
read_ok = Read_GERBER_File( gbr_fn.GetFullPath() );
|
|
||||||
|
|
||||||
if( read_ok )
|
|
||||||
{
|
|
||||||
layer = getNextAvailableLayer( layer );
|
|
||||||
SetActiveLayer( layer, false );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
read_ok = false;
|
|
||||||
|
|
||||||
if( !read_ok )
|
|
||||||
{
|
|
||||||
wxString err;
|
|
||||||
err.Printf( _( "Can't load Gerber file:<br><i>%s</i><br>" ), gbr_fn.GetFullPath() );
|
|
||||||
reporter.Report( err, REPORTER::RPT_WARNING );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
GetImagesList()->SortImagesByZOrder();
|
|
||||||
ReFillLayerWidget();
|
|
||||||
syncLayerBox( true );
|
|
||||||
GetCanvas()->Refresh();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,7 +205,7 @@ bool GERBVIEW_FRAME::LoadGerberJobFile( const wxString& aFullFileName )
|
||||||
mbox.ShowModal();
|
mbox.ShowModal();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -102,8 +102,10 @@ public:
|
||||||
* aNumPhases = 1 is the usual progress bar
|
* aNumPhases = 1 is the usual progress bar
|
||||||
* aNumPhases = n creates n virtual progress bar zones: a 0 to 100 percent width
|
* aNumPhases = n creates n virtual progress bar zones: a 0 to 100 percent width
|
||||||
* of a virtual zone fills 0 to 1/n progress bar full size of the nth virtual zone index
|
* of a virtual zone fills 0 to 1/n progress bar full size of the nth virtual zone index
|
||||||
|
* @param aCanAbort is true if the abort button should be shown
|
||||||
*/
|
*/
|
||||||
WX_PROGRESS_REPORTER( wxWindow* aParent, const wxString& aTitle, int aNumPhases );
|
WX_PROGRESS_REPORTER( wxWindow* aParent, const wxString& aTitle, int aNumPhases,
|
||||||
|
bool aCanAbort = true );
|
||||||
~WX_PROGRESS_REPORTER();
|
~WX_PROGRESS_REPORTER();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue