From bfd3b406728ffe6d852ce4fca459ea12fe56044a Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 23 Dec 2022 17:39:28 +0000 Subject: [PATCH] Bug fixes for tuning. 1) Don't save SCH_ITEM pointers in long-lived structures. Use KIIDs instead. 2) Use the correct sheet for the referenced item, not the current sheet. --- eeschema/sim/sim_plot_frame.cpp | 30 +++++++++++++++--------------- eeschema/sim/sim_plot_frame.h | 4 ++-- eeschema/widgets/tuner_slider.cpp | 2 +- eeschema/widgets/tuner_slider.h | 10 ++++++---- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/eeschema/sim/sim_plot_frame.cpp b/eeschema/sim/sim_plot_frame.cpp index 2a4fff6fe2..006e08f87a 100644 --- a/eeschema/sim/sim_plot_frame.cpp +++ b/eeschema/sim/sim_plot_frame.cpp @@ -601,27 +601,27 @@ void SIM_PLOT_FRAME::AddTuner( SCH_SYMBOL* aSymbol ) } -void SIM_PLOT_FRAME::UpdateTunerValue( SCH_SYMBOL* aSymbol, const wxString& aValue ) +void SIM_PLOT_FRAME::UpdateTunerValue( const KIID& aSymbol, const wxString& aValue ) { - for( EDA_ITEM* item : m_schematicFrame->GetScreen()->Items().OfType( SCH_SYMBOL_T ) ) + SCH_SHEET_PATH sheet; + SCH_ITEM* item = m_schematicFrame->Schematic().GetSheets().GetItem( aSymbol, &sheet ); + SCH_SYMBOL* symbol = dynamic_cast( item ); + + if( symbol ) { - if( item == aSymbol ) - { - SIM_LIB_MGR mgr( &Prj() ); - SIM_MODEL& model = mgr.CreateModel( &m_schematicFrame->GetCurrentSheet(), - *aSymbol ).model; + SIM_LIB_MGR mgr( &Prj() ); + SIM_MODEL& model = mgr.CreateModel( &sheet, *symbol ).model; - const SIM_MODEL::PARAM* tunerParam = model.GetTunerParam(); + const SIM_MODEL::PARAM* tunerParam = model.GetTunerParam(); - if( !tunerParam ) - return; + if( !tunerParam ) + return; - model.SetParamValue( tunerParam->info.name, std::string( aValue.ToUTF8() ) ); - model.WriteFields( aSymbol->GetFields() ); + model.SetParamValue( tunerParam->info.name, std::string( aValue.ToUTF8() ) ); + model.WriteFields( symbol->GetFields() ); - m_schematicFrame->UpdateItem( aSymbol, false, true ); - m_schematicFrame->OnModify(); - } + m_schematicFrame->UpdateItem( symbol, false, true ); + m_schematicFrame->OnModify(); } } diff --git a/eeschema/sim/sim_plot_frame.h b/eeschema/sim/sim_plot_frame.h index ee8f77137f..f51896d0a8 100644 --- a/eeschema/sim/sim_plot_frame.h +++ b/eeschema/sim/sim_plot_frame.h @@ -112,11 +112,11 @@ public: * Safely update a field of the associated symbol without dereferencing * the symbol. * - * @param aSymbol pointer to the symbol needing updating + * @param aSymbol id of the symbol needing updating * @param aId id of the symbol field * @param aValue new value of the symbol field */ - void UpdateTunerValue( SCH_SYMBOL* aSymbol, const wxString& aValue ); + void UpdateTunerValue( const KIID& 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 1a4d2829d7..5139a1fcae 100644 --- a/eeschema/widgets/tuner_slider.cpp +++ b/eeschema/widgets/tuner_slider.cpp @@ -38,7 +38,7 @@ TUNER_SLIDER::TUNER_SLIDER( SIM_PLOT_FRAME* aFrame, wxWindow* aParent, SCH_SYMBOL* aSymbol ) : TUNER_SLIDER_BASE( aParent ), - m_symbol( aSymbol ), + m_symbol( aSymbol->m_Uuid ), m_min( 0.0 ), m_max( 0.0 ), m_value( 0.0 ), diff --git a/eeschema/widgets/tuner_slider.h b/eeschema/widgets/tuner_slider.h index 8edd07ed65..44f3e2c7bd 100644 --- a/eeschema/widgets/tuner_slider.h +++ b/eeschema/widgets/tuner_slider.h @@ -92,13 +92,15 @@ private: ///< Timer that restarts the simulation after the slider value has changed wxTimer m_simTimer; - SCH_SYMBOL* m_symbol; + KIID m_symbol; const SPICE_ITEM* m_item; - SPICE_VALUE m_min, m_max, m_value; - bool m_changed; + SPICE_VALUE m_min; + SPICE_VALUE m_max; + SPICE_VALUE m_value; + bool m_changed; - SIM_PLOT_FRAME* m_frame; + SIM_PLOT_FRAME* m_frame; }; #endif /* TUNER_SLIDER_H */