From 0cb82a0985e9ffc31d74604f6dc7c3282209515c Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Sun, 13 Feb 2022 14:26:20 +0100 Subject: [PATCH] Import netlist: fix issues: do not read netlist before it is selected. Now the netlist must be explicitly selected and read instead of beeing read during dialog creation. It also avoid a useless netlist read when closing the dialog or trying to change the netlist filename. From master branch --- pcbnew/dialogs/dialog_netlist.cpp | 53 +++++++++++++++----------- pcbnew/dialogs/dialog_netlist.h | 21 +++++----- pcbnew/dialogs/dialog_netlist_base.cpp | 52 +++++++++++++------------ pcbnew/dialogs/dialog_netlist_base.fbp | 17 ++++++--- pcbnew/dialogs/dialog_netlist_base.h | 25 ++++++------ 5 files changed, 94 insertions(+), 74 deletions(-) diff --git a/pcbnew/dialogs/dialog_netlist.cpp b/pcbnew/dialogs/dialog_netlist.cpp index d42a8faec4..b62590db7e 100644 --- a/pcbnew/dialogs/dialog_netlist.cpp +++ b/pcbnew/dialogs/dialog_netlist.cpp @@ -1,7 +1,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -46,18 +46,18 @@ void PCB_EDIT_FRAME::InstallNetlistFrame() { wxString netlistName = GetLastPath( LAST_PATH_NETLIST ); - DIALOG_NETLIST dlg( this, netlistName ); + DIALOG_NETLIST_IMPORT dlg( this, netlistName ); dlg.ShowModal(); SetLastPath( LAST_PATH_NETLIST, netlistName ); } -bool DIALOG_NETLIST::m_matchByUUID = false; +bool DIALOG_NETLIST_IMPORT::m_matchByUUID = false; -DIALOG_NETLIST::DIALOG_NETLIST( PCB_EDIT_FRAME* aParent, wxString& aNetlistFullFilename ) - : DIALOG_NETLIST_BASE( aParent ), +DIALOG_NETLIST_IMPORT::DIALOG_NETLIST_IMPORT( PCB_EDIT_FRAME* aParent, wxString& aNetlistFullFilename ) + : DIALOG_NETLIST_IMPORT_BASE( aParent ), m_parent( aParent ), m_netlistPath( aNetlistFullFilename ), m_initialized( false ), @@ -78,20 +78,18 @@ DIALOG_NETLIST::DIALOG_NETLIST( PCB_EDIT_FRAME* aParent, wxString& aNetlistFullF m_MessageWindow->SetVisibleSeverities( cfg->m_NetlistDialog.report_filter ); m_MessageWindow->SetFileName( Prj().GetProjectPath() + wxT( "report.txt" ) ); - // We use a sdbSizer to get platform-dependent ordering of the action buttons, but - // that requires us to correct the button labels here. - m_sdbSizer1OK->SetLabel( _( "Update PCB" ) ); - m_sdbSizer1Cancel->SetLabel( _( "Close" ) ); + m_sdbSizerApply->SetLabel( _( "Update PCB" ) ); + m_sdbSizerCancel->SetLabel( _( "Close" ) ); + m_sdbSizerOK->SetLabel( _( "Load and Test Netlist" ) ); m_buttonsSizer->Layout(); - m_sdbSizer1OK->SetDefault(); + m_sdbSizerOK->SetDefault(); finishDialogSettings(); m_initialized = true; - loadNetlist( true ); } -DIALOG_NETLIST::~DIALOG_NETLIST() +DIALOG_NETLIST_IMPORT::~DIALOG_NETLIST_IMPORT() { m_matchByUUID = m_matchByTimestamp->GetSelection() == 0; @@ -111,7 +109,7 @@ DIALOG_NETLIST::~DIALOG_NETLIST() } -void DIALOG_NETLIST::OnOpenNetlistClick( wxCommandEvent& event ) +void DIALOG_NETLIST_IMPORT::onBrowseNetlistFiles( wxCommandEvent& event ) { wxString dirPath = wxFileName( Prj().GetProjectFullName() ).GetPath(); @@ -131,10 +129,17 @@ void DIALOG_NETLIST::OnOpenNetlistClick( wxCommandEvent& event ) return; m_NetlistFilenameCtrl->SetValue( FilesDialog.GetPath() ); - onFilenameChanged(); + onFilenameChanged( false ); } -void DIALOG_NETLIST::OnUpdatePCB( wxCommandEvent& event ) + +void DIALOG_NETLIST_IMPORT::onImportNetlist( wxCommandEvent& event ) +{ + onFilenameChanged( true ); +} + + +void DIALOG_NETLIST_IMPORT::onUpdatePCB( wxCommandEvent& event ) { wxFileName fn = m_NetlistFilenameCtrl->GetValue(); @@ -153,18 +158,18 @@ void DIALOG_NETLIST::OnUpdatePCB( wxCommandEvent& event ) m_MessageWindow->SetLabel( _( "Changes Applied to PCB" ) ); loadNetlist( false ); - m_sdbSizer1Cancel->SetDefault(); + m_sdbSizerCancel->SetDefault(); + m_sdbSizerCancel->SetFocus(); } -void DIALOG_NETLIST::OnFilenameKillFocus( wxFocusEvent& event ) +void DIALOG_NETLIST_IMPORT::OnFilenameKillFocus( wxFocusEvent& event ) { - onFilenameChanged(); event.Skip(); } -void DIALOG_NETLIST::onFilenameChanged() +void DIALOG_NETLIST_IMPORT::onFilenameChanged( bool aLoadNetlist ) { if( m_initialized ) { @@ -175,7 +180,9 @@ void DIALOG_NETLIST::onFilenameChanged() if( fn.FileExists() ) { m_netlistPath = m_NetlistFilenameCtrl->GetValue(); - loadNetlist( true ); + + if( aLoadNetlist ) + loadNetlist( true ); } else { @@ -188,21 +195,21 @@ void DIALOG_NETLIST::onFilenameChanged() } -void DIALOG_NETLIST::OnMatchChanged( wxCommandEvent& event ) +void DIALOG_NETLIST_IMPORT::OnMatchChanged( wxCommandEvent& event ) { if( m_initialized ) loadNetlist( true ); } -void DIALOG_NETLIST::OnOptionChanged( wxCommandEvent& event ) +void DIALOG_NETLIST_IMPORT::OnOptionChanged( wxCommandEvent& event ) { if( m_initialized ) loadNetlist( true ); } -void DIALOG_NETLIST::loadNetlist( bool aDryRun ) +void DIALOG_NETLIST_IMPORT::loadNetlist( bool aDryRun ) { wxString netlistFileName = m_NetlistFilenameCtrl->GetValue(); wxFileName fn = netlistFileName; diff --git a/pcbnew/dialogs/dialog_netlist.h b/pcbnew/dialogs/dialog_netlist.h index 6c6542a3fe..3c691f79da 100644 --- a/pcbnew/dialogs/dialog_netlist.h +++ b/pcbnew/dialogs/dialog_netlist.h @@ -5,7 +5,7 @@ /* * This program source code file is part of KiCad, a free EDA CAD application. * - * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -25,8 +25,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifndef _DIALOG_NETLIST_H_ -#define _DIALOG_NETLIST_H_ +#ifndef _DIALOG_NETLIST_IMPORT_H_ +#define _DIALOG_NETLIST_IMPORT_H_ #include @@ -35,20 +35,21 @@ class FOOTPRINT; class NETLIST; -class DIALOG_NETLIST : public DIALOG_NETLIST_BASE +class DIALOG_NETLIST_IMPORT : public DIALOG_NETLIST_IMPORT_BASE { public: - DIALOG_NETLIST( PCB_EDIT_FRAME* aParent, wxString& aNetlistFullFilename ); - ~DIALOG_NETLIST(); + DIALOG_NETLIST_IMPORT( PCB_EDIT_FRAME* aParent, wxString& aNetlistFullFilename ); + ~DIALOG_NETLIST_IMPORT(); private: - void onFilenameChanged(); + void onFilenameChanged( bool aLoadNetlist ); void loadNetlist( bool aDryRun ); // Virtual event handlers: - void OnOpenNetlistClick( wxCommandEvent& event ) override; - void OnUpdatePCB( wxCommandEvent& event ) override; + void onBrowseNetlistFiles( wxCommandEvent& event ) override; + void onImportNetlist( wxCommandEvent& event ) override; + void onUpdatePCB( wxCommandEvent& event ) override; void OnFilenameKillFocus( wxFocusEvent& event ) override; void OnMatchChanged( wxCommandEvent& event ) override; void OnOptionChanged( wxCommandEvent& event ) override; @@ -64,4 +65,4 @@ private: }; -#endif // _DIALOG_NETLIST_H_ +#endif // _DIALOG_NETLIST_IMPORT_H_ diff --git a/pcbnew/dialogs/dialog_netlist_base.cpp b/pcbnew/dialogs/dialog_netlist_base.cpp index 84be2e9c05..7b001e76b6 100644 --- a/pcbnew/dialogs/dialog_netlist_base.cpp +++ b/pcbnew/dialogs/dialog_netlist_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Oct 26 2018) +// C++ code generated with wxFormBuilder (version 3.10.0-39-g3487c3cb) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -11,7 +11,7 @@ /////////////////////////////////////////////////////////////////////////// -DIALOG_NETLIST_BASE::DIALOG_NETLIST_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style ) +DIALOG_NETLIST_IMPORT_BASE::DIALOG_NETLIST_IMPORT_BASE( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : DIALOG_SHIM( parent, id, title, pos, size, style ) { this->SetSizeHints( wxDefaultSize, wxDefaultSize ); @@ -78,14 +78,16 @@ DIALOG_NETLIST_BASE::DIALOG_NETLIST_BASE( wxWindow* parent, wxWindowID id, const m_buttonsSizer = new wxBoxSizer( wxHORIZONTAL ); - m_sdbSizer1 = new wxStdDialogButtonSizer(); - m_sdbSizer1OK = new wxButton( this, wxID_OK ); - m_sdbSizer1->AddButton( m_sdbSizer1OK ); - m_sdbSizer1Cancel = new wxButton( this, wxID_CANCEL ); - m_sdbSizer1->AddButton( m_sdbSizer1Cancel ); - m_sdbSizer1->Realize(); + m_sdbSizer = new wxStdDialogButtonSizer(); + m_sdbSizerOK = new wxButton( this, wxID_OK ); + m_sdbSizer->AddButton( m_sdbSizerOK ); + m_sdbSizerApply = new wxButton( this, wxID_APPLY ); + m_sdbSizer->AddButton( m_sdbSizerApply ); + m_sdbSizerCancel = new wxButton( this, wxID_CANCEL ); + m_sdbSizer->AddButton( m_sdbSizerCancel ); + m_sdbSizer->Realize(); - m_buttonsSizer->Add( m_sdbSizer1, 1, wxEXPAND, 5 ); + m_buttonsSizer->Add( m_sdbSizer, 1, wxEXPAND, 5 ); bMainSizer->Add( m_buttonsSizer, 0, wxEXPAND|wxALL, 5 ); @@ -96,24 +98,26 @@ DIALOG_NETLIST_BASE::DIALOG_NETLIST_BASE( wxWindow* parent, wxWindowID id, const bMainSizer->Fit( this ); // Connect Events - m_NetlistFilenameCtrl->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_NETLIST_BASE::OnFilenameKillFocus ), NULL, this ); - m_browseButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_NETLIST_BASE::OnOpenNetlistClick ), NULL, this ); - m_matchByTimestamp->Connect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_NETLIST_BASE::OnMatchChanged ), NULL, this ); - m_cbUpdateFootprints->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_NETLIST_BASE::OnOptionChanged ), NULL, this ); - m_cbDeleteExtraFootprints->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_NETLIST_BASE::OnOptionChanged ), NULL, this ); - m_cbDeleteShortingTracks->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_NETLIST_BASE::OnOptionChanged ), NULL, this ); - m_sdbSizer1OK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_NETLIST_BASE::OnUpdatePCB ), NULL, this ); + m_NetlistFilenameCtrl->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_NETLIST_IMPORT_BASE::OnFilenameKillFocus ), NULL, this ); + m_browseButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_NETLIST_IMPORT_BASE::onBrowseNetlistFiles ), NULL, this ); + m_matchByTimestamp->Connect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_NETLIST_IMPORT_BASE::OnMatchChanged ), NULL, this ); + m_cbUpdateFootprints->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_NETLIST_IMPORT_BASE::OnOptionChanged ), NULL, this ); + m_cbDeleteExtraFootprints->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_NETLIST_IMPORT_BASE::OnOptionChanged ), NULL, this ); + m_cbDeleteShortingTracks->Connect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_NETLIST_IMPORT_BASE::OnOptionChanged ), NULL, this ); + m_sdbSizerApply->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_NETLIST_IMPORT_BASE::onUpdatePCB ), NULL, this ); + m_sdbSizerOK->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_NETLIST_IMPORT_BASE::onImportNetlist ), NULL, this ); } -DIALOG_NETLIST_BASE::~DIALOG_NETLIST_BASE() +DIALOG_NETLIST_IMPORT_BASE::~DIALOG_NETLIST_IMPORT_BASE() { // Disconnect Events - m_NetlistFilenameCtrl->Disconnect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_NETLIST_BASE::OnFilenameKillFocus ), NULL, this ); - m_browseButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_NETLIST_BASE::OnOpenNetlistClick ), NULL, this ); - m_matchByTimestamp->Disconnect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_NETLIST_BASE::OnMatchChanged ), NULL, this ); - m_cbUpdateFootprints->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_NETLIST_BASE::OnOptionChanged ), NULL, this ); - m_cbDeleteExtraFootprints->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_NETLIST_BASE::OnOptionChanged ), NULL, this ); - m_cbDeleteShortingTracks->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_NETLIST_BASE::OnOptionChanged ), NULL, this ); - m_sdbSizer1OK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_NETLIST_BASE::OnUpdatePCB ), NULL, this ); + m_NetlistFilenameCtrl->Disconnect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_NETLIST_IMPORT_BASE::OnFilenameKillFocus ), NULL, this ); + m_browseButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_NETLIST_IMPORT_BASE::onBrowseNetlistFiles ), NULL, this ); + m_matchByTimestamp->Disconnect( wxEVT_COMMAND_RADIOBOX_SELECTED, wxCommandEventHandler( DIALOG_NETLIST_IMPORT_BASE::OnMatchChanged ), NULL, this ); + m_cbUpdateFootprints->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_NETLIST_IMPORT_BASE::OnOptionChanged ), NULL, this ); + m_cbDeleteExtraFootprints->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_NETLIST_IMPORT_BASE::OnOptionChanged ), NULL, this ); + m_cbDeleteShortingTracks->Disconnect( wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler( DIALOG_NETLIST_IMPORT_BASE::OnOptionChanged ), NULL, this ); + m_sdbSizerApply->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_NETLIST_IMPORT_BASE::onUpdatePCB ), NULL, this ); + m_sdbSizerOK->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_NETLIST_IMPORT_BASE::onImportNetlist ), NULL, this ); } diff --git a/pcbnew/dialogs/dialog_netlist_base.fbp b/pcbnew/dialogs/dialog_netlist_base.fbp index 1262ade243..01c12d7237 100644 --- a/pcbnew/dialogs/dialog_netlist_base.fbp +++ b/pcbnew/dialogs/dialog_netlist_base.fbp @@ -1,6 +1,6 @@ - + C++ @@ -14,6 +14,7 @@ dialog_netlist_base 1000 none + 1 dialog_netlist_base @@ -25,6 +26,7 @@ 1 1 UI + 0 1 0 @@ -43,13 +45,14 @@ wxID_ANY - DIALOG_NETLIST_BASE + DIALOG_NETLIST_IMPORT_BASE -1,-1 wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER DIALOG_SHIM; dialog_shim.h Import Netlist + 0 @@ -206,6 +209,7 @@ + 0 @@ -263,7 +267,7 @@ - OnOpenNetlistClick + onBrowseNetlistFiles @@ -637,7 +641,7 @@ wxEXPAND 1 - 0 + 1 1 0 0 @@ -646,9 +650,10 @@ 0 0 - m_sdbSizer1 + m_sdbSizer protected - OnUpdatePCB + onUpdatePCB + onImportNetlist diff --git a/pcbnew/dialogs/dialog_netlist_base.h b/pcbnew/dialogs/dialog_netlist_base.h index 4411ae74ef..ba2281c8a1 100644 --- a/pcbnew/dialogs/dialog_netlist_base.h +++ b/pcbnew/dialogs/dialog_netlist_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Oct 26 2018) +// C++ code generated with wxFormBuilder (version 3.10.0-39-g3487c3cb) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -35,9 +35,9 @@ class WX_HTML_REPORT_PANEL; /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// -/// Class DIALOG_NETLIST_BASE +/// Class DIALOG_NETLIST_IMPORT_BASE /////////////////////////////////////////////////////////////////////////////// -class DIALOG_NETLIST_BASE : public DIALOG_SHIM +class DIALOG_NETLIST_IMPORT_BASE : public DIALOG_SHIM { private: @@ -50,22 +50,25 @@ class DIALOG_NETLIST_BASE : public DIALOG_SHIM wxCheckBox* m_cbDeleteShortingTracks; WX_HTML_REPORT_PANEL* m_MessageWindow; wxBoxSizer* m_buttonsSizer; - wxStdDialogButtonSizer* m_sdbSizer1; - wxButton* m_sdbSizer1OK; - wxButton* m_sdbSizer1Cancel; + wxStdDialogButtonSizer* m_sdbSizer; + wxButton* m_sdbSizerOK; + wxButton* m_sdbSizerApply; + wxButton* m_sdbSizerCancel; - // Virtual event handlers, overide them in your derived class + // Virtual event handlers, override them in your derived class virtual void OnFilenameKillFocus( wxFocusEvent& event ) { event.Skip(); } - virtual void OnOpenNetlistClick( wxCommandEvent& event ) { event.Skip(); } + virtual void onBrowseNetlistFiles( wxCommandEvent& event ) { event.Skip(); } virtual void OnMatchChanged( wxCommandEvent& event ) { event.Skip(); } virtual void OnOptionChanged( wxCommandEvent& event ) { event.Skip(); } - virtual void OnUpdatePCB( wxCommandEvent& event ) { event.Skip(); } + virtual void onUpdatePCB( wxCommandEvent& event ) { event.Skip(); } + virtual void onImportNetlist( wxCommandEvent& event ) { event.Skip(); } public: - DIALOG_NETLIST_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Import Netlist"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); - ~DIALOG_NETLIST_BASE(); + DIALOG_NETLIST_IMPORT_BASE( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("Import Netlist"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( -1,-1 ), long style = wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER ); + + ~DIALOG_NETLIST_IMPORT_BASE(); };