Avoid netlist export dialog crash from trying to delete a non-custom format

Fixes https://gitlab.com/kicad/code/kicad/-/issues/12229
This commit is contained in:
Marek Roszko 2022-08-15 19:10:43 -04:00
parent e4ba1d4879
commit d4e4071be3
1 changed files with 40 additions and 22 deletions

View File

@ -83,8 +83,8 @@ public:
* @param title is the title of the notebook page. * @param title is the title of the notebook page.
* @param id_NetType is the netlist ID type. * @param id_NetType is the netlist ID type.
*/ */
NETLIST_PAGE_DIALOG( wxNotebook* parent, const wxString& title, NETLIST_PAGE_DIALOG( wxNotebook* aParent, const wxString& aTitle,
NETLIST_TYPE_ID id_NetType ); NETLIST_TYPE_ID aIdNetType, bool aCustom );
~NETLIST_PAGE_DIALOG() { }; ~NETLIST_PAGE_DIALOG() { };
/** /**
@ -103,8 +103,12 @@ public:
wxBoxSizer* m_RightOptionsBoxSizer; wxBoxSizer* m_RightOptionsBoxSizer;
wxBoxSizer* m_LowBoxSizer; wxBoxSizer* m_LowBoxSizer;
bool IsCustom() const { return m_custom; }
private: private:
wxString m_pageNetFmtName; wxString m_pageNetFmtName;
bool m_custom;
}; };
@ -126,6 +130,8 @@ private:
bool TransferDataFromWindow() override; bool TransferDataFromWindow() override;
void NetlistUpdateOpt(); void NetlistUpdateOpt();
void updateGeneratorButtons();
// Called when changing the notebook page (and therefore the current netlist format) // Called when changing the notebook page (and therefore the current netlist format)
void OnNetlistTypeSelection( wxNotebookEvent& event ) override; void OnNetlistTypeSelection( wxNotebookEvent& event ) override;
@ -208,18 +214,19 @@ BEGIN_EVENT_TABLE( NETLIST_DIALOG, NETLIST_DIALOG_BASE )
END_EVENT_TABLE() END_EVENT_TABLE()
NETLIST_PAGE_DIALOG::NETLIST_PAGE_DIALOG( wxNotebook* parent, const wxString& title, NETLIST_PAGE_DIALOG::NETLIST_PAGE_DIALOG( wxNotebook* aParent, const wxString& aTitle,
NETLIST_TYPE_ID id_NetType ) : NETLIST_TYPE_ID aIdNetType, bool aCustom ) :
wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ) wxPanel( aParent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL )
{ {
m_IdNetType = id_NetType; m_IdNetType = aIdNetType;
m_pageNetFmtName = title; m_pageNetFmtName = aTitle;
m_CommandStringCtrl = nullptr; m_CommandStringCtrl = nullptr;
m_TitleStringCtrl = nullptr; m_TitleStringCtrl = nullptr;
m_SaveAllVoltages = nullptr; m_SaveAllVoltages = nullptr;
m_SaveAllCurrents = nullptr; m_SaveAllCurrents = nullptr;
m_custom = aCustom;
parent->AddPage( this, title, false ); aParent->AddPage( this, aTitle, false );
wxBoxSizer* MainBoxSizer = new wxBoxSizer( wxVERTICAL ); wxBoxSizer* MainBoxSizer = new wxBoxSizer( wxVERTICAL );
SetSizer( MainBoxSizer ); SetSizer( MainBoxSizer );
@ -248,14 +255,14 @@ NETLIST_DIALOG::NETLIST_DIALOG( SCH_EDIT_FRAME* parent ) :
page = nullptr; page = nullptr;
// Add notebook pages: // Add notebook pages:
m_PanelNetType[PANELPCBNEW] = new NETLIST_PAGE_DIALOG( m_NoteBook, wxT( "KiCad" ), m_PanelNetType[PANELPCBNEW] =
NET_TYPE_PCBNEW ); new NETLIST_PAGE_DIALOG( m_NoteBook, wxT( "KiCad" ), NET_TYPE_PCBNEW, false );
m_PanelNetType[PANELORCADPCB2] = new NETLIST_PAGE_DIALOG( m_NoteBook, wxT( "OrcadPCB2" ), m_PanelNetType[PANELORCADPCB2] =
NET_TYPE_ORCADPCB2 ); new NETLIST_PAGE_DIALOG( m_NoteBook, wxT( "OrcadPCB2" ), NET_TYPE_ORCADPCB2, false );
m_PanelNetType[PANELCADSTAR] = new NETLIST_PAGE_DIALOG( m_NoteBook, wxT( "CadStar" ), m_PanelNetType[PANELCADSTAR] =
NET_TYPE_CADSTAR ); new NETLIST_PAGE_DIALOG( m_NoteBook, wxT( "CadStar" ), NET_TYPE_CADSTAR, false );
InstallPageSpice(); InstallPageSpice();
InstallCustomPages(); InstallCustomPages();
@ -274,6 +281,8 @@ NETLIST_DIALOG::NETLIST_DIALOG( SCH_EDIT_FRAME* parent ) :
// Now all widgets have the size fixed, call FinishDialogSettings // Now all widgets have the size fixed, call FinishDialogSettings
finishDialogSettings(); finishDialogSettings();
updateGeneratorButtons();
} }
@ -325,7 +334,7 @@ void NETLIST_DIALOG::OnRunSpiceButtUI( wxUpdateUIEvent& aEvent )
void NETLIST_DIALOG::InstallPageSpice() void NETLIST_DIALOG::InstallPageSpice()
{ {
NETLIST_PAGE_DIALOG* page = m_PanelNetType[PANELSPICE] = NETLIST_PAGE_DIALOG* page = m_PanelNetType[PANELSPICE] =
new NETLIST_PAGE_DIALOG( m_NoteBook, wxT( "Spice" ), NET_TYPE_SPICE ); new NETLIST_PAGE_DIALOG( m_NoteBook, wxT( "Spice" ), NET_TYPE_SPICE, false );
SCHEMATIC_SETTINGS& settings = m_Parent->Schematic().Settings(); SCHEMATIC_SETTINGS& settings = m_Parent->Schematic().Settings();
@ -397,7 +406,7 @@ NETLIST_PAGE_DIALOG* NETLIST_DIALOG::AddOneCustomPage( const wxString& aTitle,
const wxString& aCommandString, const wxString& aCommandString,
NETLIST_TYPE_ID aNetTypeId ) NETLIST_TYPE_ID aNetTypeId )
{ {
NETLIST_PAGE_DIALOG* currPage = new NETLIST_PAGE_DIALOG( m_NoteBook, aTitle, aNetTypeId ); NETLIST_PAGE_DIALOG* currPage = new NETLIST_PAGE_DIALOG( m_NoteBook, aTitle, aNetTypeId, true );
currPage->m_LowBoxSizer->Add( new wxStaticText( currPage, -1, _( "Title:" ) ), 0, currPage->m_LowBoxSizer->Add( new wxStaticText( currPage, -1, _( "Title:" ) ), 0,
wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 ); wxGROW | wxLEFT | wxRIGHT | wxTOP, 5 );
@ -425,12 +434,7 @@ NETLIST_PAGE_DIALOG* NETLIST_DIALOG::AddOneCustomPage( const wxString& aTitle,
void NETLIST_DIALOG::OnNetlistTypeSelection( wxNotebookEvent& event ) void NETLIST_DIALOG::OnNetlistTypeSelection( wxNotebookEvent& event )
{ {
NETLIST_PAGE_DIALOG* currPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage(); updateGeneratorButtons();
if( currPage == nullptr )
return;
m_buttonDelGenerator->Enable( currPage->m_IdNetType >= NET_TYPE_CUSTOM1 );
} }
@ -606,6 +610,9 @@ void NETLIST_DIALOG::OnDelGenerator( wxCommandEvent& event )
{ {
NETLIST_PAGE_DIALOG* currPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage(); NETLIST_PAGE_DIALOG* currPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage();
if( !currPage->IsCustom() )
return;
currPage->m_CommandStringCtrl->SetValue( wxEmptyString ); currPage->m_CommandStringCtrl->SetValue( wxEmptyString );
currPage->m_TitleStringCtrl->SetValue( wxEmptyString ); currPage->m_TitleStringCtrl->SetValue( wxEmptyString );
@ -730,6 +737,17 @@ void NETLIST_DIALOG_ADD_GENERATOR::OnBrowseGenerators( wxCommandEvent& event )
} }
void NETLIST_DIALOG::updateGeneratorButtons()
{
NETLIST_PAGE_DIALOG* currPage = (NETLIST_PAGE_DIALOG*) m_NoteBook->GetCurrentPage();
if( currPage == nullptr )
return;
m_buttonDelGenerator->Enable( currPage->IsCustom() );
}
int InvokeDialogNetList( SCH_EDIT_FRAME* aCaller ) int InvokeDialogNetList( SCH_EDIT_FRAME* aCaller )
{ {
NETLIST_DIALOG dlg( aCaller ); NETLIST_DIALOG dlg( aCaller );