TinkerCell Core 1.0
TinkerCell's Core library providing all basic functionalities
CThread.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 
00003 Copyright (c) 2008 Deepak Chandran
00004 Contact: Deepak Chandran (dchandran1@gmail.com)
00005 See COPYRIGHT.TXT
00006 
00007 This file defines the class that is used to create new threads in the 
00008 Tinkercell main window. The threads can be associated with a dialog that provides
00009 users with the option to terminate the thread.
00010 
00011 
00012 ****************************************************************************/
00013 
00014 #ifndef TINKERCELL_CTHREAD_H
00015 #define TINKERCELL_CTHREAD_H
00016 
00017 #include <QMainWindow>
00018 #include <QTextEdit>
00019 #include <QSyntaxHighlighter>
00020 #include <QHash>
00021 #include <QTextCharFormat>
00022 #include <QDialog>
00023 #include <QCompleter>
00024 #include <QListWidget>
00025 #include <QThread>
00026 #include <QToolBar>
00027 #include <QTabWidget>
00028 #include <QTableWidget>
00029 #include <QComboBox>
00030 #include <QPushButton>
00031 #include <QActionGroup>
00032 #include <QLibrary>
00033 #include <QProcess>
00034 #include <QProgressBar>
00035 #include <QItemDelegate>
00036 #include "Tool.h"
00037 #include "TC_structs.h"
00038 #include "DataTable.h"
00039 
00040 namespace Tinkercell
00041 {
00050         class TINKERCELLCOREEXPORT CThread : public QThread
00051         {
00052                 Q_OBJECT
00053 
00054         signals:
00057                 void setProgress(int);
00058                 
00060                 void setTitle(const QString&);
00061                 
00063                 void hideProgressBar();
00064                 
00066                 void showProgressBar();
00067                 
00068         public slots:
00069         
00071                 virtual void unload();
00075                 virtual void update();
00076 
00077         public:
00078 
00082                 virtual void showProgress(const QString &, int);
00083                 
00088                 static QLibrary * loadLibrary(const QString& name, QObject * parent = 0);
00089 
00091                 static QList<CThread*> cthreads;
00092 
00099                 CThread(MainWindow * main, QLibrary * lib = 0, bool autoUnload=false);
00100 
00107                 CThread(MainWindow * main, const QString & lib, bool autoUnload=false);
00108 
00110                 virtual ~CThread();
00111 
00116                 virtual void setFunction( void (*f)(void), QSemaphore * sem=0);
00121                 virtual void setFunction( void (*f)(double), QSemaphore * sem=0 );
00126                 virtual void setFunction( void (*f)(const char*), QSemaphore * sem=0 );
00131                 virtual void setFunction( void (*f)(tc_matrix), QSemaphore * sem=0 );
00136                 virtual void setVoidFunction(const char*, QSemaphore * sem=0);
00141                 virtual void setDoubleFunction(const char*, QSemaphore * sem=0);
00146                 virtual void setCharFunction(const char*, QSemaphore * sem=0);
00151                 virtual void setMatrixFunction(const char*, QSemaphore * sem=0);
00157                 virtual void setLibrary(QLibrary*);
00162                 virtual void setLibrary(const QString&);
00167                 virtual QLibrary * library();
00168 
00173                 virtual void setAutoUnload(bool);
00178                 virtual bool autoUnload();
00183                 virtual void setArg(double, QSemaphore * sem=0);
00188                 virtual void setArg(const QString&, QSemaphore * sem=0);
00193                 virtual void setArg(const DataTable<qreal>&, QSemaphore * sem=0);
00197                 MainWindow * mainWindow;
00198 
00199         protected:
00200                 
00201                 bool hasDialog;
00202                 
00206                 virtual void setupCFunctionPointers(QLibrary * lib = 0);
00210                 bool autoUnloadLibrary;
00214                 void (*f1)(void);
00218                 void (*f2)(double);
00222                 void (*f3)(const char*);
00226                 void (*f4)(tc_matrix);
00230                 void (*callbackPtr)(void);
00234                 void (*callWhenExitPtr)(void);
00238                 QLibrary * lib;
00242                 double argDouble;
00246                 QString argString;
00250                 DataTable<qreal> argMatrix;
00254                 virtual void call_tc_main();
00258                 virtual void run();
00259                 
00260         protected slots:
00264                 virtual void cleanupAfterTerminated();
00265                 
00266         private:
00267                 QString _prevProgressBarTitle;
00268                 int _prevProgress;
00269                 void createProgressBarDialog();
00276                 static void _setProgress(long ptr, const char * title, int progress);
00280                 static void _setCallback(long ptr,  void (*f)(void) );
00284                 static void _setCallWhenExiting(long ptr,  void (*f)(void) );
00285         };
00286 
00290         class TINKERCELLCOREEXPORT ProcessThread : public QThread
00291         {
00292                 Q_OBJECT
00293 
00294         public:
00300                 ProcessThread(const QString&, const QString& ,MainWindow* main);
00304                 virtual QString output() const;
00308                 virtual QString errors() const;
00311                 virtual ~ProcessThread();
00318                 static QWidget * dialog(MainWindow *, ProcessThread*, const QString& text = QString("Process"), QIcon icon = QIcon());
00319 
00320         protected slots:
00322                 virtual void stopProcess();
00323 
00324         protected:
00326                 QString exe;
00328                 QString args;
00330                 QString outputStream;
00332                 QString errStream;
00334                 MainWindow * mainWindow;
00336                 QProcess process;
00338                 virtual void run();
00339         };
00340 
00341 }
00342 
00343 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines