From ec9624a26897fa83e8d1a815a2d36e68de56d014 Mon Sep 17 00:00:00 2001 From: Vadim Kuznetsov Date: Sun, 19 Jan 2025 19:19:38 +0300 Subject: [PATCH 1/2] Fix processing of nested subcircuits with SpiceLibComp --- qucs/extsimkernels/spicelibcompdialog.cpp | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/qucs/extsimkernels/spicelibcompdialog.cpp b/qucs/extsimkernels/spicelibcompdialog.cpp index a93f6b371..5325b7805 100644 --- a/qucs/extsimkernels/spicelibcompdialog.cpp +++ b/qucs/extsimkernels/spicelibcompdialog.cpp @@ -289,6 +289,7 @@ int SpiceLibCompDialog::parseLibFile(const QString &filename) QString last_subcir; QString subname; QString subcir_body; + int nested_count = 0; while (!ts.atEnd()) { QString line = ts.readLine(); line = line.trimmed(); @@ -317,9 +318,10 @@ int SpiceLibCompDialog::parseLibFile(const QString &filename) } } - if (line.startsWith(".SUBCKT")) { + if (line.startsWith(".SUBCKT") && ! subcir_start) { subcir_start = true; header_start = true; + nested_count++; subcir_body.clear(); QStringList pin_names; QStringList tokens = line.split(QRegularExpression("[ \\t]"),Qt::SkipEmptyParts); @@ -336,13 +338,18 @@ int SpiceLibCompDialog::parseLibFile(const QString &filename) } } a_subcirPins[subname] = pin_names; + } else if (line.startsWith(".SUBCKT") && subcir_start) { // nested subcircuit + nested_count++; } if (subcir_start) { subcir_body += line + "\n"; } if (line.startsWith(".ENDS")) { - subcir_start = false; - a_subcirSPICE[subname] = subcir_body; + if (nested_count > 0) nested_count--; + if (nested_count == 0) { + subcir_start = false; + a_subcirSPICE[subname] = subcir_body; + } } } From 5dfd16975b82b44e0d7dc9f7aaa6571d166b4ffc Mon Sep 17 00:00:00 2001 From: Vadim Kuznetsov Date: Sun, 19 Jan 2025 19:25:19 +0300 Subject: [PATCH 2/2] Don't put OPTIONAL in the pins list --- qucs/extsimkernels/spicelibcompdialog.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/qucs/extsimkernels/spicelibcompdialog.cpp b/qucs/extsimkernels/spicelibcompdialog.cpp index 5325b7805..3b5bd9dfa 100644 --- a/qucs/extsimkernels/spicelibcompdialog.cpp +++ b/qucs/extsimkernels/spicelibcompdialog.cpp @@ -306,8 +306,10 @@ int SpiceLibCompDialog::parseLibFile(const QString &filename) line.remove(0,1); QStringList pins = line.split(QRegularExpression("[ \\t]"),Qt::SkipEmptyParts); for (const auto &s1: pins) { - if (s1 == "PARAMS:") header_start = false; - if (!s1.contains('=') && (s1 != "PARAMS:")) { + if (s1 == "PARAMS:" || s1 == ".OPTIONAL:") { + header_start = false; + } + if (!s1.contains('=') && (s1 != "PARAMS:") && (s1 != ".OPTIONAL:")) { a_subcirPins[subname].append(s1); } } @@ -332,8 +334,10 @@ int SpiceLibCompDialog::parseLibFile(const QString &filename) tokens.removeFirst(); tokens.removeFirst(); for (const auto &s1: tokens) { - if (s1 == "PARAMS:") header_start = false; - if (!s1.contains('=') && (s1 != "PARAMS:")) { + if (s1 == "PARAMS:" || s1 == ".OPTIONAL:") { + header_start = false; + } + if (!s1.contains('=') && (s1 != "PARAMS:") && (s1 != ".OPTIONAL:")) { pin_names.append(s1); } }