COPASI API  4.16.103
copasiui3window.h
Go to the documentation of this file.
1 // Copyright (C) 2010 - 2015 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 // Copyright (C) 2008 - 2009 by Pedro Mendes, Virginia Tech Intellectual
7 // Properties, Inc., EML Research, gGmbH, University of Heidelberg,
8 // and The University of Manchester.
9 // All rights reserved.
10 
11 // Copyright (C) 2002 - 2007 by Pedro Mendes, Virginia Tech Intellectual
12 // Properties, Inc. and EML Research, gGmbH.
13 // All rights reserved.
14 
15 #include <string>
16 
17 #include <QtGui/QMainWindow>
18 #include <QtCore/QModelIndex>
19 #include <QtCore/QMap>
20 #include <QtCore/QPointer>
21 
22 #ifdef COPASI_SBW_INTEGRATION
23 # include <QtGui/QApplication>
24 # include <QtCore/QEvent>
25 # include <QtCore/QMutex>
26 # include <QtCore/QWaitCondition>
27 
28 # define WIN32_LEAN_AND_MEAN
29 # include <SBW/SBW.h>
30 # undef DELETE
31 # undef ERROR
32 # undef TRUE
33 # undef FALSE
34 using namespace SystemsBiologyWorkbench;
35 #else
36 class SBWListener;
37 #endif // COPASI_SBW_INTEGRATION
38 
40 
41 //class QToolButton;
42 class ListViews;
43 class DataModelGUI;
44 class SliderDialog;
45 class QAction;
47 class QComboBox;
48 class CMIRIAMResources;
50 class QEvent;
51 class QActionGroup;
52 class QThread;
53 
54 class CopasiUI3Window : public QMainWindow
55 #ifdef COPASI_SBW_INTEGRATION
56  // A SBW listener can catch messages from SBW ... used here to allow COPASI to be shut down
57  , public SBWListener
58 #endif // COPASI_SBW_INTEGRATION
59 
60 {
61  Q_OBJECT
62 
63 public:
64  static CopasiUI3Window * create();
65 
66  static CopasiUI3Window * getMainWindow();
67 
68  static bool isMainThread();
69 
70  ~CopasiUI3Window();
71 
72  DataModelGUI* getDataModel();
73 
74  ListViews* getMainWidget();
75 
76  void checkPendingMessages();
77  void suspendAutoSave(const bool & suspend);
78 
79  /**
80  * The slider dialog has to be disabled before
81  * a task is run and reenabled afterwards.
82  * Actually the methods stores the state
83  * when the value true is passed and restores that
84  * state when the value false is passed.
85  */
86  void disableSliders(bool disable);
87 
88  /**
89  * This is used to import an SBML file from a std::string in the GUI
90  * it does all the necessary GUI stuff like asking to save the old
91  * document, displaying messages, etc.
92  */
93  void importSBMLFromString(const std::string & sbmlDocumentText);
94 
95  void exportSBMLToString(std::string & SBML);
96 
97  //TODO SEDML
98 #ifdef COPASI_SEDML
99  /**
100  * This is used to import an SEDML file from a std::string in the GUI
101  * it does all the necessary GUI stuff like asking to save the old
102  * document, displaying messages, etc.
103  */
104  void importSEDMLFromString(const std::string & sedmlDocumentText);
105 
106  void exportSEDMLToString(std::string & SEDML);
107 #endif
108 
109  void addWindow(QMainWindow * pWindow);
110  void removeWindow(QMainWindow * pWindow);
111 
112  void setMessageShown(const bool & shown);
113 
114  const bool & messageShown() const;
115 
116  /**
117  * Returns the list of current windows
118  */
119  const QList< QPointer<QMainWindow> >& getWindows() const;
120 
121 signals:
122  void signalLoadFile(QString newFile);
123  void signalQuit();
124 
125 protected:
126  virtual void closeEvent(QCloseEvent* e);
127 
128  /*
129  * This is used for doing drag-and-drop action (16.04.10)
130  */
131  void dragEnterEvent(QDragEnterEvent *event);
132  void dropEvent(QDropEvent *event);
133 
134 public slots:
135  void slotShowSliders(bool flag);
136 
137  /**
138  * This should only be called by the destructor of the object browser dialog
139  * otherwise a memory leak occurs
140  */
141  void slotObjectBrowserDialogWasClosed();
142 
143  void autoSave();
144 
145  void openInitialDocument(const QString & file);
146 
147  void slotFileOpen(QString file = QString::null);
148 
149 protected slots:
150  void slotFileOpenFinished(bool success);
151  void slotFileExamplesCopasiFiles(QString file = QString::null);
152  void slotFileExamplesSBMLFiles(QString file = QString::null);
153  void slotFileSave();
154  void slotFileSaveAs(QString str = QString::null);
155  void slotFileSaveFinished(bool success);
156  void slotFunctionDBSave(QString str = QString::null);
157  void slotFunctionDBLoad(QString str = QString::null);
158  void newDoc();
159  void slotFilePrint();
160  void slotImportSBML(QString file = QString::null);
161  void slotImportSBMLFinished(bool success);
162  void slotImportSBMLFromStringFinished(bool success);
163  void slotExportSBML();
164  void slotExportSBMLFinished(bool success);
165  void slotExportSBMLToStringFinished(bool success);
166  void slotExportMathModel();
167  void slotExportMathModelFinished(bool success);
168  void slotTutorialWizard();
169  void about();
170  void license();
171  void aboutQt();
172  void slotQuit();
173  void slotQuitFinished(bool success);
174  void slotPreferences();
175  void slotConvertToIrreversible();
176 #ifdef WITH_PE_EVENT_CREATION
177  void slotCreateEventsForTimeseries();
178 #endif
179  void listViewsFolderChanged(const QModelIndex & index);
180  void slotOpenRecentFile(QAction * pAction);
181  void slotOpenRecentSBMLFile(QAction * pAction);
182  void slotCheckModel();
183  void slotApplyInitialState();
184  void slotUpdateInitialState();
185  void slotFrameworkChanged(int index);
186  void slotCapture();
187  void slotUpdateMIRIAM();
188  void slotUpdateMIRIAMFinished(bool);
189  void slotExpandModel();
190  void slotFontSelection();
191 
192  void slotCloseAllWindows();
193  void slotActivateWindowTriggered(QAction* action);
194 
195 #ifdef WITH_MERGEMODEL
196  void slotAddFileOpen(QString file = QString::null);
197  void slotAddFileOpenFinished(bool success);
198  void slotMergeModels();
199 #endif
200 
201  // SBW: handle the custom events
202  void customEvent(QEvent *);
203 
204  /**
205  * This should only be called via signal by the corresponding QAction mpaObjectBrowser.
206  * Otherwise the QAction will not be up to date.
207  */
208  void slotShowObjectBrowserDialog(bool flag);
209 
210  //TODO SEDML
211 #ifdef COPASI_SEDML
212  void slotFileExamplesSEDMLFiles(QString file = QString::null);
213  void slotImportSEDML(QString file = QString::null);
214  void slotImportSEDMLFinished(bool success);
215  void slotImportSEDMLFromStringFinished(bool success);
216  void slotExportSEDML();
217  void slotExportSEDMLFinished(bool success);
218  void slotExportSEDMLToStringFinished(bool success);
219  void slotOpenRecentSEDMLFile(QAction * pAction);
220 #endif
221 
222 private:
223  CopasiUI3Window();
224 
225  void createActions();
226  void createToolBar();
227  void createMenuBar();
228 
229  void CleanUp();
230 
231  void updateTitle();
232 
233  void setApplicationFont();
234 
235  DataModelGUI* mpDataModelGUI; // to keep track of the data model..
237  QComboBox * mpBoxSelectFramework;
238 
239  QString FixedTitle;
240 
241  QAction* mpaNew;
242  QAction* mpaOpen;
245  QAction* mpaSave;
246  QAction* mpaSaveAs;
249  QAction* mpaImportSBML;
250  QAction* mpaExportSBML;
251  QAction* mpaExportODE;
252  QAction* mpaQuit;
254  QAction* mpaSliders;
255  QAction* mpaCheckModel;
258  QAction* mpaCapture;
259  QAction* mpaUpdateMIRIAM;
260  QAction* mpaExpandModel;
262 
264 
265 #ifdef WITH_MERGEMODEL
266  QAction* mpaAddModel;
267  QAction* mpaMergeModels;
268 #endif
269  SliderDialog* mpSliders;
271 
275 
276  //menus
277  QMenu * mpMenuExamples;
279  QMenu * mpWindowsMenu;
280  QMap< QAction *, int > mRecentFilesActionMap;
281  QActionGroup * mpRecentFilesActionGroup;
282  void refreshRecentFileMenu();
283  void refreshWindowsMenu();
284 
286  QMap< QAction *, int > mRecentSBMLFilesActionMap;
288  QActionGroup * mpWindowsActionGroup;
289  void refreshRecentSBMLFileMenu();
290 
291  QMenu * mpTools;
292 
294 
295  QThread * mpMainThread;
296  QString mNewFile;
301 
302  QList< QPointer<QMainWindow> > mWindows;
303 
305 
306  //TODO SEDML
307 #ifdef COPASI_SEDML
308  QMenu * mpMenuSEDMLSupport;
309  QAction* mpaImportSEDML;
310  QAction* mpaExportSEDML;
311  QAction* mpaOpenSEDMLFiles;
312  QMenu * mpMenuRecentSEDMLFiles;
313  QMap< QAction *, int > mRecentSEDMLFilesActionMap;
314  QActionGroup * mpRecentSEDMLFilesActionGroup;
315  void refreshRecentSEDMLFileMenu();
316 #endif
317 
318 #ifdef COPASI_SBW_INTEGRATION
319 public:
320  /**
321  * This event is triggered by SBW asking COPASI to import an SBML document provided as a string
322  */
323  class QSBWSBMLEvent : public QEvent
324  {
325  public:
326  /**
327  * Constructor
328  * @param const std::string & SBMLModel
329  */
330  QSBWSBMLEvent(const std::string & SBMLModel);
331 
332  /**
333  * Retrieve the SBML model
334  * @return const std::string & SBMLModel
335  */
336  const std::string & getSBMLModel() const;
337 
338  private:
339  /**
340  * A string holding the SBML model
341  */
342  std::string mSBML;
343  };
344 
345  /**
346  * This event is triggered by SBW asking COPASI shut down.
347  */
348  class QSBWShutdownEvent: public QEvent
349  {
350  public:
351  QSBWShutdownEvent();
352  };
353 
354  // We expose 2 methods to SBW, one to load an SBML file
355  SystemsBiologyWorkbench::DataBlockWriter sbwAnalysis(SystemsBiologyWorkbench::Module from,
356  SystemsBiologyWorkbench::DataBlockReader reader);
357 
358  // and another to return the SBML file COAPSI is currently working with
359  SystemsBiologyWorkbench::DataBlockWriter sbwGetSBML(SystemsBiologyWorkbench::Module from,
360  SystemsBiologyWorkbench::DataBlockReader reader);
361 
362  // This method must not be renamed as SBW calls it by name
363  void registerMethods(SystemsBiologyWorkbench::MethodTable<CopasiUI3Window> & table);
364 
365  // as part of the SBWListener we tell SBW here, that we want to react on the shutdown event
366  virtual void onShutdown();
367 
368 private:
369  /**
370  * Connect to SBW
371  */
372  void sbwConnect();
373 
374  /**
375  * Disconnect to SBW
376  */
377  void sbwDisconnect();
378 
379  /**
380  * Register COPASI as a module ins SBW
381  */
382  void sbwRegister();
383 
384  /**
385  * Unregister a module in SBW
386  * @param const std::string & moduleName
387  */
388  void sbwUnregister(const std::string & moduleName) const;
389 
390  /**
391  * Refresh the SBW menu.
392  */
393  void sbwRefreshMenu();
394 
395  /**
396  * Retrieve the list of all services from the SBW broker
397  * @param const std::string & category
398  * @param const bool & recursive
399  * @return std::vector< SystemsBiologyWorkbench::DataBlockReader > services
400  */
401  std::vector< SystemsBiologyWorkbench::DataBlockReader > sbwFindServices(const std::string & category,
402  const bool & recursive);
403 
404 protected slots:
405  void sbwSlotMenuTriggered(QAction * pAction);
406  void sbwSlotMenuTriggeredFinished(bool success);
407  void sbwSlotGetSBMLFinished(bool success);
408 
409 private:
410  /**
411  * The SBW module which handles the interaction with the SBW broker
412  */
413  SystemsBiologyWorkbench::ModuleImpl * mpSBWModule;
414 
415  /**
416  * A list of SBW analyzer modules
417  */
418  QStringList mSBWAnalyzerModules;
419 
420  /**
421  * A list of the corresponding SBW services
422  */
423  QStringList mSBWAnalyzerServices;
424 
425  /**
426  * Map between actions and the index of SBW modules and services
427  */
428  QMap< QAction *, int > mSBWActionMap;
429 
430  /**
431  * A group containing all actions of the SBW menu
432  */
433  QActionGroup * mpSBWActionGroup;
434 
435  /**
436  * The SBW menu
437  */
438  QMenu * mpSBWMenu;
439 
440  /**
441  * The SBW Action
442  */
443  QAction * mpSBWAction;
444 
445  /**
446  * This variable indicates whether COPASI is to ignore SBW shutdown events
447  */
448  bool mSBWIgnoreShutdownEvent;
449 
450  QMutex mSBWMutex;
451 
452  QWaitCondition mSBWWaitSlot;
453 
454  bool mSBWCallFinished;
455 
456  bool mSBWSuccess;
457 
458  std::string mSBWDocumentString;
459 
460  QStringList::size_type mSBWActionId;
461 
462 #endif // COPASI_SBW_INTEGRATION
463 };
ListViews * mpListView
ObjectBrowserDialog * mpObjectBrowser
QActionGroup * mpWindowsActionGroup
SliderDialog(QWidget *parent, const char *name=0, bool modal=false, Qt::WFlags fl=0)
QAction * mpaUpdateInitialState
QAction * mpaFontSelectionDialog
QMenu * mpMenuRecentFiles
QActionGroup * mpRecentSBMLFilesActionGroup
SliderDialog * mpSliders
QAction * mpaFunctionDBLoad
QAction * mpaOpenSBMLFiles
QAction * mpaCapture
QComboBox * mpBoxSelectFramework
QTimer * mpAutoSaveTimer
QMenu * mpMenuRecentSBMLFiles
QAction * mpaObjectBrowser
QAction * mpaCloseAllWindows
QAction * mpaImportSBML
QAction * mpaFunctionDBSave
QActionGroup * mpRecentFilesActionGroup
QAction * mpaSliders
static CopasiUI3Window * pMainWindow
QAction * mpaExportODE
QAction * mpaCheckModel
QMap< QAction *, int > mRecentFilesActionMap
long int flag
Definition: f2c.h:52
QAction * mpaExpandModel
QAction * mpaOpenCopasiFiles
QAction * mpaApplyInitialState
QAction * mpaExportSBML
QAction * mpaUpdateMIRIAM
CMIRIAMResources * mpMIRIAMResources
DataModelGUI * mpDataModelGUI
QMap< QAction *, int > mRecentSBMLFilesActionMap
QThread * mpMainThread
QList< QPointer< QMainWindow > > mWindows