From 5507575d643b0747fa442e940c4087748fae1e5e Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 3 Nov 2020 19:24:05 +0000 Subject: [PATCH] Move ERC dialog to EE_INSPECTION_TOOL and kill when resetting. Fixes https://gitlab.com/kicad/code/kicad/issues/6111 --- eeschema/dialogs/dialog_erc.cpp | 11 +-------- eeschema/files-io.cpp | 2 ++ eeschema/invoke_sch_dialog.h | 4 --- eeschema/tools/ee_inspection_tool.cpp | 35 +++++++++++++++++++++------ eeschema/tools/ee_inspection_tool.h | 6 +++++ include/id.h | 2 -- 6 files changed, 36 insertions(+), 24 deletions(-) diff --git a/eeschema/dialogs/dialog_erc.cpp b/eeschema/dialogs/dialog_erc.cpp index 85a799a1f3..568a60d3eb 100644 --- a/eeschema/dialogs/dialog_erc.cpp +++ b/eeschema/dialogs/dialog_erc.cpp @@ -52,7 +52,7 @@ #include DIALOG_ERC::DIALOG_ERC( SCH_EDIT_FRAME* parent ) : - DIALOG_ERC_BASE( parent, ID_DIALOG_ERC ), // parent looks for this ID explicitly + DIALOG_ERC_BASE( parent ), PROGRESS_REPORTER( 1 ), m_parent( parent ), m_running( false ), @@ -745,12 +745,3 @@ bool DIALOG_ERC::writeReport( const wxString& aFullFileName ) } -wxDialog* InvokeDialogERC( SCH_EDIT_FRAME* aCaller ) -{ - // This is a modeless dialog, so new it rather than instantiating on stack. - DIALOG_ERC* dlg = new DIALOG_ERC( aCaller ); - - dlg->Show( true ); - - return dlg; // wxDialog is information hiding about DIALOG_ERC. -} diff --git a/eeschema/files-io.cpp b/eeschema/files-io.cpp index ac4f4c36c4..f0251b51fd 100644 --- a/eeschema/files-io.cpp +++ b/eeschema/files-io.cpp @@ -58,6 +58,7 @@ #include #include #include +#include bool SCH_EDIT_FRAME::SaveEEFile( SCH_SHEET* aSheet, bool aSaveUnderNewName ) { @@ -278,6 +279,7 @@ bool SCH_EDIT_FRAME::OpenProjectFiles( const std::vector& aFileSet, in // unload current project file before loading new { SetScreen( nullptr ); + m_toolManager->GetTool()->Reset( TOOL_BASE::MODEL_RELOAD ); CreateScreens(); } diff --git a/eeschema/invoke_sch_dialog.h b/eeschema/invoke_sch_dialog.h index 40aec1acbc..cabc738810 100644 --- a/eeschema/invoke_sch_dialog.h +++ b/eeschema/invoke_sch_dialog.h @@ -70,10 +70,6 @@ class SCH_EDIT_FRAME; int InvokeDialogRescueEach( wxWindow* aParent, RESCUER& aRescuer, SCH_SHEET_PATH* aCurrentSheet, EDA_DRAW_PANEL_GAL::GAL_TYPE aGalBackEndType, bool aAskShowAgain ); -/// Create the modeless DIALOG_ERC and show it, return something to -/// destroy or close it. The dialog will have ID_DIALOG_ERC from id.h -wxDialog* InvokeDialogERC( SCH_EDIT_FRAME* aCaller ); - /// Create and show DIALOG_PRINT_USING_PRINTER and return whatever /// DIALOG_PRINT_USING_PRINTER::ShowModal() returns. int InvokeDialogPrintUsingPrinter( SCH_EDIT_FRAME* aCaller ); diff --git a/eeschema/tools/ee_inspection_tool.cpp b/eeschema/tools/ee_inspection_tool.cpp index 1696604f12..c1562468de 100644 --- a/eeschema/tools/ee_inspection_tool.cpp +++ b/eeschema/tools/ee_inspection_tool.cpp @@ -41,11 +41,13 @@ #include #include #include +#include #include // for KiROUND -EE_INSPECTION_TOOL::EE_INSPECTION_TOOL() - : EE_TOOL_BASE( "eeschema.InspectionTool" ) +EE_INSPECTION_TOOL::EE_INSPECTION_TOOL() : + EE_TOOL_BASE( "eeschema.InspectionTool" ), + m_ercDialog( nullptr ) { } @@ -67,6 +69,20 @@ bool EE_INSPECTION_TOOL::Init() } +void EE_INSPECTION_TOOL::Reset( RESET_REASON aReason ) +{ + EE_TOOL_BASE::Reset( aReason ); + + if( aReason == MODEL_RELOAD ) + { + if( m_ercDialog ) + m_ercDialog->Destroy(); + + m_ercDialog = nullptr; + } +} + + int EE_INSPECTION_TOOL::RunERC( const TOOL_EVENT& aEvent ) { if( m_frame->IsType( FRAME_SCH_SYMBOL_EDITOR ) ) @@ -75,17 +91,20 @@ int EE_INSPECTION_TOOL::RunERC( const TOOL_EVENT& aEvent ) } else if( m_frame->IsType( FRAME_SCH ) ) { - wxWindow* erc = wxWindow::FindWindowById( ID_DIALOG_ERC, m_frame ); - - if( erc ) + if( m_ercDialog ) { // Needed at least on Windows. Raise() is not enough - erc->Show( true ); + m_ercDialog->Show( true ); // Bring it to the top if already open. Dual monitor users need this. - erc->Raise(); + m_ercDialog->Raise(); } else - InvokeDialogERC( static_cast( m_frame ) ); + { + // This is a modeless dialog, so new it rather than instantiating on stack. + m_ercDialog = new DIALOG_ERC( static_cast( m_frame ) ); + + m_ercDialog->Show( true ); + } } return 0; diff --git a/eeschema/tools/ee_inspection_tool.h b/eeschema/tools/ee_inspection_tool.h index 1a9b257f21..265bbf4a81 100644 --- a/eeschema/tools/ee_inspection_tool.h +++ b/eeschema/tools/ee_inspection_tool.h @@ -32,6 +32,7 @@ class EE_SELECTION_TOOL; class SCH_BASE_FRAME; +class DIALOG_ERC; class EE_INSPECTION_TOOL : public EE_TOOL_BASE @@ -43,6 +44,8 @@ public: /// @copydoc TOOL_INTERACTIVE::Init() bool Init() override; + void Reset( RESET_REASON aReason ) override; + int RunERC( const TOOL_EVENT& aEvent ); int RunSimulation( const TOOL_EVENT& aEvent ); @@ -55,6 +58,9 @@ private: ///> @copydoc TOOL_INTERACTIVE::setTransitions(); void setTransitions() override; + +private: + DIALOG_ERC* m_ercDialog; }; #endif /* EE_INSPECTION_TOOL_H */ diff --git a/include/id.h b/include/id.h index c4de9eefe1..a7dcde2ea0 100644 --- a/include/id.h +++ b/include/id.h @@ -181,8 +181,6 @@ enum main_id ID_EDA_SOCKET_EVENT_SERV, ID_EDA_SOCKET_EVENT, - ID_DIALOG_ERC, ///< eeschema ERC modeless dialog ID - // IDs specifics to a sub-application (Eeschema, Kicad manager....) start here // // We reserve here Ids for each sub-application, to avoid duplicate IDs