From 453f1f393e6e38ede1cbd22cdaaebb6fd62d08d5 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 13 Jan 2023 19:10:09 +0000 Subject: [PATCH] Add scanning for coupled inductor declarations to SPICE directives. Fixes https://gitlab.com/kicad/code/kicad/issues/13431 --- .../netlist_exporter_spice.cpp | 106 +++++++++++------- 1 file changed, 67 insertions(+), 39 deletions(-) diff --git a/eeschema/netlist_exporters/netlist_exporter_spice.cpp b/eeschema/netlist_exporters/netlist_exporter_spice.cpp index 88ca903237..81fbe449fb 100644 --- a/eeschema/netlist_exporters/netlist_exporter_spice.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_spice.cpp @@ -389,46 +389,74 @@ void NETLIST_EXPORTER_SPICE::ReadDirectives( unsigned aNetlistOptions ) { wxString line = tokenizer.GetNextToken().Upper(); - if( line.StartsWith( wxT( ".AC" ) ) - || line.StartsWith( wxT( ".CONTROL" ) ) - || line.StartsWith( wxT( ".CSPARAM" ) ) - || line.StartsWith( wxT( ".DISTO" ) ) - || line.StartsWith( wxT( ".ELSE" ) ) - || line.StartsWith( wxT( ".ELSEIF" ) ) - || line.StartsWith( wxT( ".END" ) ) - || line.StartsWith( wxT( ".ENDC" ) ) - || line.StartsWith( wxT( ".ENDIF" ) ) - || line.StartsWith( wxT( ".ENDS" ) ) - || line.StartsWith( wxT( ".FOUR" ) ) - || line.StartsWith( wxT( ".FUNC" ) ) - || line.StartsWith( wxT( ".GLOBAL" ) ) - || line.StartsWith( wxT( ".IC" ) ) - || line.StartsWith( wxT( ".IF" ) ) - || line.StartsWith( wxT( ".INCLUDE" ) ) - || line.StartsWith( wxT( ".LIB" ) ) - || line.StartsWith( wxT( ".MEAS" ) ) - || line.StartsWith( wxT( ".MODEL" ) ) - || line.StartsWith( wxT( ".NODESET" ) ) - || line.StartsWith( wxT( ".NOISE" ) ) - || line.StartsWith( wxT( ".OP" ) ) - || line.StartsWith( wxT( ".OPTIONS" ) ) - || line.StartsWith( wxT( ".PARAM" ) ) - || line.StartsWith( wxT( ".PLOT" ) ) - || line.StartsWith( wxT( ".PRINT" ) ) - || line.StartsWith( wxT( ".PROBE" ) ) - || line.StartsWith( wxT( ".PZ" ) ) - || line.StartsWith( wxT( ".SAVE" ) ) - || line.StartsWith( wxT( ".SENS" ) ) - || line.StartsWith( wxT( ".SP" ) ) - || line.StartsWith( wxT( ".SUBCKT" ) ) - || line.StartsWith( wxT( ".TEMP" ) ) - || line.StartsWith( wxT( ".TF" ) ) - || line.StartsWith( wxT( ".TITLE" ) ) - || line.StartsWith( wxT( ".TRAN" ) ) - || line.StartsWith( wxT( ".WIDTH" ) ) ) + if( line.StartsWith( wxT( "." ) ) ) { - foundDirective = true; - break; + if( line.StartsWith( wxT( ".AC" ) ) + || line.StartsWith( wxT( ".CONTROL" ) ) + || line.StartsWith( wxT( ".CSPARAM" ) ) + || line.StartsWith( wxT( ".DISTO" ) ) + || line.StartsWith( wxT( ".ELSE" ) ) + || line.StartsWith( wxT( ".ELSEIF" ) ) + || line.StartsWith( wxT( ".END" ) ) + || line.StartsWith( wxT( ".ENDC" ) ) + || line.StartsWith( wxT( ".ENDIF" ) ) + || line.StartsWith( wxT( ".ENDS" ) ) + || line.StartsWith( wxT( ".FOUR" ) ) + || line.StartsWith( wxT( ".FUNC" ) ) + || line.StartsWith( wxT( ".GLOBAL" ) ) + || line.StartsWith( wxT( ".IC" ) ) + || line.StartsWith( wxT( ".IF" ) ) + || line.StartsWith( wxT( ".INCLUDE" ) ) + || line.StartsWith( wxT( ".LIB" ) ) + || line.StartsWith( wxT( ".MEAS" ) ) + || line.StartsWith( wxT( ".MODEL" ) ) + || line.StartsWith( wxT( ".NODESET" ) ) + || line.StartsWith( wxT( ".NOISE" ) ) + || line.StartsWith( wxT( ".OP" ) ) + || line.StartsWith( wxT( ".OPTIONS" ) ) + || line.StartsWith( wxT( ".PARAM" ) ) + || line.StartsWith( wxT( ".PLOT" ) ) + || line.StartsWith( wxT( ".PRINT" ) ) + || line.StartsWith( wxT( ".PROBE" ) ) + || line.StartsWith( wxT( ".PZ" ) ) + || line.StartsWith( wxT( ".SAVE" ) ) + || line.StartsWith( wxT( ".SENS" ) ) + || line.StartsWith( wxT( ".SP" ) ) + || line.StartsWith( wxT( ".SUBCKT" ) ) + || line.StartsWith( wxT( ".TEMP" ) ) + || line.StartsWith( wxT( ".TF" ) ) + || line.StartsWith( wxT( ".TITLE" ) ) + || line.StartsWith( wxT( ".TRAN" ) ) + || line.StartsWith( wxT( ".WIDTH" ) ) ) + { + foundDirective = true; + break; + } + } + else if( line.StartsWith( wxT( "K" ) ) ) + { + // Check for mutual inductor declaration + wxStringTokenizer line_t( line, wxT( " \t" ), wxTOKEN_STRTOK ); + + // Coupling ID + if( !line_t.HasMoreTokens() || !line_t.GetNextToken().StartsWith( wxT( "K" ) ) ) + continue; + + // Inductor 1 ID + if( !line_t.HasMoreTokens() || !line_t.GetNextToken().StartsWith( wxT( "L" ) ) ) + continue; + + // Inductor 2 ID + if( !line_t.HasMoreTokens() || !line_t.GetNextToken().StartsWith( wxT( "L" ) ) ) + continue; + + // That's probably distinctive enough not to bother trying to parse the + // coupling value. If there's anything else, assume it's the value. + if( line_t.HasMoreTokens() ) + { + foundDirective = true; + break; + } } }