Generalize infobar MESSAGE_TYPE handling and use for DRC errors.

Fixes https://gitlab.com/kicad/code/kicad/issues/8782
This commit is contained in:
Jeff Young 2021-08-01 21:51:08 +01:00
parent d40712d9d6
commit c51b1dad72
9 changed files with 40 additions and 40 deletions

View File

@ -847,14 +847,15 @@ void EDA_BASE_FRAME::FinishAUIInitialization()
}
void EDA_BASE_FRAME::ShowInfoBarError( const wxString& aErrorMsg, bool aShowCloseButton )
void EDA_BASE_FRAME::ShowInfoBarError( const wxString& aErrorMsg, bool aShowCloseButton,
WX_INFOBAR::MESSAGE_TYPE aType )
{
m_infoBar->RemoveAllButtons();
if( aShowCloseButton )
m_infoBar->AddCloseButton();
GetInfoBar()->ShowMessageFor( aErrorMsg, 8000, wxICON_ERROR );
GetInfoBar()->ShowMessageFor( aErrorMsg, 8000, wxICON_ERROR, aType );
}

View File

@ -120,7 +120,8 @@ void WX_INFOBAR::QueueDismiss()
}
void WX_INFOBAR::ShowMessageFor( const wxString& aMessage, int aTime, int aFlags )
void WX_INFOBAR::ShowMessageFor( const wxString& aMessage, int aTime, int aFlags,
MESSAGE_TYPE aType )
{
// Don't do anything if we requested the UI update
if( m_updateLock )
@ -128,6 +129,8 @@ void WX_INFOBAR::ShowMessageFor( const wxString& aMessage, int aTime, int aFlags
m_showTime = aTime;
ShowMessage( aMessage, aFlags );
m_type = aType;
}
@ -164,15 +167,6 @@ void WX_INFOBAR::ShowMessage( const wxString& aMessage, int aFlags, MESSAGE_TYPE
}
void WX_INFOBAR::DismissOutdatedSave()
{
if( m_updateLock || m_type != MESSAGE_TYPE::OUTDATED_SAVE )
return;
Dismiss();
}
void WX_INFOBAR::Dismiss()
{
// Don't do anything if we requested the UI update

View File

@ -1023,7 +1023,8 @@ bool SCH_EDIT_FRAME::SaveProject()
UpdateTitle();
m_infoBar->DismissOutdatedSave();
if( m_infoBar->GetMessageType() == WX_INFOBAR::MESSAGE_TYPE::OUTDATED_SAVE )
m_infoBar->Dismiss();
return success;
}

View File

@ -41,6 +41,7 @@
#include <kiway_holder.h>
#include <tool/tools_holder.h>
#include <widgets/ui_common.h>
#include <widgets/infobar.h>
#include <undo_redo_container.h>
#include <eda_units.h>
@ -78,7 +79,6 @@ class FILE_HISTORY;
class SETTINGS_MANAGER;
class SEARCH_STACK;
class APP_SETTINGS_BASE;
class WX_INFOBAR;
struct WINDOW_SETTINGS;
struct WINDOW_STATE;
@ -242,7 +242,8 @@ public:
* @param aErrorMsg is the message to display.
* @param aShowCloseButton true to show a close button on the right of the #WX_INFOBAR.
*/
void ShowInfoBarError( const wxString& aErrorMsg, bool aShowCloseButton = false );
void ShowInfoBarError( const wxString& aErrorMsg, bool aShowCloseButton = false,
WX_INFOBAR::MESSAGE_TYPE aType = WX_INFOBAR::MESSAGE_TYPE::GENERIC );
/**
* Show the #WX_INFOBAR displayed on the top of the canvas with a message and an error

View File

@ -91,9 +91,13 @@ public:
enum class MESSAGE_TYPE
{
GENERIC, /**< GENERIC Are messages that do not have special handling */
OUTDATED_SAVE/**< OUTDATED_SAVE Messages that should be cleared on save */
OUTDATED_SAVE, /**< OUTDATED_SAVE Messages that should be cleared on save */
DRC_RULES_ERROR,
DRC_VIOLATION
};
MESSAGE_TYPE GetMessageType() const { return m_type; }
/**
* Set the time period to show the infobar.
*
@ -162,7 +166,8 @@ public:
* @param aTime is the amount of time in milliseconds to show the infobar
* @param aFlags is the flag containing the icon to display on the left side of the infobar
*/
void ShowMessageFor( const wxString& aMessage, int aTime, int aFlags = wxICON_INFORMATION );
void ShowMessageFor( const wxString& aMessage, int aTime, int aFlags = wxICON_INFORMATION,
MESSAGE_TYPE aType = WX_INFOBAR::MESSAGE_TYPE::GENERIC );
/**
* Show the info bar with the provided message and icon.
@ -187,12 +192,6 @@ public:
*/
void Dismiss() override;
/**
* Dismisses the infobar for outdated save warnings and updates the containing
* layout and AUI manager (if one is provided).
*/
void DismissOutdatedSave();
/**
* Send the infobar an event telling it to show a message.
*

View File

@ -1073,7 +1073,8 @@ bool PCB_EDIT_FRAME::SavePcbFile( const wxString& aFileName, bool addToHistory,
SetStatusText( lowerTxt, 0 );
// Get rid of the old version conversion warning, or any other dismissable warning :)
m_infoBar->DismissOutdatedSave();
if( m_infoBar->GetMessageType() == WX_INFOBAR::MESSAGE_TYPE::OUTDATED_SAVE )
m_infoBar->Dismiss();
if( m_infoBar->IsShown() && m_infoBar->HasCloseButton() )
m_infoBar->Dismiss();

View File

@ -1612,7 +1612,9 @@ void PCB_EDIT_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVars
try
{
drcTool->GetDRCEngine()->InitEngine( GetDesignRulesPath() );
infobar->Hide();
if( infobar->GetMessageType() == WX_INFOBAR::MESSAGE_TYPE::DRC_RULES_ERROR )
infobar->Dismiss();
}
catch( PARSE_ERROR& )
{
@ -1628,7 +1630,8 @@ void PCB_EDIT_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVars
infobar->RemoveAllButtons();
infobar->AddButton( button );
infobar->AddCloseButton();
infobar->ShowMessage( _( "Could not compile custom design rules." ), wxICON_ERROR );
infobar->ShowMessage( _( "Could not compile custom design rules." ), wxICON_ERROR,
WX_INFOBAR::MESSAGE_TYPE::DRC_RULES_ERROR );
}
// Update the environment variables in the Python interpreter

View File

@ -839,7 +839,7 @@ int ROUTER_TOOL::handleLayerSwitch( const TOOL_EVENT& aEvent, bool aForceVia )
infobar->ShowMessageFor( _( "Blind/buried vias must first be enabled in "
"Board Setup > Design Rules > Constraints." ),
10000, wxICON_ERROR );
10000, wxICON_ERROR, WX_INFOBAR::MESSAGE_TYPE::DRC_VIOLATION );
return false;
}
@ -860,7 +860,7 @@ int ROUTER_TOOL::handleLayerSwitch( const TOOL_EVENT& aEvent, bool aForceVia )
infobar->ShowMessageFor( _( "Microvias must first be enabled in "
"Board Setup > Design Rules > Constraints." ),
10000, wxICON_ERROR );
10000, wxICON_ERROR, WX_INFOBAR::MESSAGE_TYPE::DRC_VIOLATION );
return false;
}
}

View File

@ -2273,15 +2273,13 @@ int DRAWING_TOOL::DrawVia( const TOOL_EVENT& aEvent )
int m_drcEpsilon;
int m_worstClearance;
bool m_allowDRCViolations;
bool m_flaggedDRC;
VIA_PLACER( PCB_BASE_EDIT_FRAME* aFrame ) :
m_frame( aFrame ),
m_gridHelper( aFrame->GetToolManager(), aFrame->GetMagneticItemsSettings() ),
m_drcEngine( aFrame->GetBoard()->GetDesignSettings().m_DRCEngine ),
m_drcEpsilon( aFrame->GetBoard()->GetDesignSettings().GetDRCEpsilon() ),
m_worstClearance( 0 ),
m_flaggedDRC( false )
m_worstClearance( 0 )
{
ROUTER_TOOL* router = m_frame->GetToolManager()->GetTool<ROUTER_TOOL>();
@ -2545,10 +2543,11 @@ int DRAWING_TOOL::DrawVia( const TOOL_EVENT& aEvent )
bool PlaceItem( BOARD_ITEM* aItem, BOARD_COMMIT& aCommit ) override
{
WX_INFOBAR* infobar = m_frame->GetInfoBar();
PCB_VIA* via = static_cast<PCB_VIA*>( aItem );
wxPoint viaPos = via->GetPosition();
PCB_TRACK* track = findTrack( via );
PAD * pad = findPad( via );
PAD* pad = findPad( via );
if( track )
via->SetNetCode( track->GetNetCode() );
@ -2557,14 +2556,15 @@ int DRAWING_TOOL::DrawVia( const TOOL_EVENT& aEvent )
if( !m_allowDRCViolations && checkDRCViolation( via ) )
{
m_frame->ShowInfoBarError( _( "Via location violates DRC." ) );
m_frame->ShowInfoBarError( _( "Via location violates DRC." ), true,
WX_INFOBAR::MESSAGE_TYPE::DRC_VIOLATION );
via->SetNetCode( 0 );
m_flaggedDRC = true;
return false;
}
else if( m_flaggedDRC )
else
{
m_frame->GetInfoBar()->Dismiss();
if( infobar->GetMessageType() == WX_INFOBAR::MESSAGE_TYPE::DRC_VIOLATION )
infobar->Dismiss();
}
if( track )