Merge pull request #1201 from ThomasZecha/current

Introduce optional netlisting to console
This commit is contained in:
Vadim Kuznetsov 2025-02-04 13:08:12 +03:00 committed by GitHub
commit 75040f363d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
35 changed files with 897 additions and 610 deletions

View File

@ -828,7 +828,7 @@ QString Component::getVerilogACode() {
}
}
QString Component::getExpression(bool, bool) {
QString Component::getExpression(spicecompat::SpiceDialect) {
return QString();
}
@ -840,7 +840,7 @@ QStringList Component::getExtraVariables() {
return QStringList();
}
QString Component::getProbeVariable(bool) {
QString Component::getProbeVariable(spicecompat::SpiceDialect) {
return QString();
}

View File

@ -44,10 +44,10 @@ public:
QString getNetlist();
QString getSpiceNetlist(spicecompat::SpiceDialect dialect = spicecompat::SPICEDefault);
QString getVerilogACode();
virtual QString getExpression(bool isXyce = false, bool isCdl = false);
virtual QString getExpression(spicecompat::SpiceDialect dialect = spicecompat::SPICEDefault);
virtual QString getEquations(QString sim, QStringList &dep_vars);
virtual QStringList getExtraVariables();
virtual QString getProbeVariable(bool isXyce = false);
virtual QString getProbeVariable(spicecompat::SpiceDialect dialect = spicecompat::SPICEDefault);
virtual QString getSpiceModel();
virtual QString getSpiceLibrary() { return QString(); }
virtual QStringList getSpiceLibraryFiles() { return QStringList(); }

View File

@ -119,14 +119,11 @@ QString Equation::getVAExpressions()
/*!
* \brief Equation::getExpression Extract equations that don't contain simulation variables
* (voltages/cureents) in .PARAM section of spice netlist
* \param isXyce True if Xyce is used.
* \param isCdl True if CDL is used.
* \param dialect Which spice-dialect is used.
* \return .PARAM section of spice netlist as a single string.
*/
QString Equation::getExpression(bool isXyce, bool isCdl /* = false */)
QString Equation::getExpression(spicecompat::SpiceDialect dialect /* = spicecompat::SPICEDefault */)
{
Q_UNUSED(isCdl);
if (isActive != COMP_IS_ACTIVE) return QString();
QStringList ng_vars,ngsims;
@ -145,9 +142,9 @@ QString Equation::getExpression(bool isXyce, bool isCdl /* = false */)
QStringList tokens;
QString eqn = Props.at(i)->Value;
spicecompat::splitEqn(eqn,tokens);
spicecompat::convert_functions(tokens,isXyce);
spicecompat::convert_functions(tokens, dialect == spicecompat::SPICEXyce);
eqn = tokens.join("");
if (isXyce) {
if (dialect == spicecompat::SPICEXyce) {
eqn.replace("^","**");
if (!(fp_pattern.match(eqn).hasMatch()||

View File

@ -28,7 +28,7 @@ public:
~Equation();
Component* newOne();
static Element* info(QString&, char* &, bool getNewOne=false);
QString getExpression(bool isXyce, bool isCdl = false);
QString getExpression(spicecompat::SpiceDialect dialect = spicecompat::SPICEDefault);
QString getEquations(QString sim, QStringList &dep_vars);
QString getVAvariables();
QString getVAExpressions();

View File

@ -90,13 +90,13 @@ QString iProbe::spice_netlist(spicecompat::SpiceDialect dialect /* = spicecompat
/*!
* \brief iProbe::getProbeVariable Get current probe variable
* \param isXyce True if Xyce simulator
* \param dialect Spice dialect used
* \return Current probe variable in Ngspice or Xyce notation
*/
QString iProbe::getProbeVariable(bool isXyce)
QString iProbe::getProbeVariable(spicecompat::SpiceDialect dialect)
{
QString s;
if (isXyce) {
if (dialect == spicecompat::SPICEXyce) {
s = QStringLiteral("I(V%1)").arg(Name);
} else {
s = QStringLiteral("V%1#branch").arg(Name);

View File

@ -27,8 +27,8 @@ public:
~iProbe();
Component* newOne();
static Element* info(QString&, char* &, bool getNewOne=false);
QString getExpression(bool, bool) { return "";}
QString getProbeVariable(bool isXyce = false);
QString getExpression(spicecompat::SpiceDialect) { return "";}
QString getProbeVariable(spicecompat::SpiceDialect dialect = spicecompat::SPICEDefault);
protected:
QString spice_netlist(spicecompat::SpiceDialect dialect = spicecompat::SPICEDefault);

View File

@ -73,7 +73,7 @@ Element* vProbe::info(QString& Name, char* &BitmapFile, bool getNewOne)
return 0;
}
QString vProbe::getProbeVariable(bool)
QString vProbe::getProbeVariable(spicecompat::SpiceDialect)
{
return Name;
}

View File

@ -27,7 +27,7 @@ public:
~vProbe();
Component* newOne();
static Element* info(QString&, char* &, bool getNewOne=false);
QString getProbeVariable(bool isXyce = false);
QString getProbeVariable(spicecompat::SpiceDialect dialect = spicecompat::SPICEDefault);
protected:
QString spice_netlist(spicecompat::SpiceDialect dialect = spicecompat::SPICEDefault);
};

View File

@ -149,7 +149,7 @@ void CdlNetlistWriter::startNetlist()
{
if (pc->isEquation)
{
s = pc->getExpression(false, true);
s = pc->getExpression(spicecompat::CDL);
a_netlistStream << s;
}
}

View File

@ -25,7 +25,7 @@
#include "main.h"
#include "qucs.h"
ExternSimDialog::ExternSimDialog(Schematic *sch, bool netlist_mode) :
ExternSimDialog::ExternSimDialog(Schematic* sch, bool netlist2Console, bool netlist_mode) :
QDialog(sch),
a_schematic(sch),
a_buttonStopSim(new QPushButton(tr("Stop"),this)),
@ -37,7 +37,8 @@ ExternSimDialog::ExternSimDialog(Schematic *sch, bool netlist_mode) :
a_ngspice(new Ngspice(sch,this)),
a_xyce(new Xyce(sch,this)),
a_wasSimulated(true),
a_hasError(false)
a_hasError(false),
a_netlist2Console(netlist2Console)
{
const QString workdir(QucsSettings.S4Qworkdir);
@ -296,27 +297,40 @@ void ExternSimDialog::slotStop()
void ExternSimDialog::slotSaveNetlist()
{
QFileInfo inf(a_schematic->getDocName());
QString filename = QFileDialog::getSaveFileName(this,tr("Save netlist"),inf.path()+QDir::separator()+"netlist.cir",
"All files (*)");
if (filename.isEmpty()) return;
QString filename;
switch (QucsSettings.DefaultSimulator) {
if (!a_netlist2Console)
{
filename = QFileDialog::getSaveFileName(
this,
tr("Save netlist"),
inf.path() + QDir::separator() + "netlist.cir",
"All files (*)");
if (filename.isEmpty())
{
return;
}
}
switch (QucsSettings.DefaultSimulator)
{
case spicecompat::simNgspice:
case spicecompat::simSpiceOpus: {
a_ngspice->SaveNetlist(filename);
}
case spicecompat::simSpiceOpus:
a_ngspice->SaveNetlist(filename, a_netlist2Console);
break;
case spicecompat::simXyce: {
a_xyce->SaveNetlist(filename);
}
case spicecompat::simXyce:
a_xyce->SaveNetlist(filename, a_netlist2Console);
break;
default:
break;
}
if (!QFile::exists(filename)) {
QMessageBox::critical(0, QObject::tr("Save netlist"),
QObject::tr("Disk write error!"), QMessageBox::Ok);
if (!a_netlist2Console && !QFile::exists(filename))
{
QMessageBox::critical(
nullptr,
QObject::tr("Save netlist"),
QObject::tr("Disk write error!"), QMessageBox::Ok);
}
}

View File

@ -30,7 +30,7 @@ class ExternSimDialog : public QDialog
Q_OBJECT
private:
Schematic *a_schematic;
Schematic* a_schematic;
QPushButton *a_buttonStopSim;
QPushButton *a_buttonSaveNetlist;
@ -46,10 +46,13 @@ private:
bool a_wasSimulated;
bool a_hasError;
bool a_netlist2Console;
public:
explicit ExternSimDialog(Schematic *sch,
bool netlist_mode = false);
explicit ExternSimDialog(
Schematic* sch,
bool netlist2Console,
bool netlist_mode = false);
~ExternSimDialog();
bool wasSimulated() const { return a_wasSimulated; }

View File

@ -33,6 +33,10 @@
#include "config.h"
#endif
#include <QScopedPointer>
#include <iostream>
/*!
\file ngspice.cpp
\brief Implementation of the Ngspice class
@ -43,7 +47,7 @@
* \param schematic Schematic that need to be simulated with Ngspice.
* \param parent Parent object
*/
Ngspice::Ngspice(Schematic *schematic, QObject *parent) :
Ngspice::Ngspice(Schematic* schematic, QObject *parent) :
AbstractSpiceKernel(schematic, parent),
a_spinit_name()
{
@ -67,8 +71,11 @@ Ngspice::Ngspice(Schematic *schematic, QObject *parent) :
* \param[out] vars The list of output variables and node names.
* \param[out] outputs The list of spice output raw text files.
*/
void Ngspice::createNetlist(QTextStream &stream, int ,
QStringList &simulations, QStringList &vars, QStringList &outputs)
void Ngspice::createNetlist(
QTextStream& stream,
QStringList& simulations,
QStringList& vars,
QStringList& outputs)
{
Q_UNUSED(simulations);
@ -464,7 +471,7 @@ void Ngspice::slotSimulate()
QString netfile = "spice4qucs.cir";
QString tmp_path = QDir::toNativeSeparators(a_workdir+QDir::separator()+netfile);
SaveNetlist(tmp_path);
SaveNetlist(tmp_path, false);
removeAllSimulatorOutputs();
@ -583,24 +590,43 @@ void Ngspice::slotProcessOutput()
* \brief Ngspice::SaveNetlist Create netlist and save it to file without execution
* of simulator.
* \param[in] filename Absolute path to netlist
* \param[in] netlist2Console Whether netlist to console instead to file
*/
void Ngspice::SaveNetlist(QString filename)
void Ngspice::SaveNetlist(QString filename, bool netlist2Console)
{
int num=0;
a_sims.clear();
a_vars.clear();
QFile spice_file(filename);
if (spice_file.open(QFile::WriteOnly)) {
QTextStream stream(&spice_file);
createNetlist(stream,num,a_sims,a_vars,a_output_files);
spice_file.close();
QScopedPointer<QString> netlistString;
QScopedPointer<QTextStream> netlistStream;
QScopedPointer<QFile> netlistFile;
if (netlist2Console)
{
netlistString.reset(new QString);
netlistStream.reset(new QTextStream(netlistString.get()));
}
else
{
QString msg=QStringLiteral("Tried to save netlist \nin %1\n(could not open for writing!)").arg(filename);
QString final_msg=QStringLiteral("%1\n This could be an error in the QSettings settings file\n(usually in ~/.config/qucs/qucs_s.conf)\nThe value for S4Q_workdir (default:/spice4qucs) needs to be writeable!\nFor a Simulation Simulation will raise error! (most likely S4Q_workdir does not exists)").arg(msg);
QMessageBox::critical(nullptr,tr("Problem with SaveNetlist"),final_msg,QMessageBox::Ok);
netlistFile.reset(new QFile(filename));
if (netlistFile->open(QFile::WriteOnly))
{
netlistStream.reset(new QTextStream(netlistFile.get()));
}
else
{
QString msg = QStringLiteral("Tried to save netlist \nin %1\n(could not open for writing!)").arg(filename);
QString final_msg = QStringLiteral("%1\n This could be an error in the QSettings settings file\n(usually in ~/.config/qucs/qucs_s.conf)\nThe value for S4Q_workdir (default:/spice4qucs) needs to be writeable!\nFor a Simulation Simulation will raise error! (most likely S4Q_workdir does not exists)").arg(msg);
QMessageBox::critical(nullptr,tr("Problem with SaveNetlist"), final_msg, QMessageBox::Ok);
return;
}
}
createNetlist(*netlistStream, a_sims, a_vars, a_output_files);
if (netlist2Console)
{
std::cout << netlistString->toUtf8().constData() << std::endl;
}
}

View File

@ -41,7 +41,7 @@ private:
QString a_spinit_name;
bool checkNodeNames(QStringList &incompat);
static QString collectSpiceinit(Schematic *sch);
static QString collectSpiceinit(Schematic* sch);
bool findMathFuncInc(QString &mathf_inc);
QString getParentSWPscript(Component *pc_swp, QString sim, bool before, bool &hasDblSWP);
QString getParentSWPCntVar(Component *pc_swp, QString sim);
@ -49,14 +49,17 @@ private:
void createSpiceinit(const QString &initial_spiceinit);
public:
explicit Ngspice(Schematic *schematic, QObject *parent = 0);
void SaveNetlist(QString filename);
explicit Ngspice(Schematic* schematic, QObject *parent = 0);
void SaveNetlist(QString filename, bool netlist2Console);
void setSimulatorCmd(QString cmd);
void setSimulatorParameters(QString parameters);
protected:
void createNetlist(QTextStream &stream, int NumPorts, QStringList &simulations,
QStringList &vars, QStringList &outputs);
void createNetlist(
QTextStream& stream,
QStringList& simulations,
QStringList& vars,
QStringList& outputs);
public slots:
void slotSimulate();

View File

@ -25,6 +25,10 @@
#include "config.h"
#endif
#include <QScopedPointer>
#include <iostream>
/*!
\file xyce.cpp
\brief Implementation of the Xyce class
@ -35,7 +39,7 @@
* \param schematic Schematic that need to be simulated with Ngspice.
* \param parent Parent object
*/
Xyce::Xyce(Schematic *schematic, QObject *parent) :
Xyce::Xyce(Schematic* schematic, QObject *parent) :
AbstractSpiceKernel(schematic, parent),
a_Noisesim(false),
a_simulationsQueue(),
@ -79,8 +83,11 @@ void Xyce::determineUsedSimulations(QStringList *sim_lst)
* \param[out] vars The list of output variables and node names.
* \param[out] outputs The list of spice output raw text files.
*/
void Xyce::createNetlist(QTextStream &stream, int , QStringList &simulations,
QStringList &vars, QStringList &outputs)
void Xyce::createNetlist(
QTextStream& stream,
QStringList& simulations,
QStringList& vars,
QStringList& outputs)
{
QString s;
bool hasParSweep = false;
@ -110,7 +117,7 @@ void Xyce::createNetlist(QTextStream &stream, int , QStringList &simulations,
}
for(Component *pc = a_schematic->a_DocComps.first(); pc != 0; pc = a_schematic->a_DocComps.next()) {
if (pc->isProbe) {
QString var_pr = pc->getProbeVariable(true);
QString var_pr = pc->getProbeVariable(spicecompat::SPICEXyce);
if (!vars.contains(var_pr)) {
vars.append(var_pr);
}
@ -312,7 +319,6 @@ void Xyce::slotSimulate()
return;
}
int num=0;
a_netlistQueue.clear();
a_output_files.clear();
@ -332,7 +338,7 @@ void Xyce::slotSimulate()
QFile spice_file(tmp_path);
if (spice_file.open(QFile::WriteOnly)) {
QTextStream stream(&spice_file);
createNetlist(stream,num,sim_lst,a_vars,a_output_files);
createNetlist(stream,sim_lst,a_vars,a_output_files);
spice_file.close();
}
}
@ -347,16 +353,36 @@ void Xyce::slotSimulate()
* \brief Xyce::SaveNetlist Save netlist into specified file without
* execution of simulator.
* \param[in] filename The name of file in which netlist is saved
* \param[in] netlist2Console Whether netlist to console instead to file
*/
void Xyce::SaveNetlist(QString filename)
void Xyce::SaveNetlist(QString filename, bool netlist2Console)
{
determineUsedSimulations();
int num = 0;
QFile spice_file(filename);
if (spice_file.open(QFile::WriteOnly)) {
QTextStream stream(&spice_file);
createNetlist(stream,num,a_simulationsQueue,a_vars,a_output_files);
spice_file.close();
QScopedPointer<QString> netlistString;
QScopedPointer<QTextStream> netlistStream;
QScopedPointer<QFile> netlistFile;
if (netlist2Console)
{
netlistString.reset(new QString);
netlistStream.reset(new QTextStream(netlistString.get()));
}
else
{
netlistFile.reset(new QFile(filename));
if (netlistFile->open(QFile::WriteOnly))
{
netlistStream.reset(new QTextStream(netlistFile.get()));
}
}
createNetlist(*netlistStream, a_simulationsQueue, a_vars, a_output_files);
if (netlist2Console)
{
std::cout << netlistString->toUtf8().constData() << std::endl;
}
}

View File

@ -46,15 +46,19 @@ private:
public:
void determineUsedSimulations(QStringList *sim_lst = NULL);
explicit Xyce(Schematic *schematic, QObject *parent = 0);
explicit Xyce(Schematic* schematic, QObject *parent = 0);
void SaveNetlist(QString filename);
void SaveNetlist(QString filename, bool netlist2Console);
void setParallel(bool par);
bool waitEndOfSimulation();
protected:
void createNetlist(QTextStream &stream, int NumPorts, QStringList &simulations,
QStringList &vars, QStringList &outputs);
void createNetlist(
QTextStream& stream,
QStringList& simulations,
QStringList& vars,
QStringList& outputs);
protected slots:
void slotFinished();
void slotProcessOutput();

File diff suppressed because it is too large Load Diff

View File

@ -88,9 +88,9 @@
//#include "extsimkernels/codemodelgen.h"
#include "symbolwidget.h"
QucsApp::QucsApp()
QucsApp::QucsApp(bool netlist2Console) :
a_netlist2Console(netlist2Console)
{
windowTitle = misc::getWindowTitle();
setWindowTitle(windowTitle);
@ -575,11 +575,11 @@ void QucsApp::initView()
messageDock = new MessageDock(this);
// initial projects directory model
m_homeDirModel = new QucsFileSystemModel(this);
m_proxyModel = new QucsSortFilterProxyModel();
//m_proxyModel->setDynamicSortFilter(true);
a_homeDirModel = new QucsFileSystemModel(this);
a_proxyModel = new QucsSortFilterProxyModel();
//a_proxyModel->setDynamicSortFilter(true);
// show all directories (project and non-project)
m_homeDirModel->setFilter(QDir::NoDot | QDir::AllDirs);
a_homeDirModel->setFilter(QDir::NoDot | QDir::AllDirs);
// ............................................
QString path = QucsSettings.qucsWorkspaceDir.absolutePath();
@ -1386,21 +1386,21 @@ void QucsApp::readProjects()
if (path == homepath) {
// in Qucs Home, disallow further up in the dirs tree
m_homeDirModel->setFilter(QDir::NoDotAndDotDot | QDir::AllDirs);
a_homeDirModel->setFilter(QDir::NoDotAndDotDot | QDir::AllDirs);
} else {
m_homeDirModel->setFilter(QDir::NoDot | QDir::AllDirs);
a_homeDirModel->setFilter(QDir::NoDot | QDir::AllDirs);
}
// set the root path
QModelIndex rootModelIndex = m_homeDirModel->setRootPath(path);
QModelIndex rootModelIndex = a_homeDirModel->setRootPath(path);
// assign the model to the proxy and the proxy to the view
m_proxyModel->setSourceModel(m_homeDirModel);
m_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
a_proxyModel->setSourceModel(a_homeDirModel);
a_proxyModel->setSortCaseSensitivity(Qt::CaseInsensitive);
// sort by first column (file name, only column show in the QListView)
m_proxyModel->sort(0);
Projects->setModel(m_proxyModel);
a_proxyModel->sort(0);
Projects->setModel(a_proxyModel);
// fix the listview on the root path of the model
Projects->setRootIndex(m_proxyModel->mapFromSource(rootModelIndex));
Projects->setRootIndex(a_proxyModel->mapFromSource(rootModelIndex));
}
// ----------------------------------------------------------
@ -2410,7 +2410,7 @@ void QucsApp::slotTune(bool checked)
return;
}
Schematic *d = dynamic_cast<Schematic*>(w);
Schematic* d(dynamic_cast<Schematic*>(w));
assert(d);
bool found = false;
@ -3463,57 +3463,83 @@ void QucsApp::slotSimSettings()
void QucsApp::slotSimulateWithSpice()
{
if (!isTextDocument(DocumentTab->currentWidget())) {
Schematic *sch = (Schematic*)DocumentTab->currentWidget();
if (TuningMode) {
QFileInfo Info(sch->getDocName());
if (!isTextDocument(DocumentTab->currentWidget()))
{
Schematic* schematic(dynamic_cast<Schematic*>(DocumentTab->currentWidget()));
if (TuningMode)
{
QFileInfo Info(schematic->getDocName());
QString ext = Info.suffix();
if (ext == "dpl") {
QucsDoc *Doc = (QucsDoc *)sch;
sch = (Schematic *) getSchematicWidget(Doc);
if (sch == nullptr) return;
if (ext == "dpl")
{
QucsDoc *doc(dynamic_cast<QucsDoc*>(schematic));
Q_ASSERT(doc != nullptr);
schematic = dynamic_cast<Schematic*>(getSchematicWidget(doc));
if (schematic == nullptr)
{
return;
}
}
}
if (sch->getDocName().isEmpty()) {
auto biasState = sch->getShowBias();
QMessageBox::warning(this,tr("Simulate schematic"),
if (schematic->getDocName().isEmpty())
{
auto biasState = schematic->getShowBias();
QMessageBox::warning(
this,
tr("Simulate schematic"),
tr("Schematic not saved! Simulation of unsaved schematic "
"not possible. Save schematic first!"));
"not possible. Save schematic first!"));
slotFileSaveAs();
sch->setShowBias(biasState);
schematic->setShowBias(biasState);
}
ExternSimDialog *SimDlg = new ExternSimDialog(sch);
connect(SimDlg,SIGNAL(simulated(ExternSimDialog*)),
this,SLOT(slotAfterSpiceSimulation(ExternSimDialog*)));
connect(SimDlg,SIGNAL(warnings()),this,SLOT(slotShowWarnings()));
connect(SimDlg,SIGNAL(success()),this,SLOT(slotResetWarnings()));
if (TuningMode || sch->getShowBias() == 0) SimDlg->slotStart();
else SimDlg->exec();
/*disconnect(SimDlg,SIGNAL(simulated()),this,SLOT(slotAfterSpiceSimulation()));
disconnect(SimDlg,SIGNAL(warnings()),this,SLOT(slotShowWarnings()));
disconnect(SimDlg,SIGNAL(success()),this,SLOT(slotResetWarnings()));*/
/*if (SimDlg->wasSimulated && sch->getSimOpenDpl())
if (sch->getShowBias() < 1) slotChangePage(sch->getDocName(),sch->getDataDisplay());
ExternSimDialog *SimDlg = new ExternSimDialog(schematic, false);
connect(SimDlg, SIGNAL(simulated(ExternSimDialog*)), this, SLOT(slotAfterSpiceSimulation(ExternSimDialog*)));
connect(SimDlg, SIGNAL(warnings()), this, SLOT(slotShowWarnings()));
connect(SimDlg, SIGNAL(success()), this, SLOT(slotResetWarnings()));
if (TuningMode || schematic->getShowBias() == 0)
{
SimDlg->slotStart();
}
else
{
SimDlg->exec();
}
/*disconnect(SimDlg, SIGNAL(simulated()), this, SLOT(slotAfterSpiceSimulation()));
disconnect(SimDlg, SIGNAL(warnings()), this, SLOT(slotShowWarnings()));
disconnect(SimDlg, SIGNAL(success()), this, SLOT(slotResetWarnings()));*/
/*if (SimDlg->wasSimulated && schematic->getSimOpenDpl())
if (schematic->getShowBias() < 1) slotChangePage(schematic->getDocName(), schematic->getDataDisplay());
delete SimDlg;*/
} else {
QMessageBox::warning(this,tr("Simulate schematic"),
tr("Simulation of text document is not possible!"));
}
else
{
QMessageBox::warning(
this,
tr("Simulate schematic"),
tr("Simulation of text document is not possible!"));
}
}
void QucsApp::slotSaveNetlist()
{
if (QucsSettings.DefaultSimulator == spicecompat::simQucsator) {
QMessageBox::information(this,tr("Save netlist"),
tr("This action is supported only for SPICE simulators!"));
if (QucsSettings.DefaultSimulator == spicecompat::simQucsator)
{
QMessageBox::information(
this,
tr("Save netlist"),
tr("This action is supported only for SPICE simulators!"));
return;
}
if (!isTextDocument(DocumentTab->currentWidget())) {
Schematic *sch = (Schematic*)DocumentTab->currentWidget();
ExternSimDialog *SimDlg = new ExternSimDialog(sch, true);
SimDlg->slotSaveNetlist();
delete SimDlg;
if (!isTextDocument(DocumentTab->currentWidget()))
{
Schematic* schematic(dynamic_cast<Schematic*>(DocumentTab->currentWidget()));
Q_ASSERT(schematic != nullptr);
ExternSimDialog simDlg(schematic, a_netlist2Console, true);
simDlg.slotSaveNetlist();
}
}
@ -3524,53 +3550,55 @@ void QucsApp::slotSaveCdlNetlist()
Schematic* schematic = dynamic_cast<Schematic*>(DocumentTab->currentWidget());
Q_ASSERT(schematic != nullptr);
#ifdef NETLIST_CDL_TO_CONSOLE // for fast testing purposes
QString netlistString;
if (a_netlist2Console)
{
QTextStream netlistStream(&netlistString);
CdlNetlistWriter cdlWriter(netlistStream, schematic);
if (!cdlWriter.write())
QString netlistString;
{
QMessageBox::critical(
this,
tr("Save CDL netlist"),
tr("Save CDL netlist failed!"),
QMessageBox::Ok);
QTextStream netlistStream(&netlistString);
CdlNetlistWriter cdlWriter(netlistStream, schematic);
if (!cdlWriter.write())
{
QMessageBox::critical(
this,
tr("Save CDL netlist"),
tr("Save CDL netlist failed!"),
QMessageBox::Ok);
}
printf("\nCDL netlist:\n%s\n", netlistString.toUtf8().constData());
Content->refresh();
}
printf("\nCDL netlist:\n%s\n", netlistString.toUtf8().constData());
Content->refresh();
}
#else
QFileInfo inf(schematic->getDocName());
QString filename = QFileDialog::getSaveFileName(
this,
tr("Save CDL netlist"),
inf.path() + QDir::separator() + "netlist.cdl",
"CDL netlist (*.cdl)");
if (filename.isEmpty())
else
{
return;
}
QFileInfo inf(schematic->getDocName());
QString filename = QFileDialog::getSaveFileName(
this,
tr("Save CDL netlist"),
inf.path() + QDir::separator() + "netlist.cdl",
"CDL netlist (*.cdl)");
QFile netlistFile(filename);
if (netlistFile.open(QIODevice::WriteOnly))
{
QTextStream netlistStream(&netlistFile);
CdlNetlistWriter cdlWriter(netlistStream, schematic);
if (!cdlWriter.write())
if (filename.isEmpty())
{
QMessageBox::critical(
this,
tr("Save CDL netlist"),
tr("Save CDL netlist failed!"),
QMessageBox::Ok);
return;
}
netlistFile.close();
Content->refresh();
}
#endif
QFile netlistFile(filename);
if (netlistFile.open(QIODevice::WriteOnly))
{
QTextStream netlistStream(&netlistFile);
CdlNetlistWriter cdlWriter(netlistStream, schematic);
if (!cdlWriter.write())
{
QMessageBox::critical(
this,
tr("Save CDL netlist"),
tr("Save CDL netlist failed!"),
QMessageBox::Ok);
}
netlistFile.close();
Content->refresh();
}
}
}
}

View File

@ -88,7 +88,7 @@ protected:
class QucsApp : public QMainWindow {
Q_OBJECT
public:
QucsApp();
QucsApp(bool netlist2Console);
~QucsApp();
bool closeAllFiles();
bool gotoPage(const QString&); // to load a document
@ -251,10 +251,10 @@ private:
// ********** Properties ************************************************
QStack<QString> HierarchyHistory; // keeps track of "go into subcircuit"
QString QucsFileFilter;
QFileSystemModel *m_homeDirModel;
QucsSortFilterProxyModel *m_proxyModel;
QFileSystemModel *m_projModel;
QFileSystemModel *a_homeDirModel;
QucsSortFilterProxyModel *a_proxyModel;
int ccCurIdx; // CompChooser current index (used during search)
bool a_netlist2Console;
// ********** Methods ***************************************************
void initView();

View File

@ -574,12 +574,12 @@ void QucsApp::initActions()
save_netlist = new QAction(tr("Save netlist"), this);
save_netlist->setStatusTip(tr("Save netlist"));
save_netlist->setWhatsThis(tr("Save netlist to file"));
save_netlist->setWhatsThis(tr(QString::fromUtf8("Save netlist to %1").arg(a_netlist2Console ? "console" : "file").toLatin1().constData()));
connect(save_netlist, SIGNAL(triggered()), SLOT(slotSaveNetlist()));
saveCdlNetlist = new QAction(tr("Save CDL netlist"), this);
saveCdlNetlist->setStatusTip(tr("Save CDL netlist"));
saveCdlNetlist->setWhatsThis(tr("Save CDL netlist to file"));
saveCdlNetlist->setWhatsThis(tr(QString::fromUtf8("Save CDL netlist to %1").arg(a_netlist2Console ? "console" : "file").toLatin1().constData()));
connect(saveCdlNetlist, SIGNAL(triggered()), SLOT(slotSaveCdlNetlist()));
setMarker = new QAction(QIcon((":/bitmaps/svg/marker.svg")), tr("Set Marker on Graph"), this);

View File

@ -77,9 +77,9 @@ Element* InclScript::info(QString& Name, char* &BitmapFile, bool getNewOne)
return 0;
}
QString InclScript::getExpression(bool, bool isCdl /* = false */)
QString InclScript::getExpression(spicecompat::SpiceDialect dialect /* = spicecompat::SPICEDefault */)
{
if (isActive != COMP_IS_ACTIVE || isCdl)
if (isActive != COMP_IS_ACTIVE || dialect == spicecompat::CDL)
return QString();
return Props.at(0)->Value+"\n";
}

View File

@ -27,7 +27,7 @@ public:
~InclScript();
Component* newOne();
static Element* info(QString&, char* &, bool getNewOne=false);
QString getExpression(bool isXyce, bool isCdl = false);
QString getExpression(spicecompat::SpiceDialect dialect = spicecompat::SPICEDefault);
protected:
QString vhdlCode(int) { return QString(); }

View File

@ -69,8 +69,10 @@ Element* SpiceCSParam::info(QString& Name, char* &BitmapFile, bool getNewOne)
return 0;
}
QString SpiceCSParam::getExpression(bool)
QString SpiceCSParam::getExpression(spicecompat::SpiceDialect dialect /* = spicecompat::SPICEDefault */)
{
Q_UNUSED(dialect);
if (isActive != COMP_IS_ACTIVE) return QString();
QString s;

View File

@ -29,7 +29,7 @@ public:
Component* newOne();
static Element* info(QString&, char* &, bool getNewOne=false);
static void splitEqn(QString &eqn, QStringList &tokens);
QString getExpression(bool isXyce = false);
QString getExpression(spicecompat::SpiceDialect dialect = spicecompat::SPICEDefault);
protected:
QString netlist() { return QString(); }

View File

@ -70,9 +70,9 @@ Element* SpiceFunc::info(QString& Name, char* &BitmapFile, bool getNewOne)
return 0;
}
QString SpiceFunc::getExpression(bool, bool isCdl /* = false */)
QString SpiceFunc::getExpression(spicecompat::SpiceDialect dialect /* = spicecompat::SPICEDefault */)
{
if (isActive != COMP_IS_ACTIVE || isCdl) return QString();
if (isActive != COMP_IS_ACTIVE || dialect == spicecompat::CDL) return QString();
QString s;
s.clear();

View File

@ -28,7 +28,7 @@ public:
~SpiceFunc();
Component* newOne();
static Element* info(QString&, char* &, bool getNewOne=false);
QString getExpression(bool isXyce, bool isCdl = false);
QString getExpression(spicecompat::SpiceDialect dialect = spicecompat::SPICEDefault);
protected:
QString vhdlCode(int) { return QString(); }

View File

@ -70,14 +70,15 @@ Element* SpiceGlobalParam::info(QString& Name, char* &BitmapFile, bool getNewOne
}
QString SpiceGlobalParam::getExpression(bool, bool isCdl /* = false */)
QString SpiceGlobalParam::getExpression(spicecompat::SpiceDialect dialect /* = spicecompat::SPICEDefault */)
{
if (isActive != COMP_IS_ACTIVE) return QString();
QString s;
s.clear();
for (Property *pp : Props) {
s += QStringLiteral(".%1PARAM %2 = %3\n").arg(isCdl ? "" : "GLOBAL_").arg(pp->Name).arg(pp->Value);
s += QStringLiteral(".%1PARAM %2 = %3\n")
.arg(dialect == spicecompat::CDL ? "" : "GLOBAL_").arg(pp->Name).arg(pp->Value);
}
return s;
}

View File

@ -29,7 +29,7 @@ public:
Component* newOne();
static Element* info(QString&, char* &, bool getNewOne=false);
static void splitEqn(QString &eqn, QStringList &tokens);
QString getExpression(bool isXyce, bool isCdl = false);
QString getExpression(spicecompat::SpiceDialect dialect = spicecompat::SPICEDefault);
protected:
QString vhdlCode(int) { return QString(); }

View File

@ -69,9 +69,9 @@ Element* SpiceIC::info(QString& Name, char* &BitmapFile, bool getNewOne)
return 0;
}
QString SpiceIC::getExpression(bool, bool isCdl /* = false */)
QString SpiceIC::getExpression(spicecompat::SpiceDialect dialect /* = spicecompat::SPICEDefault */)
{
if (isActive != COMP_IS_ACTIVE || isCdl) return QString();
if (isActive != COMP_IS_ACTIVE || dialect == spicecompat::CDL) return QString();
QString s;
s.clear();

View File

@ -28,7 +28,7 @@ public:
~SpiceIC();
Component* newOne();
static Element* info(QString&, char* &, bool getNewOne=false);
QString getExpression(bool isXyce, bool isCdl = false);
QString getExpression(spicecompat::SpiceDialect dialect = spicecompat::SPICEDefault);
protected:
QString vhdlCode(int) { return QString(); }

View File

@ -69,9 +69,9 @@ Element* SpiceNodeset::info(QString& Name, char* &BitmapFile, bool getNewOne)
return 0;
}
QString SpiceNodeset::getExpression(bool, bool isCdl /* = false */)
QString SpiceNodeset::getExpression(spicecompat::SpiceDialect dialect /* = spicecompat::SPICEDefault */)
{
if (isActive != COMP_IS_ACTIVE || isCdl) return QString();
if (isActive != COMP_IS_ACTIVE || dialect == spicecompat::CDL) return QString();
QString s;
s.clear();

View File

@ -28,7 +28,7 @@ public:
~SpiceNodeset();
Component* newOne();
static Element* info(QString&, char* &, bool getNewOne=false);
QString getExpression(bool isXyce, bool isCdl = false);
QString getExpression(spicecompat::SpiceDialect dialect = spicecompat::SPICEDefault);
protected:
QString vhdlCode(int) { return QString(); }

View File

@ -71,13 +71,13 @@ Element* SpiceOptions::info(QString& Name, char* &BitmapFile, bool getNewOne)
return 0;
}
QString SpiceOptions::getExpression(bool isXyce, bool isCdl /* = false */)
QString SpiceOptions::getExpression(spicecompat::SpiceDialect dialect /* = spicecompat::SPICEDefault */)
{
if (isActive != COMP_IS_ACTIVE || isCdl) return QString();
if (isActive != COMP_IS_ACTIVE || dialect == spicecompat::CDL) return QString();
QString s;
s.clear();
if (isXyce) {
if (dialect == spicecompat::SPICEXyce) {
s += QStringLiteral(".OPTIONS %1 ").arg(Props.at(0)->Value);
for (int i=1;i<Props.count();i++) {
s += QStringLiteral(" %1 = %2 ").arg(Props.at(i)->Name).arg(Props.at(i)->Value);

View File

@ -29,7 +29,7 @@ public:
Component* newOne();
static Element* info(QString&, char* &, bool getNewOne=false);
static void splitEqn(QString &eqn, QStringList &tokens);
QString getExpression(bool isXyce, bool isCdl = false);
QString getExpression(spicecompat::SpiceDialect dialect = spicecompat::SPICEDefault);
protected:
QString vhdlCode(int) { return QString(); }

View File

@ -69,14 +69,14 @@ Element* SpiceParam::info(QString& Name, char* &BitmapFile, bool getNewOne)
return 0;
}
QString SpiceParam::getExpression(bool, bool isCdl /* = false */)
QString SpiceParam::getExpression(spicecompat::SpiceDialect dialect /* = spicecompat::SPICEDefault */)
{
if (isActive != COMP_IS_ACTIVE) return QString();
QString s;
s.clear();
for (Property *pp : Props) {
if (isCdl)
if (dialect == spicecompat::CDL)
{
s += QStringLiteral(".PARAM %1=%2\n").arg(pp->Name).arg(pp->Value);
}

View File

@ -29,7 +29,7 @@ public:
Component* newOne();
static Element* info(QString&, char* &, bool getNewOne=false);
static void splitEqn(QString &eqn, QStringList &tokens);
QString getExpression(bool isXyce, bool isCdl = false);
QString getExpression(spicecompat::SpiceDialect dialect = spicecompat::SPICEDefault);
protected:
QString vhdlCode(int) { return QString(); }