From 80e40b862c7829a795b53d8a28303abfafb0e296 Mon Sep 17 00:00:00 2001 From: Oleg Endo Date: Mon, 13 Apr 2020 20:54:35 +0900 Subject: [PATCH] destroy window when list nets dialog is closed avoid potential performance issues when the dialog is still listening to the board updates and refreshing its data and view structures. it seems useful to keep the settings of the dialog across dialog open-close cycles. --- .../dialogs/dialog_select_net_from_list.cpp | 13 +++++++-- pcbnew/dialogs/dialog_select_net_from_list.h | 10 ++++++- pcbnew/tools/pcb_inspection_tool.cpp | 29 +++++++++++++++++-- pcbnew/tools/pcb_inspection_tool.h | 6 ++-- 4 files changed, 50 insertions(+), 8 deletions(-) diff --git a/pcbnew/dialogs/dialog_select_net_from_list.cpp b/pcbnew/dialogs/dialog_select_net_from_list.cpp index 44ba420b15..ebae8c36c2 100644 --- a/pcbnew/dialogs/dialog_select_net_from_list.cpp +++ b/pcbnew/dialogs/dialog_select_net_from_list.cpp @@ -119,8 +119,9 @@ struct DIALOG_SELECT_NET_FROM_LIST::ROW_DESC }; -DIALOG_SELECT_NET_FROM_LIST::DIALOG_SELECT_NET_FROM_LIST( PCB_EDIT_FRAME* aParent ) - : DIALOG_SELECT_NET_FROM_LIST_BASE( aParent ), m_frame( aParent ) +DIALOG_SELECT_NET_FROM_LIST::DIALOG_SELECT_NET_FROM_LIST( + PCB_EDIT_FRAME* aParent, const SETTINGS& aSettings ) + : DIALOG_SELECT_NET_FROM_LIST_BASE( aParent ), m_frame( aParent ) { m_brd = aParent->GetBoard(); m_wasSelected = false; @@ -144,6 +145,9 @@ DIALOG_SELECT_NET_FROM_LIST::DIALOG_SELECT_NET_FROM_LIST( PCB_EDIT_FRAME* aParen // expander buttons... but it doesn't. Fix by forcing the indent to 0. m_netsList->SetIndent( 0 ); + m_textCtrlFilter->SetValue( aSettings.filter_string ); + m_cbShowZeroPad->SetValue( aSettings.show_zero_pad_nets ); + buildNetsList(); adjustListColumns(); @@ -181,9 +185,14 @@ DIALOG_SELECT_NET_FROM_LIST::~DIALOG_SELECT_NET_FROM_LIST() m_brd->RemoveListener( this ); } +DIALOG_SELECT_NET_FROM_LIST::SETTINGS DIALOG_SELECT_NET_FROM_LIST::Settings() const +{ + return { m_textCtrlFilter->GetValue(), m_cbShowZeroPad->IsChecked() }; +} void DIALOG_SELECT_NET_FROM_LIST::onParentWindowClosed( wxCommandEvent& event ) { + Close(); event.Skip(); } diff --git a/pcbnew/dialogs/dialog_select_net_from_list.h b/pcbnew/dialogs/dialog_select_net_from_list.h index 0e5716fcc2..1127327e4f 100644 --- a/pcbnew/dialogs/dialog_select_net_from_list.h +++ b/pcbnew/dialogs/dialog_select_net_from_list.h @@ -36,9 +36,17 @@ class CN_ITEM; class DIALOG_SELECT_NET_FROM_LIST : public DIALOG_SELECT_NET_FROM_LIST_BASE, public BOARD_LISTENER { public: - DIALOG_SELECT_NET_FROM_LIST( PCB_EDIT_FRAME* aParent ); + struct SETTINGS + { + wxString filter_string; + bool show_zero_pad_nets = true; + }; + + DIALOG_SELECT_NET_FROM_LIST( PCB_EDIT_FRAME* aParent, const SETTINGS& aSettings ); ~DIALOG_SELECT_NET_FROM_LIST(); + SETTINGS Settings() const; + // returns true if a net was selected, and its name in aName bool GetNetName( wxString& aName ) const; diff --git a/pcbnew/tools/pcb_inspection_tool.cpp b/pcbnew/tools/pcb_inspection_tool.cpp index e3f6c42636..23e8ba2363 100644 --- a/pcbnew/tools/pcb_inspection_tool.cpp +++ b/pcbnew/tools/pcb_inspection_tool.cpp @@ -28,7 +28,6 @@ #include #include #include -#include #include #include "pcb_inspection_tool.h" @@ -448,13 +447,37 @@ void PCB_INSPECTION_TOOL::calculateSelectionRatsnest() int PCB_INSPECTION_TOOL::ListNets( const TOOL_EVENT& aEvent ) { if( m_listNetsDialog == nullptr ) - m_listNetsDialog = std::make_unique( m_frame ); + { + m_listNetsDialog = + std::make_unique( m_frame, m_listNetsDialogSettings ); + + m_listNetsDialog->Connect( wxEVT_CLOSE_WINDOW, + wxCommandEventHandler( PCB_INSPECTION_TOOL::onListNetsDialogClosed ), nullptr, + this ); + + m_listNetsDialog->Connect( wxEVT_BUTTON, + wxCommandEventHandler( PCB_INSPECTION_TOOL::onListNetsDialogClosed ), nullptr, + this ); + } m_listNetsDialog->Show( true ); - return 0; } +void PCB_INSPECTION_TOOL::onListNetsDialogClosed( wxCommandEvent& event ) +{ + m_listNetsDialogSettings = m_listNetsDialog->Settings(); + + m_listNetsDialog->Disconnect( wxEVT_CLOSE_WINDOW, + wxCommandEventHandler( PCB_INSPECTION_TOOL::onListNetsDialogClosed ), nullptr, this ); + + m_listNetsDialog->Disconnect( wxEVT_BUTTON, + wxCommandEventHandler( PCB_INSPECTION_TOOL::onListNetsDialogClosed ), nullptr, this ); + + m_listNetsDialog->Destroy(); + m_listNetsDialog.release(); +} + void PCB_INSPECTION_TOOL::setTransitions() { Go( &PCB_INSPECTION_TOOL::CrossProbePcbToSch, EVENTS::SelectedEvent ); diff --git a/pcbnew/tools/pcb_inspection_tool.h b/pcbnew/tools/pcb_inspection_tool.h index 7e4cf6698e..23a5d85511 100644 --- a/pcbnew/tools/pcb_inspection_tool.h +++ b/pcbnew/tools/pcb_inspection_tool.h @@ -26,12 +26,11 @@ #include +#include #include #include #include -class DIALOG_SELECT_NET_FROM_LIST; - /** * PCB_INSPECTION_TOOL * @@ -95,6 +94,8 @@ private: ///> Bind handlers to corresponding TOOL_ACTIONs void setTransitions() override; + void onListNetsDialogClosed( wxCommandEvent& event ); + private: PCB_EDIT_FRAME* m_frame; // Pointer to the currently used edit frame. @@ -105,6 +106,7 @@ private: wxTimer m_ratsnestTimer; // Timer to initiate lazy ratsnest calculation (ie: when slow) std::unique_ptr m_listNetsDialog; + DIALOG_SELECT_NET_FROM_LIST::SETTINGS m_listNetsDialogSettings; }; #endif //__BOARD_STATISTICS_TOOL_H