From a713ee852cb8fe20d7cb41141dad2f457353490d Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 20 Mar 2023 16:14:21 +0000 Subject: [PATCH] Ignore extraneous LTSpice parameters for VDMOS models. Also adds special case handling of VDMOS syntax to allow parens (or extra spaces, linebreaks, etc.) between "VDMOS" and "NCHAN"/"PCHAN". Fixes https://gitlab.com/kicad/code/kicad/issues/14299 --- eeschema/sim/sim_model_ngspice.cpp | 11 +++++++++++ eeschema/sim/spice_model_parser.cpp | 30 ++++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/eeschema/sim/sim_model_ngspice.cpp b/eeschema/sim/sim_model_ngspice.cpp index 3575275fba..a3b120657d 100644 --- a/eeschema/sim/sim_model_ngspice.cpp +++ b/eeschema/sim/sim_model_ngspice.cpp @@ -210,6 +210,17 @@ bool SIM_MODEL_NGSPICE::canSilentlyIgnoreParam( const std::string& aParamName ) } } + if( GetType() == TYPE::NMOS_VDMOS || GetType() == TYPE::PMOS_VDMOS ) + { + // Ignore the purely informative LTspice-specific parameters "Vds", "Ron" and "Qg". + if( aParamName == "vds" + || aParamName == "ron" + || aParamName == "qg" ) + { + return true; + } + } + return false; } diff --git a/eeschema/sim/spice_model_parser.cpp b/eeschema/sim/spice_model_parser.cpp index 862705f305..76c242d9a0 100644 --- a/eeschema/sim/spice_model_parser.cpp +++ b/eeschema/sim/spice_model_parser.cpp @@ -277,12 +277,32 @@ SIM_MODEL::TYPE SPICE_MODEL_PARSER::ReadTypeFromSpiceStrings( const std::string& if( typePrefix == "" ) continue; - // Check if `aTypeString` starts with `typePrefix`. - if( boost::starts_with( boost::to_upper_copy( aTypeString ), typePrefix ) - && ( level == readLevel || ( !aSkipDefaultLevel && isDefaultLevel && aLevel == "" ) ) - && version == aVersion ) + if( boost::starts_with( typePrefix, "VDMOS" ) ) { - return type; + wxString deviceType = wxString( typePrefix ).BeforeFirst( ' ' ); // VDMOS + wxString channelType = wxString( typePrefix ).AfterFirst( ' ' ); // NCHAN or PCHAN + + wxStringTokenizer tokenizer( aTypeString, wxT( " \t\n\r+(" ), wxTOKEN_STRTOK ); + + if( tokenizer.HasMoreTokens() && tokenizer.GetNextToken().Upper() == deviceType + && tokenizer.HasMoreTokens() && tokenizer.GetNextToken().Upper() == channelType ) + { + return type; + } + } + else if( boost::starts_with( boost::to_upper_copy( aTypeString ), typePrefix ) ) + { + if( version != aVersion ) + continue; + + if( level == readLevel ) + return type; + + if( aSkipDefaultLevel ) + continue; + + if( isDefaultLevel && aLevel == "" ) + return type; } }