Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed nested subcircuits processing in Spice Library Device #1211

Merged
merged 2 commits into from
Jan 19, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading