From 9e760512ac652c776941c68d4dda531c9ec531bb Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Mon, 1 Nov 2021 17:04:09 -0700 Subject: [PATCH] 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 --- eeschema/sim/sim_plot_frame.cpp | 16 ++++++++++++++++ eeschema/sim/sim_plot_frame.h | 9 +++++++++ eeschema/widgets/tuner_slider.cpp | 3 +-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/eeschema/sim/sim_plot_frame.cpp b/eeschema/sim/sim_plot_frame.cpp index 2a3b2d583b..857ecce5be 100644 --- a/eeschema/sim/sim_plot_frame.cpp +++ b/eeschema/sim/sim_plot_frame.cpp @@ -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 ) { diff --git a/eeschema/sim/sim_plot_frame.h b/eeschema/sim/sim_plot_frame.h index c009f08290..802195445f 100644 --- a/eeschema/sim/sim_plot_frame.h +++ b/eeschema/sim/sim_plot_frame.h @@ -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). */ diff --git a/eeschema/widgets/tuner_slider.cpp b/eeschema/widgets/tuner_slider.cpp index 27ece33153..0a8310d7e3 100644 --- a/eeschema/widgets/tuner_slider.cpp +++ b/eeschema/widgets/tuner_slider.cpp @@ -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() ); }