Skip to content

Commit

Permalink
Add library parse error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ra3xdh committed Jun 23, 2024
1 parent 2d3262c commit 278a5bb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
40 changes: 34 additions & 6 deletions qucs/extsimkernels/spicelibcompdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ SpiceLibCompDialog::SpiceLibCompDialog(Component *pc, Schematic *sch) : QDialog{
Doc = sch;
symbolPinsCount = 0;
isChanged = false;
libError = false;

QString file = comp->Props.at(0)->Value;
if (!file.isEmpty()) {
Expand Down Expand Up @@ -203,8 +204,23 @@ void SpiceLibCompDialog::slotFillSubcirComboBox()
{
QString libfile = edtLibPath->text();
if (!QFile::exists(libfile)) return;
if (!parseLibFile(libfile)) {
QMessageBox::critical(this,tr("Error"),tr("SPICE library parse error"));
int r = parseLibFile(libfile);
libError = false;
if (r != noError) {
libError = true;
QString msg;
switch (r) {
case failedOpenFile:
msg = tr("Failed open file: ") + libfile;
break;
case noSUBCKT:
msg = tr("SPICE library parse error.\n"
"No SUBCKT directive found in library ") + libfile;
break;
default:
msg = tr("SPICE library parse error");
}
QMessageBox::critical(this,tr("Error"),msg);
return;
}

Expand Down Expand Up @@ -235,12 +251,13 @@ void SpiceLibCompDialog::slotFillPinsTable()
edtSPICE->setPlainText(subcirSPICE[subcir_name]);
}

bool SpiceLibCompDialog::parseLibFile(const QString &filename)
int SpiceLibCompDialog::parseLibFile(const QString &filename)
{
if (!QFileInfo::exists(filename)) return false;
QFile f(filename);
if (!f.open(QIODevice::ReadOnly)) {
return false;
QMessageBox::critical(this,tr("Error"),tr("Failed to open file: ") + filename);
return failedOpenFile;
}

subcirPins.clear();
Expand Down Expand Up @@ -282,9 +299,9 @@ bool SpiceLibCompDialog::parseLibFile(const QString &filename)

f.close();
if (subcirPins.isEmpty()) {
return false;
return noSUBCKT;
}
return true;
return noError;

}

Expand Down Expand Up @@ -453,6 +470,11 @@ bool SpiceLibCompDialog::setCompProps()
void SpiceLibCompDialog::slotBtnApply()
{
if (isChanged) {
if (libError) {
QMessageBox::critical(this,tr("Error"),
tr("There were library file parse error! Cannot apply changes."));
return;
}
if (setCompProps()) {
isChanged = false;
btnApply->setEnabled(false);
Expand All @@ -463,6 +485,12 @@ void SpiceLibCompDialog::slotBtnApply()
void SpiceLibCompDialog::slotBtnOK()
{
if (isChanged) {
if (libError) {
QMessageBox::critical(this,tr("Error"),
tr("There were library file parse error! Cannot apply changes."));
reject();
return;
}
if (setCompProps()) accept();
} else {
accept();
Expand Down
6 changes: 5 additions & 1 deletion qucs/extsimkernels/spicelibcompdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class SpiceLibCompDialog : public QDialog {
private:
int symbolPinsCount;
bool isChanged;
bool libError;

QString lastSymbolDir;
QString lastLibDir;

Expand All @@ -39,7 +41,9 @@ class SpiceLibCompDialog : public QDialog {
QMap<QString,QStringList> subcirPins;
QMap<QString,QString> subcirSPICE;

bool parseLibFile(const QString &filename);
enum SPICEparseError { noError=0, failedOpenFile = -1, noSUBCKT = -2 };

int parseLibFile(const QString &filename);
bool setCompProps();

private slots:
Expand Down

0 comments on commit 278a5bb

Please sign in to comment.