Move cvpcb DISPLAY_FOOTPRINTS_FRAME loading error handling to a reporter

This commit is contained in:
Ian McInerney 2020-06-04 00:34:42 +01:00
parent d46f9a5273
commit a074b32615
2 changed files with 21 additions and 22 deletions

View File

@ -39,6 +39,7 @@
#include <pcb_draw_panel_gal.h> #include <pcb_draw_panel_gal.h>
#include <pcb_painter.h> #include <pcb_painter.h>
#include <pgm_base.h> #include <pgm_base.h>
#include <reporter.h>
#include <settings/settings_manager.h> #include <settings/settings_manager.h>
#include <tool/action_toolbar.h> #include <tool/action_toolbar.h>
#include <tool/common_tools.h> #include <tool/common_tools.h>
@ -341,49 +342,40 @@ COLOR4D DISPLAY_FOOTPRINTS_FRAME::GetGridColor()
} }
MODULE* DISPLAY_FOOTPRINTS_FRAME::Get_Module( const wxString& aFootprintName ) MODULE* DISPLAY_FOOTPRINTS_FRAME::GetModule( const wxString& aFootprintName, REPORTER& aReporter )
{ {
MODULE* footprint = NULL; MODULE* footprint = NULL;
// Prep the infobar. The infobar is used for as many notifications as possible
// since it doesn't steal focus into the frame like a dialog does.
m_infoBar->Dismiss();
m_infoBar->RemoveAllButtons();
m_infoBar->AddCloseButton();
LIB_ID fpid; LIB_ID fpid;
if( fpid.Parse( aFootprintName, LIB_ID::ID_PCB ) >= 0 ) if( fpid.Parse( aFootprintName, LIB_ID::ID_PCB ) >= 0 )
{ {
wxString msg = wxString::Format( _( "Footprint ID \"%s\" is not valid." ), aReporter.Report( wxString::Format( _( "Footprint ID \"%s\" is not valid." ),
GetChars( aFootprintName ) ); aFootprintName ),
m_infoBar->ShowMessage( msg, wxICON_ERROR ); RPT_SEVERITY_ERROR );
return NULL; return NULL;
} }
wxString libNickname = FROM_UTF8( fpid.GetLibNickname().c_str() ); wxString libNickname = FROM_UTF8( fpid.GetLibNickname().c_str() );
wxString fpName = FROM_UTF8( fpid.GetLibItemName().c_str() ); wxString fpName = FROM_UTF8( fpid.GetLibItemName().c_str() );
wxLogDebug( wxT( "Load footprint \"%s\" from library \"%s\"." ), fpName, libNickname );
FP_LIB_TABLE* fpTable = Prj().PcbFootprintLibs( Kiway() ); FP_LIB_TABLE* fpTable = Prj().PcbFootprintLibs( Kiway() );
wxASSERT( fpTable ); wxASSERT( fpTable );
// See if the library requested is in the library table // See if the library requested is in the library table
if( !fpTable->HasLibrary( libNickname ) ) if( !fpTable->HasLibrary( libNickname ) )
{ {
wxString msg = wxString::Format( _( "Library \"%s\" is not in the footprint library table." ), aReporter.Report( wxString::Format( _( "Library \"%s\" is not in the footprint library table." ),
libNickname ); libNickname ),
m_infoBar->ShowMessage( msg, wxICON_ERROR ); RPT_SEVERITY_ERROR );
return NULL; return NULL;
} }
// See if the footprint requested is in the library // See if the footprint requested is in the library
if( !fpTable->FootprintExists( libNickname, fpName ) ) if( !fpTable->FootprintExists( libNickname, fpName ) )
{ {
wxString msg = wxString::Format( _( "Footprint \"%s\" not found." ), aFootprintName ); aReporter.Report( wxString::Format( _( "Footprint \"%s\" not found." ), aFootprintName ),
m_infoBar->ShowMessage( msg, wxICON_ERROR ); RPT_SEVERITY_ERROR );
return NULL; return NULL;
} }
@ -404,8 +396,8 @@ MODULE* DISPLAY_FOOTPRINTS_FRAME::Get_Module( const wxString& aFootprintName )
return footprint; return footprint;
} }
wxString msg = wxString::Format( _( "Footprint \"%s\" not found." ), aFootprintName ); aReporter.Report( wxString::Format( _( "Footprint \"%s\" not found." ), aFootprintName ),
m_infoBar->ShowMessage( msg, wxICON_ERROR ); RPT_SEVERITY_ERROR );
return NULL; return NULL;
} }
@ -429,11 +421,14 @@ void DISPLAY_FOOTPRINTS_FRAME::InitDisplay()
footprintName = comp->GetFPID().GetUniStringLibId(); footprintName = comp->GetFPID().GetUniStringLibId();
} }
INFOBAR_REPORTER infoReporter( m_infoBar );
m_infoBar->Dismiss();
if( !footprintName.IsEmpty() ) if( !footprintName.IsEmpty() )
{ {
SetTitle( wxString::Format( _( "Footprint: %s" ), footprintName ) ); SetTitle( wxString::Format( _( "Footprint: %s" ), footprintName ) );
module = Get_Module( footprintName ); module = GetModule( footprintName, infoReporter );
module_info = parentframe->m_FootprintsList->GetModuleInfo( footprintName ); module_info = parentframe->m_FootprintsList->GetModuleInfo( footprintName );
} }
@ -446,6 +441,8 @@ void DISPLAY_FOOTPRINTS_FRAME::InitDisplay()
else else
SetStatusText( wxEmptyString, 0 ); SetStatusText( wxEmptyString, 0 );
infoReporter.Finalize();
updateView(); updateView();
UpdateStatusBar(); UpdateStatusBar();

View File

@ -31,6 +31,8 @@
#include <pcb_base_frame.h> #include <pcb_base_frame.h>
#include <pcbnew_settings.h> #include <pcbnew_settings.h>
class REPORTER;
// The name (for wxWidgets) of the footprint viewer frame // The name (for wxWidgets) of the footprint viewer frame
#define FOOTPRINTVIEWER_FRAME_NAME wxT( "FootprintViewerFrame" ) #define FOOTPRINTVIEWER_FRAME_NAME wxT( "FootprintViewerFrame" )
@ -88,7 +90,7 @@ public:
*/ */
COLOR4D GetGridColor() override; COLOR4D GetGridColor() override;
MODULE* Get_Module( const wxString& CmpName ); MODULE* GetModule( const wxString& CmpName, REPORTER& aReporter );
/* SaveCopyInUndoList() virtual /* SaveCopyInUndoList() virtual
* currently: do nothing in CvPcb. * currently: do nothing in CvPcb.