Implemented progressbar for Ngspice

This commit is contained in:
Vadim Kuznetzov 2015-05-04 12:18:45 +03:00
parent 82ee1ee4c5
commit b591279e68
6 changed files with 40 additions and 2 deletions

View File

@ -54,6 +54,7 @@ AbstractSpiceKernel::AbstractSpiceKernel(Schematic *sch_, QObject *parent) :
SimProcess = new QProcess(this);
SimProcess->setProcessChannelMode(QProcess::MergedChannels);
connect(SimProcess,SIGNAL(finished(int)),this,SLOT(slotFinished()));
connect(SimProcess,SIGNAL(readyRead()),this,SLOT(slotProcessOutput()));
connect(this,SIGNAL(destroyed()),this,SLOT(killThemAll()));
}
@ -621,9 +622,18 @@ void AbstractSpiceKernel::slotErrors(QProcess::ProcessError err)
*/
void AbstractSpiceKernel::slotFinished()
{
output.clear();
output = SimProcess->readAllStandardOutput();
//output.clear();
output += SimProcess->readAllStandardOutput();
emit finished();
//emit progress(100);
}
/*!
* \brief AbstractSpiceKernel::slotProcessOutput Process SimProcess output and report progress
*/
void AbstractSpiceKernel::slotProcessOutput()
{
}
/*!

View File

@ -84,9 +84,11 @@ signals:
void started();
void finished();
void errors(QProcess::ProcessError);
void progress(int);
protected slots:
virtual void slotFinished();
virtual void slotProcessOutput();
public slots:
virtual void slotSimulate();

View File

@ -68,6 +68,10 @@ ExternSimDialog::ExternSimDialog(Schematic *sch,QWidget *parent) :
vbl1->addWidget(editSimConsole);
grp1->setLayout(vbl1);
simProgress = new QProgressBar(this);
connect(ngspice,SIGNAL(progress(int)),simProgress,SLOT(setValue(int)));
connect(xyce,SIGNAL(progress(int)),simProgress,SLOT(setValue(int)));
QVBoxLayout *vl_top = new QVBoxLayout;
QHBoxLayout *hl2 = new QHBoxLayout;
hl2->addWidget(lblSimulator);
@ -75,6 +79,7 @@ ExternSimDialog::ExternSimDialog(Schematic *sch,QWidget *parent) :
hl2->addWidget(buttonSimSettings);
vl_top->addLayout(hl2);
vl_top->addWidget(grp1);
vl_top->addWidget(simProgress);
QHBoxLayout *hl1 = new QHBoxLayout;
hl1->addWidget(buttonSimulate);
hl1->addWidget(buttonStopSim);

View File

@ -40,6 +40,8 @@ private:
QTextEdit *editSimConsole;
QProgressBar *simProgress;
QString workdir;
Ngspice *ngspice;

View File

@ -240,6 +240,7 @@ void Ngspice::createNetlist(QTextStream &stream, int ,
*/
void Ngspice::slotSimulate()
{
//output.clear();
QString tmp_path = QDir::convertSeparators(workdir+"/spice4qucs.cir");
SaveNetlist(tmp_path);
@ -250,6 +251,21 @@ void Ngspice::slotSimulate()
emit started();
}
/*!
* \brief Ngspice::slotProcessOutput Process Ngspice output and report completetion
* percentage.
*/
void Ngspice::slotProcessOutput()
{
QString s = SimProcess->readAllStandardOutput();
QRegExp percentage_pattern("^%\\d\\d.\\d\\d.*$");
if (percentage_pattern.exactMatch(s)) {
int percent = round(s.mid(1,5).toFloat());
emit progress(percent);
}
output += s;
}
/*!
* \brief Ngspice::SaveNetlist Create netlist and save it to file without execution
* of simulator.

View File

@ -43,6 +43,9 @@ protected:
QStringList &vars, QStringList &outputs);
public slots:
void slotSimulate();
protected slots:
void slotProcessOutput();
};
#endif // NGSPICE_H