diff --git a/eeschema/annotate.cpp b/eeschema/annotate.cpp index ab3a62ade7..835b5a97d7 100644 --- a/eeschema/annotate.cpp +++ b/eeschema/annotate.cpp @@ -33,7 +33,7 @@ #include #include #include - +#include void SCH_EDIT_FRAME::mapExistingAnnotation( std::map& aMap ) { @@ -114,6 +114,11 @@ void SCH_EDIT_FRAME::DeleteAnnotation( ANNOTATE_SCOPE_T aAnnotateScope, bool* aA // Update the references for the sheet that is currently being displayed. GetCurrentSheet().UpdateAllScreenReferences(); + wxWindow* erc_dlg = wxWindow::FindWindowByName( DIALOG_ERC_WINDOW_NAME ); + + if( erc_dlg ) + static_cast( erc_dlg )->UpdateAnnotationWarning(); + SyncView(); GetCanvas()->Refresh(); OnModify(); @@ -330,6 +335,11 @@ void SCH_EDIT_FRAME::AnnotateSymbols( ANNOTATE_SCOPE_T aAnnotateScope, GetCurrentSheet().UpdateAllScreenReferences(); SetSheetNumberAndCount(); + wxWindow* erc_dlg = wxWindow::FindWindowByName( DIALOG_ERC_WINDOW_NAME ); + + if( erc_dlg ) + static_cast( erc_dlg )->UpdateAnnotationWarning(); + SyncView(); GetCanvas()->Refresh(); OnModify(); diff --git a/eeschema/dialogs/dialog_erc.cpp b/eeschema/dialogs/dialog_erc.cpp index e195dc1331..328e6c4186 100644 --- a/eeschema/dialogs/dialog_erc.cpp +++ b/eeschema/dialogs/dialog_erc.cpp @@ -32,17 +32,14 @@ #include #include #include -#include #include #include #include #include -#include #include #include #include #include -#include #include #include #include @@ -60,6 +57,8 @@ DIALOG_ERC::DIALOG_ERC( SCH_EDIT_FRAME* parent ) : m_ercRun( false ), m_severities( RPT_SEVERITY_ERROR | RPT_SEVERITY_WARNING ) { + SetName( DIALOG_ERC_WINDOW_NAME ); // Set a window name to be able to find it + EESCHEMA_SETTINGS* settings = dynamic_cast( Kiface().KifaceSettings() ); m_severities = settings->m_Appearance.erc_severities; @@ -86,26 +85,7 @@ DIALOG_ERC::DIALOG_ERC( SCH_EDIT_FRAME* parent ) : m_warningsBadge->SetMaximumNumber( 999 ); m_exclusionsBadge->SetMaximumNumber( 999 ); - if( m_parent->CheckAnnotate( []( ERCE_T, const wxString&, SCH_REFERENCE*, - SCH_REFERENCE* ) {} ) ) - { - wxHyperlinkCtrl* button = new wxHyperlinkCtrl( m_infoBar, wxID_ANY, - _("Show Annotation dialog"), - wxEmptyString ); - - button->Bind( wxEVT_COMMAND_HYPERLINK, std::function( - [&]( wxHyperlinkEvent& aEvent ) - { - wxHtmlLinkEvent htmlEvent( aEvent.GetId(), - wxHtmlLinkInfo( aEvent.GetURL() ) ); - OnLinkClicked( htmlEvent ); - } ) ); - - m_infoBar->RemoveAllButtons(); - m_infoBar->AddButton( button ); - m_infoBar->ShowMessage( _( "Schematic is not fully annotated. " - "ERC results will be incomplete." ) ); - } + UpdateAnnotationWarning(); // Now all widgets have the size fixed, call FinishDialogSettings finishDialogSettings(); @@ -124,6 +104,42 @@ DIALOG_ERC::~DIALOG_ERC() } +void DIALOG_ERC::UpdateAnnotationWarning() +{ + if( m_parent->CheckAnnotate( []( ERCE_T, const wxString&, SCH_REFERENCE*, SCH_REFERENCE* ) + { } ) ) + { + if( !m_infoBar->IsShown() ) + { + wxHyperlinkCtrl* button = new wxHyperlinkCtrl( m_infoBar, wxID_ANY, + _("Show Annotation dialog"), + wxEmptyString ); + + button->Bind( wxEVT_COMMAND_HYPERLINK, std::function( + [&]( wxHyperlinkEvent& aEvent ) + { + wxHtmlLinkEvent htmlEvent( aEvent.GetId(), + wxHtmlLinkInfo( aEvent.GetURL() ) ); + OnLinkClicked( htmlEvent ); + } ) ); + + m_infoBar->RemoveAllButtons(); + m_infoBar->AddButton( button ); + m_infoBar->ShowMessage( _( "Schematic is not fully annotated. " + "ERC results will be incomplete." ) ); + } + } + else + { + if( m_infoBar->IsShown() ) + { + m_infoBar->RemoveAllButtons(); + m_infoBar->Hide(); + } + } +} + + // PROGRESS_REPORTER calls bool DIALOG_ERC::updateUI() @@ -250,11 +266,6 @@ void DIALOG_ERC::OnLinkClicked( wxHtmlLinkEvent& event ) { wxCommandEvent dummy; m_parent->OnAnnotate( dummy ); - - // We don't actually get notified when the annotation error is resolved, but we can assume - // that the user will take corrective action. If they don't, we can just show the infobar - // again. - m_infoBar->Hide(); } @@ -264,7 +275,7 @@ void DIALOG_ERC::OnRunERCClick( wxCommandEvent& event ) SCHEMATIC* sch = &m_parent->Schematic(); - m_infoBar->Hide(); + UpdateAnnotationWarning(); m_parent->RecordERCExclusions(); deleteAllMarkers( true ); diff --git a/eeschema/dialogs/dialog_erc.h b/eeschema/dialogs/dialog_erc.h index 47afc2b496..f3735c7c34 100644 --- a/eeschema/dialogs/dialog_erc.h +++ b/eeschema/dialogs/dialog_erc.h @@ -34,6 +34,9 @@ #include +#define DIALOG_ERC_WINDOW_NAME "DialogErcWindowName" + + class DIALOG_ERC : public DIALOG_ERC_BASE, PROGRESS_REPORTER_BASE { public: @@ -49,6 +52,8 @@ public: void NextMarker(); void ExcludeMarker(); + void UpdateAnnotationWarning(); + private: // from DIALOG_ERC_BASE: void OnCloseErcDialog( wxCloseEvent& event ) override; diff --git a/eeschema/sch_edit_frame.cpp b/eeschema/sch_edit_frame.cpp index c2a4ae756a..4aada50c3f 100644 --- a/eeschema/sch_edit_frame.cpp +++ b/eeschema/sch_edit_frame.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -310,6 +311,12 @@ SCH_EDIT_FRAME::~SCH_EDIT_FRAME() // Ensure m_canvasType is up to date, to save it in config m_canvasType = GetCanvas()->GetBackend(); + // Close modeless dialogs + wxWindow* open_dlg = wxWindow::FindWindowByName( DIALOG_ERC_WINDOW_NAME ); + + if( open_dlg ) + open_dlg->Close( true ); + // Shutdown all running tools if( m_toolManager ) { @@ -675,6 +682,13 @@ bool SCH_EDIT_FRAME::canCloseWindow( wxCloseEvent& aEvent ) } } + // Close modeless dialogs. They're trouble when they get destroyed after the frame and/or + // board. + wxWindow* open_dlg = wxWindow::FindWindowByName( DIALOG_ERC_WINDOW_NAME ); + + if( open_dlg ) + open_dlg->Close( true ); + return true; } @@ -783,6 +797,12 @@ void SCH_EDIT_FRAME::ResolveERCExclusions() } +SEVERITY SCH_EDIT_FRAME::GetSeverity( int aErrorCode ) const +{ + return Schematic().ErcSettings().GetSeverity( aErrorCode ); +} + + wxString SCH_EDIT_FRAME::GetUniqueFilenameForCurrentSheet() { // Filename is rootSheetName-sheetName-...-sheetName diff --git a/eeschema/sch_edit_frame.h b/eeschema/sch_edit_frame.h index 44965424d3..77356debc1 100644 --- a/eeschema/sch_edit_frame.h +++ b/eeschema/sch_edit_frame.h @@ -192,6 +192,8 @@ public: */ void ResolveERCExclusions(); + SEVERITY GetSeverity( int aErrorCode ) const override; + /** * Return a human-readable description of the current screen. */