Eeschema: fix crash when attempting to edit missing library symbol.

Disable the edit symbol buttons in the symbol properties dialog when
there is no library symbol to edit.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/11318

(cherry picked from commit 5afeb45a84)
This commit is contained in:
Wayne Stambaugh 2022-09-02 15:48:10 -04:00
parent cfdf6c097d
commit 4c096fee15
9 changed files with 57 additions and 3 deletions

View File

@ -1209,3 +1209,16 @@ void DIALOG_SYMBOL_PROPERTIES::OnUnitChoice( wxCommandEvent& event )
OnModify(); OnModify();
} }
void DIALOG_SYMBOL_PROPERTIES::onUpdateEditSymbol( wxUpdateUIEvent& event )
{
event.Enable( m_symbol && m_symbol->GetLibSymbolRef() );
}
void DIALOG_SYMBOL_PROPERTIES::onUpdateEditLibrarySymbol( wxUpdateUIEvent& event )
{
event.Enable( m_symbol && m_symbol->GetLibSymbolRef() );
}

View File

@ -95,6 +95,11 @@ private:
void HandleDelayedFocus( wxCommandEvent& event ); void HandleDelayedFocus( wxCommandEvent& event );
void HandleDelayedSelection( wxCommandEvent& event ); void HandleDelayedSelection( wxCommandEvent& event );
virtual void onUpdateEditSymbol( wxUpdateUIEvent& event ) override;
virtual void onUpdateEditLibrarySymbol( wxUpdateUIEvent& event ) override;
void AdjustGridColumns( int aWidth );
private: private:
SCH_SYMBOL* m_symbol; SCH_SYMBOL* m_symbol;
LIB_SYMBOL* m_part; LIB_SYMBOL* m_part;

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.10.0-39-g3487c3cb) // C++ code generated with wxFormBuilder (version 3.10.0-4761b0c5)
// http://www.wxformbuilder.org/ // http://www.wxformbuilder.org/
// //
// PLEASE DO *NOT* EDIT THIS FILE! // PLEASE DO *NOT* EDIT THIS FILE!
@ -363,7 +363,9 @@ DIALOG_SYMBOL_PROPERTIES_BASE::DIALOG_SYMBOL_PROPERTIES_BASE( wxWindow* parent,
m_updateSymbolBtn->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::OnUpdateSymbol ), NULL, this ); m_updateSymbolBtn->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::OnUpdateSymbol ), NULL, this );
m_changeSymbolBtn->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::OnExchangeSymbol ), NULL, this ); m_changeSymbolBtn->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::OnExchangeSymbol ), NULL, this );
m_editSchematicSymbolBtn->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::OnEditSymbol ), NULL, this ); m_editSchematicSymbolBtn->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::OnEditSymbol ), NULL, this );
m_editSchematicSymbolBtn->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::onUpdateEditSymbol ), NULL, this );
m_editLibrarySymbolBtn->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::OnEditLibrarySymbol ), NULL, this ); m_editLibrarySymbolBtn->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::OnEditLibrarySymbol ), NULL, this );
m_editLibrarySymbolBtn->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::onUpdateEditLibrarySymbol ), NULL, this );
m_pinGrid->Connect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::OnPinTableCellEdited ), NULL, this ); m_pinGrid->Connect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::OnPinTableCellEdited ), NULL, this );
m_pinGrid->Connect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::OnSizePinsGrid ), NULL, this ); m_pinGrid->Connect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::OnSizePinsGrid ), NULL, this );
m_spiceFieldsButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::OnEditSpiceModel ), NULL, this ); m_spiceFieldsButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::OnEditSpiceModel ), NULL, this );
@ -393,7 +395,9 @@ DIALOG_SYMBOL_PROPERTIES_BASE::~DIALOG_SYMBOL_PROPERTIES_BASE()
m_updateSymbolBtn->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::OnUpdateSymbol ), NULL, this ); m_updateSymbolBtn->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::OnUpdateSymbol ), NULL, this );
m_changeSymbolBtn->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::OnExchangeSymbol ), NULL, this ); m_changeSymbolBtn->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::OnExchangeSymbol ), NULL, this );
m_editSchematicSymbolBtn->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::OnEditSymbol ), NULL, this ); m_editSchematicSymbolBtn->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::OnEditSymbol ), NULL, this );
m_editSchematicSymbolBtn->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::onUpdateEditSymbol ), NULL, this );
m_editLibrarySymbolBtn->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::OnEditLibrarySymbol ), NULL, this ); m_editLibrarySymbolBtn->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::OnEditLibrarySymbol ), NULL, this );
m_editLibrarySymbolBtn->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::onUpdateEditLibrarySymbol ), NULL, this );
m_pinGrid->Disconnect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::OnPinTableCellEdited ), NULL, this ); m_pinGrid->Disconnect( wxEVT_GRID_CELL_CHANGED, wxGridEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::OnPinTableCellEdited ), NULL, this );
m_pinGrid->Disconnect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::OnSizePinsGrid ), NULL, this ); m_pinGrid->Disconnect( wxEVT_SIZE, wxSizeEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::OnSizePinsGrid ), NULL, this );
m_spiceFieldsButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::OnEditSpiceModel ), NULL, this ); m_spiceFieldsButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SYMBOL_PROPERTIES_BASE::OnEditSpiceModel ), NULL, this );

View File

