From 2c5fe55d443a33b8510cd11a0724a1af58d3ff05 Mon Sep 17 00:00:00 2001 From: "N. Brouard" Date: Tue, 27 Feb 2018 23:00:08 +0000 Subject: [PATCH] Summary: imach gui --- imach-gui/dialog.cpp | 221 ++++++++++++++++++++++++++++++++++++++++ imach-gui/dialog.h | 49 +++++++++ imach-gui/dialog.ui | 187 ++++++++++++++++++++++++++++++++++ imach-gui/imach-gui.pro | 22 ++++ imach-gui/main.cpp | 13 +++ 5 files changed, 492 insertions(+) create mode 100644 imach-gui/dialog.cpp create mode 100644 imach-gui/dialog.h create mode 100644 imach-gui/dialog.ui create mode 100644 imach-gui/imach-gui.pro create mode 100644 imach-gui/main.cpp diff --git a/imach-gui/dialog.cpp b/imach-gui/dialog.cpp new file mode 100644 index 0000000..d328c59 --- /dev/null +++ b/imach-gui/dialog.cpp @@ -0,0 +1,221 @@ +// dialog.cpp + +#include "dialog.h" +#include "ui_dialog.h" +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog) +{ + ui->setupUi(this); + + // Play button for output - initially disabled + //ui->playOutputButton->setEnabled(false); + ui->openGnuplotButton->setEnabled(false); + + // Create three processes + // 1.imachexec, 2.input play 3.output play + mImachexecProcess = new QProcess(this); + mGnuplotProcess = new QProcess(this); + //mOutputPlayProcess = new QProcess(this); + + connect(mImachexecProcess, SIGNAL(started()), this, SLOT(processStarted())); + + connect(mImachexecProcess,SIGNAL(readyReadStandardOutput()),this,SLOT(readyReadStandardOutput())); + connect(mImachexecProcess, SIGNAL(finished(int)), this, SLOT(imachexecFinished())); +} + +Dialog::~Dialog() +{ + delete ui; +} + +void Dialog::processStarted() +{ + qDebug() << "processStarted()"; +} + +// imach start +void Dialog::on_startButton_clicked() +{ + QString program = "imach"; + + QStringList arguments; + + QString input = ui->fromLineEdit->text(); + if(input.isEmpty()) { + qDebug() << "No input"; + QMessageBox::information(this, + tr("imach"),tr("Input file not specified")); + return; + } + QString output = input; +// QString output = ui->toLineEdit->text(); +// if(output.isEmpty()) { +// qDebug() << "No output"; +// QMessageBox::information(this, +// tr("imach"),tr("Output file not specified")); +// return; +// } + +// QString fileName = ui->toLineEdit->text(); +// qDebug() << "output file check " << fileName; +// qDebug() << "QFile::exists(fileName) = " << QFile::exists(fileName); +// if (QFile::exists(fileName)) { +// if (QMessageBox::question(this, tr("imach"), +// tr("There already exists a file called %1 in " +// "the current directory. Overwrite?").arg(fileName), +// QMessageBox::Yes|QMessageBox::No, QMessageBox::No) +// == QMessageBox::No) +// return; +// QFile::remove(fileName); +// while(QFile::exists(fileName)) { +// qDebug() << "output file still there"; +// } +// } + +// arguments << input << output; + arguments << input << " q"; + + qDebug() << arguments; + + mImachexecProcess->setProcessChannelMode(QProcess::MergedChannels); + mImachexecProcess->start(program, arguments); +} + +void Dialog::readyReadStandardOutput() +{ + mOutputString.append(mImachexecProcess->readAllStandardOutput()); + ui->textEdit->setText(mOutputString); + + // put the slider at the bottom + ui->textEdit->verticalScrollBar() + ->setSliderPosition( + ui->textEdit->verticalScrollBar()->maximum()); +} + +void Dialog::imachexecFinished() +{ + // Set the imachexec status by checking output gnuplot file's existence + //QString fileName = ui->toLineEdit->text(); + QString fichnom = ui->fromLineEdit->text(); + QFileInfo fileInfor(fichnom); + QString NomComplet = fileInfor.completeBaseName(); + //QString NomSuffix = fileInfor.suffix(); + //QString NomCheminsansEx = fileInfor.canonicalPath()+NomComplet; + QString NomCompGp = fileInfor.canonicalPath()+"/"+NomComplet+".gp"; + //QFileInfo fileInfoGp(NomCompGp); + + //if (QFile::exists(fileName)) { + if (QFile::exists(NomCompGp)) { + ui->imachStatusLabel + ->setText("IMaCh Status: Successful!"); + //ui->playOutputButton->setEnabled(true); + ui->openGnuplotButton->setEnabled(true); + } + else { + ui->imachStatusLabel + ->setText("IMaCh Status: Failed!"); + } +} + +// Browse... button clicked - this is for input file +void Dialog::on_fileOpenButton_clicked() +{ + QString fileName = + QFileDialog::getOpenFileName( + this, + tr("Open File"), + "/tmp/test", + tr("imach parameter files (*.imach *.txt *.log *.gp)")); + QFileInfo fileInfor(fileName); + if (!fileName.isEmpty()) { + ui->fromLineEdit->setText(fileName); + } + +} + +void Dialog::on_openLogButton_clicked() +{ + QString fichnom = ui->fromLineEdit->text(); + QFileInfo fileInfor(fichnom); + QString NomComplet = fileInfor.completeBaseName(); + QString NomCompLog = fileInfor.canonicalPath()+"/"+NomComplet+".log"; + //QFileInfo fileInfolog(NomCompLog); + QDesktopServices::openUrl(QUrl("file://"+NomCompLog,QUrl::TolerantMode)); +} + +void Dialog::on_launchbrowButton_clicked() +{ + QString fichnom = ui->fromLineEdit->text(); + QFileInfo fileInfor(fichnom); + QString NomComplet = fileInfor.completeBaseName(); + QString NomCompLaunch = fileInfor.canonicalPath()+"/"+NomComplet+".htm"; + //QFileInfo fileInfolog(NomCompLaunch; + QDesktopServices::openUrl(QUrl("file://"+NomCompLaunch,QUrl::TolerantMode)); +} + +void Dialog::on_openGnuplotButton_clicked() +{ + // QString program = "ffplay"; + // QStringList arguments; + QString fichnom = ui->fromLineEdit->text(); + QFileInfo fileInfor(fichnom); + QString NomComplet = fileInfor.completeBaseName(); + //QString NomSuffix = fileInfor.suffix(); + //QString NomCheminsansEx = fileInfor.canonicalPath()+NomComplet; + QString NomCompGp = fileInfor.canonicalPath()+"/"+NomComplet+".gp"; + QFileInfo fileInfoGp(NomCompGp); + //QString input = NomCheminsansEx; + // arguments << input; + // mInputPlayProcess->start(program, arguments); + // QFile file(NomCompLog); + // if(!file.open(QIODevice::ReadOnly)) + // QMessageBox::information(0,"info",file.errorString()); + + QDesktopServices::openUrl(QUrl("file://"+NomCompGp,QUrl::TolerantMode)); +//o QTextStream in(&file); +//o ui->playInputButton->setText(in.readAll()); +} + + +void Dialog::on_runGnuplotButton_clicked() +{ + QString program = "gnuplot"; + QStringList arguments; + QString fichnom = ui->fromLineEdit->text(); + QFileInfo fileInfor(fichnom); + QString NomComplet = fileInfor.completeBaseName(); + QString NomCompGp = fileInfor.canonicalPath()+"/"+NomComplet+".gp"; + //QFileInfo fileInfoGp(NomCompGp); + //QString input = NomCheminsansEx; + arguments << NomCompGp; + mGnuplotProcess->start(program, arguments); + // QFile file(NomCompLog); + // if(!file.open(QIODevice::ReadOnly)) + // QMessageBox::information(0,"info",file.errorString()); + + //QDesktopServices::openUrl(QUrl("file://"+NomCompGp,QUrl::TolerantMode)); +//o QTextStream in(&file); +//o ui->playInputButton->setText(in.readAll()); +} + +//void Dialog::on_playOutputButton_clicked() +//{ +// QString program = "ffplay"; +// QStringList arguments; +// QString output = ui->toLineEdit->text(); +// arguments << output; +// mInputPlayProcess->start(program, arguments); +//} + diff --git a/imach-gui/dialog.h b/imach-gui/dialog.h new file mode 100644 index 0000000..cc0f9a6 --- /dev/null +++ b/imach-gui/dialog.h @@ -0,0 +1,49 @@ +// dialog.h + +#ifndef DIALOG_H +#define DIALOG_H + +#include +#include +#include +#include + +namespace Ui { +class Dialog; +} + +class Dialog : public QDialog +{ + Q_OBJECT + +public: + explicit Dialog(QWidget *parent = 0); + ~Dialog(); + +public slots: + +public: + +private slots: + void on_startButton_clicked(); + void readyReadStandardOutput(); + void processStarted(); + void imachexecFinished(); + void on_fileOpenButton_clicked(); + void on_openLogButton_clicked(); + void on_openGnuplotButton_clicked(); + void on_launchbrowButton_clicked(); + void on_runGnuplotButton_clicked(); + + + //void on_playOutputButton_clicked(); + +private: + Ui::Dialog *ui; + QProcess *mImachexecProcess; + QProcess *mGnuplotProcess; + QProcess *mOutputPlayProcess; + QString mOutputString; +}; + +#endif // DIALOG_H diff --git a/imach-gui/dialog.ui b/imach-gui/dialog.ui new file mode 100644 index 0000000..a7de37d --- /dev/null +++ b/imach-gui/dialog.ui @@ -0,0 +1,187 @@ + + + Dialog + + + + 0 + 0 + 400 + 406 + + + + Dialog + + + + + + + + + + IMaCh parameter file + + + fromLineEdit + + + + + + + + + + + + + + + + Browse... + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + Run imach + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + + + Run Gnuplot file + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + Browse log file + + + + + + + Edit gnuplot file + + + + + + + + + Close + + + + + + + Visualize results + + + + + + + Qt::Horizontal + + + + 298 + 20 + + + + + + + + + + + pushButton + clicked() + Dialog + close() + + + 267 + 125 + + + 267 + 174 + + + + + diff --git a/imach-gui/imach-gui.pro b/imach-gui/imach-gui.pro new file mode 100644 index 0000000..1d88588 --- /dev/null +++ b/imach-gui/imach-gui.pro @@ -0,0 +1,22 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2013-10-03T22:30:49 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = imach-gui +TEMPLATE = app + + +SOURCES += main.cpp\ + dialog.cpp \ + +HEADERS += dialog.h \ + dialog.h + +FORMS += dialog.ui \ + dialog.ui diff --git a/imach-gui/main.cpp b/imach-gui/main.cpp new file mode 100644 index 0000000..4c3f5e4 --- /dev/null +++ b/imach-gui/main.cpp @@ -0,0 +1,13 @@ +#include "dialog.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + Dialog w; + w.setWindowTitle("Imach-Gui Dialog"); + w.show(); + + return a.exec(); +} + -- 2.43.0