Skip to content

Commit

Permalink
Merge pull request #1211 from ra3xdh/fix_1120
Browse files Browse the repository at this point in the history
Fixed nested subcircuits processing in Spice Library Device
  • Loading branch information
ra3xdh authored Jan 19, 2025
2 parents a09b9c6 + 5dfd169 commit 1600e3f
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions qucs/extsimkernels/spicelibcompdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -305,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);
}
}
Expand All @@ -317,9 +320,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);
Expand All @@ -330,19 +334,26 @@ 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);
}
}
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;
}
}
}

Expand Down

0 comments on commit 1600e3f

Please sign in to comment.