Q_OBJECT
private:
///internal use vars
SmootherSettings settings;
unsigned short int columns;
unsigned int rows;
enum SmoothingStep { INPUT_FILE, OUTPUT_FILE_1, OUTPUT_FILE_2, SAMPLES_AMOUNT, COLUMNS_AMOUNT,
SMOOTHED_COLUMN, POINTS_NUMBER_IN_SINGLE_STEP, APPROX_POLYNOM_ORDER,
DERIVATIVE_ORDER, SMOOTHINGS_NUMBER, END };
enum SmoothingStep curr_step;
//data returned from SMOOTHER
//internal use functions
void interpretSmootherProcAnswer(const QString& answer);
void askSmootherProc();
void preprocessInputFile();
void convertOutputDATtoXLS();
public:
Smoother(const QString& arg_fortranSmoother, const struct SmootherSettings& arg_data);
~Smoother();
void run();
public slots:
void smootherStarted();
void smootherFinished
(int exitCode,
QProcess::ExitStatus exitStatus
);
void readyToRead();
void processError
(QProcess::ProcessError error
);
signals:
void finished
(int exitCode,
QProcess::ExitStatus exitStatus
);
void started();
void progress
(unsigned short percent,
QString currentActionDescription
);
void error(Exception e);
void strSent(const QString& str);
void strReceived(const QString& str);
};
class Smoother : public QObject {
Q_OBJECT
private:
///internal use vars
SmootherSettings settings;
QString fortranSmoother;
unsigned short int columns;
unsigned int rows;
QTemporaryFile* tmpInputFile;
QTemporaryFile* tmpOutputFile2;
QString originalOutputFile2;
QProcess proc;
enum SmoothingStep { INPUT_FILE, OUTPUT_FILE_1, OUTPUT_FILE_2, SAMPLES_AMOUNT, COLUMNS_AMOUNT,
SMOOTHED_COLUMN, POINTS_NUMBER_IN_SINGLE_STEP, APPROX_POLYNOM_ORDER,
DERIVATIVE_ORDER, SMOOTHINGS_NUMBER, END };
enum SmoothingStep curr_step;
//data returned from SMOOTHER
//internal use functions
void interpretSmootherProcAnswer(const QString& answer);
void askSmootherProc();
void preprocessInputFile();
QString convertInputXLStoDAT();
void convertOutputDATtoXLS();
public:
Smoother(const QString& arg_fortranSmoother, const struct SmootherSettings& arg_data);
~Smoother();
void run();
public slots:
void smootherStarted();
void smootherFinished(int exitCode, QProcess::ExitStatus exitStatus);
void readyToRead();
void processError(QProcess::ProcessError error);
signals:
void finished(int exitCode, QProcess::ExitStatus exitStatus);
void started();
void progress(unsigned short percent, QString currentActionDescription);
void error(Exception e);
void strSent(const QString& str);
void strReceived(const QString& str);
};
To copy to clipboard, switch view to plain text mode
Smoother::Smoother(const QString& arg_fortranSmoother, const SmootherSettings &arg_data)
: settings(arg_data), fortranSmoother(arg_fortranSmoother), columns(0), rows(0), tmpInputFile(0), tmpOutputFile2(0), curr_step(INPUT_FILE) {
QObject::connect(&(this
->proc
),
SIGNAL(started
()),
this,
SLOT(smootherStarted
()));
QObject::connect(&(this
->proc
),
SIGNAL(finished
(int,
QProcess::ExitStatus)),
this,
SLOT(smootherFinished
(int,
QProcess::ExitStatus)));
QObject::connect(&(this
->proc
),
SIGNAL(error
(QProcess::ProcessError)),
this,
SLOT(processError
(QProcess::ProcessError)));
QObject::connect(&(this
->proc
),
SIGNAL(readyRead
()),
this,
SLOT(readyToRead
()));
}
Smoother::~Smoother() {
QObject::disconnect(&(this
->proc
));
this->proc.close();
if(tmpInputFile) {
tmpInputFile->close();
tmpInputFile->remove();
delete tmpInputFile;
}
if(tmpOutputFile2){
tmpOutputFile2->close();
tmpOutputFile2->remove();
delete tmpOutputFile2;
}
}
void Smoother::run() {
//input file preprocessing
preprocessInputFile();
if(columns == 0 || rows == 0) {
emit strSent("Process cannot be started. Invalid input file");
return;
}
this->originalOutputFile2 = settings.outputFile2;
if(ext == "xls") {
settings.
outputFile2 = QDir::tempPath() + QDir::separator() + "pwsmoother_tmp.out.dat";
}
QString cmd
= QString("\"%1\"").
arg(( this
->fortranSmoother
)).
toStdString().
c_str();
try {
} catch(...) {
emit Exception(102, trUtf8("BÅ‚ad uruchamiania podprocesu: %1").arg(cmd));
}
emit started();
emit strSent(cmd);
}
void Smoother::smootherStarted() {
emit progress(1,"Just started...");
}
void Smoother
::smootherFinished(int exitCode,
QProcess::ExitStatus exitStatus
) { if(tmpInputFile) {
delete tmpInputFile;
tmpInputFile = 0;
}
emit progress(100,"Finished");
//output file postprocessing possible here
if( originalOutputFile2 != settings.outputFile2 ) {
convertOutputDATtoXLS();
}
emit finished(exitCode, exitStatus);
}
void Smoother::readyToRead() {
da = this->proc.readAll();
emit strReceived(readStr);
interpretSmootherProcAnswer(readStr);
askSmootherProc();
}
void Smoother
::processError(QProcess::ProcessError error
) { Exception e(error);
emit this->error(e);
}
void Smoother
::interpretSmootherProcAnswer(const QString &answer
) { switch(curr_step) {
default:
break;
}
}
void Smoother::askSmootherProc() {
switch(curr_step) {
case INPUT_FILE:
emit progress(5, "Input file");
proc.
write(QString("%1\n").
arg(settings.
inputFile).
toStdString().
c_str());
emit strSent(settings.inputFile);
curr_step = OUTPUT_FILE_1;
break;
case OUTPUT_FILE_1:
emit progress(10, "First output file");
proc.
write(QString("%1\n").
arg(settings.
outputFile1).
toStdString().
c_str());
emit strSent(settings.outputFile1);
curr_step = OUTPUT_FILE_2;
break;
case OUTPUT_FILE_2:
emit progress(15, "Second output file");
proc.
write(QString("%1\n").
arg(settings.
outputFile2).
toStdString().
c_str());
emit strSent(settings.outputFile2);
curr_step = SAMPLES_AMOUNT;
break;
case SAMPLES_AMOUNT:
emit progress(20, "Samples amount");
proc.
write(QString("%1\n").
arg(rows
).
toStdString().
c_str());
emit strSent
(QString::number(rows
));
curr_step = COLUMNS_AMOUNT;
break;
case COLUMNS_AMOUNT:
emit progress(25, "Columns amount");
proc.
write(QString("%1\n").
arg(columns
).
toStdString().
c_str());
emit strSent
(QString::number(columns
));
curr_step = SMOOTHED_COLUMN;
break;
case SMOOTHED_COLUMN:
emit progress(30, "Smoothed column");
proc.
write(QString("%1\n").
arg(settings.
smoothedColumn).
toStdString().
c_str());
emit strSent
(QString::number(settings.
smoothedColumn));
curr_step = POINTS_NUMBER_IN_SINGLE_STEP;
break;
case POINTS_NUMBER_IN_SINGLE_STEP:
emit progress(35, "Points number in signle smoothing step");
proc.
write(QString("%1\n").
arg(settings.
pointsNumberInSingleStep).
toStdString().
c_str());
emit strSent
(QString::number(settings.
pointsNumberInSingleStep));
curr_step = APPROX_POLYNOM_ORDER;
break;
case APPROX_POLYNOM_ORDER:
emit progress(40, "Order of approx. polynom");
proc.
write(QString("%1\n").
arg(settings.
approxPolynomOrder).
toStdString().
c_str());
emit strSent
(QString::number(settings.
approxPolynomOrder));
curr_step = DERIVATIVE_ORDER;
break;
case DERIVATIVE_ORDER:
emit progress(45, "Derivative order");
proc.
write(QString("%1\n").
arg(settings.
derivativeOrder).
toStdString().
c_str());
emit strSent
(QString::number(settings.
derivativeOrder));
curr_step = SMOOTHINGS_NUMBER;
break;
case SMOOTHINGS_NUMBER:
emit progress(50, "Smoothings number");
proc.
write(QString("%1\n").
arg(settings.
smoothingsNumber).
toStdString().
c_str());
emit strSent
(QString::number(settings.
smoothingsNumber));
curr_step = END;
break;
case END:
emit progress(100,"Done");
break;
default:
break;
}
}
Smoother::Smoother(const QString& arg_fortranSmoother, const SmootherSettings &arg_data)
: settings(arg_data), fortranSmoother(arg_fortranSmoother), columns(0), rows(0), tmpInputFile(0), tmpOutputFile2(0), curr_step(INPUT_FILE) {
QObject::connect(&(this->proc),SIGNAL(started()),this,SLOT(smootherStarted()));
QObject::connect(&(this->proc),SIGNAL(finished(int, QProcess::ExitStatus)),this,SLOT(smootherFinished(int, QProcess::ExitStatus)));
QObject::connect(&(this->proc),SIGNAL(error(QProcess::ProcessError)),this,SLOT(processError(QProcess::ProcessError)));
QObject::connect(&(this->proc),SIGNAL(readyRead()),this,SLOT(readyToRead()));
}
Smoother::~Smoother() {
QObject::disconnect(&(this->proc));
this->proc.close();
if(tmpInputFile) {
tmpInputFile->close();
tmpInputFile->remove();
delete tmpInputFile;
}
if(tmpOutputFile2){
tmpOutputFile2->close();
tmpOutputFile2->remove();
delete tmpOutputFile2;
}
}
void Smoother::run() {
//input file preprocessing
preprocessInputFile();
if(columns == 0 || rows == 0) {
emit strSent("Process cannot be started. Invalid input file");
return;
}
this->originalOutputFile2 = settings.outputFile2;
QFileInfo fi(settings.outputFile2);
QString ext = fi.suffix();
if(ext == "xls") {
settings.outputFile2 = QDir::tempPath() + QDir::separator() + "pwsmoother_tmp.out.dat";
}
QString cmd = QString("\"%1\"").arg(( this->fortranSmoother )).toStdString().c_str();
try {
proc.start(cmd, QIODevice::ReadWrite | QIODevice::Text);
} catch(...) {
emit Exception(102, trUtf8("BÅ‚ad uruchamiania podprocesu: %1").arg(cmd));
}
emit started();
emit strSent(cmd);
}
void Smoother::smootherStarted() {
emit progress(1,"Just started...");
}
void Smoother::smootherFinished(int exitCode, QProcess::ExitStatus exitStatus) {
if(tmpInputFile) {
delete tmpInputFile;
tmpInputFile = 0;
}
emit progress(100,"Finished");
//output file postprocessing possible here
if( originalOutputFile2 != settings.outputFile2 ) {
convertOutputDATtoXLS();
}
emit finished(exitCode, exitStatus);
}
void Smoother::readyToRead() {
QString readStr;
QByteArray da;
da = this->proc.readAll();
readStr = QString(da);
emit strReceived(readStr);
interpretSmootherProcAnswer(readStr);
askSmootherProc();
}
void Smoother::processError(QProcess::ProcessError error) {
Exception e(error);
emit this->error(e);
}
void Smoother::interpretSmootherProcAnswer(const QString &answer) {
switch(curr_step) {
default:
break;
}
}
void Smoother::askSmootherProc() {
switch(curr_step) {
case INPUT_FILE:
emit progress(5, "Input file");
proc.write(QString("%1\n").arg(settings.inputFile).toStdString().c_str());
emit strSent(settings.inputFile);
curr_step = OUTPUT_FILE_1;
break;
case OUTPUT_FILE_1:
emit progress(10, "First output file");
proc.write(QString("%1\n").arg(settings.outputFile1).toStdString().c_str());
emit strSent(settings.outputFile1);
curr_step = OUTPUT_FILE_2;
break;
case OUTPUT_FILE_2:
emit progress(15, "Second output file");
proc.write(QString("%1\n").arg(settings.outputFile2).toStdString().c_str());
emit strSent(settings.outputFile2);
curr_step = SAMPLES_AMOUNT;
break;
case SAMPLES_AMOUNT:
emit progress(20, "Samples amount");
proc.write(QString("%1\n").arg(rows).toStdString().c_str());
emit strSent(QString::number(rows));
curr_step = COLUMNS_AMOUNT;
break;
case COLUMNS_AMOUNT:
emit progress(25, "Columns amount");
proc.write(QString("%1\n").arg(columns).toStdString().c_str());
emit strSent(QString::number(columns));
curr_step = SMOOTHED_COLUMN;
break;
case SMOOTHED_COLUMN:
emit progress(30, "Smoothed column");
proc.write(QString("%1\n").arg(settings.smoothedColumn).toStdString().c_str());
emit strSent(QString::number(settings.smoothedColumn));
curr_step = POINTS_NUMBER_IN_SINGLE_STEP;
break;
case POINTS_NUMBER_IN_SINGLE_STEP:
emit progress(35, "Points number in signle smoothing step");
proc.write(QString("%1\n").arg(settings.pointsNumberInSingleStep).toStdString().c_str());
emit strSent(QString::number(settings.pointsNumberInSingleStep));
curr_step = APPROX_POLYNOM_ORDER;
break;
case APPROX_POLYNOM_ORDER:
emit progress(40, "Order of approx. polynom");
proc.write(QString("%1\n").arg(settings.approxPolynomOrder).toStdString().c_str());
emit strSent(QString::number(settings.approxPolynomOrder));
curr_step = DERIVATIVE_ORDER;
break;
case DERIVATIVE_ORDER:
emit progress(45, "Derivative order");
proc.write(QString("%1\n").arg(settings.derivativeOrder).toStdString().c_str());
emit strSent(QString::number(settings.derivativeOrder));
curr_step = SMOOTHINGS_NUMBER;
break;
case SMOOTHINGS_NUMBER:
emit progress(50, "Smoothings number");
proc.write(QString("%1\n").arg(settings.smoothingsNumber).toStdString().c_str());
emit strSent(QString::number(settings.smoothingsNumber));
curr_step = END;
break;
case END:
emit progress(100,"Done");
break;
default:
break;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks