Shellp

shellmainwin.h

00001 /*
00002     
00003   This file is a part of Shellp, a 'shell helper' library.
00004   
00005   Copyright (C) 2011-2012 Jori Liesenborgs
00006   
00007   Contact: jori.liesenborgs@gmail.com
00008 
00009   This library is free software; you can redistribute it and/or
00010   modify it under the terms of the GNU Lesser General Public
00011   License as published by the Free Software Foundation; either
00012   version 2.1 of the License, or (at your option) any later version.
00013 
00014   This library is distributed in the hope that it will be useful,
00015   but WITHOUT ANY WARRANTY; without even the implied warranty of
00016   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017   Lesser General Public License for more details.
00018 
00019   You should have received a copy of the GNU Lesser General Public
00020   License along with this library; if not, write to the Free Software
00021   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  
00022   USA
00023 
00024 */
00025 
00026 #ifndef SHELLP_SHELLMAINWIN_H
00027 
00028 #define SHELLP_SHELLMAINWIN_H
00029 
00030 #include "shellconfig.h"
00031 #include <errut/errorbase.h>
00032 #include <jthread/jmutex.h>
00033 #include <QMainWindow>
00034 #include <QThread>
00035 #include <QPalette>
00036 #include <map>
00037 
00038 class QTextEdit;
00039 class QLineEdit;
00040 class QProgressBar;
00041 
00042 namespace shellp
00043 {
00044 
00045 class Shell2DPlotWindow;
00046 class Shell2DPlotRequest;
00047 class Shell3DPlotWindow;
00048 class Shell3DPlotRequest;
00049 
00050 class ShellMainWinThread : public QThread
00051 {
00052         Q_OBJECT
00053 public:
00054         ShellMainWinThread(const std::string &shellPrefix, QObject *pParent = 0);
00055         ~ShellMainWinThread();
00056 
00057         void run();
00058 private:
00059         std::string m_shellPrefix;
00060 };
00061 
00062 class ShellMainWin : public QMainWindow, public errut::ErrorBase
00063 {
00064         Q_OBJECT
00065 public:
00066         ShellMainWin(const std::string &title, const std::string &shellPrefix);
00067         ~ShellMainWin();
00068 
00069         void startThread();
00070         void requestWriteOutputLine(const std::string &line, bool newline);
00071         void requestNewPercentage(double pct);
00072         void waitingForInput();
00073 
00074         bool requestPlot2D(int id, const std::string &title,
00075                             const std::string &xLabel, const std::string &yLabel,
00076                             const std::vector<double> &xPoints, const std::vector<double> &yPoints,
00077                             bool forceShow);
00078         bool requestPlot3D(int id, const std::string &title, 
00079                           const std::string &xLabel, const std::string &yLabel,
00080                           const std::string &zLabel,
00081                           double xOff, double yOff, double xDist, double yDist,
00082                           double xMultiplier, double yMultiplier, double zMultiplier,
00083                           const std::vector<double> &data, int numX, int numY, bool forceShow);
00084         void requestStatusLine(const std::string &line);
00085 signals:
00086         void signalWriteOutputLine(const QString &line, bool newline);
00087         void signalWaitingForInput();
00088         void signalProgressBarValue(int val);
00089         void signalNew2DPlotRequest();
00090         void signalNew3DPlotRequest();
00091         void signalStatusLine(const QString &line);
00092 public slots:
00093         void lineEntered();
00094         void writeOutputLine(const QString &line, bool newline);
00095         void slotWaitingForInput();
00096         void slotForceQuit();
00097         void slotNew2DPlotRequest();
00098         void slotNew3DPlotRequest();
00099         void slotInterrupt();
00100         void slotStatusLine(const QString &line);
00101 private:
00102         void closeEvent(QCloseEvent *pEvent);
00103 
00104         QTextEdit *m_pTextEdit;
00105         QLineEdit *m_pLineEdit;
00106         QProgressBar *m_pPctBar;
00107         ShellMainWinThread *m_pThread;
00108 
00109         jthread::JMutex m_plotRequestMutex;
00110         std::list<Shell2DPlotRequest *> m_plot2DRequestQueue;
00111         std::list<Shell3DPlotRequest *> m_plot3DRequestQueue;
00112 
00113         std::map<int, Shell2DPlotWindow *> m_2DPlots;
00114         std::map<int, Shell3DPlotWindow *> m_3DPlots;
00115 };
00116 
00117 } // end namespace
00118 
00119 #endif // SHELLP_SHELLMAINWIN_H