From c51b1dad724f90c62a5e7875be0b2c7768748dba Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 1 Aug 2021 21:51:08 +0100 Subject: [PATCH] Generalize infobar MESSAGE_TYPE handling and use for DRC errors. Fixes https://gitlab.com/kicad/code/kicad/issues/8782 --- common/eda_base_frame.cpp | 5 +++-- common/widgets/infobar.cpp | 14 ++++---------- eeschema/files-io.cpp | 3 ++- include/eda_base_frame.h | 5 +++-- include/widgets/infobar.h | 17 ++++++++--------- pcbnew/files.cpp | 3 ++- pcbnew/pcb_edit_frame.cpp | 7 +++++-- pcbnew/router/router_tool.cpp | 4 ++-- pcbnew/tools/drawing_tool.cpp | 22 +++++++++++----------- 9 files changed, 40 insertions(+), 40 deletions(-) diff --git a/common/eda_base_frame.cpp b/common/eda_base_frame.cpp index 82245a761f..1bb48300bd 100644 --- a/common/eda_base_frame.cpp +++ b/common/eda_base_frame.cpp @@ -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 ); } diff --git a/common/widgets/infobar.cpp b/common/widgets/infobar.cpp index c55d75359b..fb96ff85ef 100644 --- a/common/widgets/infobar.cpp +++ b/common/widgets/infobar.cpp @@ -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 diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index 7ffbc3986c..5c12db06ff 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -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; } diff --git a/include/eda_base_frame.h b/include/eda_base_frame.h index ba1515caea..d861b4f079 100644 --- a/include/eda_base_frame.h +++ b/include/eda_base_frame.h @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -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 diff --git a/include/widgets/infobar.h b/include/widgets/infobar.h index 30d54089b4..d1643c72ce 100644 --- a/include/widgets/infobar.h +++ b/include/widgets/infobar.h @@ -90,10 +90,14 @@ 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 */ + GENERIC, /**< GENERIC Are messages that do not have special handling */ + 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. * diff --git a/pcbnew/files.cpp b/pcbnew/files.cpp index 97b9839d2f..fdf29fc853 100644 --- a/pcbnew/files.cpp +++ b/pcbnew/files.cpp @@ -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(); diff --git a/pcbnew/pcb_edit_frame.cpp b/pcbnew/pcb_edit_frame.cpp index f986eb6fdf..080d29c1d9 100644 --- a/pcbnew/pcb_edit_frame.cpp +++ b/pcbnew/pcb_edit_frame.cpp @@ -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 diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index be86c16923..4e6b92c135 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -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; } } diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index d9aa4f7895..61c07c6d28 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -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(); @@ -2545,10 +2543,11 @@ int DRAWING_TOOL::DrawVia( const TOOL_EVENT& aEvent ) bool PlaceItem( BOARD_ITEM* aItem, BOARD_COMMIT& aCommit ) override { - PCB_VIA* via = static_cast( aItem ); - wxPoint viaPos = via->GetPosition(); - PCB_TRACK* track = findTrack( via ); - PAD * pad = findPad( via ); + WX_INFOBAR* infobar = m_frame->GetInfoBar(); + PCB_VIA* via = static_cast( aItem ); + wxPoint viaPos = via->GetPosition(); + PCB_TRACK* track = findTrack( 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 )