Move model inference to SIM_MODEL so it can also be used for behavioral models.
Fixes https://gitlab.com/kicad/code/kicad/issues/12505
This commit is contained in:
parent
aff5245041
commit
3ae404f764
|
@ -230,20 +230,28 @@ bool NETLIST_EXPORTER_SPICE::ReadSchematicAndLibraries( unsigned aNetlistOptions
|
|||
spiceItem.fields.back().SetText( symbol->GetFields()[i].GetShownText( 0, false ) );
|
||||
}
|
||||
|
||||
// Infer RLC passive models if they aren't specified
|
||||
// Infer RLC models if they aren't specified
|
||||
if( !symbol->FindField( SIM_MODEL::DEVICE_TYPE_FIELD, false )
|
||||
&& !symbol->FindField( SIM_MODEL::PARAMS_FIELD, false ) )
|
||||
{
|
||||
wxString simParams = SIM_MODEL_IDEAL::InferSimParams( symbol->GetPrefix(),
|
||||
symbol->GetValueFieldText( true ) );
|
||||
// pair.first: wxString sim model type
|
||||
// pair.second: wxString sim model parameters
|
||||
auto model = SIM_MODEL_IDEAL::InferSimModel( symbol->GetPrefix(),
|
||||
symbol->GetValueFieldText( true ) );
|
||||
|
||||
if( !simParams.IsEmpty() )
|
||||
if( !model.second.IsEmpty() )
|
||||
{
|
||||
spiceItem.fields.emplace_back( VECTOR2I(), -1, symbol, SIM_MODEL::DEVICE_TYPE_FIELD );
|
||||
spiceItem.fields.back().SetText( symbol->GetPrefix() );
|
||||
|
||||
if( !model.first.IsEmpty() )
|
||||
{
|
||||
spiceItem.fields.emplace_back( VECTOR2I(), -1, symbol, SIM_MODEL::TYPE_FIELD );
|
||||
spiceItem.fields.back().SetText( model.first );
|
||||
}
|
||||
|
||||
spiceItem.fields.emplace_back( VECTOR2I(), -1, symbol, SIM_MODEL::PARAMS_FIELD );
|
||||
spiceItem.fields.back().SetText( simParams );
|
||||
spiceItem.fields.back().SetText( model.second );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -140,20 +140,28 @@ SIM_LIBRARY::MODEL SIM_LIB_MGR::CreateModel( const SCH_SHEET_PATH* aSheetPath, S
|
|||
fields.back().SetText( aSymbol.GetFields()[ i ].GetShownText( 0, false ) );
|
||||
}
|
||||
|
||||
// Infer RLC passive models if they aren't specified
|
||||
// Infer RLC models if they aren't specified
|
||||
if( !aSymbol.FindField( SIM_MODEL::DEVICE_TYPE_FIELD, false )
|
||||
&& !aSymbol.FindField( SIM_MODEL::PARAMS_FIELD, false ) )
|
||||
{
|
||||
wxString simParams = SIM_MODEL_IDEAL::InferSimParams( aSymbol.GetPrefix(),
|
||||
aSymbol.GetValueFieldText( true ) );
|
||||
// pair.first: wxString sim model type
|
||||
// pair.second: wxString sim model parameters
|
||||
auto model = SIM_MODEL_IDEAL::InferSimModel( aSymbol.GetPrefix(),
|
||||
aSymbol.GetValueFieldText( true ) );
|
||||
|
||||
if( !simParams.IsEmpty() )
|
||||
if( !model.second.IsEmpty() )
|
||||
{
|
||||
fields.emplace_back( VECTOR2I(), -1, &aSymbol, SIM_MODEL::DEVICE_TYPE_FIELD );
|
||||
fields.back().SetText( aSymbol.GetPrefix() );
|
||||
|
||||
if( !model.first.IsEmpty() )
|
||||
{
|
||||
fields.emplace_back( VECTOR2I(), -1, &aSymbol, SIM_MODEL::TYPE_FIELD );
|
||||
fields.back().SetText( model.first );
|
||||
}
|
||||
|
||||
fields.emplace_back( VECTOR2I(), -1, &aSymbol, SIM_MODEL::PARAMS_FIELD );
|
||||
fields.back().SetText( simParams );
|
||||
fields.back().SetText( model.second );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -51,6 +51,7 @@
|
|||
#include <pegtl/contrib/parse_tree.hpp>
|
||||
|
||||
#include <iterator>
|
||||
#include "wx/regex.h"
|
||||
|
||||
using TYPE = SIM_MODEL::TYPE;
|
||||
|
||||
|
@ -1006,6 +1007,51 @@ bool SIM_MODEL::requiresSpiceModelLine() const
|
|||
}
|
||||
|
||||
|
||||
std::pair<wxString, wxString> SIM_MODEL::InferSimModel( const wxString& aPrefix,
|
||||
const wxString& aValue )
|
||||
{
|
||||
wxString spiceModelType;
|
||||
wxString spiceModelParams;
|
||||
|
||||
if( !aValue.IsEmpty() )
|
||||
{
|
||||
if( aPrefix.StartsWith( wxT( "R" ) )
|
||||
|| aPrefix.StartsWith( wxT( "L" ) )
|
||||
|| aPrefix.StartsWith( wxT( "C" ) ) )
|
||||
{
|
||||
wxRegEx passiveVal( wxT( "^"
|
||||
"([0-9\\. ]+)"
|
||||
"([fFpPnNuUmMkKgGtTμµ𝛍𝜇𝝁 ]|M(e|E)(g|G))?"
|
||||
"([fFhHΩΩ𝛀𝛺𝝮]|ohm)?"
|
||||
"([-1-9 ]*)"
|
||||
"$" ) );
|
||||
|
||||
if( passiveVal.Matches( aValue ) )
|
||||
{
|
||||
wxString valuePrefix( passiveVal.GetMatch( aValue, 1 ) );
|
||||
wxString valueUnits( passiveVal.GetMatch( aValue, 2 ) );
|
||||
wxString valueSuffix( passiveVal.GetMatch( aValue, 6 ) );
|
||||
|
||||
if( valueUnits == wxT( "M" ) )
|
||||
valueUnits = wxT( "Meg" );
|
||||
|
||||
spiceModelParams = wxString::Format( wxT( "%s=\"%s%s\"" ),
|
||||
aPrefix.Lower(),
|
||||
valuePrefix,
|
||||
valueUnits );
|
||||
}
|
||||
else
|
||||
{
|
||||
spiceModelType = wxT( "=" );
|
||||
spiceModelParams = wxString::Format( wxT( "%s=\"%s\"" ), aPrefix.Lower(), aValue );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return std::make_pair( spiceModelType, spiceModelParams );
|
||||
}
|
||||
|
||||
|
||||
template <typename T_symbol, typename T_field>
|
||||
void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol )
|
||||
{
|
||||
|
@ -1120,7 +1166,7 @@ void SIM_MODEL::MigrateSimModel( T_symbol& aSymbol )
|
|||
|
||||
wxStringSplit( legacyPins->GetText(), pinIndexes, ' ' );
|
||||
|
||||
if( SIM_MODEL_IDEAL::InferSimParams( prefix, value ).length() )
|
||||
if( SIM_MODEL::InferSimModel( prefix, value ).second.length() )
|
||||
{
|
||||
if( pinIndexes[0] == wxT( "2" ) )
|
||||
pins = "1=- 2=+";
|
||||
|
|
|
@ -519,6 +519,9 @@ public:
|
|||
}
|
||||
bool IsStoredInValue() const { return m_isStoredInValue; }
|
||||
|
||||
static std::pair<wxString, wxString> InferSimModel( const wxString& aPrefix,
|
||||
const wxString& aValue );
|
||||
|
||||
template <class T_symbol, class T_field>
|
||||
static void MigrateSimModel( T_symbol& aSymbol );
|
||||
|
||||
|
|
|
@ -73,41 +73,6 @@ SIM_MODEL_IDEAL::SIM_MODEL_IDEAL( TYPE aType ) :
|
|||
}
|
||||
|
||||
|
||||
wxString SIM_MODEL_IDEAL::InferSimParams( const wxString& aPrefix, const wxString& aValue )
|
||||
{
|
||||
wxString spiceModel;
|
||||
|
||||
if( aPrefix.StartsWith( wxT( "R" ) )
|
||||
|| aPrefix.StartsWith( wxT( "L" ) )
|
||||
|| aPrefix.StartsWith( wxT( "C" ) ) )
|
||||
{
|
||||
wxRegEx passiveVal(
|
||||
wxT( "^([0-9\\. ]+)([fFpPnNuUmMkKgGtTμµ𝛍𝜇𝝁 ]|M(e|E)(g|G))?([fFhHΩΩ𝛀𝛺𝝮]|ohm)?([-1-9 ]*)$" ) );
|
||||
|
||||
if( passiveVal.Matches( aValue ) )
|
||||
{
|
||||
wxString valuePrefix( passiveVal.GetMatch( aValue, 1 ) );
|
||||
wxString valueUnits( passiveVal.GetMatch( aValue, 2 ) );
|
||||
wxString valueSuffix( passiveVal.GetMatch( aValue, 6 ) );
|
||||
|
||||
if( valueUnits == wxT( "M" ) )
|
||||
valueUnits = wxT( "Meg" );
|
||||
|
||||
spiceModel = valuePrefix + valueUnits;
|
||||
}
|
||||
else
|
||||
{
|
||||
spiceModel = aValue;
|
||||
}
|
||||
}
|
||||
|
||||
if( !spiceModel.IsEmpty() )
|
||||
return wxString::Format( wxT( "%s=\"%s\"" ), aPrefix.Lower(), spiceModel );
|
||||
else
|
||||
return wxEmptyString;
|
||||
}
|
||||
|
||||
|
||||
SIM_MODEL::PARAM::INFO SIM_MODEL_IDEAL::makeParamInfo( std::string aName, std::string aDescription,
|
||||
std::string aUnit )
|
||||
{
|
||||
|
|
|
@ -49,8 +49,6 @@ public:
|
|||
const PARAM* GetTunerParam() const override { return &GetParam( 0 ); }
|
||||
bool HasPrimaryValue() const override { return true; }
|
||||
|
||||
static wxString InferSimParams( const wxString& aPrefix, const wxString& aValue );
|
||||
|
||||
private:
|
||||
std::vector<std::string> getPinNames() const override { return { "+", "-" }; }
|
||||
|
||||
|
|
Loading…
Reference in New Issue