OpenFCST: The open-source Fuel Cell Simulation Toolbox
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
main_window.h
Go to the documentation of this file.
1 //---------------------------------------------------------------------------
2 //
3 // FCST: Fuel Cell Simulation Toolbox
4 //
5 // Copyright (C) 2014 by Energy Systems Design Laboratory, University of Alberta
6 //
7 // This software is distributed under the MIT License.
8 // For more information, see the README file in /doc/LICENSE
9 //
10 // - Class: main_window.h
11 // - Description: GUI for running FCST
12 // - Developers: Phil Wardlaw, 2014
13 // - $Id: fcst_utilities.h 2605 2014-08-15 03:36:44Z secanell $
14 //
15 //---------------------------------------------------------------------------
16 
17 
18 #ifndef MAINWINDOW_H
19 #define MAINWINDOW_H
20 
21 //QT
22 #include <QMainWindow>
23 #include <QTreeWidget>
24 #include <QDialog>
25 #include <QSettings>
26 #include <QList>
27 #include <QtGui>
28 #include <QTextEdit>
29 #include <QPushButton>
30 #include <QDir>
31 #include <QStringList>
32 #include <QLabel>
33 #include <QFile>
34 #include <QListWidget>
35 #include <QListWidgetItem>
36 #include <QFileSystemWatcher>
37 #include <QFont>
38 //STD
39 #include <iostream>
40 #include <stdexcept>
41 #include <fstream>
42 #include <string>
43 #include <ctime>
44 //Linux Sleep mechanism
45 #include <unistd.h>
46 //Deal.ii contribs developed by Martin Steigemann, Wolfgang Bangerth, 2010.
47 #include "parameter_delegate.h"
48 #include "xml_parameter_reader.h"
49 #include "xml_parameter_writer.h"
50 
51 
52 namespace FCSTGUI
53 {
144 class MainWindow : public QMainWindow
145 {
146  Q_OBJECT
147 
148 public:
155  MainWindow(const QString &filename = "");
156 
157 
158 
159 
160 
161 
162 protected:
167  void closeEvent(QCloseEvent *event);
168 
169  private slots:
170 
174  void openProject();
178  bool saveAll();
182  bool save_as();
186  void about();
190  void aboutOpenFCST();
195  void tree_was_modified();
199  void next_click();
204  void printOutput();
208  void finishedFCST(int status ,QProcess::ExitStatus qStatus);
215  void newProject();
219  void updateFolderView(const QString & path);
224  void fileBrowserClicked( QListWidgetItem * item);
229  void save_log();
230 
231  private:
235  void create_actions();
239  void create_menus();
246  bool maybe_save ();
250  bool save_file (const QString &filename, const QString &newfilename = "");
254  void load_file (const QString &filename, bool showMsg = true);
258  void create_widgets();
263  void create_tab(QString name_);
264 
269  bool callFCST(QStringList arguments, bool pipeMsg);
270  bool callQuit; //Bool associated with the killFCST command
271  void killFCST();
272 
276  bool setWorkingDir();
277 
281  void log(const std::string &input);
282 
283 
287  std::map<QString ,QTreeWidget *> tree_widget;
291  std::map<QString , bool> treeStatus;
296  QMenu * file_menu;
301  QMenu * help_menu;
302 
306  QAction *save_log_act;
310  QAction *new_act;
314  QAction * open_act;
318  QAction * save_act;
322  QAction * save_as_act;
326  QAction * exit_act;
330  QAction * about_act;
334  QAction * aboutFCST_act;
338  QAction * about_qt_act;
342  QStringList current_files;
346  QSettings * gui_settings;
350  QPushButton * nextButton;
354  QWidget *body , *buttonPanel;
358  QTextEdit *textOut;
362  QLabel * logoLabel;
366  QHBoxLayout *hBox, *buttonBox;
367  QVBoxLayout *vBoxLeft, *vBoxRight;
368  QTabWidget *tabWidget;
372  enum States {
373  Start = 0,
374  Main, //preparing main
375  Ready, //ready to run
376  Running //running
377  };
385  QListWidget *outputList;
386  QFileSystemWatcher *fileWatcher;
387  QFont font;
392  QProcess *process;
396  QString workingDir;
397  QString FCSTBinAddr;
398 
402  std::ofstream flog;
406  QString paramArg;
408 };
409 }
410 
411 #endif
QStringList current_files
This value stores the current filename we work on.
Definition: main_window.h:342
void create_tab(QString name_)
Function for creating tab given a file in the local working directory Throws an std::runtime_error if...
void create_actions()
This function creates all actions.
QListWidget * outputList
Elements for displaying files output by FCST.
Definition: main_window.h:385
bool save_file(const QString &filename, const QString &newfilename="")
Save parameters to filename in XML format.
QString mainFileName
Definition: main_window.h:407
void load_file(const QString &filename, bool showMsg=true)
Load parameters from filename in XML format.
QVBoxLayout * vBoxRight
Definition: main_window.h:367
QSettings * gui_settings
An object for storing user settings.
Definition: main_window.h:346
QMenu * file_menu
This menu provides all file actions as open, save, save as and exit
Definition: main_window.h:296
QString workingDir
Strings for important locations.
Definition: main_window.h:396
void create_menus()
This function creates all menus.
Definition: main_window.h:376
bool callQuit
Definition: main_window.h:270
void about()
Show some information on the parameterGUI.
bool callFCST(QStringList arguments, bool pipeMsg)
Functions for calling and killing FCST, if pipeMsg is true then FCST output will be displayed on scre...
void log(const std::string &input)
Logging function, appends to gui_log.txt.
QLabel * fileLabel
Definition: main_window.h:388
bool maybe_save()
This function checks, if parameters were changed and show a dialog, if changes should be saved...
QHBoxLayout * buttonBox
Definition: main_window.h:366
Definition: main_window.h:375
QLabel * logoLabel
Elements for displaying FCST logo in bottom left corner.
Definition: main_window.h:362
void closeEvent(QCloseEvent *event)
Reimplemented from QMainWindow.
Definition: main_window.h:373
QTabWidget * tabWidget
Definition: main_window.h:368
QString dataFileName
Definition: main_window.h:407
The MainWindow class of the the FCST parameterGUI.
Definition: main_window.h:144
void printOutput()
A slot that should be called to take output from the current process&#39;s std and err streams...
QPushButton * nextButton
Button for driving user events forward.
Definition: main_window.h:350
Definition: main_window.h:374
States
Enumeration describing states of project creation/simulation execution.
Definition: main_window.h:372
bool save_as()
Open a file dialog to save the parameter file.
void finishedFCST(int status, QProcess::ExitStatus qStatus)
A slot that is called when FCST ends, updates GUI state.
QFileSystemWatcher * fileWatcher
Definition: main_window.h:386
QString optFileName
Definition: main_window.h:407
QHBoxLayout * hBox
Dynamic sizers for managing the size and position of visual elements.
Definition: main_window.h:366
QVBoxLayout * vBoxLeft
Definition: main_window.h:367
QAction * new_act
QAction Start a new project.
Definition: main_window.h:310
void tree_was_modified()
A slot that should be always called, if parameter values were changed.
void save_log()
A slot to manage user interaction when the menu &quot;Save Log File&quot; action is triggered.
void updateFolderView(const QString &path)
A slot that is called when fileWatcher reports new files in the workingDir.
bool setWorkingDir()
Function for getting working directory from user.
QAction * save_as_act
QAction save as a file.
Definition: main_window.h:322
std::map< QString, bool > treeStatus
The status of the individual trees, true if they do not need to be saved.
Definition: main_window.h:291
QWidget * buttonPanel
Definition: main_window.h:354
QAction * save_act
QAction save a file.
Definition: main_window.h:318
QAction * open_act
QAction open a file.
Definition: main_window.h:314
std::map< QString,QTreeWidget * > tree_widget
This is the trees which we display all parameters.
Definition: main_window.h:287
QString FCSTBinAddr
Definition: main_window.h:397
QWidget * body
QWidget elements, essentially panels, to house other elements of interest.
Definition: main_window.h:354
QFont font
Definition: main_window.h:387
void create_widgets()
Function for setting up GUI, used by constructor.
MainWindow(const QString &filename="")
Constructor.
QAction * about_qt_act
QAction about Qt.
Definition: main_window.h:338
States currentState
The GUI&#39;s current state.
Definition: main_window.h:381
QString paramArg
OpenFCST binary arguments and file names produced by OpenFCST.
Definition: main_window.h:406
void next_click()
A slot for the next button, progresses the GUI&#39;s state.
QMenu * help_menu
This menu provides some informations about the parameterGUI and about Qt
Definition: main_window.h:301
void openProject()
Open a project.
QLabel * FCSToutputLabel
Definition: main_window.h:388
void fileBrowserClicked(QListWidgetItem *item)
A slot to manage user interaction when a file name is double clicked in the file browser.
void aboutOpenFCST()
Show some information on the OpenFCST.
QProcess * process
Object for calling FCST.
Definition: main_window.h:392
std::ofstream flog
ofstream object for logging
Definition: main_window.h:402
QAction * exit_act
QAction exit the GUI.
Definition: main_window.h:326
QAction * save_log_act
QAction Start a new project.
Definition: main_window.h:306
QTextEdit * textOut
QTextEdit for displaying FCST output to user.
Definition: main_window.h:358
void newProject()
A slot attached to a menu action, to start a new project.
QAction * aboutFCST_act
QAction about the parameterGUI.
Definition: main_window.h:334
bool saveAll()
Save the parameter file.
QAction * about_act
QAction about the parameterGUI.
Definition: main_window.h:330