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.
This commit is contained in:
Jeff Young 2022-12-23 17:39:28 +00:00
parent 604d7a72d6
commit bfd3b40672
4 changed files with 24 additions and 22 deletions

View File

@ -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<SCH_SYMBOL*>( item );
if( symbol )
{ {
if( item == aSymbol ) SIM_LIB_MGR mgr( &Prj() );
{ SIM_MODEL& model = mgr.CreateModel( &sheet, *symbol ).model;
SIM_LIB_MGR mgr( &Prj() );
SIM_MODEL& model = mgr.CreateModel( &m_schematicFrame->GetCurrentSheet(),
*aSymbol ).model;
const SIM_MODEL::PARAM* tunerParam = model.GetTunerParam(); const SIM_MODEL::PARAM* tunerParam = model.GetTunerParam();
if( !tunerParam ) if( !tunerParam )
return; return;
model.SetParamValue( tunerParam->info.name, std::string( aValue.ToUTF8() ) ); model.SetParamValue( tunerParam->info.name, std::string( aValue.ToUTF8() ) );
model.WriteFields( aSymbol->GetFields() ); model.WriteFields( symbol->GetFields() );
m_schematicFrame->UpdateItem( aSymbol, false, true ); m_schematicFrame->UpdateItem( symbol, false, true );
m_schematicFrame->OnModify(); m_schematicFrame->OnModify();
}
} }
} }

View File

@ -112,11 +112,11 @@ public:
* Safely update a field of the associated symbol without dereferencing * Safely update a field of the associated symbol without dereferencing
* the symbol. * 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 aId id of the symbol field
* @param aValue new value 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). * Return the currently opened plot panel (or NULL if there is none).

View File

@ -38,7 +38,7 @@
TUNER_SLIDER::TUNER_SLIDER( SIM_PLOT_FRAME* aFrame, wxWindow* aParent, SCH_SYMBOL* aSymbol ) : TUNER_SLIDER::TUNER_SLIDER( SIM_PLOT_FRAME* aFrame, wxWindow* aParent, SCH_SYMBOL* aSymbol ) :
TUNER_SLIDER_BASE( aParent ), TUNER_SLIDER_BASE( aParent ),
m_symbol( aSymbol ), m_symbol( aSymbol->m_Uuid ),
m_min( 0.0 ), m_min( 0.0 ),
m_max( 0.0 ), m_max( 0.0 ),
m_value( 0.0 ), m_value( 0.0 ),

View File

@ -92,13 +92,15 @@ private:
///< Timer that restarts the simulation after the slider value has changed ///< Timer that restarts the simulation after the slider value has changed
wxTimer m_simTimer; wxTimer m_simTimer;
SCH_SYMBOL* m_symbol; KIID m_symbol;
const SPICE_ITEM* m_item; const SPICE_ITEM* m_item;
SPICE_VALUE m_min, m_max, m_value; SPICE_VALUE m_min;
bool m_changed; 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 */ #endif /* TUNER_SLIDER_H */