Make SIM_MODEL_SPICE_FALLBACK act more like the model it's a fallback for.

In particular, install/show the parameters, and keep the existing name
field.

Fixes https://gitlab.com/kicad/code/kicad/issues/14102
This commit is contained in:
Jeff Young 2023-02-28 12:20:45 +00:00
parent a87550a2c6
commit 281fde71b9
3 changed files with 55 additions and 19 deletions

View File

@ -162,6 +162,14 @@ bool DIALOG_SIM_MODEL<T_symbol, T_field>::TransferDataToWindow()
m_fields[ VALUE_FIELD ].SetText( wxT( "${SIM.PARAMS}" ) );
}
std::vector<LIB_PIN*> sourcePins = m_symbol.GetAllLibPins();
std::sort( sourcePins.begin(), sourcePins.end(),
[]( const LIB_PIN* lhs, const LIB_PIN* rhs )
{
return StrNumCmp( lhs->GetNumber(), rhs->GetNumber(), true ) < 0;
} );
std::string libraryFilename = SIM_MODEL::GetFieldValue( &m_fields, SIM_LIBRARY::LIBRARY_FIELD );
if( libraryFilename != "" )
@ -172,8 +180,11 @@ bool DIALOG_SIM_MODEL<T_symbol, T_field>::TransferDataToWindow()
if( !loadLibrary( libraryFilename ) )
{
m_libraryPathText->ChangeValue( libraryFilename );
m_modelNameChoice->SetSelection( -1 );
m_curModelType = SIM_MODEL::ReadTypeFromFields( m_fields );
m_libraryModelsMgr.CreateModel( nullptr, sourcePins, m_fields );
m_modelNameChoice->Append( _( "<unknown>" ) );
m_modelNameChoice->SetSelection( 0 );
}
else
{
@ -248,14 +259,6 @@ bool DIALOG_SIM_MODEL<T_symbol, T_field>::TransferDataToWindow()
m_curModelType = SIM_MODEL::ReadTypeFromFields( m_fields );
}
std::vector<LIB_PIN*> sourcePins = m_symbol.GetAllLibPins();
std::sort( sourcePins.begin(), sourcePins.end(),
[]( const LIB_PIN* lhs, const LIB_PIN* rhs )
{
return StrNumCmp( lhs->GetNumber(), rhs->GetNumber(), true ) < 0;
} );
for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
{
wxString msg;
@ -309,7 +312,9 @@ bool DIALOG_SIM_MODEL<T_symbol, T_field>::TransferDataFromWindow()
if( fn.MakeRelativeTo( Prj().GetProjectPath() ) && !fn.GetFullPath().StartsWith( ".." ) )
path = fn.GetFullPath();
if( !m_modelNameChoice->IsEmpty() )
if( dynamic_cast<SIM_MODEL_SPICE_FALLBACK*>( &curModel() ) )
name = SIM_MODEL::GetFieldValue( &m_fields, SIM_LIBRARY::NAME_FIELD, false );
else if( !m_modelNameChoice->IsEmpty() )
name = m_modelNameChoice->GetStringSelection().ToStdString();
}
@ -436,15 +441,10 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::updateInstanceWidgets( SIM_MODEL* aMod
m_typeChoice->Enable( !m_useLibraryModelRadioButton->GetValue() || isIbisLoaded() );
if( dynamic_cast<SIM_MODEL_RAW_SPICE*>( aModel )
|| dynamic_cast<SIM_MODEL_SPICE_FALLBACK*>( aModel ) )
{
if( dynamic_cast<SIM_MODEL_RAW_SPICE*>( aModel ) )
m_modelNotebook->SetSelection( 1 );
}
else
{
m_modelNotebook->SetSelection( 0 );
}
if( aModel->HasPrimaryValue() )
{
@ -562,6 +562,9 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::updateModelParamsTab( SIM_MODEL* aMode
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::updateModelCodeTab( SIM_MODEL* aModel )
{
if( dynamic_cast<SIM_MODEL_SPICE_FALLBACK*>( aModel ) )
return;
wxString text;
SPICE_ITEM item;

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -23,11 +23,18 @@
#include <sim/sim_model_spice_fallback.h>
#include <fmt/format.h>
#include <boost/algorithm/string/case_conv.hpp>
SIM_MODEL_SPICE_FALLBACK::SIM_MODEL_SPICE_FALLBACK( TYPE aType, const std::string& aRawSpiceCode ) :
SIM_MODEL_SPICE( aType, std::make_unique<SPICE_GENERATOR_SPICE>( *this ) )
{
// Create the model we *should* have had to copy its parameter list
std::unique_ptr<SIM_MODEL> model = SIM_MODEL::Create( aType );
for( const SIM_MODEL::PARAM& param : model->GetParams() )
AddParam( param.info );
m_spiceCode = aRawSpiceCode;
}
@ -53,4 +60,26 @@ std::vector<std::string> SIM_MODEL_SPICE_FALLBACK::GetPinNames() const
// If we're a fall-back for a paticular model type, then return its pin names
std::unique_ptr<SIM_MODEL> model = SIM_MODEL::Create( GetType() );
return model->GetPinNames();
}
}
int SIM_MODEL_SPICE_FALLBACK::doFindParam( const std::string& aParamName ) const
{
// Special case to allow escaped model parameters (suffixed with "_")
std::string lowerParamName = boost::to_lower_copy( aParamName );
std::vector<std::reference_wrapper<const PARAM>> params = GetParams();
for( int ii = 0; ii < (int) params.size(); ++ii )
{
const PARAM& param = params[ii];
if( param.info.name == lowerParamName || param.info.name == lowerParamName + "_" )
return ii;
}
return -1;
}

View File

@ -1,7 +1,7 @@
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors.
* Copyright (C) 2022-2023 KiCad Developers, see AUTHORS.txt for contributors.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
@ -36,6 +36,10 @@ public:
const std::string& aSymbolPinNumber ) override;
std::vector<std::string> GetPinNames() const override;
protected:
int doFindParam( const std::string& aParamName ) const override;
};
#endif // SIM_MODEL_SPICE_FALLBACK_H