Skip to content

Commit

Permalink
Add error message pattern recognition #433
Browse files Browse the repository at this point in the history
  • Loading branch information
ra3xdh committed Jan 7, 2024
1 parent ef5cb8e commit f3b56ad
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
56 changes: 54 additions & 2 deletions qucs/extsimkernels/externsimdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,11 @@ void ExternSimDialog::slotProcessOutput()
break;
}

if (out.contains("error",Qt::CaseInsensitive)) {
if (logContainsError(out)) {
addLogEntry(tr("There were simulation errors. Please check log."),
this->style()->standardIcon(QStyle::SP_MessageBoxCritical));
emit warnings();
} else if (out.contains("warning",Qt::CaseInsensitive)) {
} else if (logContainsWarning(out)) {
addLogEntry(tr("There were simulation warnings. Please check log."),
this->style()->standardIcon(QStyle::SP_MessageBoxWarning));
addLogEntry(tr("Simulation finished. Now place diagram on schematic to plot the result."),
Expand Down Expand Up @@ -324,3 +324,55 @@ void ExternSimDialog::addLogEntry(const QString &text, const QIcon &icon)
itm->setIcon(icon);
simStatusLog->addItem(itm);
}

bool ExternSimDialog::logContainsError(const QString &out)
{
bool found = false;
QStringList err_patterns;
switch (QucsSettings.DefaultSimulator) {
case spicecompat::simNgspice:
err_patterns<<"Error:"<<"ERROR"<<"Error "
<<"Syntax error:"<<"Expression err:"
<<"errors:";
break;
case spicecompat::simXyce:
err_patterns<<"Error:"<<"ERROR"<<"MSG_ERROR"
<<"error:"<<"MSG_FATAL";
break;
default: err_patterns<<"error";
break;
}
for(const auto &err_str: err_patterns) {
if (out.contains(err_str)) {
found = true;
break;
}
}
return found;
}

bool ExternSimDialog::logContainsWarning(const QString &out)
{
bool found = false;
QStringList warn_patterns;
switch (QucsSettings.DefaultSimulator) {
case spicecompat::simNgspice:
warn_patterns<<"Warning:"<<"WARNING"<<"Warning "
<<"warning:";
break;
case spicecompat::simXyce:
warn_patterns<<"Warning:"<<"WARNING"<<"Warning "
<<"warning:";
break;
default: warn_patterns<<"warning";
break;
}
for(const auto &warn_str: warn_patterns) {
if (out.contains(warn_str)) {
found = true;
break;
}
}
return found;
}

2 changes: 2 additions & 0 deletions qucs/extsimkernels/externsimdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class ExternSimDialog : public QDialog
private:
void saveLog();
void addLogEntry(const QString&text, const QIcon &icon);
bool logContainsError(const QString &out);
bool logContainsWarning(const QString &out);

signals:
void simulated(ExternSimDialog *);
Expand Down

0 comments on commit f3b56ad

Please sign in to comment.