7
mirror of https://gitlab.com/kicad/code/kicad.git synced 2025-04-07 18:45:32 +00:00

Simulation model lib is not sorted, but listbox is.

Don't attempt to use an index from one in the other.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/19306
This commit is contained in:
Jeff Young 2024-12-21 14:27:23 +00:00
parent aaf94ecbad
commit bc29c145af
2 changed files with 28 additions and 6 deletions

View File

@ -253,7 +253,12 @@ bool DIALOG_SIM_MODEL<T>::TransferDataToWindow()
if( isIbisLoaded() && ( m_modelListBox->GetSelection() >= 0 ) )
{
int idx = m_modelListBox->GetSelection();
int idx = 0;
wxString sel = m_modelListBox->GetStringSelection();
if( m_modelListBoxEntryToLibraryIdx.contains( sel ) )
idx = m_modelListBoxEntryToLibraryIdx.at( sel );
auto ibismodel = dynamic_cast<SIM_MODEL_IBIS*>( &m_libraryModelsMgr.GetModels()[idx].get() );
if( ibismodel )
@ -375,8 +380,13 @@ bool DIALOG_SIM_MODEL<T>::TransferDataFromWindow()
if( isIbisLoaded() )
{
SIM_MODEL_IBIS* ibismodel = static_cast<SIM_MODEL_IBIS*>(
&m_libraryModelsMgr.GetModels().at( m_modelListBox->GetSelection() ).get() );
int idx = 0;
wxString sel = m_modelListBox->GetStringSelection();
if( m_modelListBoxEntryToLibraryIdx.contains( sel ) )
idx = m_modelListBoxEntryToLibraryIdx.at( sel );
auto* ibismodel = static_cast<SIM_MODEL_IBIS*>( &m_libraryModelsMgr.GetModels().at( idx ).get() );
if( ibismodel )
{
@ -832,10 +842,14 @@ bool DIALOG_SIM_MODEL<T>::loadLibrary( const wxString& aLibraryPath, REPORTER& a
m_rbLibraryModel->SetValue( true );
m_libraryPathText->ChangeValue( aLibraryPath );
m_modelListBoxEntryToLibraryIdx.clear();
wxArrayString modelNames;
for( const auto& [name, model] : library()->GetModels() )
{
modelNames.Add( name );
m_modelListBoxEntryToLibraryIdx[name] = m_modelListBoxEntryToLibraryIdx.size();
}
modelNames.Sort();
@ -1084,8 +1098,10 @@ SIM_MODEL& DIALOG_SIM_MODEL<T>::curModel() const
{
if( m_rbLibraryModel->GetValue() )
{
if( library() && m_modelListBox->GetSelection() >= 0 )
return *library()->FindModel( m_modelListBox->GetStringSelection().ToStdString() );
wxString sel = m_modelListBox->GetStringSelection();
if( m_modelListBoxEntryToLibraryIdx.contains( sel ) )
return m_libraryModelsMgr.GetModels().at( m_modelListBoxEntryToLibraryIdx.at( sel ) ).get();
}
else
{
@ -1453,7 +1469,11 @@ void DIALOG_SIM_MODEL<T>::onWaveformChoice( wxCommandEvent& aEvent )
if( equivalent( deviceType, SIM_MODEL::TypeInfo( type ).deviceType )
&& typeDescription == SIM_MODEL::TypeInfo( type ).description )
{
int idx = m_modelListBox->GetSelection();
int idx = 0;
wxString sel = m_modelListBox->GetStringSelection();
if( m_modelListBoxEntryToLibraryIdx.contains( sel ) )
idx = m_modelListBoxEntryToLibraryIdx.at( sel );
auto& baseModel = static_cast<SIM_MODEL_IBIS&>( m_libraryModelsMgr.GetModels()[idx].get() );

View File

@ -133,6 +133,8 @@ private:
wxString m_prevLibrary;
const SIM_MODEL* m_prevModel;
std::map<wxString, int> m_modelListBoxEntryToLibraryIdx;
std::vector<SCH_PIN*> m_sortedPartPins; //< Pins of the current part.
std::map<SIM_MODEL::DEVICE_T, SIM_MODEL::TYPE> m_curModelTypeOfDeviceType;
SIM_MODEL::TYPE m_curModelType;