Update schematic when saving tuned value

Also avoids a known(!) crash when the existing item has been deleted
while tuning.

Fixes https://gitlab.com/kicad/code/kicad/issues/9502
This commit is contained in:
Seth Hillbrand 2021-11-01 17:04:09 -07:00
parent f79cb382c4
commit 9e760512ac
3 changed files with 26 additions and 2 deletions

View File

@ -572,6 +572,22 @@ void SIM_PLOT_FRAME::AddTuner( SCH_SYMBOL* aSymbol )
}
}
void SIM_PLOT_FRAME::UpdateTunerValue( SCH_SYMBOL* aSymbol, const wxString& aValue )
{
for( auto& item : m_schematicFrame->GetScreen()->Items().OfType( SCH_SYMBOL_T ) )
{
if( item == aSymbol )
{
aSymbol->SetValue( aValue );
m_schematicFrame->UpdateItem( aSymbol, false, true );
m_schematicFrame->OnModify();
break;
}
}
}
void SIM_PLOT_FRAME::RemoveTuner( TUNER_SLIDER* aTuner, bool aErase )
{

View File

@ -109,6 +109,15 @@ public:
*/
void RemoveTuner( TUNER_SLIDER* aTuner, bool aErase = true );
/**
* Safely update the value of the associated symbol without dereferencing
* the symbol.
*
* @param aSymbol pointer to the symbol needing updating
* @param aValue new value of the symbol
*/
void UpdateTunerValue( SCH_SYMBOL* aSymbol, const wxString& aValue );
/**
* Return the currently opened plot panel (or NULL if there is none).
*/

View File

@ -185,8 +185,7 @@ void TUNER_SLIDER::onClose( wxCommandEvent& event )
void TUNER_SLIDER::onSave( wxCommandEvent& event )
{
/// @todo it will crash when component is removed; completely remove m_symbol
m_symbol->GetField( VALUE_FIELD )->SetText( m_value.ToOrigString() );
m_frame->UpdateTunerValue( m_symbol, m_value.ToOrigString() );
}