Skip to content

Commit

Permalink
Merge pull request #851 from ra3xdh/global_compatmode
Browse files Browse the repository at this point in the history
Set Ngspice compatibility mode from GUI
  • Loading branch information
ra3xdh authored Jul 20, 2024
2 parents e262445 + 03a5148 commit 6ca42f0
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 10 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Redesign of schematic rendering engine. Improve rendering quality on HiDPI displays #723
* Improved Qucsconv GUI to reflect new converter features #826
* Improved libraries portability, relative path support for libraries, show libraries from project directory #567
* Added a global setting for Ngspice compatibility mode (LTspice, HSPICE, etc.) #851
* QucsatorRF updated to version 1.0.1

## Deprecated features
Expand Down
35 changes: 26 additions & 9 deletions qucs/extsimkernels/ngspice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "main.h"
#include "misc.h"
#include "qucs.h"
#include "settings.h"

#ifdef HAVE_CONFIG_H
#include "config.h"
Expand Down Expand Up @@ -631,13 +632,29 @@ void Ngspice::cleanSpiceinit()

void Ngspice::createSpiceinit(const QString &initial_spiceinit)
{
if (initial_spiceinit.isEmpty()) return;
QFile spinit(spinit_name);
if (spinit.open(QIODevice::WriteOnly)) {
QTextStream stream(&spinit);
if (!initial_spiceinit.isEmpty()) {
stream << initial_spiceinit << '\n';
}
spinit.close();
}
auto compat_mode = _settings::Get().item<int>("NgspiceCompatMode");
QString compat_str;
switch(compat_mode) {
case spicecompat::NgspLTspice:
compat_str = "set ngbehavior=ltpsa\n";
break;
case spicecompat::NgspHSPICE:
compat_str = "set ngbehavior=hsa\n";
break;
case spicecompat::NgspS3:
compat_str = "set ngbehavior=s3\n";
break;
default: break;
}
if (initial_spiceinit.isEmpty() &&
compat_str.isEmpty()) {
return;
}
QFile spinit(spinit_name);
if (spinit.open(QIODevice::WriteOnly)) {
QTextStream stream(&spinit);
stream << compat_str << '\n';
stream << initial_spiceinit << '\n';
spinit.close();
}
}
16 changes: 16 additions & 0 deletions qucs/extsimkernels/simsettingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "simsettingsdialog.h"
#include "main.h"
#include "settings.h"

SimSettingsDialog::SimSettingsDialog(QWidget *parent) :
QDialog(parent)
Expand Down Expand Up @@ -76,6 +77,14 @@ SimSettingsDialog::SimSettingsDialog(QWidget *parent) :
btnSetQucsator = new QPushButton(tr("Select ..."));
connect(btnSetQucsator,SIGNAL(clicked()),this,SLOT(slotSetQucsator()));

lblCompatMode = new QLabel(tr("Ngspice compatibility mode"));
cbxCompatMode = new QComboBox;
QStringList lst_modes;
lst_modes<<"Default"<<"LTspice"<<"HSPICE"<<"Spice3";
cbxCompatMode->addItems(lst_modes);
auto compat_mode = _settings::Get().item<int>("NgspiceCompatMode");
cbxCompatMode->setCurrentIndex(compat_mode);

QVBoxLayout *top = new QVBoxLayout;

// QHBoxLayout *h8 = new QHBoxLayout;
Expand All @@ -92,6 +101,11 @@ SimSettingsDialog::SimSettingsDialog(QWidget *parent) :
h1->addWidget(btnSetNgspice,1);
top2->addLayout(h1);

QHBoxLayout *h4 = new QHBoxLayout;
h4->addWidget(lblCompatMode);
h4->addWidget(cbxCompatMode);
top2->addLayout(h4);

top2->addWidget(lblXyce);
QHBoxLayout *h2 = new QHBoxLayout;
h2->addWidget(edtXyce,3);
Expand Down Expand Up @@ -172,6 +186,8 @@ void SimSettingsDialog::slotApply()
// "Please restart Qucs to affect changes!"));
// }
// QucsSettings.DefaultSimulator = cbxSimulator->currentIndex();
settingsManager& qs = _settings::Get();
qs.setItem<int>("NgspiceCompatMode", cbxCompatMode->currentIndex());
accept();
saveApplSettings();
}
Expand Down
3 changes: 2 additions & 1 deletion qucs/extsimkernels/simsettingsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ class SimSettingsDialog : public QDialog
//QLabel *lblNprocs;
QLabel *lblQucsator;
//QLabel *lblSimulator;
QLabel *lblSimParam;
QLabel *lblSimParam, *lblCompatMode;

QComboBox *cbxCompatMode;
//QComboBox *cbxSimulator;

QLineEdit *edtNgspice;
Expand Down
2 changes: 2 additions & 0 deletions qucs/extsimkernels/spicecompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ namespace spicecompat {
simSpice = 0b00000111,
simAll = 0b11111111};
enum CMgen_mode {cmgenSUBifs = 0, cmgenEDDifs = 1, cmgenSUBmod = 2, cmgenEDDmod = 3};

enum NgspiceCompatMode { NgspDefault = 0, NgspLTspice = 1, NgspHSPICE = 2, NgspS3 = 3 };
}

#endif // SPICECOMPAT_H
1 change: 1 addition & 0 deletions qucs/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ void settingsManager::initDefaults()
m_Defaults["GraphAntiAliasing"] = false;
m_Defaults["TextAntiAliasing"] = false;
m_Defaults["fullTraceName"] = false;
m_Defaults["NgspiceCompatMode"] = spicecompat::NgspDefault;
}

void settingsManager::initAliases()
Expand Down

0 comments on commit 6ca42f0

Please sign in to comment.