diff --git a/qucs/extsimkernels/abstractspicekernel.cpp b/qucs/extsimkernels/abstractspicekernel.cpp index af985f10f..7f7d7b46a 100644 --- a/qucs/extsimkernels/abstractspicekernel.cpp +++ b/qucs/extsimkernels/abstractspicekernel.cpp @@ -41,37 +41,43 @@ /*! * \brief AbstractSpiceKernel::AbstractSpiceKernel class constructor - * \param sch_ Schematic that should be simulated with Spice-compatible + * \param schematic Schematic that should be simulated with Spice-compatible * simulator * \param parent Parent object */ -AbstractSpiceKernel::AbstractSpiceKernel(Schematic *sch_, QObject *parent) : - QObject(parent) +AbstractSpiceKernel::AbstractSpiceKernel(Schematic *schematic, QObject *parent) : + QObject(parent), + a_workdir(), + a_simulator_cmd(), + a_simulator_parameters(), + a_output(), + a_simProcess(new QProcess(this)), + a_console(nullptr), + a_sims(), + a_vars(), + a_output_files(), + a_DC_OP_only(schematic->showBias == 0 ? true : false), + a_needsPrefix(false), + a_schematic(schematic), + a_parseFourTHD(false), + a_parsePZzeros(false) { - Sch = sch_; - console = nullptr; - needsPrefix = false; - - if (Sch->showBias == 0) DC_OP_only = true; - else DC_OP_only = false; - if (!checkDCSimulation()) { // Run Show bias mode automatically - DC_OP_only = true; // If schematic contains DC simulation only - Sch->showBias = 0; + a_DC_OP_only = true; // If schematic contains DC simulation only + a_schematic->showBias = 0; } - workdir = QucsSettings.S4Qworkdir; - QFileInfo inf(workdir); + a_workdir = QucsSettings.S4Qworkdir; + QFileInfo inf(a_workdir); if (!inf.exists()) { QDir dir; - dir.mkpath(workdir); + dir.mkpath(a_workdir); } - SimProcess = new QProcess(this); - SimProcess->setProcessChannelMode(QProcess::MergedChannels); - connect(SimProcess,SIGNAL(finished(int)),this,SLOT(slotFinished())); - connect(SimProcess,SIGNAL(readyRead()),this,SLOT(slotProcessOutput())); - connect(SimProcess,SIGNAL(errorOccurred(QProcess::ProcessError)),this,SLOT(slotErrors(QProcess::ProcessError))); + a_simProcess->setProcessChannelMode(QProcess::MergedChannels); + connect(a_simProcess,SIGNAL(finished(int)),this,SLOT(slotFinished())); + connect(a_simProcess,SIGNAL(readyRead()),this,SLOT(slotProcessOutput())); + connect(a_simProcess,SIGNAL(errorOccurred(QProcess::ProcessError)),this,SLOT(slotErrors(QProcess::ProcessError))); connect(this,SIGNAL(destroyed()),this,SLOT(killThemAll())); } @@ -84,8 +90,8 @@ AbstractSpiceKernel::~AbstractSpiceKernel() void AbstractSpiceKernel::killThemAll() { - if (SimProcess->state()!=QProcess::NotRunning) { - SimProcess->kill(); + if (a_simProcess->state()!=QProcess::NotRunning) { + a_simProcess->kill(); } } @@ -101,14 +107,14 @@ bool AbstractSpiceKernel::prepareSpiceNetlist(QTextStream &stream, bool isSubckt { QStringList collect; QPlainTextEdit *err = new QPlainTextEdit; - if (Sch->prepareNetlist(stream,collect,err)==-10) { // Broken netlist - output.append(err->toPlainText()); + if (a_schematic->prepareNetlist(stream,collect,err)==-10) { // Broken netlist + a_output.append(err->toPlainText()); delete err; return false; } delete err; - if (isSubckt) Sch->clearSignals(); - else Sch->clearSignalsAndFileList(); // for proper build of subckts + if (isSubckt) a_schematic->clearSignals(); + else a_schematic->clearSignalsAndFileList(); // for proper build of subckts return true; // TODO: Add feature to determine ability of spice simulation } @@ -122,7 +128,7 @@ bool AbstractSpiceKernel::prepareSpiceNetlist(QTextStream &stream, bool isSubckt bool AbstractSpiceKernel::checkSchematic(QStringList &incompat) { incompat.clear(); - for(Component *pc = Sch->DocComps.first(); pc != 0; pc = Sch->DocComps.next()) { + for(Component *pc = a_schematic->DocComps.first(); pc != 0; pc = a_schematic->DocComps.next()) { if ((!pc->isEquation)&&!(pc->isProbe)) { if (pc->SpiceModel.isEmpty() && pc->isActive) incompat.append(pc->Name); } @@ -138,7 +144,7 @@ bool AbstractSpiceKernel::checkSchematic(QStringList &incompat) bool AbstractSpiceKernel::checkGround() { bool r = false; - for(Component *pc = Sch->DocComps.first(); pc != 0; pc = Sch->DocComps.next()) { + for(Component *pc = a_schematic->DocComps.first(); pc != 0; pc = a_schematic->DocComps.next()) { if (pc->Model=="GND") { r = true; break; @@ -149,9 +155,9 @@ bool AbstractSpiceKernel::checkGround() bool AbstractSpiceKernel::checkSimulations() { - if (DC_OP_only) return true; + if (a_DC_OP_only) return true; bool r = false; - for(Component *pc = Sch->DocComps.first(); pc != 0; pc = Sch->DocComps.next()) { + for(Component *pc = a_schematic->DocComps.first(); pc != 0; pc = a_schematic->DocComps.next()) { if (pc->isSimulation) { r = true; break; @@ -164,9 +170,9 @@ bool AbstractSpiceKernel::checkDCSimulation() { return true; // DC OP is now saved in the dataset - //if (DC_OP_only) return true; + //if (a_DC_OP_only) return true; //bool r = false; - //for(Component *pc = Sch->DocComps.first(); pc != 0; pc = Sch->DocComps.next()) { + //for(Component *pc = a_schematic->DocComps.first(); pc != 0; pc = a_schematic->DocComps.next()) { // if (!pc->isActive) continue; // if (pc->isSimulation && pc->Model != ".DC") { // r = true; @@ -190,7 +196,7 @@ void AbstractSpiceKernel::startNetlist(QTextStream &stream, bool xyce) QString s; // User-defined functions - for(Component *pc = Sch->DocComps.first(); pc != 0; pc = Sch->DocComps.next()) { + for(Component *pc = a_schematic->DocComps.first(); pc != 0; pc = a_schematic->DocComps.next()) { if ((pc->SpiceModel==".FUNC")|| (pc->SpiceModel=="INCLSCR")) { s = pc->getExpression(); @@ -200,7 +206,7 @@ void AbstractSpiceKernel::startNetlist(QTextStream &stream, bool xyce) // create .IC from wire labels QStringList wire_labels; - for(Wire *pw = Sch->DocWires.first(); pw != 0; pw = Sch->DocWires.next()) { + for(Wire *pw = a_schematic->DocWires.first(); pw != 0; pw = a_schematic->DocWires.next()) { if (pw->Label != nullptr) { QString label = pw->Label->Name; if (!wire_labels.contains(label)) wire_labels.append(label); @@ -212,7 +218,7 @@ void AbstractSpiceKernel::startNetlist(QTextStream &stream, bool xyce) } } } - for(Node *pn = Sch->DocNodes.first(); pn != 0; pn = Sch->DocNodes.next()) { + for(Node *pn = a_schematic->DocNodes.first(); pn != 0; pn = a_schematic->DocNodes.next()) { Conductor *pw = (Conductor*) pn; if (pw->Label != nullptr) { QString label = pw->Label->Name; @@ -227,7 +233,7 @@ void AbstractSpiceKernel::startNetlist(QTextStream &stream, bool xyce) } // Parameters, Initial conditions, Options - for(Component *pc = Sch->DocComps.first(); pc != 0; pc = Sch->DocComps.next()) { + for(Component *pc = a_schematic->DocComps.first(); pc != 0; pc = a_schematic->DocComps.next()) { if (pc->isEquation) { s = pc->getExpression(xyce); stream<DocComps.first(); pc != 0; pc = Sch->DocComps.next()) { - if(Sch->isAnalog && + for(Component *pc = a_schematic->DocComps.first(); pc != 0; pc = a_schematic->DocComps.next()) { + if(a_schematic->isAnalog && !(pc->isSimulation) && !(pc->isEquation)) { s = pc->getSpiceNetlist(xyce); @@ -245,7 +251,7 @@ void AbstractSpiceKernel::startNetlist(QTextStream &stream, bool xyce) } // Modelcards - for(Component *pc = Sch->DocComps.first(); pc != 0; pc = Sch->DocComps.next()) { + for(Component *pc = a_schematic->DocComps.first(); pc != 0; pc = a_schematic->DocComps.next()) { if (pc->SpiceModel==".MODEL") { s = pc->getSpiceModel(); stream<DocName); + QString f = misc::properFileName(a_schematic->DocName); header = QStringLiteral(".SUBCKT %1 ").arg(misc::properName(f)); QList< QPair > ports; @@ -282,7 +288,7 @@ void AbstractSpiceKernel::createSubNetlsit(QTextStream &stream, bool lib) emit errors(QProcess::FailedToStart); return; } // Unable to perform spice simulation - for(Component *pc = Sch->DocComps.first(); pc != 0; pc = Sch->DocComps.next()) { + for(Component *pc = a_schematic->DocComps.first(); pc != 0; pc = a_schematic->DocComps.next()) { if (pc->Model=="Port") { ports.append(qMakePair(pc->Props.first()->Value.toInt(), pc->Ports.first()->Connection->Name)); @@ -295,7 +301,7 @@ void AbstractSpiceKernel::createSubNetlsit(QTextStream &stream, bool lib) } Painting *pai; - for(pai = Sch->SymbolPaints.first(); pai != 0; pai = Sch->SymbolPaints.next()) + for(pai = a_schematic->SymbolPaints.first(); pai != 0; pai = a_schematic->SymbolPaints.next()) if(pai->Name == ".ID ") { ID_Text *pid = (ID_Text*)pai; QList::const_iterator it; @@ -479,7 +485,7 @@ void AbstractSpiceKernel::parseFourierOutput(QString ngspice_file, QListshowBias = 1; + a_schematic->showBias = 1; } /*! @@ -726,10 +732,10 @@ void AbstractSpiceKernel::parseDC_OPoutputXY(QString xyce_file) } // Update Node labels on schematic - SweepDialog *swpdlg = new SweepDialog(Sch,&NodeVals); + SweepDialog *swpdlg = new SweepDialog(a_schematic,&NodeVals); delete swpdlg; - Sch->showBias = 1; + a_schematic->showBias = 1; } /*! @@ -1134,10 +1140,10 @@ int AbstractSpiceKernel::checkRawOutupt(QString ngspice_file, QStringList &value */ void AbstractSpiceKernel::convertToQucsData(const QString &qucs_dataset) { - if (DC_OP_only) { // Don't touch existing datasets when only DC was simulated + if (a_DC_OP_only) { // Don't touch existing datasets when only DC was simulated // It's need to show DC bias on schematic only - for (const QString& outputfile : output_files) { - QString full_outfile = workdir+QDir::separator()+outputfile; + for (const QString& outputfile : a_output_files) { + QString full_outfile = a_workdir+QDir::separator()+outputfile; if (outputfile.endsWith(".dc_op")) { parseDC_OPoutput(full_outfile); } else if (outputfile.endsWith(".dc_op_xyce")) { @@ -1155,7 +1161,7 @@ void AbstractSpiceKernel::convertToQucsData(const QString &qucs_dataset) QString sim,indep; QStringList indep_vars; - for (const QString& ngspice_output_filename : output_files) { // For every simulation convert results to Qucs dataset + for (const QString& ngspice_output_filename : a_output_files) { // For every simulation convert results to Qucs dataset QList< QList > sim_points; QStringList var_list; QString swp_var,swp_var2; @@ -1174,13 +1180,13 @@ void AbstractSpiceKernel::convertToQucsData(const QString &qucs_dataset) isCustomPrefix = !dataset_prefix.isEmpty(); } QRegularExpression four_rx(".*\\.four[0-9]+$"); - QString full_outfile = workdir+QDir::separator()+ngspice_output_filename; + QString full_outfile = a_workdir+QDir::separator()+ngspice_output_filename; if (ngspice_output_filename.endsWith("HB.FD.prn")) { //parseHBOutput(full_outfile,sim_points,var_list,hasParSweep); //isComplex = true; parseXYCESTDOutput(full_outfile,sim_points,var_list,isComplex,hasParSweep); if (hasParSweep) { - QString res_file = QDir::toNativeSeparators(workdir + QDir::separator() + QString res_file = QDir::toNativeSeparators(a_workdir + QDir::separator() + "spice4qucs.hb.cir.res"); parseResFile(res_file,swp_var,swp_var_val); } @@ -1200,7 +1206,7 @@ void AbstractSpiceKernel::convertToQucsData(const QString &qucs_dataset) isComplex = false; parseNoiseOutput(full_outfile,sim_points,var_list,hasParSweep); if (hasParSweep) { - QString res_file = QDir::toNativeSeparators(workdir + QDir::separator() + QString res_file = QDir::toNativeSeparators(a_workdir + QDir::separator() + "spice4qucs." + dataset_prefix + ".cir.res"); parseResFile(res_file,swp_var,swp_var_val); } @@ -1208,7 +1214,7 @@ void AbstractSpiceKernel::convertToQucsData(const QString &qucs_dataset) isComplex = true; parsePZOutput(full_outfile,sim_points,var_list,hasParSweep); if (hasParSweep) { - QString res_file = QDir::toNativeSeparators(workdir + QDir::separator() + QString res_file = QDir::toNativeSeparators(a_workdir + QDir::separator() + "spice4qucs." + dataset_prefix + ".cir.res"); parseResFile(res_file,swp_var,swp_var_val); } @@ -1218,7 +1224,7 @@ void AbstractSpiceKernel::convertToQucsData(const QString &qucs_dataset) parseXYCESTDOutput(full_outfile,sim_points,var_list,isComplex,hasParSweep); if (type == xyceSTDswp) { hasParSweep = true; - QString res_file = QDir::toNativeSeparators(workdir + QDir::separator() + QString res_file = QDir::toNativeSeparators(a_workdir + QDir::separator() + "spice4qucs.sens.cir.res"); parseResFile(res_file,swp_var,swp_var_val); } @@ -1226,12 +1232,12 @@ void AbstractSpiceKernel::convertToQucsData(const QString &qucs_dataset) hasParSweep = true; if (ngspice_output_filename.endsWith("_swp_swp.plot")) { // 2-var parameter sweep hasDblParSweep = true; - QString res2_file = QDir::toNativeSeparators(workdir + QDir::separator() + QString res2_file = QDir::toNativeSeparators(a_workdir + QDir::separator() + "spice4qucs." + dataset_prefix + ".cir.res1"); parseResFile(res2_file,swp_var2,swp_var2_val); } - QString res_file = QDir::toNativeSeparators(workdir + QDir::separator() + QString res_file = QDir::toNativeSeparators(a_workdir + QDir::separator() + "spice4qucs." + dataset_prefix + ".cir.res"); parseResFile(res_file,swp_var,swp_var_val); @@ -1351,11 +1357,11 @@ void AbstractSpiceKernel::convertToQucsData(const QString &qucs_dataset) */ void AbstractSpiceKernel::removeAllSimulatorOutputs() { - for (const QString& output_filename : output_files) { - QString full_outfile = workdir+QDir::separator()+output_filename; + for (const QString& output_filename : a_output_files) { + QString full_outfile = a_workdir+QDir::separator()+output_filename; QFile::remove(full_outfile); } - QDir dir(workdir); + QDir dir(a_workdir); dir.setNameFilters(QStringList() << "*.cir.res*"); dir.setFilter(QDir::Files); foreach(QString file, dir.entryList()) @@ -1425,7 +1431,7 @@ void AbstractSpiceKernel::normalizeVarsNames(QStringList &var_list, const QStrin } } - if ( needsPrefix || isCustom ) + if ( a_needsPrefix || isCustom ) if ( !dataset_prefix.isEmpty() ) { for ( it = var_list.begin() ; it != var_list.end() ; ++it) if ( !(*it).isEmpty() ) @@ -1447,14 +1453,14 @@ void AbstractSpiceKernel::slotErrors(QProcess::ProcessError err) */ void AbstractSpiceKernel::slotFinished() { - //output.clear(); - output += SimProcess->readAllStandardOutput(); + //a_output.clear(); + a_output += a_simProcess->readAllStandardOutput(); emit finished(); emit progress(100); } /*! - * \brief AbstractSpiceKernel::slotProcessOutput Process SimProcess output and report progress + * \brief AbstractSpiceKernel::slotProcessOutput Process a_simProcess output and report progress */ void AbstractSpiceKernel::slotProcessOutput() { @@ -1468,7 +1474,7 @@ void AbstractSpiceKernel::slotProcessOutput() */ QString AbstractSpiceKernel::getOutput() { - return output; + return a_output; } /*! @@ -1477,7 +1483,7 @@ QString AbstractSpiceKernel::getOutput() */ void AbstractSpiceKernel::setSimulatorCmd(QString cmd) { - simulator_cmd = cmd; + a_simulator_cmd = cmd; } @@ -1487,7 +1493,7 @@ void AbstractSpiceKernel::setSimulatorCmd(QString cmd) */ void AbstractSpiceKernel::setSimulatorParameters(QString parameters) { - simulator_parameters = parameters; + a_simulator_parameters = parameters; } /*! @@ -1497,11 +1503,11 @@ void AbstractSpiceKernel::setSimulatorParameters(QString parameters) */ void AbstractSpiceKernel::setWorkdir(QString path) { - workdir = path; - QFileInfo inf(workdir); + a_workdir = path; + QFileInfo inf(a_workdir); if (!inf.exists()) { QDir dir; - dir.mkpath(workdir); + dir.mkpath(a_workdir); } } @@ -1516,7 +1522,7 @@ void AbstractSpiceKernel::SaveNetlist(QString) bool AbstractSpiceKernel::waitEndOfSimulation() { - return SimProcess->waitForFinished(10000); + return a_simProcess->waitForFinished(10000); } QString AbstractSpiceKernel::collectSpiceLibs(Schematic* sch) diff --git a/qucs/extsimkernels/abstractspicekernel.h b/qucs/extsimkernels/abstractspicekernel.h index e03b12e5e..6807fc98c 100644 --- a/qucs/extsimkernels/abstractspicekernel.h +++ b/qucs/extsimkernels/abstractspicekernel.h @@ -45,6 +45,7 @@ class QPlainTextEdit; class AbstractSpiceKernel : public QObject { Q_OBJECT + private: enum outType {xyceSTD, spiceRaw, spiceRawSwp, xyceSTDswp, spicePrn, Unknown}; @@ -56,19 +57,23 @@ class AbstractSpiceKernel : public QObject int NumVars, bool isComplex); protected: - QString netlist,workdir, simulator_cmd, - simulator_parameters, output; - QProcess *SimProcess; + QString a_workdir; + QString a_simulator_cmd; + QString a_simulator_parameters; + QString a_output; + QProcess *a_simProcess; - QPlainTextEdit *console; - QStringList sims,vars,output_files; + QPlainTextEdit *a_console; + QStringList a_sims; + QStringList a_vars; + QStringList a_output_files; - bool DC_OP_only; // only calculate operating point to show DC bias - bool needsPrefix; - Schematic *Sch; + bool a_DC_OP_only; // only calculate operating point to show DC bias + bool a_needsPrefix; + Schematic *a_schematic; - bool parseFourTHD = false; // Fourier output is parsed twice, first freqencies, then THD - bool parsePZzeros = false; // PZ output is parsed twice, first poles, then zeros + bool a_parseFourTHD; // Fourier output is parsed twice, first freqencies, then THD + bool a_parsePZzeros; // PZ output is parsed twice, first poles, then zeros bool prepareSpiceNetlist(QTextStream &stream, bool isSubckt = false); virtual void startNetlist(QTextStream& stream, bool xyce = false); @@ -82,7 +87,7 @@ class AbstractSpiceKernel : public QObject public: - explicit AbstractSpiceKernel(Schematic *sch_, QObject *parent = 0); + explicit AbstractSpiceKernel(Schematic *schematic, QObject *parent = 0); ~AbstractSpiceKernel(); bool checkSchematic(QStringList &incompat); @@ -124,8 +129,8 @@ class AbstractSpiceKernel : public QObject void setWorkdir(QString path); virtual void SaveNetlist(QString filename); virtual bool waitEndOfSimulation(); - void setConsole(QPlainTextEdit *console_) { console = console_; } - + void setConsole(QPlainTextEdit *console) { a_console = console; } + signals: void started(); void finished(); @@ -140,7 +145,7 @@ public slots: virtual void slotSimulate(); void killThemAll(); void slotErrors(QProcess::ProcessError err); - + }; #endif // ABSTRACTSPICEKERNEL_H diff --git a/qucs/extsimkernels/customsimdialog.cpp b/qucs/extsimkernels/customsimdialog.cpp index 40850cd37..c2d1a2f0c 100644 --- a/qucs/extsimkernels/customsimdialog.cpp +++ b/qucs/extsimkernels/customsimdialog.cpp @@ -29,47 +29,48 @@ /*! * \brief CustomSimDialog::CustomSimDialog class constructor * \param pc[in] Component that need to be edit. - * \param sch[in] Schematic on which component presents. + * \param sch[in] Schematic on which a_component presents. */ CustomSimDialog::CustomSimDialog(SpiceCustomSim *pc, Schematic *sch) : - QDialog(sch) + QDialog(sch), + a_isXyceScr(false), + a_isChanged(false), + a_comp(pc), + a_schematic(sch), + a_edtCode(new QTextEdit(this)), + a_checkCode(new QCheckBox(tr("display in schematic"), this)), + a_btnOK(new QPushButton(tr("OK"))), + a_btnApply(new QPushButton(tr("Apply"))), + a_btnCancel(new QPushButton(tr("Cancel"))), + a_btnPlotAll(new QPushButton(tr("Find all variables"))), + a_btnFindOutputs(new QPushButton(tr("Find all outputs"))), + a_edtVars(new QLineEdit(a_comp->Props.at(1)->Value)), + a_edtOutputs(new QLineEdit(a_comp->Props.at(2)->Value)) { - comp = pc; - Sch = sch; - resize(640, 480); setWindowTitle(tr("Edit SPICE code")); - QLabel* lblName = new QLabel(tr("Component: ")+comp->Description); + QLabel* lblName = new QLabel(tr("Component: ")+a_comp->Description); - edtCode = new QTextEdit(this); - edtCode->document()->setDefaultFont(QucsSettings.textFont); - edtCode->setWordWrapMode(QTextOption::NoWrap); - edtCode->insertPlainText(comp->Props.at(0)->Value); - connect(edtCode, SIGNAL(textChanged()), this, SLOT(slotChanged())); + a_edtCode->document()->setDefaultFont(QucsSettings.textFont); + a_edtCode->setWordWrapMode(QTextOption::NoWrap); + a_edtCode->insertPlainText(a_comp->Props.at(0)->Value); + connect(a_edtCode, SIGNAL(textChanged()), this, SLOT(slotChanged())); - checkCode = new QCheckBox(tr("display in schematic"), this); - checkCode->setChecked(comp->Props.at(0)->display); - connect(checkCode, SIGNAL(stateChanged(int)), this, SLOT(slotChanged())); + a_checkCode->setChecked(a_comp->Props.at(0)->display); + connect(a_checkCode, SIGNAL(stateChanged(int)), this, SLOT(slotChanged())); QLabel* lblVars = new QLabel(tr("Variables to plot (semicolon separated)")); - edtVars = new QLineEdit(comp->Props.at(1)->Value); - connect(edtVars, SIGNAL(textChanged(const QString&)), this, SLOT(slotChanged())); + connect(a_edtVars, SIGNAL(textChanged(const QString&)), this, SLOT(slotChanged())); QLabel* lblOut = new QLabel(tr("Extra outputs (semicolon separated; raw-SPICE or XYCE-STD or scalars print format)")); - edtOutputs = new QLineEdit(comp->Props.at(2)->Value); - connect(edtOutputs, SIGNAL(textChanged(const QString&)), this, SLOT(slotChanged())); - - btnApply = new QPushButton(tr("Apply")); - connect(btnApply,SIGNAL(clicked()),this,SLOT(slotApply())); - btnCancel = new QPushButton(tr("Cancel")); - connect(btnCancel,SIGNAL(clicked()),this,SLOT(slotCancel())); - btnOK = new QPushButton(tr("OK")); - connect(btnOK,SIGNAL(clicked()),this,SLOT(slotOK())); - btnPlotAll = new QPushButton(tr("Find all variables")); - connect(btnPlotAll,SIGNAL(clicked()),this,SLOT(slotFindVars())); - btnFindOutputs = new QPushButton(tr("Find all outputs")); - connect(btnFindOutputs,SIGNAL(clicked()),this,SLOT(slotFindOutputs())); + connect(a_edtOutputs, SIGNAL(textChanged(const QString&)), this, SLOT(slotChanged())); + + connect(a_btnApply,SIGNAL(clicked()),this,SLOT(slotApply())); + connect(a_btnCancel,SIGNAL(clicked()),this,SLOT(slotCancel())); + connect(a_btnOK,SIGNAL(clicked()),this,SLOT(slotOK())); + connect(a_btnPlotAll,SIGNAL(clicked()),this,SLOT(slotFindVars())); + connect(a_btnFindOutputs,SIGNAL(clicked()),this,SLOT(slotFindOutputs())); QVBoxLayout *vl1 = new QVBoxLayout; QVBoxLayout *vl2 = new QVBoxLayout; @@ -77,64 +78,64 @@ CustomSimDialog::CustomSimDialog(SpiceCustomSim *pc, Schematic *sch) : vl1->addWidget(lblName); QGroupBox *gpb1 = new QGroupBox(tr("SPICE code editor")); - vl2->addWidget(edtCode); - vl2->addWidget(checkCode); + vl2->addWidget(a_edtCode); + vl2->addWidget(a_checkCode); gpb1->setLayout(vl2); vl1->addWidget(gpb1); vl1->addWidget(lblVars); - vl1->addWidget(edtVars); - vl1->addWidget(btnPlotAll); + vl1->addWidget(a_edtVars); + vl1->addWidget(a_btnPlotAll); vl1->addWidget(lblOut); - vl1->addWidget(edtOutputs); - vl1->addWidget(btnFindOutputs); + vl1->addWidget(a_edtOutputs); + vl1->addWidget(a_btnFindOutputs); - hl1->addWidget(btnOK); - hl1->addWidget(btnApply); - hl1->addWidget(btnCancel); + hl1->addWidget(a_btnOK); + hl1->addWidget(a_btnApply); + hl1->addWidget(a_btnCancel); vl1->addLayout(hl1); this->setLayout(vl1); this->setWindowTitle(tr("Edit SPICE code")); - if (comp->Model == ".XYCESCR") { + if (a_comp->Model == ".XYCESCR") { lblVars->setEnabled(false); - edtVars->setEnabled(false); - btnPlotAll->setEnabled(false); - isXyceScr = true; - } else if (comp->Model == "INCLSCR") { + a_edtVars->setEnabled(false); + a_btnPlotAll->setEnabled(false); + a_isXyceScr = true; + } else if (a_comp->Model == "INCLSCR") { lblVars->setEnabled(false); - edtVars->setEnabled(false); - btnPlotAll->setEnabled(false); - btnFindOutputs->setEnabled(false); + a_edtVars->setEnabled(false); + a_btnPlotAll->setEnabled(false); + a_btnFindOutputs->setEnabled(false); lblOut->setEnabled(false); - } else isXyceScr = false; + } else a_isXyceScr = false; } /*! - * \brief CustomSimDialog::slotChanged Set isChanged state. + * \brief CustomSimDialog::slotChanged Set a_isChanged state. */ void CustomSimDialog::slotChanged() { - isChanged = true; + a_isChanged = true; } /*! - * \brief CustomSimDialog::slotApply Apply changes of component properties. + * \brief CustomSimDialog::slotApply Apply changes of a_component properties. */ void CustomSimDialog::slotApply() { - if ( isChanged ) { - edtVars->setText(edtVars->text().remove(' ')); - edtOutputs->setText(edtOutputs->text().remove(' ')); + if ( a_isChanged ) { + a_edtVars->setText(a_edtVars->text().remove(' ')); + a_edtOutputs->setText(a_edtOutputs->text().remove(' ')); - comp->Props.at(0)->Value = edtCode->document()->toPlainText(); - comp->Props.at(0)->display = checkCode->isChecked(); - comp->Props.at(1)->Value = edtVars->text(); - comp->Props.at(2)->Value = edtOutputs->text(); + a_comp->Props.at(0)->Value = a_edtCode->document()->toPlainText(); + a_comp->Props.at(0)->display = a_checkCode->isChecked(); + a_comp->Props.at(1)->Value = a_edtVars->text(); + a_comp->Props.at(2)->Value = a_edtOutputs->text(); - Sch->recreateComponent(comp); - Sch->viewport()->repaint(); + a_schematic->recreateComponent(a_comp); + a_schematic->viewport()->repaint(); - isChanged = false; + a_isChanged = false; } } @@ -157,19 +158,19 @@ void CustomSimDialog::slotCancel() /*! * \brief CustomSimDialog::slotFindVars Auto-find used variables and nodes - * in simulation script and place them into edtVars line edit. + * in simulation script and place them into a_edtVars line edit. */ void CustomSimDialog::slotFindVars() { QStringList vars; - for(Node *pn = Sch->DocNodes.first(); pn != 0; pn = Sch->DocNodes.next()) { + for(Node *pn = a_schematic->DocNodes.first(); pn != 0; pn = a_schematic->DocNodes.next()) { if(pn->Label != 0) { if (!vars.contains(pn->Label->Name)) { vars.append(pn->Label->Name); } } } - for(Wire *pw = Sch->DocWires.first(); pw != 0; pw = Sch->DocWires.next()) { + for(Wire *pw = a_schematic->DocWires.first(); pw != 0; pw = a_schematic->DocWires.next()) { if(pw->Label != 0) { if (!vars.contains(pw->Label->Name)) { vars.append(pw->Label->Name); @@ -177,7 +178,7 @@ void CustomSimDialog::slotFindVars() } } - for(Component *pc=Sch->DocComps.first();pc!=0;pc=Sch->DocComps.next()) { + for(Component *pc=a_schematic->DocComps.first();pc!=0;pc=a_schematic->DocComps.next()) { if(pc->isProbe) { if (!vars.contains(pc->getProbeVariable())) { vars.append(pc->getProbeVariable()); @@ -191,7 +192,7 @@ void CustomSimDialog::slotFindVars() - QStringList strings = edtCode->toPlainText().split('\n'); + QStringList strings = a_edtCode->toPlainText().split('\n'); QRegularExpression let_pattern("^\\s*let\\s+[A-Za-z].*=.+"); for (const QString& line : strings) { @@ -203,15 +204,15 @@ void CustomSimDialog::slotFindVars() } } - edtVars->setText(vars.join(";")); + a_edtVars->setText(vars.join(";")); } void CustomSimDialog::slotFindOutputs() { QStringList outps; QString outp; - QStringList strings = edtCode->toPlainText().split('\n'); - if (isXyceScr) { + QStringList strings = a_edtCode->toPlainText().split('\n'); + if (a_isXyceScr) { QRegularExpression print_ex("^\\s*\\.print\\s.*", QRegularExpression::CaseInsensitiveOption); QRegularExpression file_ex("\\s*file\\s*=\\s*", QRegularExpression::CaseInsensitiveOption); for (const QString& line : strings) { @@ -242,5 +243,5 @@ void CustomSimDialog::slotFindOutputs() } } - edtOutputs->setText(outps.join(";")); + a_edtOutputs->setText(outps.join(";")); } diff --git a/qucs/extsimkernels/customsimdialog.h b/qucs/extsimkernels/customsimdialog.h index 72fde7b14..c2e43696f 100644 --- a/qucs/extsimkernels/customsimdialog.h +++ b/qucs/extsimkernels/customsimdialog.h @@ -42,26 +42,26 @@ class CustomSimDialog : public QDialog private: - bool isXyceScr; - bool isChanged = false; + bool a_isXyceScr; + bool a_isChanged = false; - SpiceCustomSim* comp; - Schematic *Sch; + SpiceCustomSim* a_comp; + Schematic *a_schematic; - QTextEdit* edtCode; - QCheckBox *checkCode; - QPushButton *btnOK; - QPushButton *btnApply; - QPushButton *btnCancel; - QPushButton *btnPlotAll; - QPushButton *btnFindOutputs; + QTextEdit* a_edtCode; + QCheckBox *a_checkCode; + QPushButton *a_btnOK; + QPushButton *a_btnApply; + QPushButton *a_btnCancel; + QPushButton *a_btnPlotAll; + QPushButton *a_btnFindOutputs; - QLineEdit *edtVars; - QLineEdit *edtOutputs; + QLineEdit *a_edtVars; + QLineEdit *a_edtOutputs; public: explicit CustomSimDialog(SpiceCustomSim *pc, Schematic *sch); - + signals: private slots: @@ -71,9 +71,9 @@ private slots: void slotFindVars(); void slotFindOutputs(); void slotChanged(); - + public slots: - + }; #endif // CUSTOMSIMDIALOG_H diff --git a/qucs/extsimkernels/externsimdialog.cpp b/qucs/extsimkernels/externsimdialog.cpp index 731ed0e4b..ea0618073 100644 --- a/qucs/extsimkernels/externsimdialog.cpp +++ b/qucs/extsimkernels/externsimdialog.cpp @@ -25,11 +25,20 @@ #include "qucs.h" ExternSimDialog::ExternSimDialog(Schematic *sch, bool netlist_mode) : - QDialog(sch) + QDialog(sch), + a_schematic(sch), + a_buttonStopSim(new QPushButton(tr("Stop"),this)), + a_buttonSaveNetlist(new QPushButton(tr("Save netlist"),this)), + a_buttonExit(new QPushButton(tr("Exit"),this)), + a_editSimConsole(new QPlainTextEdit(this)), + a_simStatusLog(new QListWidget), + a_simProgress(new QProgressBar(this)), + a_ngspice(new Ngspice(sch,this)), + a_xyce(new Xyce(sch,this)), + a_wasSimulated(false), + a_hasError(false) { - Sch = sch; - wasSimulated = false; - hasError = false; + const QString workdir(QucsSettings.S4Qworkdir); QSettings settings("qucs", "qucs_s"); restoreGeometry(settings.value("ExternSimDialog/geometry").toByteArray()); @@ -37,79 +46,68 @@ ExternSimDialog::ExternSimDialog(Schematic *sch, bool netlist_mode) : setWindowTitle(tr("Simulate with external simulator")); setMinimumWidth(500); - workdir = QucsSettings.S4Qworkdir; QFileInfo inf(workdir); if (!inf.exists()) { QDir dir; dir.mkpath(workdir); } - ngspice = new Ngspice(sch,this); - xyce = new Xyce(sch,this); + connect(a_buttonStopSim,SIGNAL(clicked()),a_ngspice,SLOT(killThemAll())); + connect(a_buttonStopSim,SIGNAL(clicked()),a_xyce,SLOT(killThemAll())); + a_buttonStopSim->setEnabled(false); - buttonStopSim = new QPushButton(tr("Stop"),this); - connect(buttonStopSim,SIGNAL(clicked()),ngspice,SLOT(killThemAll())); - connect(buttonStopSim,SIGNAL(clicked()),xyce,SLOT(killThemAll())); - buttonStopSim->setEnabled(false); + connect(a_buttonSaveNetlist,SIGNAL(clicked()),this,SLOT(slotSaveNetlist())); - buttonSaveNetlist = new QPushButton(tr("Save netlist"),this); - connect(buttonSaveNetlist,SIGNAL(clicked()),this,SLOT(slotSaveNetlist())); - - buttonExit = new QPushButton(tr("Exit"),this); - connect(buttonExit,SIGNAL(clicked()),this,SLOT(slotExit())); - connect(buttonExit,SIGNAL(clicked()),ngspice,SLOT(killThemAll())); - connect(buttonExit,SIGNAL(clicked()),xyce,SLOT(killThemAll())); + connect(a_buttonExit,SIGNAL(clicked()),this,SLOT(slotExit())); + connect(a_buttonExit,SIGNAL(clicked()),a_ngspice,SLOT(killThemAll())); + connect(a_buttonExit,SIGNAL(clicked()),a_xyce,SLOT(killThemAll())); QGroupBox *grp_1 = new QGroupBox(tr("Simulation console"),this); QVBoxLayout *vbl1 = new QVBoxLayout; - editSimConsole = new QPlainTextEdit(this); QFont font; font.setFamily("monospace"); font.setPointSize(10); - editSimConsole->setFont(font); - editSimConsole->setReadOnly(true); - vbl1->addWidget(editSimConsole); + a_editSimConsole->setFont(font); + a_editSimConsole->setReadOnly(true); + vbl1->addWidget(a_editSimConsole); grp_1->setLayout(vbl1); - ngspice->setConsole(editSimConsole); - xyce->setConsole(editSimConsole); - - simStatusLog = new QListWidget; + a_ngspice->setConsole(a_editSimConsole); + a_xyce->setConsole(a_editSimConsole); - simProgress = new QProgressBar(this); - connect(ngspice,SIGNAL(progress(int)),simProgress,SLOT(setValue(int))); - connect(xyce,SIGNAL(progress(int)),simProgress,SLOT(setValue(int))); + connect(a_ngspice,SIGNAL(progress(int)),a_simProgress,SLOT(setValue(int))); + connect(a_xyce,SIGNAL(progress(int)),a_simProgress,SLOT(setValue(int))); QVBoxLayout *vl_top = new QVBoxLayout; vl_top->addWidget(grp_1,3); - vl_top->addWidget(simStatusLog,1); - vl_top->addWidget(simProgress); + vl_top->addWidget(a_simStatusLog,1); + vl_top->addWidget(a_simProgress); QHBoxLayout *hl1 = new QHBoxLayout; - hl1->addWidget(buttonStopSim); - hl1->addWidget(buttonSaveNetlist); - hl1->addWidget(buttonExit); + hl1->addWidget(a_buttonStopSim); + hl1->addWidget(a_buttonSaveNetlist); + hl1->addWidget(a_buttonExit); vl_top->addLayout(hl1); setLayout(vl_top); slotSetSimulator(); - if (!netlist_mode && !QucsMain->TuningMode && Sch->showBias != 0) + if (!netlist_mode && !QucsMain->TuningMode && a_schematic->showBias != 0) slotStart(); // Start simulation } ExternSimDialog::~ExternSimDialog() { - ngspice->killThemAll(); + a_ngspice->killThemAll(); } void ExternSimDialog::slotSetSimulator() { switch (QucsSettings.DefaultSimulator) { case spicecompat::simNgspice: { - xyce->setParallel(false); - connect(ngspice,SIGNAL(started()),this,SLOT(slotNgspiceStarted())); - connect(ngspice,SIGNAL(finished()),this,SLOT(slotProcessOutput())); - connect(ngspice,SIGNAL(errors(QProcess::ProcessError)),this,SLOT(slotNgspiceStartError(QProcess::ProcessError))); + a_xyce->setParallel(false); + connect(a_ngspice,SIGNAL(started()),this,SLOT(slotNgspiceStarted())); + connect(a_ngspice,SIGNAL(finished()),this,SLOT(slotProcessOutput())); + connect(a_ngspice,SIGNAL(errors(QProcess::ProcessError)),this,SLOT(slotNgspiceStartError(QProcess::ProcessError))); QString cmd; if (QFileInfo(QucsSettings.NgspiceExecutable).isRelative()) { // this check is related to MacOS cmd = QFileInfo(QucsSettings.BinDir + QucsSettings.NgspiceExecutable).absoluteFilePath(); @@ -117,41 +115,41 @@ void ExternSimDialog::slotSetSimulator() cmd = QFileInfo(QucsSettings.NgspiceExecutable).absoluteFilePath(); } if (QFileInfo::exists(cmd)) { - ngspice->setSimulatorCmd(cmd); + a_ngspice->setSimulatorCmd(cmd); } else { - ngspice->setSimulatorCmd(QucsSettings.NgspiceExecutable); //rely on $PATH + a_ngspice->setSimulatorCmd(QucsSettings.NgspiceExecutable); //rely on $PATH } - ngspice->setSimulatorParameters(QucsSettings.SimParameters); + a_ngspice->setSimulatorParameters(QucsSettings.SimParameters); } break; case spicecompat::simXyce: { - xyce->setParallel(false); - connect(xyce,SIGNAL(started()),this,SLOT(slotNgspiceStarted())); - connect(xyce,SIGNAL(finished()),this,SLOT(slotProcessOutput())); - connect(xyce,SIGNAL(errors(QProcess::ProcessError)),this,SLOT(slotNgspiceStartError(QProcess::ProcessError))); - xyce->setSimulatorParameters(QucsSettings.SimParameters); + a_xyce->setParallel(false); + connect(a_xyce,SIGNAL(started()),this,SLOT(slotNgspiceStarted())); + connect(a_xyce,SIGNAL(finished()),this,SLOT(slotProcessOutput())); + connect(a_xyce,SIGNAL(errors(QProcess::ProcessError)),this,SLOT(slotNgspiceStartError(QProcess::ProcessError))); + a_xyce->setSimulatorParameters(QucsSettings.SimParameters); } break; // case spicecompat::simXycePar: { //#ifdef Q_OS_UNIX -// xyce->setParallel(true); +// a_xyce->setParallel(true); //#else -// xyce->setParallel(false); +// a_xyce->setParallel(false); //#endif -// connect(xyce,SIGNAL(started()),this,SLOT(slotNgspiceStarted())); -// connect(xyce,SIGNAL(finished()),this,SLOT(slotProcessOutput())); -// connect(xyce,SIGNAL(errors(QProcess::ProcessError)),this,SLOT(slotNgspiceStartError(QProcess::ProcessError))); -// connect(buttonSimulate,SIGNAL(clicked()),xyce,SLOT(slotSimulate())); -// xyce->setSimulatorParameters(QucsSettings.SimParameters); +// connect(a_xyce,SIGNAL(started()),this,SLOT(slotNgspiceStarted())); +// connect(a_xyce,SIGNAL(finished()),this,SLOT(slotProcessOutput())); +// connect(a_xyce,SIGNAL(errors(QProcess::ProcessError)),this,SLOT(slotNgspiceStartError(QProcess::ProcessError))); +// connect(buttonSimulate,SIGNAL(clicked()),a_xyce,SLOT(slotSimulate())); +// a_xyce->setSimulatorParameters(QucsSettings.SimParameters); // } // break; case spicecompat::simSpiceOpus: { - xyce->setParallel(false); - connect(ngspice,SIGNAL(started()),this,SLOT(slotNgspiceStarted()),Qt::UniqueConnection); - connect(ngspice,SIGNAL(finished()),this,SLOT(slotProcessOutput()),Qt::UniqueConnection); - connect(ngspice,SIGNAL(errors(QProcess::ProcessError)),this,SLOT(slotNgspiceStartError(QProcess::ProcessError)),Qt::UniqueConnection); - ngspice->setSimulatorCmd(QucsSettings.SpiceOpusExecutable); - ngspice->setSimulatorParameters(QucsSettings.SimParameters); + a_xyce->setParallel(false); + connect(a_ngspice,SIGNAL(started()),this,SLOT(slotNgspiceStarted()),Qt::UniqueConnection); + connect(a_ngspice,SIGNAL(finished()),this,SLOT(slotProcessOutput()),Qt::UniqueConnection); + connect(a_ngspice,SIGNAL(errors(QProcess::ProcessError)),this,SLOT(slotNgspiceStartError(QProcess::ProcessError)),Qt::UniqueConnection); + a_ngspice->setSimulatorCmd(QucsSettings.SpiceOpusExecutable); + a_ngspice->setSimulatorParameters(QucsSettings.SimParameters); } break; default: break; @@ -161,8 +159,8 @@ void ExternSimDialog::slotSetSimulator() void ExternSimDialog::slotProcessOutput() { - buttonSaveNetlist->setEnabled(true); - buttonStopSim->setEnabled(false); + a_buttonSaveNetlist->setEnabled(true); + a_buttonStopSim->setEnabled(false); QString out; // Set temporary safe output name @@ -171,14 +169,14 @@ void ExternSimDialog::slotProcessOutput() switch (QucsSettings.DefaultSimulator) { case spicecompat::simNgspice: ext = ".dat.ngspice"; - out = ngspice->getOutput(); + out = a_ngspice->getOutput(); break; case spicecompat::simXyce: ext = ".dat.xyce"; - out = xyce->getOutput(); + out = a_xyce->getOutput(); break; case spicecompat::simSpiceOpus: - out = ngspice->getOutput(); + out = a_ngspice->getOutput(); ext = ".dat.spopus"; break; default: @@ -202,39 +200,39 @@ void ExternSimDialog::slotProcessOutput() QIcon(":/bitmaps/svg/ok_apply.svg")); emit success(); } - //editSimConsole->clear(); - /*editSimConsole->insertPlainText(out); - editSimConsole->moveCursor(QTextCursor::End);*/ + //a_editSimConsole->clear(); + /*a_editSimConsole->insertPlainText(out); + a_editSimConsole->moveCursor(QTextCursor::End);*/ saveLog(); - editSimConsole->insertPlainText("Simulation finished\n"); + a_editSimConsole->insertPlainText("Simulation finished\n"); - QFileInfo inf(Sch->DocName); + QFileInfo inf(a_schematic->DocName); //QString qucs_dataset = inf.canonicalPath()+QDir::separator()+inf.baseName()+"_ngspice.dat"; QString qucs_dataset = inf.canonicalPath()+QDir::separator()+inf.completeBaseName()+ext; switch (QucsSettings.DefaultSimulator) { case spicecompat::simNgspice: case spicecompat::simSpiceOpus: - ngspice->convertToQucsData(qucs_dataset); + a_ngspice->convertToQucsData(qucs_dataset); break; case spicecompat::simXyce: - xyce->convertToQucsData(qucs_dataset); + a_xyce->convertToQucsData(qucs_dataset); break; default: break; } - wasSimulated = true; + a_wasSimulated = true; if (out.contains("error",Qt::CaseInsensitive)) - hasError = true; + a_hasError = true; emit simulated(this); - //if (Sch->showBias>0 || QucsMain->TuningMode) this->close(); + //if (a_schematic->showBias>0 || QucsMain->TuningMode) this->close(); } void ExternSimDialog::slotNgspiceStarted() { - editSimConsole->clear(); + a_editSimConsole->clear(); QString sim = spicecompat::getDefaultSimulatorName(QucsSettings.DefaultSimulator); - editSimConsole->insertPlainText(sim + tr(" started...\n")); + a_editSimConsole->insertPlainText(sim + tr(" started...\n")); addLogEntry(tr("Simulation started on: ") + QDateTime::currentDateTime().toString(), this->style()->standardIcon(QStyle::SP_MessageBoxInformation)); } @@ -254,22 +252,22 @@ void ExternSimDialog::slotNgspiceStartError(QProcess::ProcessError err) addLogEntry(msg,this->style()->standardIcon(QStyle::SP_MessageBoxCritical)); QString sim = spicecompat::getDefaultSimulatorName(QucsSettings.DefaultSimulator); - editSimConsole->insertPlainText(sim + tr(" error...")); + a_editSimConsole->insertPlainText(sim + tr(" error...")); } void ExternSimDialog::slotStart() { - buttonStopSim->setEnabled(true); - buttonSaveNetlist->setEnabled(false); + a_buttonStopSim->setEnabled(true); + a_buttonSaveNetlist->setEnabled(false); switch (QucsSettings.DefaultSimulator) { case spicecompat::simNgspice: - ngspice->slotSimulate(); + a_ngspice->slotSimulate(); break; case spicecompat::simXyce: - xyce->slotSimulate(); + a_xyce->slotSimulate(); break; case spicecompat::simSpiceOpus: - ngspice->slotSimulate(); + a_ngspice->slotSimulate(); break; default: break; } @@ -277,14 +275,14 @@ void ExternSimDialog::slotStart() void ExternSimDialog::slotStop() { - buttonStopSim->setEnabled(false); - buttonSaveNetlist->setEnabled(true); - ngspice->killThemAll(); + a_buttonStopSim->setEnabled(false); + a_buttonSaveNetlist->setEnabled(true); + a_ngspice->killThemAll(); } void ExternSimDialog::slotSaveNetlist() { - QFileInfo inf(Sch->DocName); + QFileInfo inf(a_schematic->DocName); QString filename = QFileDialog::getSaveFileName(this,tr("Save netlist"),inf.path()+QDir::separator()+"netlist.cir", "All files (*)"); if (filename.isEmpty()) return; @@ -292,11 +290,11 @@ void ExternSimDialog::slotSaveNetlist() switch (QucsSettings.DefaultSimulator) { case spicecompat::simNgspice: case spicecompat::simSpiceOpus: { - ngspice->SaveNetlist(filename); + a_ngspice->SaveNetlist(filename); } break; case spicecompat::simXyce: { - xyce->SaveNetlist(filename); + a_xyce->SaveNetlist(filename); } break; default: @@ -324,7 +322,7 @@ void ExternSimDialog::saveLog() QFile log(filename); if (log.open(QIODevice::WriteOnly)) { QTextStream ts_log(&log); - ts_log<toPlainText(); + ts_log<toPlainText(); log.flush(); log.close(); } @@ -335,7 +333,7 @@ void ExternSimDialog::addLogEntry(const QString &text, const QIcon &icon) QListWidgetItem *itm = new QListWidgetItem; itm->setText(text); itm->setIcon(icon); - simStatusLog->addItem(itm); + a_simStatusLog->addItem(itm); } bool ExternSimDialog::logContainsError(const QString &out) diff --git a/qucs/extsimkernels/externsimdialog.h b/qucs/extsimkernels/externsimdialog.h index 53883ba82..5541b4fee 100644 --- a/qucs/extsimkernels/externsimdialog.h +++ b/qucs/extsimkernels/externsimdialog.h @@ -28,43 +28,44 @@ class ExternSimDialog : public QDialog { Q_OBJECT -private: - Schematic *Sch; +private: + Schematic *a_schematic; - QPushButton *buttonStopSim; - QPushButton *buttonSaveNetlist; - QPushButton *buttonExit; + QPushButton *a_buttonStopSim; + QPushButton *a_buttonSaveNetlist; + QPushButton *a_buttonExit; - QPlainTextEdit *editSimConsole; - QListWidget *simStatusLog; + QPlainTextEdit *a_editSimConsole; + QListWidget *a_simStatusLog; - QProgressBar *simProgress; + QProgressBar *a_simProgress; - QString workdir; + Ngspice *a_ngspice; + Xyce *a_xyce; - Ngspice *ngspice; - Xyce *xyce; + bool a_wasSimulated; + bool a_hasError; public: explicit ExternSimDialog(Schematic *sch, bool netlist_mode = false); ~ExternSimDialog(); - bool wasSimulated; - bool hasError; + bool wasSimulated() const { return a_wasSimulated; } + bool hasError() const { return a_hasError; } 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 *); void warnings(); void success(); - + public slots: void slotSaveNetlist(); void slotStart(); @@ -77,7 +78,6 @@ private slots: void slotStop(); void slotSetSimulator(); void slotExit(); - }; #endif // EXTERNSIMDIALOG_H diff --git a/qucs/extsimkernels/ngspice.cpp b/qucs/extsimkernels/ngspice.cpp index 95145cd95..1e5524f8b 100644 --- a/qucs/extsimkernels/ngspice.cpp +++ b/qucs/extsimkernels/ngspice.cpp @@ -40,22 +40,23 @@ /*! * \brief Ngspice::Ngspice Class constructor - * \param sch_ Schematic that need to be simulated with Ngspice. + * \param schematic Schematic that need to be simulated with Ngspice. * \param parent Parent object */ -Ngspice::Ngspice(Schematic *sch_, QObject *parent) : - AbstractSpiceKernel(sch_, parent) +Ngspice::Ngspice(Schematic *schematic, QObject *parent) : + AbstractSpiceKernel(schematic, parent), + a_spinit_name() { if (QFileInfo(QucsSettings.NgspiceExecutable).isRelative()) { // this check is related to MacOS - simulator_cmd = QFileInfo(QucsSettings.BinDir + QucsSettings.NgspiceExecutable).absoluteFilePath(); + a_simulator_cmd = QFileInfo(QucsSettings.BinDir + QucsSettings.NgspiceExecutable).absoluteFilePath(); } else { - simulator_cmd = QFileInfo(QucsSettings.NgspiceExecutable).absoluteFilePath(); + a_simulator_cmd = QFileInfo(QucsSettings.NgspiceExecutable).absoluteFilePath(); } - if (!QFileInfo::exists(simulator_cmd)) { - simulator_cmd = QucsSettings.NgspiceExecutable; //rely on $PATH + if (!QFileInfo::exists(a_simulator_cmd)) { + a_simulator_cmd = QucsSettings.NgspiceExecutable; //rely on $PATH } - simulator_parameters = ""; - spinit_name = QDir::toNativeSeparators(QucsSettings.S4Qworkdir+"/.spiceinit"); + a_simulator_parameters = ""; + a_spinit_name = QDir::toNativeSeparators(QucsSettings.S4Qworkdir+"/.spiceinit"); } /*! @@ -71,7 +72,7 @@ void Ngspice::createNetlist(QTextStream &stream, int , { Q_UNUSED(simulations); - stream << "* Qucs " << PACKAGE_VERSION << " " << Sch->DocName << "\n"; + stream << "* Qucs " << PACKAGE_VERSION << " " << a_schematic->DocName << "\n"; // include math. functions for inter-simulator compat. QString mathf_inc; @@ -80,11 +81,11 @@ void Ngspice::createNetlist(QTextStream &stream, int , if (found && QucsSettings.DefaultSimulator != spicecompat::simSpiceOpus) stream<DocNodes.first(); pn != 0; pn = Sch->DocNodes.next()) { + for(Node *pn = a_schematic->DocNodes.first(); pn != 0; pn = a_schematic->DocNodes.next()) { if(pn->Label != 0) { if (!vars.contains(pn->Label->Name)) { vars.append(pn->Label->Name); } } } - for(Wire *pw = Sch->DocWires.first(); pw != 0; pw = Sch->DocWires.next()) { + for(Wire *pw = a_schematic->DocWires.first(); pw != 0; pw = a_schematic->DocWires.next()) { if(pw->Label != 0) { if (!vars.contains(pw->Label->Name)) { vars.append(pw->Label->Name); } } } - for(Component *pc = Sch->DocComps.first(); pc != 0; pc = Sch->DocComps.next()) { + + for(Component *pc = a_schematic->DocComps.first(); pc != 0; pc = a_schematic->DocComps.next()) { if (pc->isProbe) { QString var_pr = pc->getProbeVariable(); if (!vars.contains(var_pr)) { @@ -148,8 +150,8 @@ void Ngspice::createNetlist(QTextStream &stream, int , unsigned int pzSims = 0; outputs.clear(); - for ( unsigned int i = 0 ; i < Sch->DocComps.count() ; i++ ) { - Component *pc = Sch->DocComps.at(i); + for ( unsigned int i = 0 ; i < a_schematic->DocComps.count() ; i++ ) { + Component *pc = a_schematic->DocComps.at(i); if ( !pc->isSimulation ) continue; if ( pc->isActive != COMP_IS_ACTIVE ) continue; @@ -162,8 +164,8 @@ void Ngspice::createNetlist(QTextStream &stream, int , QString cnt_var; // Duplicate .PARAM in .control section. They may be used in euqations - for ( unsigned int i = 0 ; i < Sch->DocComps.count() ; i++ ) { - Component *pc1 = Sch->DocComps.at(i); + for ( unsigned int i = 0 ; i < a_schematic->DocComps.count() ; i++ ) { + Component *pc1 = a_schematic->DocComps.at(i); if ( pc1->isActive != COMP_IS_ACTIVE ) continue; if ( pc1->Model == "Eqn" ) { spiceNetlist.append((reinterpret_cast(pc1))->getNgspiceScript()); @@ -178,8 +180,8 @@ void Ngspice::createNetlist(QTextStream &stream, int , nods.append(QStringLiteral("v(%1) ").arg(nod)); } - for ( unsigned int i = 0 ; i < Sch->DocComps.count() ; i++ ) { - Component *pc1 = Sch->DocComps.at(i); + for ( unsigned int i = 0 ; i < a_schematic->DocComps.count() ; i++ ) { + Component *pc1 = a_schematic->DocComps.at(i); if ( !pc1->isSimulation ) continue; if ( pc1->isActive != COMP_IS_ACTIVE ) continue; QString sim_typ = pc1->Model; @@ -202,8 +204,8 @@ void Ngspice::createNetlist(QTextStream &stream, int , } else if ( sim_typ == ".TR" ) { timeSims++; spiceNetlist.append(pc->getSpiceNetlist()); - for ( unsigned int i = 0 ; i < Sch->DocComps.count() ; i++ ) { - Component *pc1 = Sch->DocComps.at(i); + for ( unsigned int i = 0 ; i < a_schematic->DocComps.count() ; i++ ) { + Component *pc1 = a_schematic->DocComps.at(i); if ( !pc1->isSimulation ) continue; if ( pc1->isActive != COMP_IS_ACTIVE ) continue; if ( pc1->Model == ".FOURIER" ) { @@ -306,8 +308,8 @@ void Ngspice::createNetlist(QTextStream &stream, int , if ( (sim_typ != ".PZ") && (sim_typ != ".SENS") && (sim_typ != ".SENS_AC") ) { QStringList dep_vars; - for ( unsigned int i = 0 ; i < Sch->DocComps.count() ; i++ ) { - Component *pc1 = Sch->DocComps.at(i); + for ( unsigned int i = 0 ; i < a_schematic->DocComps.count() ; i++ ) { + Component *pc1 = a_schematic->DocComps.at(i); if ( pc1->isActive != COMP_IS_ACTIVE ) continue; if ( pc1->Model == "Eqn" || pc1->Model == "NutmegEq" ) spiceNetlist.append(pc1->getEquations(sim_name, dep_vars)); @@ -336,8 +338,8 @@ void Ngspice::createNetlist(QTextStream &stream, int , } } - for ( unsigned int i = 0 ; i < Sch->DocComps.count() ; i++ ) { - Component *pc1 = Sch->DocComps.at(i); + for ( unsigned int i = 0 ; i < a_schematic->DocComps.count() ; i++ ) { + Component *pc1 = a_schematic->DocComps.at(i); if ( !pc1->isSimulation ) continue; if ( pc1->isActive != COMP_IS_ACTIVE ) continue; QString sim_typ = pc1->Model; @@ -361,7 +363,7 @@ void Ngspice::createNetlist(QTextStream &stream, int , << ".endc\n"; stream << ".END\n"; - needsPrefix = ( (dcSims | freqSims | timeSims | fourSims | pzSims) > 1 ); + a_needsPrefix = ( (dcSims | freqSims | timeSims | fourSims | pzSims) > 1 ); qDebug() << '\n' << "Simulations:\n" @@ -384,8 +386,8 @@ QString Ngspice::getParentSWPscript(Component *pc_swp, QString sim, bool before, { hasDblSwp = false; QString swp = pc_swp->Name.toLower(); - for ( unsigned int i = 0 ; i < Sch->DocComps.count() ; i++ ) { - Component *pc = Sch->DocComps.at(i); + for ( unsigned int i = 0 ; i < a_schematic->DocComps.count() ; i++ ) { + Component *pc = a_schematic->DocComps.at(i); if ( !pc->isSimulation ) continue; if ( pc->isActive != COMP_IS_ACTIVE ) continue; if ( pc->Model == ".SW" ) { @@ -409,83 +411,83 @@ QString Ngspice::getParentSWPscript(Component *pc_swp, QString sim, bool before, */ void Ngspice::slotSimulate() { - output.clear(); + a_output.clear(); QString mathf_inc; // drain if (!findMathFuncInc(mathf_inc)) { - output.append("[Warning!] " + mathf_inc + " file not found!\n"); + a_output.append("[Warning!] " + mathf_inc + " file not found!\n"); } bool checker_error = false; QStringList incompat; if (!checkSchematic(incompat)) { QString s = incompat.join("; "); - output.append("There were SPICE-incompatible components. Simulator cannot proceed."); - output.append("Incompatible components are: " + s + "\n"); + a_output.append("There were SPICE-incompatible components. Simulator cannot proceed."); + a_output.append("Incompatible components are: " + s + "\n"); checker_error = true; } if (!checkGround()) { - output.append("No Ground found. Please add at least one ground!\n" + a_output.append("No Ground found. Please add at least one ground!\n" "Press Insert->Ground in the main menu and connect ground to one " "of the schematic nodes.\n"); checker_error = true; } if (!checkSimulations()) { - output.append("No simulation found. Please add at least one simulation!\n" + a_output.append("No simulation found. Please add at least one simulation!\n" "Navigate to the \"simulations\" group in the components panel (left)" " and drag simulation to the schematic sheet. Then define its parameters.\n"); checker_error = true; } if (!checkDCSimulation()) { - output.append("Only DC simulation found in the schematic. It has no effect!" + a_output.append("Only DC simulation found in the schematic. It has no effect!" " Add TRAN, AC, or Sweep simulation to proceed.\n"); checker_error = true; } if (!checkNodeNames(incompat)) { QString s = incompat.join("; "); - output.append("There were Nutmeg-incompatible node names. Simulator cannot proceed.\n"); - output.append("Incompatible node names are: " + s + "\n"); + a_output.append("There were Nutmeg-incompatible node names. Simulator cannot proceed.\n"); + a_output.append("Incompatible node names are: " + s + "\n"); checker_error = true; } if (checker_error) { - if (console != nullptr) - console->insertPlainText(output); + if (a_console != nullptr) + a_console->insertPlainText(a_output); //emit finished(); emit errors(QProcess::FailedToStart); return; } QString netfile = "spice4qucs.cir"; - QString tmp_path = QDir::toNativeSeparators(workdir+QDir::separator()+netfile); + QString tmp_path = QDir::toNativeSeparators(a_workdir+QDir::separator()+netfile); SaveNetlist(tmp_path); removeAllSimulatorOutputs(); - /*XSPICE_CMbuilder *CMbuilder = new XSPICE_CMbuilder(Sch); + /*XSPICE_CMbuilder *CMbuilder = new XSPICE_CMbuilder(a_schematic); CMbuilder->cleanSpiceinit(); - CMbuilder->createSpiceinit(collectSpiceinit(Sch)); + CMbuilder->createSpiceinit(collectSpiceinit(a_schematic)); if (CMbuilder->needCompile()) { CMbuilder->cleanCModelTree(); - CMbuilder->createCModelTree(output); - CMbuilder->compileCMlib(output); + CMbuilder->createCModelTree(a_output); + CMbuilder->compileCMlib(a_output); } delete CMbuilder;*/ cleanSpiceinit(); - createSpiceinit(/*initial_spiceinit=*/collectSpiceinit(Sch)); + createSpiceinit(/*initial_spiceinit=*/collectSpiceinit(a_schematic)); //startNgSpice(tmp_path); - SimProcess->setWorkingDirectory(workdir); - qDebug()<setWorkingDirectory(a_workdir); + qDebug()<start(ngsp_cmd,cmd_args); + a_simProcess->start(ngsp_cmd,cmd_args); if (QucsMain != nullptr) emit started(); } @@ -498,7 +500,7 @@ void Ngspice::slotSimulate() bool Ngspice::checkNodeNames(QStringList &incompat) { bool result = true; - for(Node *pn = Sch->DocNodes.first(); pn != 0; pn = Sch->DocNodes.next()) { + for(Node *pn = a_schematic->DocNodes.first(); pn != 0; pn = a_schematic->DocNodes.next()) { if(pn->Label != 0) { if (!spicecompat::check_nodename(pn->Label->Name)) { incompat.append(pn->Label->Name); @@ -506,7 +508,7 @@ bool Ngspice::checkNodeNames(QStringList &incompat) } } } - for(Wire *pw = Sch->DocWires.first(); pw != 0; pw = Sch->DocWires.next()) { + for(Wire *pw = a_schematic->DocWires.first(); pw != 0; pw = a_schematic->DocWires.next()) { if(pw->Label != 0) { if (!spicecompat::check_nodename(pw->Label->Name)) { incompat.append(pw->Label->Name); @@ -537,7 +539,7 @@ QString Ngspice::collectSpiceinit(Schematic* sch) } collected_spiceinit += collectSpiceinit(sub); delete sub; - } + } } return collected_spiceinit.join(""); } @@ -564,16 +566,16 @@ bool Ngspice::findMathFuncInc(QString &mathf_inc) */ void Ngspice::slotProcessOutput() { - QString s = SimProcess->readAllStandardOutput(); + QString s = a_simProcess->readAllStandardOutput(); QRegularExpression percentage_pattern("^%\\d\\d*\\.\\d\\d.*$"); if (percentage_pattern.match(s).hasMatch()) { int percent = round(s.mid(1,5).toFloat()); emit progress(percent); } - output += s; - if (console != nullptr) { - console->insertPlainText(s); - console->moveCursor(QTextCursor::End); + a_output += s; + if (a_console != nullptr) { + a_console->insertPlainText(s); + a_console->moveCursor(QTextCursor::End); } } @@ -585,13 +587,13 @@ void Ngspice::slotProcessOutput() void Ngspice::SaveNetlist(QString filename) { int num=0; - sims.clear(); - vars.clear(); + a_sims.clear(); + a_vars.clear(); QFile spice_file(filename); if (spice_file.open(QFile::WriteOnly)) { QTextStream stream(&spice_file); - createNetlist(stream,num,sims,vars,output_files); + createNetlist(stream,num,a_sims,a_vars,a_output_files); spice_file.close(); } else @@ -609,25 +611,25 @@ void Ngspice::setSimulatorCmd(QString cmd) QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); env.remove("LANG"); env.insert("LANG","en_US"); - SimProcess->setProcessEnvironment(env); - simulator_parameters = simulator_parameters + "-c"; + a_simProcess->setProcessEnvironment(env); + a_simulator_parameters = a_simulator_parameters + "-c"; } else { // restore system environment QProcessEnvironment env = QProcessEnvironment::systemEnvironment(); - SimProcess->setProcessEnvironment(env); + a_simProcess->setProcessEnvironment(env); } - simulator_cmd = cmd; + a_simulator_cmd = cmd; } void Ngspice::setSimulatorParameters(QString parameters) { - simulator_parameters = parameters; + a_simulator_parameters = parameters; } void Ngspice::cleanSpiceinit() { - QFileInfo inf(spinit_name); - if (inf.exists()) QFile::remove(spinit_name); + QFileInfo inf(a_spinit_name); + if (inf.exists()) QFile::remove(a_spinit_name); } void Ngspice::createSpiceinit(const QString &initial_spiceinit) @@ -650,7 +652,7 @@ void Ngspice::createSpiceinit(const QString &initial_spiceinit) compat_str.isEmpty()) { return; } - QFile spinit(spinit_name); + QFile spinit(a_spinit_name); if (spinit.open(QIODevice::WriteOnly)) { QTextStream stream(&spinit); stream << compat_str << '\n'; diff --git a/qucs/extsimkernels/ngspice.h b/qucs/extsimkernels/ngspice.h index 7e4f756b1..a63f5b2e1 100644 --- a/qucs/extsimkernels/ngspice.h +++ b/qucs/extsimkernels/ngspice.h @@ -36,9 +36,9 @@ class Ngspice : public AbstractSpiceKernel { Q_OBJECT -private: - QString spinit_name; +private: + QString a_spinit_name; bool checkNodeNames(QStringList &incompat); static QString collectSpiceinit(Schematic *sch); @@ -49,11 +49,11 @@ class Ngspice : public AbstractSpiceKernel void createSpiceinit(const QString &initial_spiceinit); public: - explicit Ngspice(Schematic *sch_, QObject *parent = 0); + explicit Ngspice(Schematic *schematic, QObject *parent = 0); void SaveNetlist(QString filename); void setSimulatorCmd(QString cmd); void setSimulatorParameters(QString parameters); - + protected: void createNetlist(QTextStream &stream, int NumPorts, QStringList &simulations, QStringList &vars, QStringList &outputs); diff --git a/qucs/extsimkernels/s2spice.cpp b/qucs/extsimkernels/s2spice.cpp index 8275795d0..55ca55c78 100644 --- a/qucs/extsimkernels/s2spice.cpp +++ b/qucs/extsimkernels/s2spice.cpp @@ -30,9 +30,12 @@ #define MAXPORTS 8 #define MAXNAME 128 -S2Spice::S2Spice() +S2Spice::S2Spice(): + a_z0(-1), + a_file(), + a_device_name(), + a_err_text() { - z0 = -1; } bool S2Spice::convertTouchstone(QTextStream *stream) @@ -50,24 +53,24 @@ bool S2Spice::convertTouchstone(QTextStream *stream) double ph, offset, mag; - QFile ff(file); + QFile ff(a_file); if (!ff.open(QIODevice::ReadOnly)) { - err_text = "Failed to open file: " + file + "\n"; + a_err_text = "Failed to open file: " + a_file + "\n"; return false; } QTextStream in_stream(&ff); /* Find number of ports */ - QFileInfo inf(file); + QFileInfo inf(a_file); ports = inf.suffix().mid(1,1).toInt(); if ( (ports < 1) || (ports > MAXPORTS) ) { - err_text = "Invalid port number in file: " + file + "\n"; + a_err_text = "Invalid port number in file: " + a_file + "\n"; return false; } /* build first line of output file */ - (*stream) << ".SUBCKT " + device_name; + (*stream) << ".SUBCKT " + a_device_name; for (int i = 0; i <= ports; i++) { (*stream) << QStringLiteral(" %1").arg(i+1); } @@ -101,7 +104,7 @@ bool S2Spice::convertTouchstone(QTextStream *stream) } if (!next_line.contains(" S " )) { - err_text = "Wrong data in file: " + file + "\n"; + a_err_text = "Wrong data in file: " + a_file + "\n"; return false; } /* input impedances */ @@ -109,10 +112,10 @@ bool S2Spice::convertTouchstone(QTextStream *stream) QStringList tmp_lst = next_line.split(" ",qucs::SkipEmptyParts); z[0] = tmp_lst.at(tmp_lst.count()-1).toDouble(); for (int i = 0; i < ports; i++ ) { - if ( z0 < 0 ) { /* takes the Z value from the input file */ + if ( a_z0 < 0 ) { /* takes the Z value from the input file */ z[i] = z[0]; } else { /* takes the Z value from the command line */ - z[i] = z0; + z[i] = a_z0; } } @@ -132,7 +135,7 @@ bool S2Spice::convertTouchstone(QTextStream *stream) if(next_line.isEmpty()) continue; if(next_line.at(0)=='#') continue; if(next_line.startsWith("!noise parameters")) { - err_text = "Noise simulation in S2P files is not supported!\n" + a_err_text = "Noise simulation in S2P files is not supported!\n" "Noise data ignored"; break; } @@ -146,7 +149,7 @@ bool S2Spice::convertTouchstone(QTextStream *stream) } } if (tmp_lst.count() < 2*(ports*ports)+1) { - err_text = "Touchstone file parse error!\n"; + a_err_text = "Touchstone file parse error!\n"; return false; } numf = f + 1; diff --git a/qucs/extsimkernels/s2spice.h b/qucs/extsimkernels/s2spice.h index c02aef76d..0a283007a 100644 --- a/qucs/extsimkernels/s2spice.h +++ b/qucs/extsimkernels/s2spice.h @@ -27,21 +27,20 @@ class S2Spice { private: - double z0; - QString file; - QString device_name; - QString err_text; + double a_z0; + QString a_file; + QString a_device_name; + QString a_err_text; public: - void setZ0(double z0_) { z0 = z0_; } - void setFile(const QString &file_) { file = file_; } - void setDeviceName(const QString &name_) {device_name = name_; } + void setZ0(double z0) { a_z0 = z0; } + void setFile(const QString& file) { a_file = file; } + void setDeviceName(const QString& name) {a_device_name = name; } - QString getErrText() { return err_text; } + QString getErrText() const { return a_err_text; } bool convertTouchstone(QTextStream *stream); - S2Spice(); virtual ~S2Spice() {} }; diff --git a/qucs/extsimkernels/simsettingsdialog.cpp b/qucs/extsimkernels/simsettingsdialog.cpp index 08d6c0fbc..28598141b 100644 --- a/qucs/extsimkernels/simsettingsdialog.cpp +++ b/qucs/extsimkernels/simsettingsdialog.cpp @@ -25,114 +25,113 @@ #include "settings.h" SimSettingsDialog::SimSettingsDialog(QWidget *parent) : - QDialog(parent) + QDialog(parent), + a_lblXyce(new QLabel(tr("Xyce executable location"))), + a_lblNgspice(new QLabel(tr("Ngspice executable location"))), + a_lblSpiceOpus(new QLabel(tr("SpiceOpus executable location"))), + //a_lblXycePar(new QLabel(tr("Xyce Parallel executable location (openMPI installed required)"))), + //a_lblNprocs(new QLabel(tr("Number of processors in a system:"))), + a_lblQucsator(new QLabel(tr("Qucsator executable location"))), + //a_lblSimulator(new QLabel(tr("Default simulator"))), + a_lblSimParam(new QLabel(tr("Extra simulator parameters"))), + a_lblCompatMode(new QLabel(tr("Ngspice compatibility mode"))), + a_cbxCompatMode(new QComboBox), + //a_cbxSimulator(new QComboBox(this)), + a_edtNgspice(new QLineEdit(QucsSettings.NgspiceExecutable)), + a_edtSpiceOpus(new QLineEdit(QucsSettings.SpiceOpusExecutable)), + a_edtXyce(new QLineEdit(QucsSettings.XyceExecutable)), + //a_edtXycePar(new QLineEdit(QucsSettings.XyceParExecutable), + a_edtQucsator(new QLineEdit(QucsSettings.Qucsator)), + //a_spbNprocs(new QSpinBox(this)), + a_edtSimParam(new QLineEdit(QucsSettings.SimParameters)), + a_btnOK(new QPushButton(tr("Apply changes"))), + a_btnCancel(new QPushButton(tr("Cancel"))), + a_btnSetNgspice(new QPushButton(tr("Select ..."))), + a_btnSetSpOpus(new QPushButton(tr("Select ..."))), + a_btnSetXyce(new QPushButton(tr("Select ..."))), + //a_btnSetXycePar(new QPushButton(tr("Select ..."))), + a_btnSetQucsator(new QPushButton(tr("Select ..."))) { - //lblSimulator = new QLabel(tr("Default simulator")); - lblNgspice = new QLabel(tr("Ngspice executable location")); - lblXyce = new QLabel(tr("Xyce executable location")); - //lblXycePar = new QLabel(tr("Xyce Parallel executable location (openMPI installed required)")); - lblSpiceOpus = new QLabel(tr("SpiceOpus executable location")); - lblQucsator = new QLabel(tr("Qucsator executable location")); - //lblNprocs = new QLabel(tr("Number of processors in a system:")); - lblSimParam = new QLabel(tr("Extra simulator parameters")); - -// cbxSimulator = new QComboBox(this); -// cbxSimulator->addItem("Ngspice", 1); -// cbxSimulator->addItem("Xyce", 2); -// cbxSimulator->addItem("SpiceOpus", 4); -// cbxSimulator->addItem("Qucsator", 8); +// a_cbxSimulator->addItem("Ngspice", 1); +// a_cbxSimulator->addItem("Xyce", 2); +// a_cbxSimulator->addItem("SpiceOpus", 4); +// a_cbxSimulator->addItem("Qucsator", 8); //QStringList items; //items<<"Ngspice"<<"Xyce (Serial)"<<"Xyce (Parallel)"<<"SpiceOpus"<<"Qucsator"; - //cbxSimulator->addItems(items); + //a_cbxSimulator->addItems(items); qDebug()<setCurrentIndex(QucsSettings.DefaultSimulator); +// a_cbxSimulator->setCurrentIndex(QucsSettings.DefaultSimulator); // if (QucsSettings.DefaultSimulator==spicecompat::simNotSpecified) -// cbxSimulator->setCurrentIndex(spicecompat::simNgspice); - - edtNgspice = new QLineEdit(QucsSettings.NgspiceExecutable); - edtXyce = new QLineEdit(QucsSettings.XyceExecutable); - //edtXycePar = new QLineEdit(QucsSettings.XyceParExecutable); - edtSpiceOpus = new QLineEdit(QucsSettings.SpiceOpusExecutable); - edtQucsator = new QLineEdit(QucsSettings.Qucsator); -// spbNprocs = new QSpinBox(this); -// spbNprocs->setMinimum(1); -// spbNprocs->setMaximum(256); -// spbNprocs->setValue(1); -// spbNprocs->setValue(QucsSettings.NProcs); - edtSimParam = new QLineEdit(QucsSettings.SimParameters); - - btnOK = new QPushButton(tr("Apply changes")); - connect(btnOK,SIGNAL(clicked()),this,SLOT(slotApply())); - btnCancel = new QPushButton(tr("Cancel")); - connect(btnCancel,SIGNAL(clicked()),this,SLOT(reject())); - - btnSetNgspice = new QPushButton(tr("Select ...")); - connect(btnSetNgspice,SIGNAL(clicked()),this,SLOT(slotSetNgspice())); - btnSetXyce = new QPushButton(tr("Select ...")); - connect(btnSetXyce,SIGNAL(clicked()),this,SLOT(slotSetXyce())); - //btnSetXycePar = new QPushButton(tr("Select ...")); - //connect(btnSetXycePar,SIGNAL(clicked()),this,SLOT(slotSetXycePar())); - btnSetSpOpus = new QPushButton(tr("Select ...")); - connect(btnSetSpOpus,SIGNAL(clicked()),this,SLOT(slotSetSpiceOpus())); - btnSetQucsator = new QPushButton(tr("Select ...")); - connect(btnSetQucsator,SIGNAL(clicked()),this,SLOT(slotSetQucsator())); - - lblCompatMode = new QLabel(tr("Ngspice compatibility mode")); - cbxCompatMode = new QComboBox; +// a_cbxSimulator->setCurrentIndex(spicecompat::simNgspice); + +// a_spbNprocs->setMinimum(1); +// a_spbNprocs->setMaximum(256); +// a_spbNprocs->setValue(1); +// a_spbNprocs->setValue(QucsSettings.NProcs); + + connect(a_btnOK,SIGNAL(clicked()),this,SLOT(slotApply())); + connect(a_btnCancel,SIGNAL(clicked()),this,SLOT(reject())); + + connect(a_btnSetNgspice,SIGNAL(clicked()),this,SLOT(slotSetNgspice())); + connect(a_btnSetXyce,SIGNAL(clicked()),this,SLOT(slotSetXyce())); + //connect(a_btnSetXycePar,SIGNAL(clicked()),this,SLOT(slotSetXycePar())); + connect(a_btnSetSpOpus,SIGNAL(clicked()),this,SLOT(slotSetSpiceOpus())); + connect(a_btnSetQucsator,SIGNAL(clicked()),this,SLOT(slotSetQucsator())); + QStringList lst_modes; lst_modes<<"Default"<<"LTspice"<<"HSPICE"<<"Spice3"; - cbxCompatMode->addItems(lst_modes); + a_cbxCompatMode->addItems(lst_modes); auto compat_mode = _settings::Get().item("NgspiceCompatMode"); - cbxCompatMode->setCurrentIndex(compat_mode); + a_cbxCompatMode->setCurrentIndex(compat_mode); QVBoxLayout *top = new QVBoxLayout; // QHBoxLayout *h8 = new QHBoxLayout; -// h8->addWidget(lblSimulator,1); -// h8->addWidget(cbxSimulator,3); +// h8->addWidget(a_lblSimulator,1); +// h8->addWidget(a_cbxSimulator,3); // top->addLayout(h8); QGroupBox *gbp1 = new QGroupBox(this); gbp1->setTitle(tr("SPICE settings")); QVBoxLayout *top2 = new QVBoxLayout; - top2->addWidget(lblNgspice); + top2->addWidget(a_lblNgspice); QHBoxLayout *h1 = new QHBoxLayout; - h1->addWidget(edtNgspice,3); - h1->addWidget(btnSetNgspice,1); + h1->addWidget(a_edtNgspice,3); + h1->addWidget(a_btnSetNgspice,1); top2->addLayout(h1); QHBoxLayout *h4 = new QHBoxLayout; - h4->addWidget(lblCompatMode); - h4->addWidget(cbxCompatMode); + h4->addWidget(a_lblCompatMode); + h4->addWidget(a_cbxCompatMode); top2->addLayout(h4); - top2->addWidget(lblXyce); + top2->addWidget(a_lblXyce); QHBoxLayout *h2 = new QHBoxLayout; - h2->addWidget(edtXyce,3); - h2->addWidget(btnSetXyce,1); + h2->addWidget(a_edtXyce,3); + h2->addWidget(a_btnSetXyce,1); top2->addLayout(h2); -// top2->addWidget(lblXycePar); +// top2->addWidget(a_lblXycePar); // QHBoxLayout *h4 = new QHBoxLayout; -// h4->addWidget(edtXycePar,3); -// h4->addWidget(btnSetXycePar,1); +// h4->addWidget(a_edtXycePar,3); +// h4->addWidget(a_btnSetXycePar,1); // top2->addLayout(h4); // // QHBoxLayout *h5 = new QHBoxLayout; -// h5->addWidget(lblNprocs); -// h5->addWidget(spbNprocs); +// h5->addWidget(a_lblNprocs); +// h5->addWidget(a_spbNprocs); // top2->addLayout(h5); - top2->addWidget(lblSpiceOpus); + top2->addWidget(a_lblSpiceOpus); QHBoxLayout *h7 = new QHBoxLayout; - h7->addWidget(edtSpiceOpus,3); - h7->addWidget(btnSetSpOpus,1); + h7->addWidget(a_edtSpiceOpus,3); + h7->addWidget(a_btnSetSpOpus,1); top2->addLayout(h7); - top2->addWidget(lblSimParam); + top2->addWidget(a_lblSimParam); QHBoxLayout *h10 = new QHBoxLayout; - h10->addWidget(edtSimParam,4); + h10->addWidget(a_edtSimParam,4); top2->addLayout(h10); gbp1->setLayout(top2); @@ -141,18 +140,18 @@ SimSettingsDialog::SimSettingsDialog(QWidget *parent) : QGroupBox *gbp2 = new QGroupBox; gbp2->setTitle(tr("Qucsator settings")); QVBoxLayout *top3 = new QVBoxLayout; - top3->addWidget(lblQucsator); + top3->addWidget(a_lblQucsator); QHBoxLayout *h9 = new QHBoxLayout; - h9->addWidget(edtQucsator,3); - h9->addWidget(btnSetQucsator,1); + h9->addWidget(a_edtQucsator,3); + h9->addWidget(a_btnSetQucsator,1); top3->addLayout(h9); gbp2->setLayout(top3); top->addWidget(gbp2); QHBoxLayout *h3 = new QHBoxLayout; - h3->addWidget(btnOK); - h3->addWidget(btnCancel); + h3->addWidget(a_btnOK); + h3->addWidget(a_btnCancel); h3->addStretch(2); top->addLayout(h3); @@ -162,10 +161,10 @@ SimSettingsDialog::SimSettingsDialog(QWidget *parent) : #ifndef Q_OS_UNIX // Only Unix supports Xyce-parallel -// edtXycePar->setDisabled(true); -// lblXycePar->setDisabled(true); -// lblNprocs->setDisabled(true); -// spbNprocs->setDisabled(true); +// a_edtXycePar->setDisabled(true); +// a_lblXycePar->setDisabled(true); +// a_lblNprocs->setDisabled(true); +// a_spbNprocs->setDisabled(true); #endif } @@ -173,21 +172,21 @@ SimSettingsDialog::SimSettingsDialog(QWidget *parent) : void SimSettingsDialog::slotApply() { - QucsSettings.NgspiceExecutable = edtNgspice->text(); - QucsSettings.XyceExecutable = edtXyce->text(); - //QucsSettings.XyceParExecutable = edtXycePar->text(); - QucsSettings.SpiceOpusExecutable = edtSpiceOpus->text(); - QucsSettings.Qucsator = edtQucsator->text(); - //QucsSettings.NProcs = spbNprocs->value(); - QucsSettings.SimParameters = edtSimParam->text(); -// if ((QucsSettings.DefaultSimulator != cbxSimulator->currentIndex())&& + QucsSettings.NgspiceExecutable = a_edtNgspice->text(); + QucsSettings.XyceExecutable = a_edtXyce->text(); + //QucsSettings.XyceParExecutable = a_edtXycePar->text(); + QucsSettings.SpiceOpusExecutable = a_edtSpiceOpus->text(); + QucsSettings.Qucsator = a_edtQucsator->text(); + //QucsSettings.NProcs = a_spbNprocs->value(); + QucsSettings.SimParameters = a_edtSimParam->text(); +// if ((QucsSettings.DefaultSimulator != a_cbxSimulator->currentIndex())&& // (QucsSettings.DefaultSimulator != spicecompat::simNotSpecified)) { // QMessageBox::warning(this,tr("Simulator settings"),tr("Default simulator engine was changed!\n" // "Please restart Qucs to affect changes!")); // } -// QucsSettings.DefaultSimulator = cbxSimulator->currentIndex(); +// QucsSettings.DefaultSimulator = a_cbxSimulator->currentIndex(); settingsManager& qs = _settings::Get(); - qs.setItem("NgspiceCompatMode", cbxCompatMode->currentIndex()); + qs.setItem("NgspiceCompatMode", a_cbxCompatMode->currentIndex()); accept(); saveApplSettings(); } @@ -201,41 +200,41 @@ void SimSettingsDialog::slotCancel() void SimSettingsDialog::slotSetNgspice() { - QString s = QFileDialog::getOpenFileName(this,tr("Select Ngspice executable location"),edtNgspice->text(),"All files (*)"); + QString s = QFileDialog::getOpenFileName(this,tr("Select Ngspice executable location"),a_edtNgspice->text(),"All files (*)"); if (!s.isEmpty()) { - edtNgspice->setText(s); + a_edtNgspice->setText(s); } } void SimSettingsDialog::slotSetXyce() { - QString s = QFileDialog::getOpenFileName(this,tr("Select Xyce executable location"),edtXyce->text(),"All files (*)"); + QString s = QFileDialog::getOpenFileName(this,tr("Select Xyce executable location"),a_edtXyce->text(),"All files (*)"); if (!s.isEmpty()) { - edtXyce->setText(s); + a_edtXyce->setText(s); } } void SimSettingsDialog::slotSetXycePar() // TODO ZERGUD { -// QString s = QFileDialog::getOpenFileName(this,tr("Select Xyce Parallel executable location"),edtXycePar->text(),"All files (*)"); +// QString s = QFileDialog::getOpenFileName(this,tr("Select Xyce Parallel executable location"),a_edtXycePar->text(),"All files (*)"); // if (!s.isEmpty()) { // if (s.endsWith("xmpirun")) s += " -np %p"; -// edtXycePar->setText(s); +// a_edtXycePar->setText(s); // } } void SimSettingsDialog::slotSetSpiceOpus() { - QString s = QFileDialog::getOpenFileName(this,tr("Select SpiceOpus executable location"),edtSpiceOpus->text(),"All files (*)"); + QString s = QFileDialog::getOpenFileName(this,tr("Select SpiceOpus executable location"),a_edtSpiceOpus->text(),"All files (*)"); if (!s.isEmpty()) { - edtSpiceOpus->setText(s); + a_edtSpiceOpus->setText(s); } } void SimSettingsDialog::slotSetQucsator() { - QString s = QFileDialog::getOpenFileName(this,tr("Select Qucsator executable location"),edtQucsator->text(),"All files (*)"); + QString s = QFileDialog::getOpenFileName(this,tr("Select Qucsator executable location"),a_edtQucsator->text(),"All files (*)"); if (!s.isEmpty()) { - edtQucsator->setText(s); + a_edtQucsator->setText(s); } } diff --git a/qucs/extsimkernels/simsettingsdialog.h b/qucs/extsimkernels/simsettingsdialog.h index ab4625d07..b0e04f2cb 100644 --- a/qucs/extsimkernels/simsettingsdialog.h +++ b/qucs/extsimkernels/simsettingsdialog.h @@ -27,39 +27,40 @@ class SimSettingsDialog : public QDialog Q_OBJECT private: - QLabel *lblXyce; - QLabel *lblNgspice; - QLabel *lblSpiceOpus; - //QLabel *lblXycePar; - //QLabel *lblNprocs; - QLabel *lblQucsator; - //QLabel *lblSimulator; - QLabel *lblSimParam, *lblCompatMode; + QLabel *a_lblXyce; + QLabel *a_lblNgspice; + QLabel *a_lblSpiceOpus; + //QLabel *a_lblXycePar; + //QLabel *a_lblNprocs; + QLabel *a_lblQucsator; + //QLabel *a_lblSimulator; + QLabel *a_lblSimParam; + QLabel *a_lblCompatMode; - QComboBox *cbxCompatMode; - //QComboBox *cbxSimulator; + QComboBox *a_cbxCompatMode; + //QComboBox *a_cbxSimulator; - QLineEdit *edtNgspice; - QLineEdit *edtSpiceOpus; - QLineEdit *edtXyce; - //QLineEdit *edtXycePar; - QLineEdit *edtQucsator; - //QSpinBox *spbNprocs; - QLineEdit *edtSimParam; + QLineEdit *a_edtNgspice; + QLineEdit *a_edtSpiceOpus; + QLineEdit *a_edtXyce; + //QLineEdit *a_edtXycePar; + QLineEdit *a_edtQucsator; + //QSpinBox *a_spbNprocs; + QLineEdit *a_edtSimParam; - QPushButton *btnOK; - QPushButton *btnCancel; + QPushButton *a_btnOK; + QPushButton *a_btnCancel; - QPushButton *btnSetNgspice; - QPushButton *btnSetSpOpus; - QPushButton *btnSetXyce; - //QPushButton *btnSetXycePar; - QPushButton *btnSetQucsator; + QPushButton *a_btnSetNgspice; + QPushButton *a_btnSetSpOpus; + QPushButton *a_btnSetXyce; + //QPushButton *a_btnSetXycePar; + QPushButton *a_btnSetQucsator; public: explicit SimSettingsDialog(QWidget *parent = 0); - - + + private slots: void slotApply(); void slotCancel(); @@ -68,7 +69,7 @@ private slots: void slotSetXycePar(); void slotSetSpiceOpus(); void slotSetQucsator(); - + }; #endif // SIMSETTINGSDIALOG_H diff --git a/qucs/extsimkernels/spicelibcompdialog.cpp b/qucs/extsimkernels/spicelibcompdialog.cpp index 18f46e943..677600615 100644 --- a/qucs/extsimkernels/spicelibcompdialog.cpp +++ b/qucs/extsimkernels/spicelibcompdialog.cpp @@ -11,161 +11,165 @@ #include "spicelibcompdialog.h" -SpiceLibCompDialog::SpiceLibCompDialog(Component *pc, Schematic *sch) : QDialog{sch} +SpiceLibCompDialog::SpiceLibCompDialog(Component *pc, Schematic *sch) : + QDialog(sch), + a_symbolPinsCount(0), + a_isChanged(false), + a_libError(false), + a_prev_row(-1), + a_prev_col(-1), + a_lastSymbolDir(), + a_lastLibDir(), + a_comp(pc), + a_schematic(sch), + a_symbol(new SymbolWidget), + a_edtLibPath(new QLineEdit), + a_edtParams(new QLineEdit), + a_edtSymFile(new QLineEdit()), + a_edtSPICE(new QPlainTextEdit), + a_btnOpenLib(new QPushButton(tr("Open"))), + a_btnOK(new QPushButton(tr("OK"))), + a_btnApply(new QPushButton(tr("Apply"))), + a_btnCancel(new QPushButton(tr("Cancel"))), + a_tbwPinsTable(new QTableWidget), + a_cbxSelectSubcir(new QComboBox), + a_listSymPattern(new QListWidget), + a_rbSymFromTemplate(new QRadioButton(tr("Symbol from template"))), + a_rbAutoSymbol(new QRadioButton(tr("Automatic symbol"))), + a_rbUserSym(new QRadioButton(tr("Symbol from file"))), + a_chbShowLib(new QCheckBox(tr("Show"))), + a_chbShowModel(new QCheckBox(tr("Show"))), + a_chbShowParams(new QCheckBox(tr("Show"))), + a_subcirPins(), + a_subcirSPICE() { - comp = pc; - Doc = sch; - symbolPinsCount = 0; - isChanged = false; - libError = false; - prev_col = -1; - prev_row = -1; - - QString file = comp->Props.at(0)->Value; + QString file = a_comp->Props.at(0)->Value; if (!file.isEmpty()) { - file = misc::properAbsFileName(file, Doc); + file = misc::properAbsFileName(file, a_schematic); QFileInfo inf(file); - lastLibDir = inf.absoluteDir().path(); + a_lastLibDir = inf.absoluteDir().path(); } else { - QFileInfo inf = Doc->getFileInfo(); + QFileInfo inf = a_schematic->getFileInfo(); if (inf.absoluteFilePath().isEmpty()) { // untitled document - lastLibDir = QucsSettings.QucsWorkDir.absolutePath(); + a_lastLibDir = QucsSettings.QucsWorkDir.absolutePath(); } else { // saved schematic - lastLibDir = inf.absoluteDir().path(); + a_lastLibDir = inf.absoluteDir().path(); } } - bool show_lib = comp->Props.at(0)->display; - QString device = comp->Props.at(1)->Value; - bool show_model = comp->Props.at(1)->display; - QString sym = comp->Props.at(2)->Value; - QString par = comp->Props.at(3)->Value; - bool show_par = comp->Props.at(3)->display; - QString pin_list = comp->Props.at(4)->Value; + bool show_lib = a_comp->Props.at(0)->display; + QString device = a_comp->Props.at(1)->Value; + bool show_model = a_comp->Props.at(1)->display; + QString sym = a_comp->Props.at(2)->Value; + QString par = a_comp->Props.at(3)->Value; + bool show_par = a_comp->Props.at(3)->display; + QString pin_list = a_comp->Props.at(4)->Value; QLabel *lblLibfile = new QLabel("SPICE library:"); - edtLibPath = new QLineEdit; - edtLibPath->setText(file); - connect(edtLibPath,SIGNAL(textChanged(QString)),this,SLOT(slotFillSubcirComboBox())); - btnOpenLib = new QPushButton(tr("Open")); - connect(btnOpenLib,SIGNAL(clicked(bool)),this,SLOT(slotBtnOpenLib())); + a_edtLibPath->setText(file); + connect(a_edtLibPath,SIGNAL(textChanged(QString)),this,SLOT(slotFillSubcirComboBox())); + connect(a_btnOpenLib,SIGNAL(clicked(bool)),this,SLOT(slotBtnOpenLib())); QLabel *lbl_par = new QLabel("Component parameters"); - edtParams = new QLineEdit; - edtParams->setText(par); + a_edtParams->setText(par); QLabel *lblDevice = new QLabel("Subcircuit:"); - cbxSelectSubcir = new QComboBox; - connect(cbxSelectSubcir,SIGNAL(currentIndexChanged(int)),this,SLOT(slotFillPinsTable())); + connect(a_cbxSelectSubcir,SIGNAL(currentIndexChanged(int)),this,SLOT(slotFillPinsTable())); - listSymPattern = new QListWidget; QStringList lst_patterns; misc::getSymbolPatternsList(lst_patterns); - listSymPattern->addItems(lst_patterns); - listSymPattern->setCurrentRow(0); - listSymPattern->setSelectionMode(QAbstractItemView::SingleSelection); - connect(listSymPattern,SIGNAL(currentRowChanged(int)),this,SLOT(slotSetSymbol())); - - rbAutoSymbol = new QRadioButton(tr("Automatic symbol")); - rbSymFromTemplate = new QRadioButton(tr("Symbol from template")); - rbUserSym = new QRadioButton(tr("Symbol from file")); - btnOpenSym = new QPushButton(tr("Open")); - edtSymFile = new QLineEdit(); - connect(btnOpenSym,SIGNAL(clicked(bool)),this,SLOT(slotBtnOpenSym())); - - chbShowLib = new QCheckBox(tr("Show")); - chbShowLib->setChecked(show_lib); - chbShowModel = new QCheckBox(tr("Show")); - chbShowModel->setChecked(show_model); - chbShowParams = new QCheckBox(tr("Show")); - chbShowParams->setChecked(show_par); - connect(chbShowLib,SIGNAL(toggled(bool)),this,SLOT(slotChanged())); - connect(chbShowModel,SIGNAL(toggled(bool)),this,SLOT(slotChanged())); - connect(chbShowParams,SIGNAL(toggled(bool)),this,SLOT(slotChanged())); - - if (QFileInfo::exists(misc::properAbsFileName(sym, Doc))) { - edtSymFile->setText(misc::properAbsFileName(sym, Doc)); - rbUserSym->setChecked(true); - QFileInfo inf(misc::properAbsFileName(sym, Doc)); - lastSymbolDir = inf.absoluteDir().path(); + a_listSymPattern->addItems(lst_patterns); + a_listSymPattern->setCurrentRow(0); + a_listSymPattern->setSelectionMode(QAbstractItemView::SingleSelection); + connect(a_listSymPattern,SIGNAL(currentRowChanged(int)),this,SLOT(slotSetSymbol())); + + a_btnOpenLib = new QPushButton(tr("Open")); + connect(a_btnOpenLib,SIGNAL(clicked(bool)),this,SLOT(slotBtnOpenSym())); + + a_chbShowLib->setChecked(show_lib); + a_chbShowModel->setChecked(show_model); + a_chbShowParams->setChecked(show_par); + connect(a_chbShowLib,SIGNAL(toggled(bool)),this,SLOT(slotChanged())); + connect(a_chbShowModel,SIGNAL(toggled(bool)),this,SLOT(slotChanged())); + connect(a_chbShowParams,SIGNAL(toggled(bool)),this,SLOT(slotChanged())); + + if (QFileInfo::exists(misc::properAbsFileName(sym, a_schematic))) { + a_edtSymFile->setText(misc::properAbsFileName(sym, a_schematic)); + a_rbUserSym->setChecked(true); + QFileInfo inf(misc::properAbsFileName(sym, a_schematic)); + a_lastSymbolDir = inf.absoluteDir().path(); } else { - QFileInfo inf = Doc->getFileInfo(); - lastSymbolDir = inf.absoluteDir().path(); + QFileInfo inf = a_schematic->getFileInfo(); + a_lastSymbolDir = inf.absoluteDir().path(); if (sym == "auto") { - rbAutoSymbol->setChecked(true); + a_rbAutoSymbol->setChecked(true); } else { - rbSymFromTemplate->setChecked(true); + a_rbSymFromTemplate->setChecked(true); } } - symbol = new SymbolWidget; - symbol->disableDragNDrop(); - symbol->enableShowPinNumbers(); - symbol->setPaintText(""); + a_symbol->disableDragNDrop(); + a_symbol->enableShowPinNumbers(); + a_symbol->setPaintText(""); - tbwPinsTable = new QTableWidget; - tbwPinsTable->setColumnCount(2); - tbwPinsTable->setRowCount(100); + a_tbwPinsTable->setColumnCount(2); + a_tbwPinsTable->setRowCount(100); QStringList lbl_cols; lbl_cols<<"Subcircuit pin"<<"Symbol pin"; - tbwPinsTable->setHorizontalHeaderLabels(lbl_cols); - tbwPinsTable->setMinimumWidth(2.2*tbwPinsTable->columnWidth(0)); - tbwPinsTable->setMinimumHeight(5*tbwPinsTable->rowHeight(0)); - connect(tbwPinsTable,SIGNAL(cellDoubleClicked(int,int)),this,SLOT(slotTableCellDoubleClick())); - - edtSPICE = new QPlainTextEdit; - edtSPICE->setReadOnly(true); - edtSPICE->setMinimumSize(tbwPinsTable->minimumSize()); - - btnOK = new QPushButton(tr("OK")); - connect(btnOK,SIGNAL(clicked(bool)),this,SLOT(slotBtnOK())); - btnApply = new QPushButton(tr("Apply")); - connect(btnApply,SIGNAL(clicked(bool)),this,SLOT(slotBtnApply())); - btnCancel = new QPushButton(tr("Cancel")); - connect(btnCancel,SIGNAL(clicked(bool)),this,SLOT(slotBtnCancel())); + a_tbwPinsTable->setHorizontalHeaderLabels(lbl_cols); + a_tbwPinsTable->setMinimumWidth(2.2*a_tbwPinsTable->columnWidth(0)); + a_tbwPinsTable->setMinimumHeight(5*a_tbwPinsTable->rowHeight(0)); + connect(a_tbwPinsTable,SIGNAL(cellDoubleClicked(int,int)),this,SLOT(slotTableCellDoubleClick())); + + a_edtSPICE->setReadOnly(true); + a_edtSPICE->setMinimumSize(a_tbwPinsTable->minimumSize()); + + connect(a_btnOK,SIGNAL(clicked(bool)),this,SLOT(slotBtnOK())); + connect(a_btnApply,SIGNAL(clicked(bool)),this,SLOT(slotBtnApply())); + connect(a_btnCancel,SIGNAL(clicked(bool)),this,SLOT(slotBtnCancel())); QVBoxLayout *top = new QVBoxLayout; QHBoxLayout *l2 = new QHBoxLayout; l2->addWidget(lblLibfile); - l2->addWidget(edtLibPath,4); - l2->addWidget(btnOpenLib,1); - l2->addWidget(chbShowLib); + l2->addWidget(a_edtLibPath,4); + l2->addWidget(a_btnOpenLib,1); + l2->addWidget(a_chbShowLib); top->addLayout(l2); QHBoxLayout *l7 = new QHBoxLayout; l7->addWidget(lbl_par); - l7->addWidget(edtParams); - l7->addWidget(chbShowParams); + l7->addWidget(a_edtParams); + l7->addWidget(a_chbShowParams); top->addLayout(l7); QGridLayout *gl1 = new QGridLayout; - gl1->addWidget(rbAutoSymbol,0,0); - gl1->addWidget(rbSymFromTemplate,1,0); - gl1->addWidget(rbUserSym,2,0); - gl1->addWidget(edtSymFile,2,1); - gl1->addWidget(btnOpenSym,2,2); - gl1->addWidget(symbol,0,3,3,2); - gl1->addWidget(listSymPattern,0,5,3,2); + gl1->addWidget(a_rbAutoSymbol,0,0); + gl1->addWidget(a_rbSymFromTemplate,1,0); + gl1->addWidget(a_rbUserSym,2,0); + gl1->addWidget(a_edtSymFile,2,1); + gl1->addWidget(a_btnOpenLib,2,2); + gl1->addWidget(a_symbol,0,3,3,2); + gl1->addWidget(a_listSymPattern,0,5,3,2); top->addLayout(gl1); QHBoxLayout *l3 = new QHBoxLayout; - l3->addWidget(tbwPinsTable); + l3->addWidget(a_tbwPinsTable); QGroupBox *gpb1 = new QGroupBox(tr("SPICE model")); QVBoxLayout *l8 = new QVBoxLayout; QHBoxLayout *l5 = new QHBoxLayout; l5->addWidget(lblDevice); - l5->addWidget(cbxSelectSubcir); - l5->addWidget(chbShowModel); + l5->addWidget(a_cbxSelectSubcir); + l5->addWidget(a_chbShowModel); l8->addLayout(l5); - l8->addWidget(edtSPICE); + l8->addWidget(a_edtSPICE); gpb1->setLayout(l8); l3->addWidget(gpb1); top->addLayout(l3,3); QHBoxLayout *l4 = new QHBoxLayout; - l4->addWidget(btnOK); - l4->addWidget(btnApply); - l4->addWidget(btnCancel); + l4->addWidget(a_btnOK); + l4->addWidget(a_btnApply); + l4->addWidget(a_btnCancel); l4->addStretch(); top->addLayout(l4); @@ -174,46 +178,46 @@ SpiceLibCompDialog::SpiceLibCompDialog(Component *pc, Schematic *sch) : QDialog{ this->setWindowTitle(tr("Edit SPICE library device")); slotFillSubcirComboBox(); - cbxSelectSubcir->setCurrentText(device); - auto items = listSymPattern->findItems(sym,Qt::MatchExactly); - if (!items.isEmpty()) listSymPattern->setCurrentItem(items.at(0)); - //listSymPattern->setCurrentText(sym); + a_cbxSelectSubcir->setCurrentText(device); + auto items = a_listSymPattern->findItems(sym,Qt::MatchExactly); + if (!items.isEmpty()) a_listSymPattern->setCurrentItem(items.at(0)); + //a_listSymPattern->setCurrentText(sym); if (!pin_list.isEmpty()) { QStringList pins = pin_list.split(";"); for(int i = 0; i < pins.count(); i++) { - QTableWidgetItem *itm = tbwPinsTable->item(i,1); + QTableWidgetItem *itm = a_tbwPinsTable->item(i,1); if (itm != nullptr) { itm->setText(pins.at(i)); } } } - listSymPattern->setMinimumWidth(0.75*tbwPinsTable->minimumWidth()); - symbol->setMinimumWidth(0.75*tbwPinsTable->minimumWidth()); - - btnApply->setEnabled(false); - connect(rbAutoSymbol,SIGNAL(toggled(bool)),this,SLOT(slotSetSymbol())); - connect(rbSymFromTemplate,SIGNAL(toggled(bool)),this,SLOT(slotSetSymbol())); - connect(rbUserSym,SIGNAL(toggled(bool)),this,SLOT(slotSetSymbol())); - connect(edtLibPath,SIGNAL(textChanged(QString)),this,SLOT(slotChanged())); - connect(edtParams,SIGNAL(textChanged(QString)),this,SLOT(slotChanged())); - connect(tbwPinsTable,SIGNAL(cellChanged(int,int)),this,SLOT(slotChanged())); - connect(listSymPattern,SIGNAL(currentIndexChanged(int)),this,SLOT(slotChanged())); - connect(cbxSelectSubcir,SIGNAL(currentIndexChanged(int)),this,SLOT(slotChanged())); - connect(edtSymFile,SIGNAL(textChanged(QString)),this,SLOT(slotSetSymbol())); - connect(edtSymFile,SIGNAL(textChanged(QString)),this,SLOT(slotChanged())); + a_listSymPattern->setMinimumWidth(0.75*a_tbwPinsTable->minimumWidth()); + a_symbol->setMinimumWidth(0.75*a_tbwPinsTable->minimumWidth()); + + a_btnApply->setEnabled(false); + connect(a_rbAutoSymbol,SIGNAL(toggled(bool)),this,SLOT(slotSetSymbol())); + connect(a_rbSymFromTemplate,SIGNAL(toggled(bool)),this,SLOT(slotSetSymbol())); + connect(a_rbUserSym,SIGNAL(toggled(bool)),this,SLOT(slotSetSymbol())); + connect(a_edtLibPath,SIGNAL(textChanged(QString)),this,SLOT(slotChanged())); + connect(a_edtParams,SIGNAL(textChanged(QString)),this,SLOT(slotChanged())); + connect(a_tbwPinsTable,SIGNAL(cellChanged(int,int)),this,SLOT(slotChanged())); + connect(a_listSymPattern,SIGNAL(currentIndexChanged(int)),this,SLOT(slotChanged())); + connect(a_cbxSelectSubcir,SIGNAL(currentIndexChanged(int)),this,SLOT(slotChanged())); + connect(a_edtSymFile,SIGNAL(textChanged(QString)),this,SLOT(slotSetSymbol())); + connect(a_edtSymFile,SIGNAL(textChanged(QString)),this,SLOT(slotChanged())); } void SpiceLibCompDialog::slotFillSubcirComboBox() { - QString libfile = edtLibPath->text(); + QString libfile = a_edtLibPath->text(); if (!QFile::exists(libfile)) return; int r = parseLibFile(libfile); - libError = false; + a_libError = false; if (r != noError) { - libError = true; + a_libError = true; QString msg; switch (r) { case failedOpenFile: @@ -230,31 +234,31 @@ void SpiceLibCompDialog::slotFillSubcirComboBox() return; } - cbxSelectSubcir->blockSignals(true); - cbxSelectSubcir->clear(); - for(const auto &key: subcirPins.keys()) { - cbxSelectSubcir->addItem(key); + a_cbxSelectSubcir->blockSignals(true); + a_cbxSelectSubcir->clear(); + for(const auto &key: a_subcirPins.keys()) { + a_cbxSelectSubcir->addItem(key); } - cbxSelectSubcir->blockSignals(false); + a_cbxSelectSubcir->blockSignals(false); slotFillPinsTable(); } void SpiceLibCompDialog::slotFillPinsTable() { - QString subcir_name = cbxSelectSubcir->currentText(); - if (subcirPins.find(subcir_name) == subcirPins.end()) return; - QStringList pins = subcirPins[subcir_name]; - tbwPinsTable->clearContents(); - tbwPinsTable->setRowCount(pins.count()); + QString subcir_name = a_cbxSelectSubcir->currentText(); + if (a_subcirPins.find(subcir_name) == a_subcirPins.end()) return; + QStringList pins = a_subcirPins[subcir_name]; + a_tbwPinsTable->clearContents(); + a_tbwPinsTable->setRowCount(pins.count()); for (int i = 0; i < pins.count(); i++) { QTableWidgetItem *itm1 = new QTableWidgetItem(pins.at(i)); - tbwPinsTable->setItem(i,0,itm1); + a_tbwPinsTable->setItem(i,0,itm1); QTableWidgetItem *itm2 = new QTableWidgetItem("NC"); - tbwPinsTable->setItem(i,1,itm2); + a_tbwPinsTable->setItem(i,1,itm2); } - edtSPICE->clear(); - edtSPICE->setPlainText(subcirSPICE[subcir_name]); + a_edtSPICE->clear(); + a_edtSPICE->setPlainText(a_subcirSPICE[subcir_name]); } int SpiceLibCompDialog::parseLibFile(const QString &filename) @@ -266,8 +270,8 @@ int SpiceLibCompDialog::parseLibFile(const QString &filename) return failedOpenFile; } - subcirPins.clear(); - subcirSPICE.clear(); + a_subcirPins.clear(); + a_subcirSPICE.clear(); QTextStream ts(&f); bool subcir_start = false; @@ -292,19 +296,19 @@ int SpiceLibCompDialog::parseLibFile(const QString &filename) pin_names.append(s1); } } - subcirPins[subname] = pin_names; + a_subcirPins[subname] = pin_names; } if (subcir_start) { subcir_body += line + "\n"; } if (line.startsWith(".ENDS")) { subcir_start = false; - subcirSPICE[subname] = subcir_body; + a_subcirSPICE[subname] = subcir_body; } } f.close(); - if (subcirPins.isEmpty()) { + if (a_subcirPins.isEmpty()) { return noSUBCKT; } return noError; @@ -314,37 +318,37 @@ int SpiceLibCompDialog::parseLibFile(const QString &filename) void SpiceLibCompDialog::slotSetSymbol() { int result = -1; - if (rbAutoSymbol->isChecked()) { - tbwPinsTable->setEnabled(false); - listSymPattern->setEnabled(false); - edtSymFile->setEnabled(false); - btnOpenSym->setEnabled(false); + if (a_rbAutoSymbol->isChecked()) { + a_tbwPinsTable->setEnabled(false); + a_listSymPattern->setEnabled(false); + a_edtSymFile->setEnabled(false); + a_btnOpenLib->setEnabled(false); QString s1 = ""; QString s2 = "SpLib"; - symbol->setSymbol(s1, s1, s2); + a_symbol->setSymbol(s1, s1, s2); result = 0; - symbol->setWarning(tr("No symbol loaded")); - symbolPinsCount = 0; - } else if (rbSymFromTemplate->isChecked()) { - tbwPinsTable->setEnabled(true); - listSymPattern->setEnabled(true); - edtSymFile->setEnabled(false); - btnOpenSym->setEnabled(false); + a_symbol->setWarning(tr("No symbol loaded")); + a_symbolPinsCount = 0; + } else if (a_rbSymFromTemplate->isChecked()) { + a_tbwPinsTable->setEnabled(true); + a_listSymPattern->setEnabled(true); + a_edtSymFile->setEnabled(false); + a_btnOpenLib->setEnabled(false); QString dir_name = QucsSettings.BinDir + "/../share/" QUCS_NAME "/symbols/"; - QString file = dir_name + listSymPattern->currentItem()->text() + ".sym"; - result = symbol->loadSymFile(file); - symbolPinsCount = symbol->getPortsNumber(); - } else if (rbUserSym->isChecked()) { - tbwPinsTable->setEnabled(true); - listSymPattern->setEnabled(false); - edtSymFile->setEnabled(true); - btnOpenSym->setEnabled(true); - if (edtSymFile->text().isEmpty()) { - symbolPinsCount = 0; + QString file = dir_name + a_listSymPattern->currentItem()->text() + ".sym"; + result = a_symbol->loadSymFile(file); + a_symbolPinsCount = a_symbol->getPortsNumber(); + } else if (a_rbUserSym->isChecked()) { + a_tbwPinsTable->setEnabled(true); + a_listSymPattern->setEnabled(false); + a_edtSymFile->setEnabled(true); + a_btnOpenLib->setEnabled(true); + if (a_edtSymFile->text().isEmpty()) { + a_symbolPinsCount = 0; return; } - result = symbol->loadSymFile(edtSymFile->text()); - symbolPinsCount = symbol->getPortsNumber(); + result = a_symbol->loadSymFile(a_edtSymFile->text()); + a_symbolPinsCount = a_symbol->getPortsNumber(); } if (result < 0) { @@ -352,33 +356,33 @@ void SpiceLibCompDialog::slotSetSymbol() return; } - for (int i = 0; i < tbwPinsTable->rowCount(); i++) { + for (int i = 0; i < a_tbwPinsTable->rowCount(); i++) { QTableWidgetItem *itm = new QTableWidgetItem("NC"); - tbwPinsTable->setItem(i,1,itm); + a_tbwPinsTable->setItem(i,1,itm); } - isChanged = true; - btnApply->setEnabled(true); + a_isChanged = true; + a_btnApply->setEnabled(true); } void SpiceLibCompDialog::slotTableCellDoubleClick() { - int r = tbwPinsTable->currentRow(); - int c = tbwPinsTable->currentColumn(); + int r = a_tbwPinsTable->currentRow(); + int c = a_tbwPinsTable->currentColumn(); if (c == 0) return; // do not edit the first column - if (prev_col >= 0 && prev_row >= 0) { // remove combo box from previous cell + if (a_prev_col >= 0 && a_prev_row >= 0) { // remove combo box from previous cell QTableWidgetItem *itm = new QTableWidgetItem("NC"); - tbwPinsTable->removeCellWidget(prev_row, prev_col); - tbwPinsTable->setItem(prev_row, prev_col, itm); + a_tbwPinsTable->removeCellWidget(a_prev_row, a_prev_col); + a_tbwPinsTable->setItem(a_prev_row, a_prev_col, itm); } QComboBox *cbxSelectPin = new QComboBox; cbxSelectPin->addItem("NC"); - for (int i = 1; i <= symbolPinsCount; i++) { + for (int i = 1; i <= a_symbolPinsCount; i++) { bool pinAssigned = false; - for(int j = 0; j < tbwPinsTable->rowCount(); j++) { + for(int j = 0; j < a_tbwPinsTable->rowCount(); j++) { if (j == r) continue; - auto itm = tbwPinsTable->item(j,1); + auto itm = a_tbwPinsTable->item(j,1); if (itm == nullptr) continue; QString s = itm->text(); if (s.isEmpty()) continue; @@ -392,49 +396,49 @@ void SpiceLibCompDialog::slotTableCellDoubleClick() cbxSelectPin->addItem(QString::number(i)); } } - tbwPinsTable->item(r,c)->setText(""); - tbwPinsTable->setCellWidget(r,c,cbxSelectPin); + a_tbwPinsTable->item(r,c)->setText(""); + a_tbwPinsTable->setCellWidget(r,c,cbxSelectPin); connect(cbxSelectPin,SIGNAL(activated(int)),this,SLOT(slotSelectPin())); - prev_col = c; // remebmebr cell with combo box - prev_row = r; + a_prev_col = c; // remebmebr cell with combo box + a_prev_row = r; } void SpiceLibCompDialog::slotSelectPin() { QComboBox *cbxSelectPin = qobject_cast(sender()); QString pin = cbxSelectPin->currentText(); - int r = tbwPinsTable->currentRow(); - int c = tbwPinsTable->currentColumn(); + int r = a_tbwPinsTable->currentRow(); + int c = a_tbwPinsTable->currentColumn(); QTableWidgetItem *itm = new QTableWidgetItem(pin); - tbwPinsTable->removeCellWidget(r,c); - tbwPinsTable->setItem(r,c,itm); + a_tbwPinsTable->removeCellWidget(r,c); + a_tbwPinsTable->setItem(r,c,itm); - prev_col = -1; // clear cell index with combo box - prev_row = -1; + a_prev_col = -1; // clear cell index with combo box + a_prev_row = -1; } void SpiceLibCompDialog::slotBtnOpenLib() { QString s = QFileDialog::getOpenFileName(this, tr("Open SPICE library"), - lastLibDir, + a_lastLibDir, tr("SPICE files (*.cir +.ckt *.sp *.lib)")); if (!s.isEmpty()) { QFileInfo inf(s); - lastLibDir = inf.absoluteDir().path(); - edtLibPath->setText(s); + a_lastLibDir = inf.absoluteDir().path(); + a_edtLibPath->setText(s); } } void SpiceLibCompDialog::slotBtnOpenSym() { QString s = QFileDialog::getOpenFileName(this, tr("Open symbol file"), - lastSymbolDir, + a_lastSymbolDir, tr("Schematic symbol (*.sym)")); if (!s.isEmpty()) { QFileInfo inf(s); - lastSymbolDir = inf.absoluteDir().path(); - edtSymFile->setText(s); + a_lastSymbolDir = inf.absoluteDir().path(); + a_edtSymFile->setText(s); } } @@ -442,11 +446,11 @@ bool SpiceLibCompDialog::setCompProps() { QStringList pins; QString pin_string; - if (rbAutoSymbol->isChecked()) { + if (a_rbAutoSymbol->isChecked()) { pin_string = ""; } else { - for (int i = 0; i < tbwPinsTable->rowCount(); i++) { - QTableWidgetItem *itm = tbwPinsTable->item(i,1); + for (int i = 0; i < a_tbwPinsTable->rowCount(); i++) { + QTableWidgetItem *itm = a_tbwPinsTable->item(i,1); if (itm == nullptr) continue; QString s = itm->text(); if (s == "NC") { @@ -458,15 +462,15 @@ bool SpiceLibCompDialog::setCompProps() pin_string = pins.join(";"); } - if (rbUserSym->isChecked() && - !QFileInfo::exists(edtSymFile->text())) { + if (a_rbUserSym->isChecked() && + !QFileInfo::exists(a_edtSymFile->text())) { QMessageBox::warning(this,tr("Warning"),tr("Set a valid symbol file name")); return false; } - QString sch_dir = Doc->getFileInfo().absoluteDir().path(); - QString libpath = edtLibPath->text(); - QString sympath = edtSymFile->text(); + QString sch_dir = a_schematic->getFileInfo().absoluteDir().path(); + QString libpath = a_edtLibPath->text(); + QString sympath = a_edtSymFile->text(); if (libpath.startsWith(sch_dir)) { libpath = QDir(sch_dir).relativeFilePath(libpath); } @@ -474,50 +478,50 @@ bool SpiceLibCompDialog::setCompProps() sympath = QDir(sch_dir).relativeFilePath(sympath); } - auto pp = comp->Props.begin(); + auto pp = a_comp->Props.begin(); (*pp)->Value = libpath; - (*pp)->display = chbShowLib->isChecked(); + (*pp)->display = a_chbShowLib->isChecked(); pp++; - (*pp)->Value = cbxSelectSubcir->currentText(); - (*pp)->display = chbShowModel->isChecked(); + (*pp)->Value = a_cbxSelectSubcir->currentText(); + (*pp)->display = a_chbShowModel->isChecked(); pp++; - if (rbAutoSymbol->isChecked()) { + if (a_rbAutoSymbol->isChecked()) { (*pp)->Value = "auto"; - } else if (rbSymFromTemplate->isChecked()) { - (*pp)->Value = listSymPattern->currentItem()->text(); - } else if (rbUserSym->isChecked()) { + } else if (a_rbSymFromTemplate->isChecked()) { + (*pp)->Value = a_listSymPattern->currentItem()->text(); + } else if (a_rbUserSym->isChecked()) { (*pp)->Value = sympath; } pp++; - (*pp)->Value = edtParams->text(); - (*pp)->display = chbShowParams->isChecked(); + (*pp)->Value = a_edtParams->text(); + (*pp)->display = a_chbShowParams->isChecked(); pp++; (*pp)->Value = QString(pin_string); - Doc->recreateComponent(comp); - Doc->viewport()->repaint(); - Doc->setChanged(true,true); + a_schematic->recreateComponent(a_comp); + a_schematic->viewport()->repaint(); + a_schematic->setChanged(true,true); return true; } void SpiceLibCompDialog::slotBtnApply() { - if (isChanged) { - if (libError) { + if (a_isChanged) { + if (a_libError) { QMessageBox::critical(this,tr("Error"), tr("There were library file parse error! Cannot apply changes.")); return; } if (setCompProps()) { - isChanged = false; - btnApply->setEnabled(false); + a_isChanged = false; + a_btnApply->setEnabled(false); } } } void SpiceLibCompDialog::slotBtnOK() { - if (isChanged) { - if (libError) { + if (a_isChanged) { + if (a_libError) { QMessageBox::critical(this,tr("Error"), tr("There were library file parse error! Cannot apply changes.")); reject(); @@ -536,6 +540,6 @@ void SpiceLibCompDialog::slotBtnCancel() void SpiceLibCompDialog::slotChanged() { - isChanged = true; - btnApply->setEnabled(true); + a_isChanged = true; + a_btnApply->setEnabled(true); } diff --git a/qucs/extsimkernels/spicelibcompdialog.h b/qucs/extsimkernels/spicelibcompdialog.h index ef7cc7db9..a407a1763 100644 --- a/qucs/extsimkernels/spicelibcompdialog.h +++ b/qucs/extsimkernels/spicelibcompdialog.h @@ -16,32 +16,42 @@ class SpiceLibCompDialog : public QDialog { Q_OBJECT private: - int symbolPinsCount; - bool isChanged; - bool libError; - - int prev_row, prev_col; - - QString lastSymbolDir; - QString lastLibDir; - - Component *comp; - Schematic *Doc; - - SymbolWidget *symbol; - QLineEdit *edtLibPath, *edtParams, *edtSymFile; - QPlainTextEdit *edtSPICE; - - QPushButton *btnOpenLib, *btnOK, *btnApply, *btnCancel, *btnOpenSym; - QTableWidget *tbwPinsTable; - QComboBox *cbxSelectSubcir; - QListWidget *listSymPattern; - - QRadioButton *rbSymFromTemplate, *rbAutoSymbol, *rbUserSym; - QCheckBox *chbShowLib, *chbShowModel, *chbShowParams; - - QMap subcirPins; - QMap subcirSPICE; + int a_symbolPinsCount; + bool a_isChanged; + bool a_libError; + + int a_prev_row; + int a_prev_col; + + QString a_lastSymbolDir; + QString a_lastLibDir; + + Component *a_comp; + Schematic *a_schematic; + + SymbolWidget *a_symbol; + QLineEdit *a_edtLibPath; + QLineEdit *a_edtParams; + QLineEdit *a_edtSymFile; + QPlainTextEdit *a_edtSPICE; + + QPushButton *a_btnOpenLib; + QPushButton *a_btnOK; + QPushButton *a_btnApply; + QPushButton *a_btnCancel; + QTableWidget *a_tbwPinsTable; + QComboBox *a_cbxSelectSubcir; + QListWidget *a_listSymPattern; + + QRadioButton *a_rbSymFromTemplate; + QRadioButton *a_rbAutoSymbol; + QRadioButton *a_rbUserSym; + QCheckBox *a_chbShowLib; + QCheckBox *a_chbShowModel; + QCheckBox *a_chbShowParams; + + QMap a_subcirPins; + QMap a_subcirSPICE; enum SPICEparseError { noError=0, failedOpenFile = -1, noSUBCKT = -2 }; diff --git a/qucs/extsimkernels/verilogawriter.h b/qucs/extsimkernels/verilogawriter.h index fe09bb3ef..940203b93 100644 --- a/qucs/extsimkernels/verilogawriter.h +++ b/qucs/extsimkernels/verilogawriter.h @@ -51,7 +51,7 @@ class VerilogAwriter bool prepareToVerilogA(Schematic *sch); public: bool createVA_module(QTextStream &stream, Schematic *sch); - + }; #endif // VERILOGAWRITER_H diff --git a/qucs/extsimkernels/xyce.cpp b/qucs/extsimkernels/xyce.cpp index 1dc48cf4d..5a75375ae 100644 --- a/qucs/extsimkernels/xyce.cpp +++ b/qucs/extsimkernels/xyce.cpp @@ -32,42 +32,43 @@ /*! * \brief Xyce::Xyce Class constructor - * \param sch_ Schematic that need to be simulated with Ngspice. + * \param schematic Schematic that need to be simulated with Ngspice. * \param parent Parent object */ -Xyce::Xyce(Schematic *sch_, QObject *parent) : - AbstractSpiceKernel(sch_, parent) +Xyce::Xyce(Schematic *schematic, QObject *parent) : + AbstractSpiceKernel(schematic, parent), + a_Noisesim(false), + a_simulationsQueue(), + a_netlistQueue() { - simulator_cmd = QucsSettings.XyceExecutable; - Nprocs = QucsSettings.NProcs; - Noisesim = false; + a_simulator_cmd = QucsSettings.XyceExecutable; } /*! * \brief Xyce::determineUsedSimulations Determine simulation used - * in schematic and add them into simulationsQueue list + * in schematic and add them into a_simulationsQueue list */ void Xyce::determineUsedSimulations(QStringList *sim_lst) { - for(Component *pc = Sch->DocComps.first(); pc != 0; pc = Sch->DocComps.next()) { + for(Component *pc = a_schematic->DocComps.first(); pc != 0; pc = a_schematic->DocComps.next()) { if(pc->isSimulation && pc->isActive == COMP_IS_ACTIVE) { QString sim_typ = pc->Model; - if (sim_typ==".AC") simulationsQueue.append("ac"); - if (sim_typ==".NOISE") simulationsQueue.append("noise"); - if (sim_typ==".TR") simulationsQueue.append("tran"); - if (sim_typ==".HB") simulationsQueue.append("hb"); - if (sim_typ==".SP") simulationsQueue.append("sp"); - if (sim_typ==".SENS_XYCE") simulationsQueue.append("sens"); - if (sim_typ==".SENS_TR_XYCE") simulationsQueue.append("sens_tr"); - if (sim_typ==".XYCESCR") simulationsQueue.append(pc->Name); // May be >= XYCE scripts + if (sim_typ==".AC") a_simulationsQueue.append("ac"); + if (sim_typ==".NOISE") a_simulationsQueue.append("noise"); + if (sim_typ==".TR") a_simulationsQueue.append("tran"); + if (sim_typ==".HB") a_simulationsQueue.append("hb"); + if (sim_typ==".SP") a_simulationsQueue.append("sp"); + if (sim_typ==".SENS_XYCE") a_simulationsQueue.append("sens"); + if (sim_typ==".SENS_TR_XYCE") a_simulationsQueue.append("sens_tr"); + if (sim_typ==".XYCESCR") a_simulationsQueue.append(pc->Name); // May be >= XYCE scripts if ((sim_typ==".SW")&& - (pc->Props.at(0)->Value.startsWith("DC"))) simulationsQueue.append("dc"); + (pc->Props.at(0)->Value.startsWith("DC"))) a_simulationsQueue.append("dc"); } } if (sim_lst != NULL) { - *sim_lst = simulationsQueue; + *sim_lst = a_simulationsQueue; } } @@ -84,8 +85,8 @@ void Xyce::createNetlist(QTextStream &stream, int , QStringList &simulations, QString s; bool hasParSweep = false; - stream << "* Qucs " << PACKAGE_VERSION << " " << Sch->DocName << "\n"; - stream<DocName << "\n"; + stream<DocNodes.first(); pn != 0; pn = Sch->DocNodes.next()) { + for(Node *pn = a_schematic->DocNodes.first(); pn != 0; pn = a_schematic->DocNodes.next()) { if(pn->Label != 0) { if (!vars.contains(pn->Label->Name)) { vars.append(pn->Label->Name); } } } - for(Wire *pw = Sch->DocWires.first(); pw != 0; pw = Sch->DocWires.next()) { + for(Wire *pw = a_schematic->DocWires.first(); pw != 0; pw = a_schematic->DocWires.next()) { if(pw->Label != 0) { if (!vars.contains(pw->Label->Name)) { vars.append(pw->Label->Name); } } } - for(Component *pc = Sch->DocComps.first(); pc != 0; pc = Sch->DocComps.next()) { + for(Component *pc = a_schematic->DocComps.first(); pc != 0; pc = a_schematic->DocComps.next()) { if (pc->isProbe) { QString var_pr = pc->getProbeVariable(true); if (!vars.contains(var_pr)) { @@ -122,15 +123,15 @@ void Xyce::createNetlist(QTextStream &stream, int , QStringList &simulations, }*/ } - if (DC_OP_only) { + if (a_DC_OP_only) { // Add all remaining nodes, because XYCE has no equivalent for PRINT ALL - for(Node* pn = Sch->Nodes->first(); pn != 0; pn = Sch->Nodes->next()) { + for(Node* pn = a_schematic->Nodes->first(); pn != 0; pn = a_schematic->Nodes->next()) { if ((!vars.contains(pn->Name))&&(pn->Name!="gnd")) { vars.append(pn->Name); } } // Add DC sources - for(Component *pc = Sch->DocComps.first(); pc != 0; pc = Sch->DocComps.next()) { + for(Component *pc = a_schematic->DocComps.first(); pc != 0; pc = a_schematic->DocComps.next()) { if ((pc->Model == "S4Q_V")||(pc->Model == "Vdc")) { vars.append("I("+pc->Name+")"); } @@ -141,7 +142,7 @@ void Xyce::createNetlist(QTextStream &stream, int , QStringList &simulations, //execute simulations - //QFileInfo inf(Sch->DocName); + //QFileInfo inf(a_schematic->DocName); //QString basenam = inf.baseName(); QString basenam = "spice4qucs"; @@ -155,7 +156,7 @@ void Xyce::createNetlist(QTextStream &stream, int , QStringList &simulations, } } - if (DC_OP_only) { + if (a_DC_OP_only) { stream<<".OP\n"; stream<DocComps.first(); pc != 0; pc = Sch->DocComps.next()) { // Xyce can run + for(Component *pc = a_schematic->DocComps.first(); pc != 0; pc = a_schematic->DocComps.next()) { // Xyce can run if(pc->isSimulation && pc->isActive == COMP_IS_ACTIVE) { // only one simulations per time. QString sim_typ = pc->Model; // Multiple simulations are forbidden. QString s = pc->getSpiceNetlist(true); @@ -179,7 +180,7 @@ void Xyce::createNetlist(QTextStream &stream, int , QStringList &simulations, if (sim==pc->Name) stream< comps(Sch->DocComps); // find Fourier tran + Q3PtrList comps(a_schematic->DocComps); // find Fourier tran for(Component *pc1 = comps.first(); pc1 != 0; pc1 = comps.next()) { if (pc1->Model==".FOURIER") { if (pc1->Props.at(0)->Value==pc->Name) { @@ -213,7 +214,7 @@ void Xyce::createNetlist(QTextStream &stream, int , QStringList &simulations, stream<DocComps.first(); pc1 != 0; pc1 = Sch->DocComps.next()) { + for(Component *pc1 = a_schematic->DocComps.first(); pc1 != 0; pc1 = a_schematic->DocComps.next()) { if ((pc1->Name==SwpSim)&&(pc1->Props.at(0)->Value.startsWith("DC"))) { stream<DocComps.first(); pc != 0; pc = Sch->DocComps.next()) { + for(Component *pc = a_schematic->DocComps.first(); pc != 0; pc = a_schematic->DocComps.next()) { if (pc->isSimulation) if (sim == pc->Name) outputs.append(pc->Props.at(2)->Value.split(';')); @@ -287,56 +288,56 @@ void Xyce::slotSimulate() bool checker_error = false; if (!checkSchematic(incompat)) { QString s = incompat.join("; "); - output.append("There were SPICE-incompatible components. Simulator cannot proceed."); - output.append("Incompatible components are: " + s + "\n"); + a_output.append("There were SPICE-incompatible components. Simulator cannot proceed."); + a_output.append("Incompatible components are: " + s + "\n"); checker_error = true; } if (!checkGround()) { - output.append("No Ground found. Please add at least one ground!\n"); + a_output.append("No Ground found. Please add at least one ground!\n"); checker_error = true; } if (!checkDCSimulation()) { - output.append("Only DC simulation found in the schematic. It has no effect!" + a_output.append("Only DC simulation found in the schematic. It has no effect!" " Add TRAN, AC, or Sweep simulation to proceed.\n"); checker_error = true; } if (checker_error) { - if (console != nullptr) - console->insertPlainText(output); + if (a_console != nullptr) + a_console->insertPlainText(a_output); //emit finished(); emit errors(QProcess::FailedToStart); return; } int num=0; - netlistQueue.clear(); - output_files.clear(); + a_netlistQueue.clear(); + a_output_files.clear(); - if (DC_OP_only) { - simulationsQueue.append("dc"); + if (a_DC_OP_only) { + a_simulationsQueue.append("dc"); } else determineUsedSimulations(); - QFile::remove(workdir+"spice4qucs.sens_tr.cir.SENS.prn"); - QFile::remove(workdir+"spice4qucs.sens_tr.cir.TRADJ.prn"); + QFile::remove(a_workdir+"spice4qucs.sens_tr.cir.SENS.prn"); + QFile::remove(a_workdir+"spice4qucs.sens_tr.cir.TRADJ.prn"); - for (const QString& sim : simulationsQueue) { + for (const QString& sim : a_simulationsQueue) { QStringList sim_lst; sim_lst.clear(); sim_lst.append(sim); - QString tmp_path = QDir::toNativeSeparators(workdir+"/spice4qucs."+sim+".cir"); - netlistQueue.append(tmp_path); + QString tmp_path = QDir::toNativeSeparators(a_workdir+"/spice4qucs."+sim+".cir"); + a_netlistQueue.append(tmp_path); QFile spice_file(tmp_path); if (spice_file.open(QFile::WriteOnly)) { QTextStream stream(&spice_file); - createNetlist(stream,num,sim_lst,vars,output_files); + createNetlist(stream,num,sim_lst,a_vars,a_output_files); spice_file.close(); } } - output.clear(); + a_output.clear(); emit started(); nextSimulation(); @@ -354,7 +355,7 @@ void Xyce::SaveNetlist(QString filename) QFile spice_file(filename); if (spice_file.open(QFile::WriteOnly)) { QTextStream stream(&spice_file); - createNetlist(stream,num,simulationsQueue,vars,output_files); + createNetlist(stream,num,a_simulationsQueue,a_vars,a_output_files); spice_file.close(); } } @@ -364,21 +365,21 @@ void Xyce::SaveNetlist(QString filename) * execute the next simulation from queue. */ void Xyce::slotFinished() -{ - output += SimProcess->readAllStandardOutput();; +{ + a_output += a_simProcess->readAllStandardOutput();; - if (Noisesim) { - QFile logfile(workdir + QDir::separator() + "spice4qucs.noise_log"); + if (a_Noisesim) { + QFile logfile(a_workdir + QDir::separator() + "spice4qucs.noise_log"); if (logfile.open(QIODevice::WriteOnly)) { QTextStream ts(&logfile); - ts<waitForFinished(10000); + while (!a_netlistQueue.isEmpty()) { + ok = a_simProcess->waitForFinished(10000); } - ok = SimProcess->waitForFinished(10000); + ok = a_simProcess->waitForFinished(10000); return ok; } @@ -403,15 +404,15 @@ bool Xyce::waitEndOfSimulation() void Xyce::slotProcessOutput() { //***** Percent complete: 85.4987 % - QString s = SimProcess->readAllStandardOutput(); + QString s = a_simProcess->readAllStandardOutput(); if (s.contains("Percent complete:")) { int percent = round(s.section(' ',3,3,QString::SectionSkipEmpty).toFloat()); emit progress(percent); } - output += s; - if (console != nullptr) { - console->insertPlainText(s); - console->moveCursor(QTextCursor::End); + a_output += s; + if (a_console != nullptr) { + a_console->insertPlainText(s); + a_console->moveCursor(QTextCursor::End); } } @@ -420,17 +421,17 @@ void Xyce::slotProcessOutput() */ void Xyce::nextSimulation() { - if (!netlistQueue.isEmpty()) { - QString file = netlistQueue.takeFirst(); - if (file.endsWith(".noise.cir")) Noisesim = true; - SimProcess->setWorkingDirectory(workdir); - QString cmd = QStringLiteral("%1 %2 \"%3\"").arg(simulator_cmd,simulator_parameters,file); + if (!a_netlistQueue.isEmpty()) { + QString file = a_netlistQueue.takeFirst(); + if (file.endsWith(".noise.cir")) a_Noisesim = true; + a_simProcess->setWorkingDirectory(a_workdir); + QString cmd = QStringLiteral("%1 %2 \"%3\"").arg(a_simulator_cmd,a_simulator_parameters,file); QStringList cmd_args = misc::parseCmdArgs(cmd); QString xyce_cmd = cmd_args.at(0); cmd_args.removeAt(0); - SimProcess->start(xyce_cmd,cmd_args); + a_simProcess->start(xyce_cmd,cmd_args); } else { - output += "No simulation found. Please add at least one simulation!\n" + a_output += "No simulation found. Please add at least one simulation!\n" "Navigate to the \"simulations\" group in the components panel (left)" " and drag simulation to the schematic sheet. Then define its parameters.\n" "Exiting...\n"; @@ -444,10 +445,10 @@ void Xyce::setParallel(bool par) if (par) { QString xyce_par = QucsSettings.XyceParExecutable; xyce_par.replace("%p",QString::number(QucsSettings.NProcs)); - simulator_cmd = xyce_par; - simulator_parameters = simulator_parameters + QStringLiteral(" -a "); + a_simulator_cmd = xyce_par; + a_simulator_parameters = a_simulator_parameters + QStringLiteral(" -a "); } else { - simulator_cmd = "\"" + QucsSettings.XyceExecutable + "\""; - simulator_parameters = simulator_parameters + " -a "; + a_simulator_cmd = "\"" + QucsSettings.XyceExecutable + "\""; + a_simulator_parameters = a_simulator_parameters + " -a "; } } diff --git a/qucs/extsimkernels/xyce.h b/qucs/extsimkernels/xyce.h index e3a049da3..1917fb7fa 100644 --- a/qucs/extsimkernels/xyce.h +++ b/qucs/extsimkernels/xyce.h @@ -35,22 +35,23 @@ class Xyce : public AbstractSpiceKernel { Q_OBJECT + private: - bool Noisesim; + bool a_Noisesim; + + QStringList a_simulationsQueue; + QStringList a_netlistQueue; - unsigned int Nprocs; - QStringList simulationsQueue; - QStringList netlistQueue; void nextSimulation(); public: void determineUsedSimulations(QStringList *sim_lst = NULL); - explicit Xyce(Schematic *sch_, QObject *parent = 0); + explicit Xyce(Schematic *schematic, QObject *parent = 0); void SaveNetlist(QString filename); void setParallel(bool par); bool waitEndOfSimulation(); - + protected: void createNetlist(QTextStream &stream, int NumPorts, QStringList &simulations, QStringList &vars, QStringList &outputs); @@ -60,7 +61,7 @@ protected slots: public slots: void slotSimulate(); - + }; #endif // XYCE_H diff --git a/qucs/qucs.cpp b/qucs/qucs.cpp index 5cde9164d..74550e919 100644 --- a/qucs/qucs.cpp +++ b/qucs/qucs.cpp @@ -3494,11 +3494,11 @@ void QucsApp::slotAfterSpiceSimulation(ExternSimDialog *SimDlg) this,SLOT(slotAfterSpiceSimulation(ExternSimDialog *))); disconnect(SimDlg,SIGNAL(warnings()),this,SLOT(slotShowWarnings())); disconnect(SimDlg,SIGNAL(success()),this,SLOT(slotResetWarnings())); - if (TuningMode && SimDlg->hasError) { + if (TuningMode && SimDlg->hasError()) { SimDlg->show(); return; } - if (SimDlg->wasSimulated) { + if (SimDlg->wasSimulated()) { if(sch->SimOpenDpl) { if (sch->showBias < 1) { if (!TuningMode) {