@ -1711,6 +1711,7 @@
<property name="window_name"></property> <property name="window_name"></property>
<property name="window_style"></property> <property name="window_style"></property>
<event name="OnButtonClick">OnEditSymbol</event> <event name="OnButtonClick">OnEditSymbol</event>
<event name="OnUpdateUI">onUpdateEditSymbol</event>
</object> </object>
</object> </object>
<object class="sizeritem" expanded="1"> <object class="sizeritem" expanded="1">
@ -1795,6 +1796,7 @@
<property name="window_name"></property> <property name="window_name"></property>
<property name="window_style"></property> <property name="window_style"></property>
<event name="OnButtonClick">OnEditLibrarySymbol</event> <event name="OnButtonClick">OnEditLibrarySymbol</event>
<event name="OnUpdateUI">onUpdateEditLibrarySymbol</event>
</object> </object>
</object> </object>
</object> </object>

View File

@ -1,5 +1,5 @@
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// C++ code generated with wxFormBuilder (version 3.10.0-39-g3487c3cb) // C++ code generated with wxFormBuilder (version 3.10.0-4761b0c5)
// http://www.wxformbuilder.org/ // http://www.wxformbuilder.org/
// //
// PLEASE DO *NOT* EDIT THIS FILE! // PLEASE DO *NOT* EDIT THIS FILE!
@ -94,7 +94,9 @@ class DIALOG_SYMBOL_PROPERTIES_BASE : public DIALOG_SHIM
virtual void OnUpdateSymbol( wxCommandEvent& event ) { event.Skip(); } virtual void OnUpdateSymbol( wxCommandEvent& event ) { event.Skip(); }
virtual void OnExchangeSymbol( wxCommandEvent& event ) { event.Skip(); } virtual void OnExchangeSymbol( wxCommandEvent& event ) { event.Skip(); }
virtual void OnEditSymbol( wxCommandEvent& event ) { event.Skip(); } virtual void OnEditSymbol( wxCommandEvent& event ) { event.Skip(); }
virtual void onUpdateEditSymbol( wxUpdateUIEvent& event ) { event.Skip(); }
virtual void OnEditLibrarySymbol( wxCommandEvent& event ) { event.Skip(); } virtual void OnEditLibrarySymbol( wxCommandEvent& event ) { event.Skip(); }
virtual void onUpdateEditLibrarySymbol( wxUpdateUIEvent& event ) { event.Skip(); }
virtual void OnPinTableCellEdited( wxGridEvent& event ) { event.Skip(); } virtual void OnPinTableCellEdited( wxGridEvent& event ) { event.Skip(); }
virtual void OnSizePinsGrid( wxSizeEvent& event ) { event.Skip(); } virtual void OnSizePinsGrid( wxSizeEvent& event ) { event.Skip(); }
virtual void OnEditSpiceModel( wxCommandEvent& event ) { event.Skip(); } virtual void OnEditSpiceModel( wxCommandEvent& event ) { event.Skip(); }

View File

@ -234,6 +234,15 @@ EDA_ITEM* SCH_SYMBOL::Clone() const
} }
bool SCH_SYMBOL::IsMissingLibSymbol() const
{
if( !m_part )
return true;
return false;
}
void SCH_SYMBOL::ViewGetLayers( int aLayers[], int& aCount ) const void SCH_SYMBOL::ViewGetLayers( int aLayers[], int& aCount ) const
{ {
aCount = 7; aCount = 7;

View File

@ -120,6 +120,21 @@ public:
return wxT( "SCH_SYMBOL" ); return wxT( "SCH_SYMBOL" );
} }
/**
* Check to see if the library symbol is set to the dummy library symbol.
*
* When the library symbol is missing (which technically should not happen now that the
* library symbols are cached in the schematic file), a dummy library symbol is substituted
* for the missing symbol as an indicator that something is amiss. The dummy symbol cannot
* be edited so a check for this symbol must be performed before attempting to edit the
* library symbol with the library editor or it will crash KiCad.
*
* @see dummy()
*
* @return true if the library symbol is missing or false if it is valid.
*/
bool IsMissingLibSymbol() const;
const std::vector<SYMBOL_INSTANCE_REFERENCE>& GetInstanceReferences() const std::vector<SYMBOL_INSTANCE_REFERENCE>& GetInstanceReferences()
{ {
return m_instanceReferences; return m_instanceReferences;

View File

@ -1527,6 +1527,10 @@ int SCH_EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
if( wxWindow* blocking_win = editor->Kiway().GetBlockingDialog() ) if( wxWindow* blocking_win = editor->Kiway().GetBlockingDialog() )
blocking_win->Close( true ); blocking_win->Close( true );
// The broken library symbol link indicator cannot be edited.
if( symbol->IsMissingLibSymbol() )
return 0;
editor->LoadSymbolFromSchematic( symbol ); editor->LoadSymbolFromSchematic( symbol );
editor->Show( true ); editor->Show( true );

View File

@ -2023,7 +2023,7 @@ int SCH_EDITOR_CONTROL::EditWithSymbolEditor( const TOOL_EVENT& aEvent )
if( selection.GetSize() >= 1 ) if( selection.GetSize() >= 1 )
symbol = (SCH_SYMBOL*) selection.Front(); symbol = (SCH_SYMBOL*) selection.Front();
if( !symbol || symbol->GetEditFlags() != 0 ) if( !symbol || symbol->GetEditFlags() != 0 || symbol->IsMissingLibSymbol() )
return 0; return 0;
m_toolMgr->RunAction( ACTIONS::showSymbolEditor, true ); m_toolMgr->RunAction( ACTIONS::showSymbolEditor, true );