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.
This commit is contained in:
jean-pierre charras 2022-02-13 14:26:20 +01:00
parent 013d6d088f
commit cdd32df3a0
5 changed files with 92 additions and 71 deletions

View File

@ -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,16 +78,16 @@ 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" ) );
SetupStandardButtons( { { wxID_OK, _( "Update PCB" ) },
{ wxID_CANCEL, _( "Close" ) } } );
SetupStandardButtons( { { wxID_OK, _( "Load and Test Netlist" ) },
{ wxID_CANCEL, _( "Close" ) },
{ wxID_APPLY, _( "Update PCB" ) } } );
finishDialogSettings();
m_initialized = true;
loadNetlist( true );
}
DIALOG_NETLIST::~DIALOG_NETLIST()
DIALOG_NETLIST_IMPORT::~DIALOG_NETLIST_IMPORT()
{
m_matchByUUID = m_matchByTimestamp->GetSelection() == 0;
@ -107,7 +107,7 @@ DIALOG_NETLIST::~DIALOG_NETLIST()
}
void DIALOG_NETLIST::OnOpenNetlistClick( wxCommandEvent& event )
void DIALOG_NETLIST_IMPORT::onBrowseNetlistFiles( wxCommandEvent& event )
{
wxString dirPath = wxFileName( Prj().GetProjectFullName() ).GetPath();
@ -127,10 +127,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();
@ -149,18 +156,17 @@ void DIALOG_NETLIST::OnUpdatePCB( wxCommandEvent& event )
m_MessageWindow->SetLabel( _( "Changes Applied to PCB" ) );
loadNetlist( false );
m_sdbSizer1Cancel->SetDefault();
m_sdbSizerCancel->SetDefault();
}
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 )
{
@ -171,7 +177,9 @@ void DIALOG_NETLIST::onFilenameChanged()
if( fn.FileExists() )
{
m_netlistPath = m_NetlistFilenameCtrl->GetValue();
loadNetlist( true );
if( aLoadNetlist )
loadNetlist( true );
}
else
{
@ -184,21 +192,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;

View File

@ -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 <dialog_netlist_base.h>
@ -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_

View File

@ -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 );
}

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<wxFormBuilder_Project>
<FileVersion major="1" minor="15" />
<FileVersion major="1" minor="16" />
<object class="Project" expanded="1">
<property name="class_decoration"></property>
<property name="code_generation">C++</property>
@ -14,6 +14,7 @@
<property name="file">dialog_netlist_base</property>
<property name="first_id">1000</property>
<property name="help_provider">none</property>
<property name="image_path_wrapper_function_name"></property>
<property name="indent_with_spaces"></property>
<property name="internationalize">1</property>
<property name="name">dialog_netlist_base</property>
@ -25,6 +26,7 @@
<property name="skip_php_events">1</property>
<property name="skip_python_events">1</property>
<property name="ui_table">UI</property>
<property name="use_array_enum">0</property>
<property name="use_enum">1</property>
<property name="use_microsoft_bom">0</property>
<object class="Dialog" expanded="1">
@ -43,13 +45,14 @@
<property name="id">wxID_ANY</property>
<property name="maximum_size"></property>
<property name="minimum_size"></property>
<property name="name">DIALOG_NETLIST_BASE</property>
<property name="name">DIALOG_NETLIST_IMPORT_BASE</property>
<property name="pos"></property>
<property name="size">-1,-1</property>
<property name="style">wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER</property>
<property name="subclass">DIALOG_SHIM; dialog_shim.h</property>
<property name="title">Import Netlist</property>
<property name="tooltip"></property>
<property name="two_step_creation">0</property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
@ -206,6 +209,7 @@
<property name="aui_name"></property>
<property name="aui_position"></property>
<property name="aui_row"></property>
<property name="auth_needed">0</property>
<property name="best_size"></property>
<property name="bg"></property>
<property name="bitmap"></property>
@ -263,7 +267,7 @@
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnButtonClick">OnOpenNetlistClick</event>
<event name="OnButtonClick">onBrowseNetlistFiles</event>
</object>
</object>
</object>
@ -637,7 +641,7 @@
<property name="flag">wxEXPAND</property>
<property name="proportion">1</property>
<object class="wxStdDialogButtonSizer" expanded="1">
<property name="Apply">0</property>
<property name="Apply">1</property>
<property name="Cancel">1</property>
<property name="ContextHelp">0</property>
<property name="Help">0</property>
@ -646,9 +650,10 @@
<property name="Save">0</property>
<property name="Yes">0</property>
<property name="minimum_size"></property>
<property name="name">m_sdbSizer1</property>
<property name="name">m_sdbSizer</property>
<property name="permission">protected</property>
<event name="OnOKButtonClick">OnUpdatePCB</event>
<event name="OnApplyButtonClick">onUpdatePCB</event>
<event name="OnOKButtonClick">onImportNetlist</event>
</object>
</object>
</object>

View File

@ -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();
};