Clean up error messages.

Convert a lot of nags to InfoBar errors/warnings/messages, and some
that never should have been exposed to wxFAIL_MSGs.
This commit is contained in:
Jeff Young 2020-08-31 14:19:57 +01:00
parent 35a1b8a353
commit 88635ee5b6
21 changed files with 64 additions and 48 deletions

View File

@ -45,6 +45,7 @@
#include <tool/tool_dispatcher.h> #include <tool/tool_dispatcher.h>
#include <trace_helpers.h> #include <trace_helpers.h>
#include <widgets/paged_dialog.h> #include <widgets/paged_dialog.h>
#include <widgets/infobar.h>
#include <wx/display.h> #include <wx/display.h>
#include <wx/stdpaths.h> #include <wx/stdpaths.h>
#include <wx/string.h> #include <wx/string.h>
@ -699,6 +700,24 @@ void EDA_BASE_FRAME::PrintMsg( const wxString& text )
} }
void EDA_BASE_FRAME::ShowInfoBarError( const wxString& aErrorMsg )
{
GetInfoBar()->ShowMessageFor( aErrorMsg, 5000, wxICON_ERROR );
}
void EDA_BASE_FRAME::ShowInfoBarWarning( const wxString& aWarningMsg )
{
GetInfoBar()->ShowMessageFor( aWarningMsg, 5000, wxICON_WARNING );
}
void EDA_BASE_FRAME::ShowInfoBarMsg( const wxString& aMsg )
{
GetInfoBar()->ShowMessageFor( aMsg, 10000, wxICON_INFORMATION );
}
void EDA_BASE_FRAME::UpdateFileHistory( const wxString& FullFileName, FILE_HISTORY* aFileHistory ) void EDA_BASE_FRAME::UpdateFileHistory( const wxString& FullFileName, FILE_HISTORY* aFileHistory )
{ {
if( !aFileHistory ) if( !aFileHistory )

View File

@ -111,7 +111,7 @@ void LIB_EDIT_FRAME::ExportPart()
if( !part ) if( !part )
{ {
DisplayError( this, _( "There is no symbol selected to save." ) ); ShowInfoBarError( _( "There is no symbol selected to save." ) );
return; return;
} }

View File

@ -79,7 +79,7 @@ wxString LIB_EDIT_FRAME::SelectLibraryFromList()
if( prj.SchSymbolLibTable()->IsEmpty() ) if( prj.SchSymbolLibTable()->IsEmpty() )
{ {
DisplayError( this, _( "No symbol libraries are loaded." ) ); ShowInfoBarError( _( "No symbol libraries are loaded." ) );
return wxEmptyString; return wxEmptyString;
} }
@ -481,7 +481,7 @@ void LIB_EDIT_FRAME::savePartAs()
if( new_name.IsEmpty() ) if( new_name.IsEmpty() )
{ {
DisplayError( this, _( "No symbol name specified. Symbol could not be saved." ) ); // This is effectively a cancel. No need to nag the user about it.
return; return;
} }
@ -796,7 +796,7 @@ bool LIB_EDIT_FRAME::saveLibrary( const wxString& aLibrary, bool aNewFile )
if( !aNewFile && ( aLibrary.empty() || !prj.SchSymbolLibTable()->HasLibrary( aLibrary ) ) ) if( !aNewFile && ( aLibrary.empty() || !prj.SchSymbolLibTable()->HasLibrary( aLibrary ) ) )
{ {
DisplayError( this, _( "No library specified." ) ); ShowInfoBarError( _( "No library specified." ) );
return false; return false;
} }

View File

@ -612,7 +612,7 @@ SCH_TEXT* SCH_DRAWING_TOOLS::createNewText( const VECTOR2I& aPosition, int aType
break; break;
default: default:
DisplayError( m_frame, wxT( "SCH_EDIT_FRAME::CreateNewText() Internal error" ) ); wxFAIL_MSG( "SCH_EDIT_FRAME::CreateNewText() unknown layer type" );
return nullptr; return nullptr;
} }

View File

@ -24,6 +24,7 @@
#include <class_library.h> #include <class_library.h>
#include <confirm.h> #include <confirm.h>
#include <widgets/infobar.h>
#include <connection_graph.h> #include <connection_graph.h>
#include <dialogs/dialog_fields_editor_global.h> #include <dialogs/dialog_fields_editor_global.h>
#include <dialogs/dialog_page_settings.h> #include <dialogs/dialog_page_settings.h>
@ -916,7 +917,7 @@ int SCH_EDITOR_CONTROL::AssignNetclass( const TOOL_EVENT& aEvent )
if( conn->Name( true ).IsEmpty() ) if( conn->Name( true ).IsEmpty() )
{ {
DisplayError( m_frame, _( "Net must be labelled to assign a netclass." ) ); m_frame->ShowInfoBarError( _( "Net must be labelled to assign a netclass." ) );
highlightNet( m_toolMgr, CLEAR ); highlightNet( m_toolMgr, CLEAR );
return 0; return 0;
} }

View File

@ -261,8 +261,8 @@ bool GERBVIEW_FRAME::Read_EXCELLON_File( const wxString& aFullFileName )
if( !success ) if( !success )
{ {
delete drill_layer; delete drill_layer;
msg.Printf( _( "File %s not found" ), aFullFileName ); msg.Printf( _( "File %s not found." ), aFullFileName );
DisplayError( this, msg ); ShowInfoBarError( msg );
return false; return false;
} }
@ -271,7 +271,7 @@ bool GERBVIEW_FRAME::Read_EXCELLON_File( const wxString& aFullFileName )
if( layerId < 0 ) if( layerId < 0 )
{ {
delete drill_layer; delete drill_layer;
DisplayError( this, _( "No room to load file" ) ); ShowInfoBarError( _( "No empty layers to load file into." ) );
return false; return false;
} }

View File

@ -257,7 +257,7 @@ bool GBR_TO_PCB_EXPORTER::ExportPcb( LAYER_NUM* aLayerLookUpTable, int aCopperLa
if( m_fp == NULL ) if( m_fp == NULL )
{ {
wxString msg; wxString msg;
msg.Printf( _( "Cannot create file \"%s\"" ), GetChars( m_pcb_file_name ) ); msg.Printf( _( "Cannot create file \"%s\"" ), m_pcb_file_name );
DisplayError( m_gerbview_frame, msg ); DisplayError( m_gerbview_frame, msg );
return false; return false;
} }

View File

@ -60,7 +60,7 @@ bool GERBVIEW_FRAME::Read_GERBER_File( const wxString& GERBER_FullFileName )
{ {
delete gerber; delete gerber;
msg.Printf( _( "File \"%s\" not found" ), GERBER_FullFileName ); msg.Printf( _( "File \"%s\" not found" ), GERBER_FullFileName );
DisplayError( this, msg, 10 ); ShowInfoBarError( msg );
return false; return false;
} }

View File

@ -343,6 +343,10 @@ public:
WX_INFOBAR* GetInfoBar() { return m_infoBar; } WX_INFOBAR* GetInfoBar() { return m_infoBar; }
void ShowInfoBarError( const wxString& aErrorMsg );
void ShowInfoBarWarning( const wxString& aWarningMsg );
void ShowInfoBarMsg( const wxString& aMsg );
/** /**
* Returns the settings object used in SaveSettings(), and is overloaded in * Returns the settings object used in SaveSettings(), and is overloaded in
* KICAD_MANAGER_FRAME * KICAD_MANAGER_FRAME

View File

@ -77,7 +77,7 @@ void PCB_EDIT_FRAME::RecreateBOMFileFromBoard( wxCommandEvent& aEvent )
if( GetBoard()->Modules().empty() ) if( GetBoard()->Modules().empty() )
{ {
DisplayError( this, _( "Cannot export BOM: there are no footprints in the PCB" ) ); ShowInfoBarError( _( "Cannot export BOM: there are no footprints on the PCB." ) );
return; return;
} }

View File

@ -1000,7 +1000,7 @@ void MODULE::RunOnChildren( const std::function<void (BOARD_ITEM*)>& aFunction )
} }
catch( std::bad_function_call& ) catch( std::bad_function_call& )
{ {
DisplayError( NULL, wxT( "Error running MODULE::RunOnChildren" ) ); wxFAIL_MSG( "Error running MODULE::RunOnChildren" );
} }
} }

View File

@ -294,7 +294,7 @@ void PCB_GROUP::RunOnChildren( const std::function<void( BOARD_ITEM* )>& aFuncti
} }
catch( std::bad_function_call& ) catch( std::bad_function_call& )
{ {
DisplayError( NULL, wxT( "Error running PCB_GROUP::RunOnChildren" ) ); wxFAIL_MSG( "Error running PCB_GROUP::RunOnChildren" );
} }
} }
@ -312,6 +312,6 @@ void PCB_GROUP::RunOnDescendants( const std::function<void( BOARD_ITEM* )>& aFun
} }
catch( std::bad_function_call& ) catch( std::bad_function_call& )
{ {
DisplayError( NULL, wxT( "Error running PCB_GROUP::RunOnDescendants" ) ); wxFAIL_MSG( "Error running PCB_GROUP::RunOnDescendants" );
} }
} }

View File

@ -299,7 +299,7 @@ void DIALOG_FIND::search( bool aDirection )
else else
{ {
m_frame->SetStatusText( wxEmptyString ); m_frame->SetStatusText( wxEmptyString );
DisplayError( this, _( "No more item to show" ), 10 ); m_frame->ShowInfoBarMsg( _( "No more item to show" ) );
return; return;
} }
} }
@ -315,7 +315,7 @@ void DIALOG_FIND::search( bool aDirection )
else else
{ {
m_frame->SetStatusText( wxEmptyString ); m_frame->SetStatusText( wxEmptyString );
DisplayError( this, _( "No more item to show" ), 10 ); m_frame->ShowInfoBarMsg( _( "No more item to show" ) );
return; return;
} }
} }
@ -342,7 +342,7 @@ void DIALOG_FIND::search( bool aDirection )
m_frame->SetStatusText( wxEmptyString ); m_frame->SetStatusText( wxEmptyString );
msg.Printf( _( "\"%s\" not found" ), searchString ); msg.Printf( _( "\"%s\" not found" ), searchString );
DisplayError( this, msg, 10 ); m_frame->ShowInfoBarMsg( msg );
m_status->SetLabel( _( "No hits" ) ); m_status->SetLabel( _( "No hits" ) );
} }

View File

@ -154,7 +154,7 @@ bool DIALOG_KEEPOUT_AREA_PROPERTIES::TransferDataFromWindow()
! m_zonesettings.GetDoNotAllowFootprints() && ! m_zonesettings.GetDoNotAllowFootprints() &&
! m_zonesettings.GetDoNotAllowCopperPour() ) ! m_zonesettings.GetDoNotAllowCopperPour() )
{ {
DisplayError( NULL, _("Tracks, vias, and pads are allowed. The keepout will have no effect." ) ); DisplayError( NULL, _("No items are disallowed. The keepout will have no effect." ) );
return false; return false;
} }

View File

@ -1745,7 +1745,7 @@ bool DIALOG_PAD_PROPERTIES::transferDataToPad( D_PAD* aPad )
break; break;
default: default:
DisplayError( NULL, wxT( "Error: unknown pad type" ) ); wxFAIL_MSG( "DIALOG_PAD_PROPERTIES::transferDataToPad: unknown pad type" );
break; break;
} }

View File

@ -1252,7 +1252,8 @@ static void FootprintWriteShape( FILE* aFile, MODULE* module, const wxString& aS
break; break;
default: default:
DisplayError( NULL, wxString::Format( "Type Edge Module %d invalid.", PtStruct->Type() ) ); wxFAIL_MSG( wxString::Format( "Type Edge Module %d invalid.",
PtStruct->Type() ) );
break; break;
} }
} }

View File

@ -435,9 +435,8 @@ wxString PCB_BASE_EDIT_FRAME::CreateNewLibrary( const wxString& aLibName,
{ {
if( !writable ) if( !writable )
{ {
wxString msg = wxString::Format( _( "Library \"%s\" is read only, not writable" ), wxString msg = wxString::Format( _( "Library \"%s\" is read only." ), libPath );
libPath ); ShowInfoBarError( msg );
DisplayError( this, msg );
return wxEmptyString; return wxEmptyString;
} }
else else
@ -586,8 +585,8 @@ bool FOOTPRINT_EDIT_FRAME::DeleteModuleFromLibrary( const LIB_ID& aFPID, bool aC
if( !Prj().PcbFootprintLibs()->IsFootprintLibWritable( nickname ) ) if( !Prj().PcbFootprintLibs()->IsFootprintLibWritable( nickname ) )
{ {
wxString msg = wxString::Format( _( "Library '%s' is read only" ), nickname ); wxString msg = wxString::Format( _( "Library '%s' is read only." ), nickname );
DisplayError( this, msg ); ShowInfoBarError( msg );
return false; return false;
} }
@ -779,7 +778,7 @@ bool FOOTPRINT_EDIT_FRAME::SaveFootprintToBoard( bool aAddNew )
if( pcbframe == NULL ) // happens when the board editor is not active (or closed) if( pcbframe == NULL ) // happens when the board editor is not active (or closed)
{ {
DisplayErrorMessage( this, _( "No board currently open." ) ); ShowInfoBarError( _( "No board currently open." ) );
return false; return false;
} }

View File

@ -310,7 +310,7 @@ void MICROWAVE_TOOL::createInductorBetween( const VECTOR2I& aStart, const VECTOR
if ( !inductorModule || !errorMessage.IsEmpty() ) if ( !inductorModule || !errorMessage.IsEmpty() )
{ {
if ( !errorMessage.IsEmpty() ) if ( !errorMessage.IsEmpty() )
DisplayError( &editFrame, errorMessage ); editFrame.ShowInfoBarError( errorMessage );
} }
else else
{ {

View File

@ -266,13 +266,13 @@ MODULE* MICROWAVE_TOOL::createPolygonShape()
if( ( ShapeSize.x ) == 0 || ( ShapeSize.y == 0 ) ) if( ( ShapeSize.x ) == 0 || ( ShapeSize.y == 0 ) )
{ {
DisplayError( &editFrame, _( "Shape has a null size!" ) ); editFrame.ShowInfoBarError( _( "Shape has a null size!" ) );
return NULL; return NULL;
} }
if( PolyEdges.size() == 0 ) if( PolyEdges.size() == 0 )
{ {
DisplayError( &editFrame, _( "Shape has no points!" ) ); editFrame.ShowInfoBarError( _( "Shape has no points!" ) );
return NULL; return NULL;
} }

View File

@ -728,22 +728,22 @@ int ROUTER_TOOL::onViaCommand( const TOOL_EVENT& aEvent )
// Cannot place microvias or blind vias if not allowed (obvious) // Cannot place microvias or blind vias if not allowed (obvious)
if( ( viaType == VIATYPE::BLIND_BURIED ) && ( !bds.m_BlindBuriedViaAllowed ) ) if( ( viaType == VIATYPE::BLIND_BURIED ) && ( !bds.m_BlindBuriedViaAllowed ) )
{ {
DisplayError( frame(), frame()->ShowInfoBarError( _( "Blind/buried vias have to be enabled in "
_( "Blind/buried vias have to be enabled in Board Setup > Design Rules > Constraints." ) ); "Board Setup > Design Rules > Constraints." ) );
return false; return false;
} }
if( ( viaType == VIATYPE::MICROVIA ) && ( !bds.m_MicroViasAllowed ) ) if( ( viaType == VIATYPE::MICROVIA ) && ( !bds.m_MicroViasAllowed ) )
{ {
DisplayError( frame(), frame()->ShowInfoBarError( _( "Microvias have to be enabled in "
_( "Microvias have to be enabled in Board Setup > Design Rules > Constraints." ) ); "Board Setup > Design Rules > Constraints." ) );
return false; return false;
} }
// Can only place through vias on 2-layer boards // Can only place through vias on 2-layer boards
if( ( viaType != VIATYPE::THROUGH ) && ( layerCount <= 2 ) ) if( ( viaType != VIATYPE::THROUGH ) && ( layerCount <= 2 ) )
{ {
DisplayError( frame(), _( "Only through vias are allowed on 2 layer boards." ) ); frame()->ShowInfoBarError( _( "Only through vias are allowed on 2 layer boards." ) );
return false; return false;
} }
@ -751,8 +751,8 @@ int ROUTER_TOOL::onViaCommand( const TOOL_EVENT& aEvent )
if( ( viaType == VIATYPE::MICROVIA ) && ( currentLayer > In1_Cu ) if( ( viaType == VIATYPE::MICROVIA ) && ( currentLayer > In1_Cu )
&& ( currentLayer < layerCount - 2 ) ) && ( currentLayer < layerCount - 2 ) )
{ {
DisplayError( frame(), _( "Microvias can be placed only between the outer layers " frame()->ShowInfoBarError( _( "Microvias can only be placed between the outer layers "
"(F.Cu/B.Cu) and the ones directly adjacent to them." ) ); "(F.Cu/B.Cu) and the ones directly adjacent to them." ) );
return false; return false;
} }
} }
@ -860,7 +860,7 @@ bool ROUTER_TOOL::prepareInteractive()
if( !IsCopperLayer( routingLayer ) ) if( !IsCopperLayer( routingLayer ) )
{ {
DisplayError( frame(), _( "Tracks on Copper layers only" ) ); frame()->ShowInfoBarError( _( "Tracks on Copper layers only" ) );
return false; return false;
} }

View File

@ -59,16 +59,8 @@ using P_S_C = PCB_SELECTION_CONDITIONS;
bool CONVERT_TOOL::Init() bool CONVERT_TOOL::Init()
{ {
m_selectionTool = m_selectionTool = m_toolMgr->GetTool<SELECTION_TOOL>();
static_cast<SELECTION_TOOL*>( m_toolMgr->FindTool( "pcbnew.InteractiveSelection" ) ); m_frame = getEditFrame<PCB_BASE_FRAME>();
if( !m_selectionTool )
{
DisplayError( NULL, wxT( "pcbnew.InteractiveSelection tool is not available" ) );
return false;
}
m_frame = getEditFrame<PCB_BASE_FRAME>();
// Create a context menu and make it available through selection tool // Create a context menu and make it available through selection tool
m_menu = new CONDITIONAL_MENU( this ); m_menu = new CONDITIONAL_MENU( this );