COPASI API  4.16.103
copasiui3window.cpp
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 <sbml/SBMLDocument.h>
16 
17 #ifdef COPASI_SEDML
18 #include <sedml/SedDocument.h>
19 #endif
20 
21 #include <QtCore/QEvent>
22 #include <QtGui/QMenuBar>
23 #include <QtCore/QTimer>
24 #include <QtGui/QComboBox>
25 #include <QtGui/QToolBar>
26 #include <QtGui/QTextEdit>
27 #include <QtCore/QThread>
28 #include <QtGui/QFontDialog>
29 
30 #include <vector>
31 #include <sstream>
32 
33 #ifdef COPASI_SBW_INTEGRATION
34 #include <stdlib.h>
35 #endif // COPASI_SBW_INTEGRATION
36 
37 #include "AboutDialog.h"
38 #include "CopasiFileDialog.h"
39 #include "copasiui3window.h"
40 #include "listviews.h"
41 #include "DataModelGUI.h"
42 #include "ObjectBrowserDialog.h"
43 #include "qtUtilities.h"
44 #include "SliderDialog.h"
45 #include "CQMessageBox.h"
46 #include "CQPreferenceDialog.h"
47 #include "CQSBMLFileDialog.h"
48 #include "copasi/UI/qtUtilities.h"
49 #include "copasi/UI/CQTabWidget.h"
50 #include "copasiWidget.h"
51 #include "TaskWidget.h"
53 
57 #include "utilities/CDirEntry.h"
58 #include "model/CModel.h"
60 #include "commandline/COptions.h"
63 #include "wizard/wizard.h"
64 #include "report/CKeyFactory.h"
66 #include "MIRIAM/CConstants.h"
68 #include "model/CModelExpansion.h"
70 
71 #ifdef WITH_MERGEMODEL
72 #include "model/CModelExpansion.h"
73 #endif
74 #include <UI/CWindowInterface.h>
75 
76 #ifdef COPASI_SEDML
77 #include "CQSEDMLFileDialog.h"
78 #endif
79 
80 #define AutoSaveInterval 10*60*1000
81 
82 #ifdef DEBUG_UI
83 #include <QtCore/QtDebug>
84 #endif
85 
86 // static
87 CopasiUI3Window * CopasiUI3Window::pMainWindow = NULL;
88 
89 QMainWindow* getWindowByTitle(const QList< QPointer< QMainWindow > > & list, const QString& title)
90 {
91  for (int index = 0; index < list.count(); ++index)
92  {
93  QMainWindow *window = list[index];
94 
95  if (window == NULL) continue;
96 
97  if (window ->windowTitle() == title)
98  return window;
99  }
100 
101  return NULL;
102 }
103 
104 // static
106 {
107  return pMainWindow;
108 }
109 
110 // static
112 {
113  return pMainWindow == NULL || pMainWindow->mpMainThread == QThread::currentThread();
114 }
115 
116 // static
118 {
119  CopasiUI3Window * pWindow = NULL;
120 
121  pWindow = new CopasiUI3Window;
122 
123 #ifdef COPASI_SBW_INTEGRATION
124 
125  if (pWindow != NULL &&
126  COptions::compareValue("SBWRegister", true))
127  {
128  pWindow->sbwConnect();
129  pWindow->sbwRegister();
130  }
131 
132 #endif // COPASI_SBW_INTEGRATION
133 
134  pMainWindow = pWindow;
135 
136  return pWindow;
137 }
138 
139 /**
140  * Constructs a CopasiUI window which is a child of 'parent', with the
141  * name 'name' and widget flags set to 'f'.
142  * @param parent The widget which this window is a child of.
143  * @param name The object name is a text that can be used to identify
144  * this QObject. It's particularly useful in conjunction with the Qt Designer.
145  * You can find an object by name (and type) using child(), and more than one
146  * using queryList().
147  * @param flags Flags for this widget. Refer Qt::WidgetFlags of Qt documentation
148  * for more information about these flags.
149  */
151  QMainWindow(),
152  mpDataModelGUI(NULL),
153  mpListView(NULL),
154  mpBoxSelectFramework(NULL),
155  mpSliders(NULL),
156  mpObjectBrowser(NULL),
157  mSaveAsRequired(true),
158  mpAutoSaveTimer(NULL),
159  mSuspendAutoSave(false),
160  mpMenuExamples(NULL),
161  mpMenuRecentFiles(NULL),
162  mRecentFilesActionMap(),
163  mpRecentFilesActionGroup(NULL),
164  mpMenuRecentSBMLFiles(NULL),
165  mRecentSBMLFilesActionMap(),
166  mpRecentSBMLFilesActionGroup(NULL),
167  mpWindowsActionGroup(NULL),
168  mpMIRIAMResources(NULL),
169  mpMainThread(QThread::currentThread()),
170  mNewFile(),
171  mCommitRequired(true),
172  mQuitApplication(false),
173  mSliderDialogEnabled(false),
174  mMessageShown(false),
175  mWindows()
176 
177 #ifdef COPASI_SBW_INTEGRATION
178  , mpSBWModule(NULL)
179  , mSBWAnalyzerModules()
180  , mSBWAnalyzerServices()
181  , mSBWActionMap()
182  , mpSBWActionGroup(NULL)
183  , mpSBWMenu(NULL)
184  , mpSBWAction(NULL)
185  , mSBWIgnoreShutdownEvent(true)
186 #endif // COPASI_SBW_INTEGRATION
187 
188 #ifdef COPASI_SEDML
189  , mpMenuSEDMLSupport(NULL)
190  , mpMenuRecentSEDMLFiles(NULL)
191  , mRecentSEDMLFilesActionMap()
192  , mpRecentSEDMLFilesActionGroup(NULL)
193 #endif //COPASI_SEDML support
194 
195 {
196  // set destructive close
197  this->setAttribute(Qt::WA_DeleteOnClose);
198 
199  // Add this window to the list of windows
200  mWindows.append(this);
201 
202 #ifndef Darwin
204 #endif // not Darwin
205 
206  // Set the window caption/title
207  FixedTitle = "COPASI ";
208  FixedTitle += FROM_UTF8(CVersion::VERSION.getVersion());
209  updateTitle();
210 
211  createActions();
212  createToolBar(); // creates a tool bar
213  createMenuBar(); // creates a menu bar
214 
215  setIconSize(QSize(18, 20));
216 
217  mpaSave->setEnabled(false);
218  mpaSaveAs->setEnabled(false);
219  mpaExportSBML->setEnabled(false);
220  mpaExportODE->setEnabled(false);
221 
222  //TODO SEDML
223 #ifdef COPASI_SEDML
224  mpaExportSEDML->setEnabled(false);
225 #endif
226 
227  if (!mpDataModelGUI)
228  {
229  // create the data model
230  mpDataModelGUI = new DataModelGUI(this);
231  }
232 
233  mpListView = new ListViews(this);
234 
235  connect(mpListView, SIGNAL(signalFolderChanged(const QModelIndex &)), this, SLOT(listViewsFolderChanged(const QModelIndex &)));
236 
238  mpListView->show();
239  this->setCentralWidget(mpListView);
240 
241  //create sliders window
242  this->mpSliders = new SliderDialog(NULL);
243  this->mpSliders->setParentWindow(this);
244  size_t id = mpListView->getCurrentItemId();
245  this->mpSliders->setCurrentFolderId(id);
246  this->mpSliders->resize(320, 350);
247  this->mSliderDialogEnabled = this->mpSliders->isEnabled();
248 
249  resize(800, 600);
250  show();
251 
253 
254  // Assure that the changed flag is still false;
255  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
256  (*CCopasiRootContainer::getDatamodelList())[0]->changed(false);
257  this->mpSliders->setChanged(false);
258 
259  mpAutoSaveTimer = new QTimer(this);
260  mpAutoSaveTimer->start(AutoSaveInterval); // every 10 minutes
261 
262  // TODO CRITICAL We need to disable autosave to avoid race conditions.
263  // connect(mpAutoSaveTimer, SIGNAL(timeout()), this, SLOT(autoSave()));
264  // mpDataModelGUI->notify(ListViews::FUNCTION, ListViews::ADD, "");
265 
267 
268  // drop acceptance
269  setAcceptDrops(true);
270 }
271 
273 {
274 #ifdef COPASI_SBW_INTEGRATION
275  sbwDisconnect();
276 #endif // COPASI_SBW_INTEGRATION
277 
278  QList< QPointer<QMainWindow> >::iterator it = mWindows.begin();
279  QList< QPointer<QMainWindow> >::iterator end = mWindows.end();
280 
281  for (; it != end; ++it)
282  {
283  QPointer<QMainWindow> current = *it;
284 
285  if (current == NULL) continue;
286 
287  if (current != this)
288  current->close();
289  }
290 
295 }
296 
298 {
299  //TODO: use the QKeySequence standard shortcuts
300  //TODO: add tool tips, status tips etc.
301 
302  mpaNew = new QAction(CQIconResource::icon(CQIconResource::fileNew), "&New", this);
303  connect(mpaNew, SIGNAL(activated()), this, SLOT(newDoc()));
304  mpaNew->setShortcut(Qt::CTRL + Qt::Key_N);
305 
306  mpaOpen = new QAction(CQIconResource::icon(CQIconResource::fileOpen), "&Open...", this);
307  connect(mpaOpen, SIGNAL(activated()), this, SLOT(slotFileOpen()));
308  mpaOpen->setShortcut(Qt::CTRL + Qt::Key_O);
309 
310  mpaOpenCopasiFiles = new QAction(CQIconResource::icon(CQIconResource::fileOpen), "COP&ASI Files...", this);
311  connect(mpaOpenCopasiFiles, SIGNAL(activated()), this, SLOT(slotFileExamplesCopasiFiles()));
312  // mpaOpenCopasiFiles->setShortcut(Qt::CTRL + Qt::Key_1);
313 
314  mpaOpenSBMLFiles = new QAction(CQIconResource::icon(CQIconResource::fileOpen), "S&BML Files...", this);
315  connect(mpaOpenSBMLFiles, SIGNAL(activated()), this, SLOT(slotFileExamplesSBMLFiles()));
316  // mpaOpenSBMLFiles->setShortcut(Qt::CTRL + Qt::Key_2);
317 
318  mpaSave = new QAction(CQIconResource::icon(CQIconResource::fileSave), "&Save", this);
319  connect(mpaSave, SIGNAL(activated()), this, SLOT(slotFileSave()));
320  mpaSave->setShortcut(Qt::CTRL + Qt::Key_S);
321 
322  mpaSaveAs = new QAction(CQIconResource::icon(CQIconResource::fileSaveas), "Save &As...", this);
323  connect(mpaSaveAs, SIGNAL(activated()), this, SLOT(slotFileSaveAs()));
324  mpaSaveAs->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_S);
325 
326  mpaImportSBML = new QAction(CQIconResource::icon(CQIconResource::fileOpen), "&Import SBML...", this);
327  connect(mpaImportSBML, SIGNAL(activated()), this, SLOT(slotImportSBML()));
328  mpaImportSBML->setShortcut(Qt::CTRL + Qt::Key_I);
329 
330  mpaExportSBML = new QAction(CQIconResource::icon(CQIconResource::fileExport), "&Export SBML...", this);
331  connect(mpaExportSBML, SIGNAL(activated()), this, SLOT(slotExportSBML()));
332  mpaExportSBML->setShortcut(Qt::CTRL + Qt::Key_E);
333 
334  mpaExportODE = new QAction(CQIconResource::icon(CQIconResource::fileExport), "Export ODEs...", this);
335  connect(mpaExportODE, SIGNAL(activated()), this, SLOT(slotExportMathModel()));
336  mpaExportODE->setShortcut(Qt::CTRL + Qt::Key_M);
337 
338  mpaQuit = new QAction("&Quit", this);
339  connect(mpaQuit, SIGNAL(activated()), this, SLOT(slotQuit()));
340  mpaQuit->setShortcut(Qt::CTRL + Qt::Key_Q);
341 
342  mpaSliders = new QAction(CQIconResource::icon(CQIconResource::slider), "Show sliders", this);
343  mpaSliders->setCheckable(true);
344  connect(mpaSliders, SIGNAL(toggled(bool)), this, SLOT(slotShowSliders(bool)));
345 
346  mpaObjectBrowser = new QAction("Object &Browser", this);
347  mpaObjectBrowser->setCheckable(true);
348  connect(mpaObjectBrowser, SIGNAL(toggled(bool)), this, SLOT(slotShowObjectBrowserDialog(bool)));
349 
350  mpaCheckModel = new QAction(CQIconResource::icon(CQIconResource::checkMark), "Check model", this);
351  connect(mpaCheckModel, SIGNAL(activated()), this, SLOT(slotCheckModel()));
352 
353  mpaUpdateMIRIAM = new QAction(CQIconResource::icon(CQIconResource::miriam), "Update MIRIAM", this);
354  connect(mpaUpdateMIRIAM, SIGNAL(activated()), this, SLOT(slotUpdateMIRIAM()));
355 
356  mpaApplyInitialState = new QAction(CQIconResource::icon(CQIconResource::isToS), "Apply initial state", this);
357  connect(mpaApplyInitialState, SIGNAL(activated()), this, SLOT(slotApplyInitialState()));
358 
359  mpaUpdateInitialState = new QAction(CQIconResource::icon(CQIconResource::sToIs), "Update initial state from current state", this);
360  connect(mpaUpdateInitialState, SIGNAL(activated()), this, SLOT(slotUpdateInitialState()));
361 
362  mpaCapture = new QAction(CQIconResource::icon(CQIconResource::captureImage), "Capture the main window", this);
363  connect(mpaCapture, SIGNAL(activated()), this, SLOT(slotCapture()));
364 
365  mpaExpandModel = new QAction("Create array of compartments (debug version)", this);
366  connect(mpaExpandModel, SIGNAL(activated()), this, SLOT(slotExpandModel()));
367 
368  mpaFontSelectionDialog = new QAction("Select the Application Font", this);
369  connect(mpaFontSelectionDialog, SIGNAL(activated()), this, SLOT(slotFontSelection()));
370 
371  //TODO SEDML
372 #ifdef COPASI_SEDML
373  mpaOpenSEDMLFiles = new QAction(CQIconResource::icon(CQIconResource::fileOpen), "S&ED-ML Files...", this);
374  connect(mpaOpenSEDMLFiles, SIGNAL(activated()), this, SLOT(slotFileExamplesSEDMLFiles()));
375  // mpaOpenSEDMLFiles->setShortcut(Qt::CTRL + Qt::Key_3);
376 
377  mpaImportSEDML = new QAction(CQIconResource::icon(CQIconResource::fileOpen), "&Import SED-ML...", this);
378  connect(mpaImportSEDML, SIGNAL(activated()), this, SLOT(slotImportSEDML()));
379  // mpaImportSEDML->setShortcut(Qt::CTRL + Qt::Key_X);
380 
381  mpaExportSEDML = new QAction(CQIconResource::icon(CQIconResource::fileExport), "&Export SED-ML...", this);
382  connect(mpaExportSEDML, SIGNAL(activated()), this, SLOT(slotExportSEDML()));
383  // mpaExportSEDML->setShortcut(Qt::CTRL + Qt::Key_Z);
384 #endif
385  // QAction* mpaObjectBrowser;
386 
387 #ifdef WITH_MERGEMODEL
388  mpaAddModel = new QAction(CQIconResource::icon(CQIconResource::fileAdd), "&Add ...", this);
389  mpaAddModel->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_A);
390  connect(mpaAddModel, SIGNAL(activated()), this, SLOT(slotAddFileOpen()));
391 
392  mpaMergeModels = new QAction("&Merge ...", this);
393  mpaMergeModels->setShortcut(Qt::SHIFT + Qt::CTRL + Qt::Key_M);
394  connect(mpaMergeModels, SIGNAL(activated()), this, SLOT(slotMergeModels()));
395 #endif
396 
397  mpaCloseAllWindows = new QAction("Close all windows below:", this);
398  connect(mpaCloseAllWindows, SIGNAL(activated()), this, SLOT(slotCloseAllWindows()));
399 
400  mpaFunctionDBLoad = new QAction(CQIconResource::icon(CQIconResource::fileOpen), "Load Function DB...", this);
401  connect(mpaFunctionDBLoad, SIGNAL(activated()), this, SLOT(slotFunctionDBLoad()));
402  mpaFunctionDBSave = new QAction(CQIconResource::icon(CQIconResource::fileSaveas), "Save Function DB...", this);
403  connect(mpaFunctionDBSave, SIGNAL(activated()), this, SLOT(slotFunctionDBSave()));
404 }
405 
407 {
408  if (mCommitRequired)
409  {
411  }
412 
413  if (dbFile.isEmpty())
414  {
415  C_INT32 Answer = QMessageBox::No;
416 
417  while (Answer == QMessageBox::No)
418  {
419  dbFile =
420  CopasiFileDialog::getSaveFileName(this, "Save File Dialog",
421  "untitled.cpk", "COPASI Function DB (*.cpk)",
422  "Choose a file");
423 
424  if (dbFile.isEmpty()) return;
425 
426  // Checks whether the file exists
427  Answer = checkSelection(dbFile);
428 
429  if (Answer == QMessageBox::Cancel) return;
430  }
431  }
432 
434 }
435 
437 {
438  if (mCommitRequired)
439  {
441  }
442 
443  if (dbFile.isEmpty())
444  {
445  dbFile =
446  CopasiFileDialog::getOpenFileName(this, "Open File Dialog",
447  QString::null, "COPASI Function DB (*.cpk)",
448  "Choose a file");
449  }
450 
451  if (!dbFile.isEmpty())
452  {
454  }
455 }
456 
458 {
459  QToolBar * tb = addToolBar("MainToolBar");
460 
461  tb->addAction(mpaNew);
462  tb->addAction(mpaOpen);
463  tb->addAction(mpaSave);
464  tb->addAction(mpaCapture);
465  tb->addAction(mpaSliders);
466  tb->addAction(mpaCheckModel);
467  tb->addAction(mpaApplyInitialState);
468  tb->addAction(mpaUpdateInitialState);
469  tb->addAction(mpaUpdateMIRIAM);
470 
471 #ifdef WITH_MERGEMODEL
472  tb->addAction(mpaAddModel);
473  //tb->addAction(mpaMergeModels);
474 #endif
475 
476  tb->addSeparator();
477 
478  mpBoxSelectFramework = new QComboBox(tb);
479  QStringList items;
480  items << "Concentrations" << "Particle Numbers";
481  mpBoxSelectFramework->addItems(items);
482  tb->addWidget(mpBoxSelectFramework);
483 
484  connect(mpBoxSelectFramework, SIGNAL(activated(int)), this, SLOT(slotFrameworkChanged(int)));
485 
486  setUnifiedTitleAndToolBarOnMac(true);
487 }
488 
490 {
491 
492  QMenu * pFileMenu = menuBar()->addMenu("&File");
493 
494  pFileMenu->addAction(mpaNew);
495  pFileMenu->addAction(mpaOpen);
496 
497  mpMenuExamples = pFileMenu->addMenu("Examples");
499  mpMenuExamples->addAction(mpaOpenSBMLFiles);
500 
501 #ifdef COPASI_SEDML
502  mpMenuExamples->addAction(mpaOpenSEDMLFiles);
503 #endif
504 
505  pFileMenu->addAction(mpaSave);
506  pFileMenu->addAction(mpaSaveAs);
507 
508  pFileMenu->addSeparator();
509 
510  pFileMenu->addAction(mpaImportSBML);
511  pFileMenu->addAction(mpaExportSBML);
512  pFileMenu->addAction(mpaExportODE);
513 
514  //TODO SEDML
515 #ifdef COPASI_SEDML
516  pFileMenu->addSeparator();
517  mpMenuSEDMLSupport = pFileMenu->addMenu("SED-ML Support");
518  mpMenuSEDMLSupport->addAction(mpaImportSEDML);
519  mpMenuSEDMLSupport->addAction(mpaExportSEDML);
520 
521  mpMenuRecentSEDMLFiles = mpMenuSEDMLSupport->addMenu("Recent SED-ML Files");
522  refreshRecentSEDMLFileMenu();
523 #endif
524 
525 #ifdef WITH_MERGEMODEL
526  pFileMenu->addAction(mpaAddModel);
527  //pFileMenu->addAction(mpaMergeModels);
528 #endif
529 
530  pFileMenu->addSeparator();
531  pFileMenu->addAction(mpaFunctionDBLoad);
532  pFileMenu->addAction(mpaFunctionDBSave);
533 
534  pFileMenu->addSeparator();
535 
536  mpMenuRecentFiles = pFileMenu->addMenu("Recent Files");
538 
539  mpMenuRecentSBMLFiles = pFileMenu->addMenu("Recent SBML Files");
541 
542  pFileMenu->addSeparator();
543 
544  pFileMenu->addAction(mpaQuit);
545 
546  //****** tools menu **************
547 
548  mpTools = menuBar()->addMenu("&Tools");
549 
550  mpTools->addAction(mpaApplyInitialState);
551  mpTools->addAction(mpaUpdateInitialState);
552  mpTools->addAction(mpaSliders);
553  mpTools->addAction(mpaCapture);
554 #ifdef WITH_MERGEMODEL
555  mpTools->addAction(mpaMergeModels);
556 #endif
557 
558  mpTools->addSeparator();
559  mpTools->addAction(mpaExpandModel);
560 #ifdef COPASI_DEBUG
561  mpTools->addAction(mpaObjectBrowser);
562  mpTools->addSeparator();
563 #endif // COPASI_DEBUG
564 
565  mpTools->addAction(mpaCheckModel);
566  mpTools->addAction("&Convert to irreversible", this, SLOT(slotConvertToIrreversible()));
567 
568 #ifdef WITH_PE_EVENT_CREATION
569  mpTools->addAction("&Create Events For Timeseries Experiment", this, SLOT(slotCreateEventsForTimeseries()));
570 #endif
571 
572 #ifdef COPASI_SBW_INTEGRATION
573  // create and populate SBW menu
574  mpSBWMenu = new QMenu("&SBW", this);
575  mpSBWAction = mpTools->addMenu(mpSBWMenu);
576 #endif // COPASI_SBW_INTEGRATION
577 
578  mpTools->addSeparator();
579  mpTools->addAction(mpaUpdateMIRIAM);
580  mpTools->addAction("&Preferences", this, SLOT(slotPreferences()));
581  mpTools->addAction(mpaFontSelectionDialog);
582 
583  //****** windows menu **************
584  mpWindowsMenu = menuBar()->addMenu("&Window");
586 
587  //******* help menu *****************
588 
589  menuBar()->addSeparator();
590 
591  QMenu * help = menuBar()->addMenu("&Help");
592 
593  help->addAction("Simple &Wizard", this, SLOT(slotTutorialWizard()));
594  help->addSeparator();
595  help->addAction("&About", this, SLOT(about()), Qt::Key_F1);
596  help->addAction("&License", this, SLOT(license()));
597  help->addAction("About &Qt", this, SLOT(aboutQt()));
598  help->addSeparator();
599  // help->addAction("What's &This", this, SLOT(whatsThis()), Qt::SHIFT + Qt::Key_F1);
600 }
601 
602 //***** Slots ***************************
603 
605 {
607 
608  C_INT32 Answer = QMessageBox::No;
609  QString tmp;
610 
611  if (str.isEmpty()) str = "untitled.cps";
612 
613 #ifdef DEBUG_UI
614  qDebug() << "Filename on slotFileSaveAs = " << str;
615 #endif
616 
617  while (Answer == QMessageBox::No)
618  {
619  tmp =
620  CopasiFileDialog::getSaveFileName(this, "Save File Dialog",
621  str, "COPASI Files (*.cps)",
622  "Choose a filename to save under");
623 
624  if (tmp.isEmpty()) return;
625 
626 #ifdef DEBUG_UI
627  qDebug() << "tmp = " << tmp;
628 #endif
629 
630  // Checks whether the file exists
631  Answer = checkSelection(tmp);
632 
633  if (Answer == QMessageBox::Cancel) return;
634  }
635 
636  if (mpDataModelGUI && !tmp.isNull())
637  {
638  setCursor(Qt::WaitCursor);
639 
640  connect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(slotFileSaveFinished(bool)));
641  mpDataModelGUI->saveModel(TO_UTF8(tmp), true);
642  }
643 }
644 
646 {
647  disconnect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(slotFileSaveFinished(bool)));
648 
649  if (success)
650  {
651  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
652  (*CCopasiRootContainer::getDatamodelList())[0]->changed(false);
653  this->mpSliders->setChanged(false);
654  updateTitle();
655 
657 
658  if (msg.getNumber() != MCCopasiMessage + 1)
659  {
660  QString Message("Problem while saving file!\n\n");
661  Message += FROM_UTF8(msg.getText());
662 
664 
665  while (msg.getNumber() != MCCopasiMessage + 1)
666  {
667  Message += "\n";
668  Message += FROM_UTF8(msg.getText());
670  }
671 
672  CQMessageBox::warning(this, QString("File Warning"), Message,
673  QMessageBox::Ok, QMessageBox::Ok);
674  }
675  }
676  else
677  {
678  if (CCopasiMessage::peekLastMessage().getNumber() != MCCopasiMessage + 1)
679  {
680  CQMessageBox::critical(this, "Save File Error",
682  QMessageBox::Ok | QMessageBox::Default,
683  QMessageBox::NoButton);
685  }
686  }
687 
688  unsetCursor();
690 
691  mSaveAsRequired = false;
692 
693  if (mNewFile != "")
694  {
695  emit signalLoadFile(mNewFile);
696  mNewFile = "";
697  }
698 }
699 
701 {
702  disconnect(this, SIGNAL(signalLoadFile(QString)), this, SLOT(newDoc()));
703 
704  if (mCommitRequired)
705  {
707  }
708 
709  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
710 
711  if (mpDataModelGUI && ((*CCopasiRootContainer::getDatamodelList())[0]->isChanged() || this->mpSliders->isChanged()))
712  {
713  switch (CQMessageBox::question(this, "COPASI",
714  "The document contains unsaved changes\n"
715  "Do you want to save the changes before exiting?",
716  QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
717  QMessageBox::Save))
718  {
719  case QMessageBox::Save:
720  connect(this, SIGNAL(signalLoadFile(QString)), this, SLOT(newDoc()));
721 
722  mNewFile = "newDoc()";
723  mCommitRequired = false;
724  slotFileSave();
725  return;
726 
727  break;
728 
729  case QMessageBox::Discard:
730  break;
731 
732  case QMessageBox::Cancel:
733  default:
734  return;
735  break;
736  }
737  }
738 
740  (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getKey());
741 
743 
744  // delete the old sliders
745  if (this->mpSliders) this->mpSliders->reset();
746 
748  this->mpSliders->setChanged(false);
750  //if (!mbObject_browser_open)
751  //mpFileMenu->setItemEnabled(nobject_browser, true);
752 
753  mpaSave->setEnabled(true);
754  mpaSaveAs->setEnabled(true);
755  mpaExportSBML->setEnabled(true);
756  mpaExportODE->setEnabled(true);
757 
758 #ifdef COPASI_SEDML
759  mpaExportSEDML->setEnabled(true);
760 #endif
761 
762  updateTitle();
764  CQTabWidget *widget = dynamic_cast<CQTabWidget *>(mpListView->getCurrentWidget());
765 
766  if (widget != NULL)
767  widget->selectTab(0);
768 
769  mSaveAsRequired = true;
770  mCommitRequired = true;
771 }
772 
773 void CopasiUI3Window::openInitialDocument(const QString & file)
774 {
775  if (file != "")
776  {
777  slotFileOpen(file);
778  }
779  else if (!COptions::compareValue("ImportSBML", std::string("")))
780  {
781  // Import the SBML File
782  std::string ImportSBML;
783  COptions::getValue("ImportSBML", ImportSBML);
784  slotImportSBML(FROM_UTF8(ImportSBML));
785  }
786 
787 #ifdef COPASI_SEDML
788  else if (!COptions::compareValue("ImportSEDML", std::string("")))
789  {
790  // Import the SEDML File
791  std::string ImportSEDML;
792  COptions::getValue("ImportSEDML", ImportSEDML);
793  slotImportSEDML(FROM_UTF8(ImportSEDML));
794  }
795 
796 #endif
797  else if (COptions::getNonOptions().size())
798  {
799  // Look at commandline
801  }
802  else
803  {
804  newDoc();
805  }
806 
807 #ifdef COPASI_SBW_INTEGRATION
808  sbwConnect();
809 #endif // COPASI_SBW_INTEGRATION
810 }
811 
813 {
814  disconnect(this, SIGNAL(signalLoadFile(QString)), this, SLOT(slotFileOpen(QString)));
815 
816  if (mCommitRequired)
817  {
819  }
820 
821  QString newFile = "";
822 
823  if (file == "")
824  newFile =
825  CopasiFileDialog::getOpenFileName(this, "Open File Dialog", QString::null,
826  "COPASI Files (*.gps *.cps);;All Files (*)",
827  "Choose a file");
828  else
829  newFile = file;
830 
831  // gives the file information to the datamodel to handle it
832 
833  if (!newFile.isNull())
834  {
835  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
836 
837  if (mpDataModelGUI && ((*CCopasiRootContainer::getDatamodelList())[0]->isChanged() || this->mpSliders->isChanged()))
838  {
839  switch (CQMessageBox::question(this, "COPASI",
840  "The document contains unsaved changes\n"
841  "Do you want to save the changes before exiting?",
842  QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
843  QMessageBox::Save))
844  {
845  case QMessageBox::Save:
846  connect(this, SIGNAL(signalLoadFile(QString)), this, SLOT(slotFileOpen(QString)));
847 
848  mNewFile = newFile;
849  mCommitRequired = false;
850  slotFileSave();
851  return;
852 
853  break;
854 
855  case QMessageBox::Discard:
856  break;
857 
858  case QMessageBox::Cancel:
859  default:
860  return;
861  break;
862  }
863  }
864 
866  (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getKey());
867 
869 
870  if (this->mpSliders) this->mpSliders->reset();
871 
872  this->setCursor(Qt::WaitCursor);
873 
875 
876  mNewFile = newFile;
877  connect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(slotFileOpenFinished(bool)));
878  mpDataModelGUI->loadModel(TO_UTF8(newFile));
879  }
880 }
881 
883 {
884  disconnect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(slotFileOpenFinished(bool)));
885  unsetCursor();
886  mCommitRequired = true;
887 
888  if (!success)
889  {
890  QString Message = "Error while loading file " + mNewFile + QString("!\n\n");
892 
893  CQMessageBox::critical(this, QString("File Error"), Message,
894  QMessageBox::Ok, QMessageBox::Ok);
896  }
897 
899 
900  if (msg.getNumber() == 6303 &&
901  (msg.getText().find("'sbml'") != std::string::npos || msg.getText().find(":sbml'") != std::string::npos))
902  {
903 
904  // someone attempted to open an SBML file but failed, instead of displaying the message
905  // XML (3): Unknown element 'sbml' encountered at line '3'.
906  // we just open the SBML file!
907  if (CQMessageBox::question(this, QString("Import SBML?"), QString("You tried to open an SBML file. COPASI is not able to open SBML files but is able to import it. Would you like to import it?"),
908  QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes)
909  {
910  emit slotImportSBML(mNewFile);
911  return;
912  }
913 
914  newDoc();
915  return;
916  }
917 
918 #ifdef COPASI_SEDML
919 
920  if (msg.getNumber() == 6303 &&
921  (msg.getText().find("'sedML'") != std::string::npos || msg.getText().find(":sedML'") != std::string::npos))
922  {
923 
924  // someone attempted to open an SEDML file but failed, instead of displaying the message
925  // XML (3): Unknown element 'sedml' encountered at line '3'.
926  // we just open the SEDML file!
927  if (CQMessageBox::question(this, QString("Import SED-ML?"), QString("You tried to open an SED-ML file. COPASI is not able to open SED-ML files but is able to import it. Would you like to import it?"),
928  QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes)
929  {
930  emit slotImportSEDML(mNewFile);
931  return;
932  }
933 
934  newDoc();
935  return;
936  }
937 
938 #endif
939 
940  if (msg.getNumber() != MCCopasiMessage + 1)
941  {
942  QString Message = "Problem while loading file " + mNewFile + QString("!\n\n");
943  Message += FROM_UTF8(msg.getText());
944 
946 
947  while (msg.getNumber() != MCCopasiMessage + 1)
948  {
949  Message += "\n";
950  Message += FROM_UTF8(msg.getText());
952  }
953 
954  CQMessageBox::warning(this, QString("File Warning"), Message,
955  QMessageBox::Ok, QMessageBox::Ok);
956  }
957 
958  if (strcasecmp(CDirEntry::suffix(TO_UTF8(mNewFile)).c_str(), ".cps") == 0 &&
960  mSaveAsRequired = false;
961  else
962  mSaveAsRequired = true;
963 
964  if (!(*CCopasiRootContainer::getDatamodelList())[0]->getModel())
965  {
966  newDoc();
967  mSaveAsRequired = true;
968  }
969 
971  (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getKey());
972 
973  mpaSave->setEnabled(true);
974  mpaSaveAs->setEnabled(true);
975  mpaExportSBML->setEnabled(true);
976  mpaExportODE->setEnabled(true);
977 
978 #ifdef COPASI_SEDML
979  mpaExportSEDML->setEnabled(true);
980 #endif
981 
982  updateTitle();
984  CQTabWidget *widget = dynamic_cast<CQTabWidget *>(mpListView->getCurrentWidget());
985 
986  if (widget != NULL)
987  widget->selectTab(0);
988 
990 
991  mNewFile = "";
992 }
993 
995 {
996  CopasiFileDialog::openExampleDir(); //Sets CopasiFileDialog::LastDir
997  slotFileOpen(file);
998 }
999 
1001 {
1002  CopasiFileDialog::openExampleDir(); //Sets CopasiFileDialog::LastDir
1003  slotImportSBML(file);
1004 }
1005 
1006 #ifdef WITH_MERGEMODEL
1007 void CopasiUI3Window::slotAddFileOpen(QString file)
1008 {
1009  disconnect(this, SIGNAL(signalLoadFile(QString)), this, SLOT(slotFileOpen(QString)));
1010 
1011  if (mCommitRequired)
1012  {
1014  }
1015 
1016  QString newFile = "";
1017 
1018  if (file == "")
1019  newFile =
1020  CopasiFileDialog::getOpenFileName(this, "Open File Dialog", QString::null,
1021  "COPASI Files (*.gps *.cps);;All Files (*)",
1022  "Choose a file");
1023  else
1024  newFile = file;
1025 
1026  if (!newFile.isNull())
1027  {
1028  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
1029 
1030  //mpListView->switchToOtherWidget(0, "");
1031 
1032  this->setCursor(Qt::WaitCursor);
1033 
1035 
1036  mNewFile = newFile;
1037  connect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(slotAddFileOpenFinished(bool)));
1038  mpDataModelGUI->addModel(TO_UTF8(newFile));
1039  }
1040 }
1041 
1042 void CopasiUI3Window::slotAddFileOpenFinished(bool success)
1043 {
1044  disconnect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(slotAddFileOpenFinished(bool)));
1045  unsetCursor();
1046  mCommitRequired = true;
1047 
1048  if (!success)
1049  {
1050  QString Message = "Error while loading file " + mNewFile + QString("!\n\n");
1051  Message += FROM_UTF8(CCopasiMessage::getAllMessageText(true));
1052 
1053  CQMessageBox::critical(this, QString("File Error"), Message,
1054  QMessageBox::Ok, QMessageBox::Ok);
1055  }
1056 
1058 
1059  // TODO potentially include handling of SBML files here.
1060 
1061  if (msg.getNumber() != MCCopasiMessage + 1)
1062  {
1063  QString Message = "Problem while merging file " + mNewFile + QString("!\n\n");
1064  Message += FROM_UTF8(msg.getText());
1065 
1067 
1068  while (msg.getNumber() != MCCopasiMessage + 1)
1069  {
1070  Message += "\n";
1071  Message += FROM_UTF8(msg.getText());
1073  }
1074 
1075  CQMessageBox::warning(this, QString("File Warning"), Message,
1076  QMessageBox::Ok, QMessageBox::Ok);
1077  }
1078 
1079  (*CCopasiRootContainer::getDatamodelList())[0]->changed();
1080 
1081  mpaSave->setEnabled(true);
1082  mpaSaveAs->setEnabled(true);
1083  mpaExportSBML->setEnabled(true);
1084  mpaExportODE->setEnabled(true);
1085 
1086 #ifdef COPASI_SEDML
1087  mpaExportSEDML->setEnabled(true);
1088 #endif
1089 
1091  mNewFile = "";
1092 
1094 }
1095 
1096 #endif
1097 
1099 {
1100  // mpDataModelGUI->commit(); --> remove to the line after checking the following condition (07.04.08)
1101 
1102  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
1103  std::string FileName = (*CCopasiRootContainer::getDatamodelList())[0]->getFileName();
1104 
1105  if (mSaveAsRequired || FileName == "")
1106  {
1107  return slotFileSaveAs(FROM_UTF8(FileName));
1108  }
1109 
1111 
1112  std::ifstream File(CLocaleString::fromUtf8(FileName).c_str());
1113  std::string Line;
1114  File >> Line;
1115  File.close();
1116 
1117  if (!Line.compare(0, 8, "Version=") ||
1118  strcasecmp(FileName.c_str(), ".gps") == 0)
1119  {
1120  /* Ask for permission to overwrite write? */
1121  /* If no call slotFileSaveAs */
1122  CQMessageBox MessageBox(QMessageBox::Question,
1123  "Confirm File Version Update",
1124  "You are to overwrite an existing Gepasi File.\n"
1125  "This will render the file unreadable for Gepasi",
1126  QMessageBox::Save | QMessageBox::Ok | QMessageBox::Cancel, this);
1127 
1128  MessageBox.setDefaultButton(QMessageBox::Save);
1129  MessageBox.button(QMessageBox::Save)->setText("Save As");
1130  MessageBox.button(QMessageBox::Save)->setText("Overwrite");
1131 
1132  int choice = MessageBox.exec();
1133 
1134  switch (choice)
1135  {
1136  case QMessageBox::Save:
1137  return slotFileSaveAs(FROM_UTF8(FileName));
1138  break;
1139 
1140  case QMessageBox::Ok:
1141  break;
1142 
1143  case QMessageBox::Cancel:
1144  return;
1145  break;
1146  }
1147  }
1148 
1149  if (mpDataModelGUI)
1150  {
1151  setCursor(Qt::WaitCursor);
1152 
1153  connect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(slotFileSaveFinished(bool)));
1154  mpDataModelGUI->saveModel(FileName, true);
1155  }
1156 }
1157 
1159 {
1160  if (!CopasiUI3Window::getMainWindow()->isEnabled())
1161  {
1162  CQMessageBox::information(this, "COPASI", "COPASI is currently executing tasks.\n"
1163  "Please stop them first before closing COPASI.");
1164  return;
1165  }
1166 
1167  mQuitApplication = true;
1168 
1170 
1171  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
1172 
1173  if (mpDataModelGUI && ((*CCopasiRootContainer::getDatamodelList())[0]->isChanged() || this->mpSliders->isChanged()))
1174  {
1175  connect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(slotQuitFinished(bool)));
1176 
1177  switch (CQMessageBox::question(this, "COPASI",
1178  "The document contains unsaved changes\n"
1179  "Do you want to save the changes before exiting?",
1180  QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
1181  QMessageBox::Save))
1182  {
1183  case QMessageBox::Save:
1184  slotFileSave();
1185  break;
1186 
1187  case QMessageBox::Discard:
1188  slotQuitFinished(true);
1189  break;
1190 
1191  case QMessageBox::Cancel:
1192  default:
1193  slotQuitFinished(false);
1194  break;
1195  }
1196  }
1197  else
1198  {
1199  slotQuitFinished(true);
1200  }
1201 }
1202 
1204 {
1205  disconnect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(slotQuitFinished(bool)));
1206 
1207  mQuitApplication &= success;
1208 
1209  if (mQuitApplication)
1210  {
1211  CleanUp();
1212  qApp->quit();
1213  }
1214 }
1215 
1216 void CopasiUI3Window::closeEvent(QCloseEvent* ce)
1217 {
1218  // We handle this internally.
1219  ce->ignore();
1220 
1221  slotQuit();
1222 
1223  return;
1224 }
1225 
1226 // Cleanup all the temp .cps files created at runtime.
1228 {
1229  emit signalQuit();
1230  std::string tempDir;
1231  COptions::getValue("Tmp", tempDir);
1232 
1233  CDirEntry::removeFiles("*.cps", tempDir);
1234  CDirEntry::remove(tempDir);
1235 }
1236 
1238 {}
1239 
1241 {
1242  QString text =
1243  QString(AboutDialog::text)
1244  .arg(FROM_UTF8(CVersion::VERSION.getVersion()))
1245  .arg(LIBSBML_DOTTED_VERSION);
1246 
1247  AboutDialog* aboutDialog = new AboutDialog(this, text, 76, 30);
1248  aboutDialog->setWindowTitle(FixedTitle);
1249  aboutDialog->exec();
1250 }
1251 
1253 {
1254  AboutDialog* aboutDialog = new AboutDialog(this, CCopasiRootContainer::getLicenseHTML(), 76, 30);
1255  aboutDialog->setWindowTitle(FixedTitle);
1256  aboutDialog->exec();
1257 }
1258 
1260 {
1261  QMessageBox::aboutQt(this, "Qt");
1262 }
1263 
1265 {
1266 
1267  if (flag /*tools->isItemEnabled(2)*/)
1268  {
1269  if (mpObjectBrowser)
1270  delete mpObjectBrowser;
1271 
1272  mpObjectBrowser = new ObjectBrowserDialog(this, 0, false, 1);
1273  connect(mpObjectBrowser, SIGNAL(destroyed(QObject *)), this, SLOT(slotObjectBrowserDialogWasClosed()));
1274 
1275  mpObjectBrowser->show();
1276  }
1277  else
1278  {
1279  if (mpObjectBrowser)
1280  mpObjectBrowser->hide();
1281  }
1282 }
1283 
1285 {
1286  mpObjectBrowser = NULL;
1287  mpaObjectBrowser->setChecked(false);
1288 }
1289 
1291 {
1292  CQPreferenceDialog * preferenceDialog = new CQPreferenceDialog(this, 0, false);
1293  preferenceDialog->setAttribute(Qt::WA_DeleteOnClose);
1294  preferenceDialog->setModal(true);
1295  preferenceDialog->show();
1296 }
1297 
1299 {
1300  WizardDialog* tutorialWizard = new WizardDialog();
1301  tutorialWizard->setCopasiMainWindow(this);
1302  tutorialWizard->show();
1303 }
1304 
1305 void CopasiUI3Window::importSBMLFromString(const std::string& sbmlDocumentText)
1306 {
1307  if (mCommitRequired)
1308  {
1310  }
1311 
1312  if (!sbmlDocumentText.empty())
1313  {
1314  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
1315 
1316  if (mpDataModelGUI && ((*CCopasiRootContainer::getDatamodelList())[0]->isChanged() || this->mpSliders->isChanged()))
1317  {
1318  switch (CQMessageBox::question(this, "COPASI",
1319  "The document contains unsaved changes\n"
1320  "Do you want to save the changes before exiting?",
1321  QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
1322  QMessageBox::Save))
1323  {
1324  case QMessageBox::Save:
1325  mCommitRequired = false;
1326  slotFileSave();
1327  break;
1328 
1329  case QMessageBox::Discard:
1330  break;
1331 
1332  case QMessageBox::Cancel:
1333  default:
1334  return;
1335  break;
1336  }
1337  }
1338 
1340  (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getKey());
1341 
1343 
1344  if (!mpDataModelGUI)
1345  {
1346  mpDataModelGUI = new DataModelGUI(this); // create a new data model
1347  }
1348 
1349  setCursor(Qt::WaitCursor);
1350  connect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(slotImportSBMLFromStringFinished(bool)));
1351 
1352  mpDataModelGUI->importSBMLFromString(sbmlDocumentText);
1353  }
1354 }
1355 
1357 {
1358  disconnect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(slotImportSBMLFromStringFinished(bool)));
1359  unsetCursor();
1360  mCommitRequired = true;
1361 
1362  if (!success)
1363  {
1364  QString Message = "Error while importing SBML model!\n\n";
1365  Message += FROM_UTF8(CCopasiMessage::getLastMessage().getText());
1366 
1367  CQMessageBox::critical(this, QString("Import Error"), Message,
1368  QMessageBox::Ok, QMessageBox::Ok);
1370 
1372  }
1373 
1374  /* still check for warnings.
1375  * Maybe events or rules were ignored while reading
1376  * the file.
1377  */
1378  if (success)
1379  {
1380  this->checkPendingMessages();
1381  }
1382 
1384  (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getKey());
1385 
1386  //if (!bobject_browser_open)
1387  // mpFileMenu->setItemEnabled(nsaveas_menu_id, true);
1388  // msave_button->setEnabled(true);
1389  // mpFileMenu->setItemEnabled(nsave_menu_id, true);
1390 
1392  CQTabWidget *widget = dynamic_cast<CQTabWidget *>(mpListView->getCurrentWidget());
1393 
1394  if (widget != NULL)
1395  widget->selectTab(0);
1396 
1397  updateTitle();
1398 
1399  mSaveAsRequired = true;
1400 }
1401 
1403 {
1404  disconnect(this, SIGNAL(signalLoadFile(QString)), this, SLOT(slotImportSBML(QString)));
1405 
1406  if (mCommitRequired)
1407  {
1409  }
1410 
1411  QString SBMLFile;
1412 
1413  if (file == "")
1414  SBMLFile =
1415  CopasiFileDialog::getOpenFileName(this, "Open File Dialog",
1416  QString::null, "XML Files (*.xml);;All Files (*)",
1417  "Choose a file");
1418  else
1419  SBMLFile = file;
1420 
1421  if (!SBMLFile.isNull())
1422  {
1423  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
1424 
1425  if (mpDataModelGUI && ((*CCopasiRootContainer::getDatamodelList())[0]->isChanged() || this->mpSliders->isChanged()))
1426  {
1427  switch (CQMessageBox::question(this, "COPASI",
1428  "The document contains unsaved changes\n"
1429  "Do you want to save the changes before exiting?",
1430  QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
1431  QMessageBox::Save))
1432  {
1433  case QMessageBox::Save:
1434  connect(this, SIGNAL(signalLoadFile(QString)), this, SLOT(slotImportSBML(QString)));
1435 
1436  mNewFile = SBMLFile;
1437  mCommitRequired = false;
1438 
1439  slotFileSave();
1440  return;
1441  break;
1442 
1443  case QMessageBox::Discard:
1444  break;
1445 
1446  case QMessageBox::Cancel:
1447  default:
1448  return;
1449  break;
1450  }
1451  }
1452 
1454  (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getKey());
1455 
1457 
1458  if (this->mpSliders) this->mpSliders->reset();
1459 
1460  if (!mpDataModelGUI)
1461  {
1462  mpDataModelGUI = new DataModelGUI(this); // create a new data model
1463  }
1464 
1465  setCursor(Qt::WaitCursor);
1466  connect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(slotImportSBMLFinished(bool)));
1467 
1468  mNewFile = SBMLFile;
1469  mpDataModelGUI->importSBML(TO_UTF8(SBMLFile));
1470  }
1471 }
1472 
1474 {
1475  disconnect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(slotImportSBMLFinished(bool)));
1476  unsetCursor();
1477  mCommitRequired = true;
1478 
1479  if (!success)
1480  {
1481  QString Message = "Error while loading file " + mNewFile + QString("!\n\n");
1482  Message += FROM_UTF8(CCopasiMessage::getLastMessage().getText());
1483 
1484  CQMessageBox::critical(this, QString("File Error"), Message,
1485  QMessageBox::Ok, QMessageBox::Ok);
1486 
1488  }
1489  else
1490  // We check in all case for warnings. This will help also for unsuccessful imports
1491  this->checkPendingMessages();
1492 
1494  (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getKey());
1495 
1496  mpaSave->setEnabled(true);
1497  mpaSaveAs->setEnabled(true);
1498  mpaExportSBML->setEnabled(true);
1499  mpaExportODE->setEnabled(true);
1500 
1502  CQTabWidget *widget = dynamic_cast<CQTabWidget *>(mpListView->getCurrentWidget());
1503 
1504  if (widget != NULL)
1505  widget->selectTab(0);
1506 
1508 
1509  updateTitle();
1510 
1511  mSaveAsRequired = true;
1512 
1513  mNewFile = "";
1514 }
1515 
1517 {
1519 
1520  C_INT32 Answer = QMessageBox::No;
1521  QString tmp;
1522  bool exportIncomplete = false;
1523  int sbmlLevel = 2;
1524  int sbmlVersion = 4;
1525 
1526  while (Answer == QMessageBox::No)
1527  {
1528  QString Default = QString::null;
1529  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
1530 
1531  if ((*CCopasiRootContainer::getDatamodelList())[0]->getFileName() != "")
1532  Default
1536  + ".xml");
1537  else
1538  {
1539  Default = "untitled.xml";
1540  }
1541 
1542  // if there already is an SBML model, we present the user with the Level
1543  // and Version of that document as the selected Level and Version to
1544  // export to.
1545  if ((*CCopasiRootContainer::getDatamodelList())[0]->getCurrentSBMLDocument() != NULL)
1546  {
1547  sbmlLevel = (*CCopasiRootContainer::getDatamodelList())[0]->getCurrentSBMLDocument()->getLevel();
1548  sbmlVersion = (*CCopasiRootContainer::getDatamodelList())[0]->getCurrentSBMLDocument()->getVersion();
1549  }
1550 
1551  std::pair<QString, std::pair<unsigned C_INT32, unsigned C_INT32> > nameAndVersion =
1552  CQSBMLFileDialog::getSaveFileName(this, "Export SBML Dialog", Default,
1553  "Choose a filename and SBML version for SBML export.",
1554  sbmlLevel,
1555  sbmlVersion);
1556  tmp = nameAndVersion.first;
1557  sbmlLevel = nameAndVersion.second.first;
1558  sbmlVersion = nameAndVersion.second.second;
1559 
1560  if (tmp.isEmpty()) return;
1561 
1562  // Checks whether the file exists
1563  Answer = checkSelection(tmp);
1564 
1565  if (Answer == QMessageBox::Cancel) return;
1566  }
1567 
1568  if (mpDataModelGUI && !tmp.isNull())
1569  {
1570  setCursor(Qt::WaitCursor);
1571  connect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(slotExportSBMLFinished(bool)));
1572  mpDataModelGUI->exportSBML(TO_UTF8(tmp), true, sbmlLevel, sbmlVersion, exportIncomplete);
1573  }
1574 }
1575 
1577 {
1578  disconnect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(slotExportSBMLFinished(bool)));
1579  unsetCursor();
1580 
1583 }
1584 
1586 {
1588 
1589  C_INT32 Answer = QMessageBox::No;
1590  QString tmp;
1591  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
1593  assert(pDataModel != NULL);
1594 
1595  QString *userFilter = new QString;
1596 
1597  while (Answer == QMessageBox::No)
1598  {
1599  QString Default = QString::null;
1600 
1601  if (pDataModel->getFileName() != "")
1602  Default
1603  = FROM_UTF8(CDirEntry::dirName(pDataModel->getFileName())
1605  + CDirEntry::baseName(pDataModel->getFileName()));
1606  else
1607  Default = "untitled.c";
1608 
1609  tmp =
1610  CopasiFileDialog::getSaveFileName(this, "Save File Dialog",
1611  Default,
1612  "C Files (*.c);;Berkeley Madonna Files (*.mmd);;XPPAUT (*.ode)",
1613  "Choose an export format", userFilter);
1614 
1615  if (tmp.isEmpty()) return;
1616 
1617 #ifdef DEBUG_UI
1618  qDebug() << "user's filter pointer = " << *userFilter;
1619 #endif
1620 
1621  // Checks whether the file exists
1622  Answer = checkSelection(tmp);
1623 
1624  if (Answer == QMessageBox::Cancel) return;
1625  }
1626 
1627  if (mpDataModelGUI && !tmp.isNull())
1628  {
1629  setCursor(Qt::WaitCursor);
1630  connect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(slotExportMathModelFinished(bool)));
1631  mpDataModelGUI->exportMathModel(TO_UTF8(tmp), TO_UTF8(*userFilter), true);
1632  }
1633 }
1634 
1636 {
1637  unsetCursor();
1638  disconnect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(slotExportMathModelFinished(bool)));
1639 
1640  if (!success &&
1641  CCopasiMessage::peekLastMessage().getNumber() != MCCopasiMessage + 1)
1642  {
1643  CQMessageBox::critical(this, "Export Error",
1645  QMessageBox::Ok | QMessageBox::Default,
1646  QMessageBox::NoButton);
1648  }
1649 }
1650 #ifdef WITH_PE_EVENT_CREATION
1651 void CopasiUI3Window::slotCreateEventsForTimeseries()
1652 {
1653  if (CCopasiRootContainer::getDatamodelList()->size() == 0) return;
1654 
1655  CModel* model = (*CCopasiRootContainer::getDatamodelList())[0]->getModel();
1656 
1657  if (model == NULL) return;
1658 
1660  mpListView->switchToOtherWidget(116, "");
1661 
1663 
1664  if (!model->createEventsForTimeseries())
1665  {
1666  // Display error messages.
1667  CQMessageBox::information(this, "Event Creation Failed",
1669  QMessageBox::Ok,
1670  QMessageBox::Ok);
1672  }
1673 
1674  // show any warning messages that occured
1675  if (CCopasiMessage::size() != 0)
1676  {
1677  // Display warnings messages.
1678  CQMessageBox::information(this, "Event Creation succeded with warnings",
1680  QMessageBox::Ok,
1681  QMessageBox::Ok);
1683  }
1684 
1685  (*CCopasiRootContainer::getDatamodelList())[0]->changed();
1686 
1688 }
1689 #endif
1690 
1692 {
1693  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
1694  CModel* model = (*CCopasiRootContainer::getDatamodelList())[0]->getModel();
1695 
1696  if (!model) return;
1697 
1699  mpListView->switchToOtherWidget(114, "");
1700 
1702 
1703  if (!model->convert2NonReversible())
1704  {
1705  // Display error messages.
1706  CQMessageBox::information(this, "Conversion Failed",
1708  QMessageBox::Ok | QMessageBox::Default,
1709  QMessageBox::NoButton);
1711  }
1712 
1713  (*CCopasiRootContainer::getDatamodelList())[0]->changed();
1714 
1716 }
1717 
1719 {
1720  mpaSliders->setChecked(flag);
1721  this->mpSliders->setHidden(!flag);
1722 
1723  if (flag)
1724  addWindow(this->mpSliders);
1725  else
1726  removeWindow(this->mpSliders);
1727 }
1728 
1730 {return mpDataModelGUI;}
1731 
1733 {
1734  size_t id = mpListView->getCurrentItemId();
1735  this->mpSliders->setCurrentFolderId(id);
1737 }
1738 
1740 {
1741  return mpListView;
1742 }
1743 
1745 {
1747 
1748  if (msg_pending.getNumber() != MCCopasiMessage + 1)
1749  {
1750  QString text;
1751  QString filteredText;
1752  unsigned int numMessages = 0;
1753  unsigned int numFilteredMessages = 0;
1754 
1755  while (msg_pending.getNumber() != MCCopasiMessage + 1)
1756  {
1757  if (msg_pending.getType() & 128)
1758  {
1759  ++numFilteredMessages;
1760  filteredText += "\n";
1761  filteredText += FROM_UTF8(msg_pending.getText());
1762  }
1763  else
1764  {
1765  ++numMessages;
1766  text += "\n";
1767  text += FROM_UTF8(msg_pending.getText());
1768  }
1769 
1770  msg_pending = CCopasiMessage::getLastMessage();
1771  }
1772 
1773  if (numFilteredMessages != 0)
1774  {
1775  if (text.isEmpty())
1776  text = "There were no serious issues encountered during the import of SBML. "
1777  "However some minor issues have occurred, which can be viewed in the Minor "
1778  "Issues tab.";
1779 
1780  CQMessageBox box(QMessageBox::Information,
1781  QString("COPASI Message"), text, QMessageBox::Ok, this);
1782  box.setDefaultButton(QMessageBox::Ok);
1783  box.setFilteredText(filteredText);
1784  box.exec();
1785  }
1786  else
1787  {
1788  CQMessageBox::information(this, QString("COPASI Message"), text,
1789  QMessageBox::Ok, QMessageBox::Ok);
1790  }
1791  }
1792 }
1793 
1795 {
1796  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
1797  QString FileName = FROM_UTF8((*CCopasiRootContainer::getDatamodelList())[0]->getFileName());
1798 
1799 #ifdef WIN32 // Windows allows mixing of '/' and '\' as separator.
1800  FileName.replace("\\", "/");
1801 #endif
1802 
1803  if (FileName.length() > 40)
1804  {
1805 #ifdef WIN32
1806  QRegExp mask("^(([A-Z]:/)?[^/]+/).*(/[^/]+/[^/]+$)");
1807 #else
1808  QRegExp mask("^((/*)[^/]+/).*(/[^/]+/[^/]+$)");
1809 #endif
1810 
1811  mask.indexIn(FileName);
1812  FileName = mask.cap(1) + "..." + mask.cap(3);
1813  }
1814 
1815  std::string BaseName;
1816 
1817  if (!FileName.isEmpty())
1818  BaseName = CDirEntry::baseName(TO_UTF8(FileName)) + " - ";
1819 
1820  setWindowTitle(FROM_UTF8(BaseName) + FixedTitle + " " + FileName);
1821 }
1822 
1824 {
1825  // TODO CRITICAL This needs to be moved into a sub thread so
1826  // that a progress dialog can be displayed and the user can interrupt.
1827  if (!mSuspendAutoSave)
1828  {
1829  mSuspendAutoSave = true;
1830  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
1832  mSuspendAutoSave = false;
1833  }
1834 
1835  mpAutoSaveTimer->setInterval(AutoSaveInterval); // restart the timer
1836 }
1837 
1838 void CopasiUI3Window::suspendAutoSave(const bool & suspend)
1839 {
1840  mSuspendAutoSave = suspend;
1841 
1842  if (!mSuspendAutoSave)
1843  mpAutoSaveTimer->setInterval(AutoSaveInterval); // restart the timer
1844 }
1845 
1847 {
1848  int index = mRecentFilesActionMap[pAction];
1849 
1850  std::string FileName =
1852 
1853  slotFileOpen(FROM_UTF8(FileName));
1854 }
1855 
1857 {
1858  int index = mRecentSBMLFilesActionMap[pAction];
1859 
1860  std::string FileName =
1862 
1863  slotImportSBML(FROM_UTF8(FileName));
1864 }
1865 
1867 {
1868  mpMenuRecentFiles->clear();
1869 
1870  mRecentFilesActionMap.clear();
1871 
1872  if (mpRecentFilesActionGroup != NULL)
1873  {
1874  disconnect(mpRecentFilesActionGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotOpenRecentFile(QAction *)));
1875  mpRecentFilesActionGroup->deleteLater();
1876  mpRecentFilesActionGroup = NULL;
1877  }
1878 
1879  mpRecentFilesActionGroup = new QActionGroup(this);
1880  connect(mpRecentFilesActionGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotOpenRecentFile(QAction *)));
1881 
1882  QAction * pAction;
1883 
1888 
1889  C_INT Index = 0;
1890 
1891  for (; it != end; ++it, ++Index)
1892  {
1893  pAction = new QAction(FROM_UTF8(*(*it)->getValue().pSTRING), mpRecentFilesActionGroup);
1894  mpMenuRecentFiles->addAction(pAction);
1895  mRecentFilesActionMap[pAction] = Index;
1896  }
1897 }
1898 
1900 {
1901  mpMenuRecentSBMLFiles->clear();
1902 
1903  mRecentSBMLFilesActionMap.clear();
1904 
1905  if (mpRecentSBMLFilesActionGroup != NULL)
1906  {
1907  disconnect(mpRecentSBMLFilesActionGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotOpenRecentSBMLFile(QAction *)));
1908  mpRecentSBMLFilesActionGroup->deleteLater();
1910  }
1911 
1912  mpRecentSBMLFilesActionGroup = new QActionGroup(this);
1913  connect(mpRecentSBMLFilesActionGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotOpenRecentSBMLFile(QAction *)));
1914 
1915  QAction * pAction;
1916 
1921 
1922  C_INT Index = 0;
1923 
1924  for (; it != end; ++it, ++Index)
1925  {
1926  pAction = new QAction(FROM_UTF8(*(*it)->getValue().pSTRING), mpRecentSBMLFilesActionGroup);
1927  mpMenuRecentSBMLFiles->addAction(pAction);
1928  mRecentSBMLFilesActionMap[pAction] = Index;
1929  }
1930 }
1931 
1932 void CopasiUI3Window::exportSBMLToString(std::string & SBML)
1933 {
1935 
1936  if (mpDataModelGUI)
1937  {
1938  setCursor(Qt::WaitCursor);
1939  connect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(slotExportSBMLToStringFinished(bool)));
1940 
1942  }
1943 }
1944 
1946 {
1947  unsetCursor();
1948  disconnect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(slotExportSBMLToStringFinished(bool)));
1949 
1950  if (!success)
1951  {
1952  QString Message = "Error while exporting SBML model!\n\n";
1953  Message += FROM_UTF8(CCopasiMessage::getLastMessage().getText());
1954 
1955  CQMessageBox::critical(this, QString("File Error"), Message,
1956  QMessageBox::Ok, QMessageBox::Ok);
1958  }
1959 }
1960 
1961 const QList< QPointer<QMainWindow> >& CopasiUI3Window::getWindows() const
1962 {
1963  return mWindows;
1964 }
1965 
1966 void CopasiUI3Window::addWindow(QMainWindow * pWindow)
1967 {
1968  mWindows.append(pWindow);
1970 }
1971 
1972 void CopasiUI3Window::removeWindow(QMainWindow * pWindow)
1973 {
1974  int index = mWindows.indexOf(pWindow);
1975 
1976  if (index == -1)
1977  return;
1978 
1979  // only delete when there is such a window
1980  mWindows.removeAt(index);
1982 }
1983 
1985 {
1986  // (I assume a QActionGroup was used, so only one window will be activated at a time)
1987  if (mpWindowsActionGroup != NULL)
1988  {
1989  disconnect(mpWindowsActionGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotActivateWindowTriggered(QAction *)));
1990  mpWindowsActionGroup->deleteLater();
1991  mpWindowsActionGroup = NULL;
1992  }
1993 
1994  mpWindowsActionGroup = new QActionGroup(this);
1995  connect(mpWindowsActionGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotActivateWindowTriggered(QAction *)));
1996 
1997  // Re-initialize items the menus will always have
1998  mpWindowsMenu->clear();
1999  // COPASI main window
2000  QAction * pAction = new QAction(mWindows[0]->windowTitle(), mpWindowsActionGroup);
2001  mpWindowsMenu->addAction(pAction);
2002 
2003  if (mWindows.count() > 1)
2004  {
2005  mpWindowsMenu->addSeparator();
2006  mpWindowsMenu->addAction(mpaCloseAllWindows);
2007  mpWindowsMenu->addSeparator();
2008  }
2009 
2010  // . . . for the secondary windows, also . . .
2011  for (int index = 1; index < mWindows.count(); ++index)
2012  {
2013  QMainWindow* mainWindow = mWindows[index];
2014 
2015  if (mainWindow == NULL) continue;
2016 
2017  CWindowInterface* window = dynamic_cast<CWindowInterface*>(mainWindow);
2018  QMenu* menu = window->getWindowMenu();
2019  menu->clear();
2020  menu->addAction(pAction);
2021  menu->addSeparator();
2022  menu->addAction(mpaCloseAllWindows);
2023  menu->addSeparator();
2024  }
2025 
2026  // Add secondary windows to the Window menus
2027  for (int index = 1; index < mWindows.count(); ++index)
2028  {
2029  QMainWindow* mActionWindow = mWindows[index];
2030 
2031  if (mActionWindow == NULL) continue;
2032 
2033  pAction = new QAction(mWindows[index]->windowTitle(), mpWindowsActionGroup);
2034  mpWindowsMenu->addAction(pAction);
2035 
2036  for (int index1 = 1; index1 < mWindows.count(); ++index1)
2037  {
2038  QMainWindow* mainWindow = mWindows[index1];
2039 
2040  if (mainWindow == NULL) continue;
2041 
2042  CWindowInterface* window = dynamic_cast<CWindowInterface*>(mainWindow);
2043  QMenu* menu = window->getWindowMenu();
2044  menu->addAction(pAction);
2045  }
2046  }
2047 }
2048 
2050 {
2051  // all except main window (index == 0)
2052  for (int index = mWindows.count() - 1; index >= 1 ; --index)
2053  {
2054  QMainWindow* window = mWindows[index];
2055 
2056  if (window != NULL)
2057  window->close();
2058  }
2059 
2061 }
2062 
2064 {
2065  QMainWindow *window = getWindowByTitle(mWindows, action->text());
2066 
2067  if (window != NULL)
2068  window ->activateWindow();
2069 }
2070 
2071 void CopasiUI3Window::setMessageShown(const bool & shown)
2072 {
2073  mMessageShown = shown;
2074 }
2075 
2076 const bool & CopasiUI3Window::messageShown() const
2077 {
2078  return mMessageShown;
2079 }
2080 
2081 #include "model/CModelAnalyzer.h"
2083 {
2084  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
2086 
2087  std::ostringstream ss;
2088  // MA.writeReport(ss, true, false);
2089  MA.writeReport(ss, true, true);
2090 
2091  CQCheckModelWindow * checkModelWindow = new CQCheckModelWindow(this);
2092 
2093  checkModelWindow->setWindowTitle("Check Model");
2094  checkModelWindow->textEdit->setText(FROM_UTF8(ss.str()));
2095 
2096  checkModelWindow->show();
2097 }
2098 
2100 {
2101  disconnect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(slotFileSaveFinished(bool)));
2102  QCursor oldCursor = cursor();
2103  setCursor(Qt::WaitCursor);
2104 
2105  if (!success)
2106  {
2107  setCursor(oldCursor);
2108  QString Message = "Error while updating MIRIAM" + QString("!\n\n");
2109  Message += FROM_UTF8(CCopasiMessage::getLastMessage().getText());
2110  CQMessageBox::critical(this, QString("MIRIAM Error"), Message,
2111  QMessageBox::Ok, QMessageBox::Ok);
2113  }
2114 
2115  /* still check for warnings.
2116  * Maybe events or rules were ignored while reading
2117  * the file.
2118  */
2119  if (success)
2120  {
2123  &CCopasiRootContainer::getConfiguration()->getRecentMIRIAMResources());
2125  this->checkPendingMessages();
2126  }
2127 
2130  setCursor(oldCursor);
2131 }
2132 
2134 {
2135  bool success = true;
2136 
2138 
2139  if (!mpDataModelGUI)
2140  mpDataModelGUI = new DataModelGUI(this); // create a new data model
2141 
2142  connect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(slotUpdateMIRIAMFinished(bool)));
2143 
2144  try
2145  {
2146  success = mpDataModelGUI->updateMIRIAM(
2147  CCopasiRootContainer::getConfiguration()->getRecentMIRIAMResources());
2148  }
2149  catch (...)
2150  {
2151  success = false;
2152  }
2153 }
2154 
2156 {
2158 
2159  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
2160  CModel *pModel = (*CCopasiRootContainer::getDatamodelList())[0]->getModel();
2161 
2162  if (pModel != NULL)
2163  {
2164  pModel->compileIfNecessary(NULL);
2165  pModel->applyInitialValues();
2166  pModel->updateNonSimulatedValues();
2167 
2169  }
2170 }
2171 
2173 {
2175 
2176  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
2177  CModel *pModel = (*CCopasiRootContainer::getDatamodelList())[0]->getModel();
2178 
2179  if (pModel != NULL)
2180  {
2181  pModel->compileIfNecessary(NULL);
2182  pModel->setInitialState(pModel->getState());
2183  pModel->updateInitialValues();
2184 
2186  }
2187 }
2188 
2190 {
2192 
2193  mpDataModelGUI->setFramework(index);
2194  mpSliders->setFramework(index);
2195 }
2196 
2198 {
2199  QPixmap pixmap = QPixmap::grabWidget(mpListView->getCurrentWidget());
2200 
2201  C_INT32 Answer = QMessageBox::No;
2202  QString fileName;
2203 
2204  while (Answer == QMessageBox::No)
2205  {
2206  fileName = CopasiFileDialog::getSaveFileName(this,
2207  "Save File Dialog", "untitled.png", "PNG Files (*.png)", "Save Capture as PNG file");
2208 
2209  if (fileName.isEmpty()) return;
2210 
2211  // Checks whether the file exists
2212  Answer = checkSelection(fileName);
2213 
2214  if (Answer == QMessageBox::Cancel) return;
2215  }
2216 
2217  pixmap.save(fileName, "PNG");
2218 }
2219 
2221 {
2222  bool ok;
2223 
2224  QFont Font = QFontDialog::getFont(&ok, qApp->font(), this);
2225 
2226  if (ok)
2227  {
2228  qApp->setFont(Font);
2229 
2230  // The stylesheet (set in CQCopasiApplication.cpp) is apparently overriding
2231  // in newer versions of Qt
2232  // This appears to reload the font from setFont into the style.
2233  // Two calls so that the tabwidget labels are correct
2234  qApp->setStyleSheet(" * {font : }");
2235  qApp->setStyleSheet(" * {font : }");
2236 
2238 
2239  TaskWidget *pTaskWidget = dynamic_cast< TaskWidget * >(mpListView->getCurrentWidget());
2240 
2241  if (pTaskWidget != NULL)
2242  {
2243  pTaskWidget->adjustTable();
2244  }
2245  }
2246 
2247  return;
2248 }
2249 
2251 {
2252  std::string ApplicationFont = CCopasiRootContainer::getConfiguration()->getApplicationFont();
2253 
2254  if (ApplicationFont == "")
2255  {
2256  return;
2257  }
2258 
2259  QFont Font = qApp->font();
2260 
2261  if (ApplicationFont == TO_UTF8(Font.toString()))
2262  {
2263  // We are using the default
2265  return;
2266  }
2267 
2268  // The user has chosen another font
2269  Font.fromString(FROM_UTF8(ApplicationFont));
2270  qApp->setFont(Font);
2271 
2272  // This appears to load the fonts, etc. from the previous configuration.
2273  // Two calls so that the tabwidget labels are correct
2274  qApp->setStyleSheet(" * {font : }");
2275  qApp->setStyleSheet(" * {font : }");
2276 }
2277 
2278 #include "UI/CQExpandModelData.h"
2280 {
2281 
2282  CQExpandModelData *widget = new CQExpandModelData;
2283  widget->exec();
2284 
2286 }
2287 
2288 #ifdef WITH_MERGEMODEL
2289 
2290 #include "UI/CQMergingData.h"
2291 
2292 void CopasiUI3Window::slotMergeModels()
2293 {
2295 
2296  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
2297 
2298  CModel *pModel = (*CCopasiRootContainer::getDatamodelList())[0]->getModel();
2299 
2300  CQMergingData *widget = new CQMergingData(NULL, 0, true);
2301  widget->exec();
2302 
2304 }
2305 #endif
2306 
2307 #ifdef COPASI_SBW_INTEGRATION
2308 // Create 2 custom events, one containing the filename to an SBML document to be loaded
2309 // into COPASI
2310 CopasiUI3Window::QSBWSBMLEvent::QSBWSBMLEvent(const std::string & SBMLModel):
2311  QEvent((QEvent::Type)65433),
2312  mSBML(SBMLModel)
2313 {}
2314 
2315 const std::string & CopasiUI3Window::QSBWSBMLEvent::getSBMLModel() const
2316 {return mSBML;}
2317 
2318 CopasiUI3Window::QSBWShutdownEvent::QSBWShutdownEvent():
2319  QEvent((QEvent::Type)65434)
2320 {}
2321 
2322 void CopasiUI3Window::registerMethods(SystemsBiologyWorkbench::MethodTable< CopasiUI3Window > & table)
2323 {
2324  table.addMethod(&CopasiUI3Window::sbwAnalysis,
2325  "void doAnalysis(string)",
2326  false,
2327  "Imports a given SBML Model into CopasiUI.");
2328 
2329  table.addMethod(&CopasiUI3Window::sbwGetSBML,
2330  "string getSBML()",
2331  false,
2332  "Retrieves the currently in CopasiUI loaded model in SBML format.");
2333 }
2334 
2335 //virtual
2336 void CopasiUI3Window::onShutdown()
2337 {
2338  QApplication::postEvent(this, new QSBWShutdownEvent());
2339 }
2340 
2341 void CopasiUI3Window::customEvent(QEvent * event)
2342 {
2343  // handle the file event, that is import the SBML file
2344  switch ((int) event->type())
2345  {
2346  case 65433:
2347 
2348  try
2349  {
2350  QSBWSBMLEvent *sbwEvent = static_cast< QSBWSBMLEvent *>(event);
2351  importSBMLFromString(sbwEvent->getSBMLModel());
2352  }
2353  catch (...)
2354  {}
2355 
2356  break;
2357 
2358  case 65434:
2359 
2360  if (!mSBWIgnoreShutdownEvent)
2361  slotQuit();
2362 
2363  mSBWIgnoreShutdownEvent = true;
2364  break;
2365  }
2366 }
2367 
2368 void CopasiUI3Window::sbwConnect()
2369 {
2370  pdelete(mpSBWModule);
2371 
2372  try
2373  {
2374  // Let us define how COPASI will look to the rest of SBW
2375  std::string FullName("COPASI " + CVersion::VERSION.getVersion());
2376 
2377  // By belonging to the Analysis category, we tell all other modules that
2378  // COPASI can take SBML files and do *something* with them
2379  std::string Category("Analysis");
2380  std::string Description("COPASI Analyzer - Imports an SBML model into CopasiUI");
2381 
2382  mpSBWModule =
2383  new SystemsBiologyWorkbench::ModuleImpl(FullName, FullName,
2384  SystemsBiologyWorkbench::UniqueModule,
2385  Description);
2386 
2387  mpSBWModule->addServiceObject(FullName, FullName, Category, this, Description);
2388 
2389  // this lets SBW ask COPASI to shut down
2390  SBW::addListener(this);
2391 
2392  // here we start the SBW services and give over to QT's main loop
2393  mpSBWModule->enableModuleServices();
2394  }
2395 
2396  catch (...)
2397  {
2398  pdelete(mpSBWModule);
2399  }
2400 
2401  // Update the SBW Menu
2402  sbwRefreshMenu();
2403 }
2404 
2405 void CopasiUI3Window::sbwDisconnect()
2406 {
2407  if (mpSBWModule != NULL)
2408  {
2409  try
2410  {
2411  SBWLowLevel::disconnect();
2412  delete mpSBWModule;
2413  }
2414 
2415  catch (...)
2416  {}
2417 
2418  mpSBWModule = NULL;
2419  }
2420 }
2421 
2422 void CopasiUI3Window::sbwRegister()
2423 {
2424  if (mpSBWModule != NULL)
2425  {
2426  try
2427  {
2428  // Set the commandline so that SBW knows how to call us.
2429  std::string Self;
2430  COptions::getValue("Self", Self);
2431 
2432  mpSBWModule->setCommandLine(Self);
2433  mpSBWModule->registerModule();
2434 
2435  sbwRefreshMenu();
2436  }
2437 
2438  catch (...)
2439  {}
2440  }
2441 }
2442 
2443 void CopasiUI3Window::sbwUnregister(const std::string & moduleName) const
2444 {
2445  try
2446  {
2447  SystemsBiologyWorkbench::Module Module = SBW::getModuleInstance("BROKER");
2448  SystemsBiologyWorkbench::Service Service = Module.findServiceByName("BROKER");
2449 
2450  DataBlockWriter Arguments;
2451  Arguments.add(moduleName);
2452  Service.getMethod("void unregisterModule(string)").call(Arguments);
2453  }
2454 
2455  catch (...)
2456  {}
2457 }
2458 
2459 // get a list of all SBW analyzers and stick them into a menu
2460 void CopasiUI3Window::sbwRefreshMenu()
2461 {
2462  if (mpSBWMenu == NULL) return;
2463 
2464  bool Visible = true;
2465  bool IsSBWRegistered = false;
2466 
2467  mSBWAnalyzerModules.clear();
2468  mSBWAnalyzerServices.clear();
2469  mpSBWMenu->clear();
2470  mSBWActionMap.clear();
2471 
2472  if (mpSBWActionGroup != NULL)
2473  {
2474  disconnect(mpSBWActionGroup, SIGNAL(triggered(QAction *)), this, SLOT(sbwSlotMenuTriggered(QAction *)));
2475  mpSBWActionGroup->deleteLater();
2476  mpSBWActionGroup = NULL;
2477  }
2478 
2479  mpSBWActionGroup = new QActionGroup(this);
2480  connect(mpSBWActionGroup, SIGNAL(triggered(QAction *)), this, SLOT(sbwSlotMenuTriggered(QAction *)));
2481 
2482  try
2483  {
2484  std::vector<DataBlockReader> Services = sbwFindServices("Analysis", true);
2485  std::vector<DataBlockReader>::const_iterator it = Services.begin();
2486  std::vector<DataBlockReader>::const_iterator end = Services.end();
2487 
2488  QMap< QString, int > SortedNames;
2489  QStringList ModuleList;
2490  QStringList ServiceList;
2491 
2492  std::string Self;
2493  COptions::getValue("Self", Self);
2494 
2495  int i = 0;
2496 
2497  for (; it != end; ++it)
2498  {
2499  SystemsBiologyWorkbench::ServiceDescriptor Service(*it);
2500  SystemsBiologyWorkbench::ModuleDescriptor Module = Service.getModuleDescriptor();
2501 
2502  std::string ModuleName = Module.getName();
2503  std::string ServiceName = Service.getName();
2504  std::string MenuName = Service.getDisplayName();
2505 
2506  // Check whether the registered service is provided by COPASI
2507  if (ServiceName.compare(0, 6, "COPASI") == 0)
2508  {
2509  std::string CommandLine = Module.getCommandLine();
2510 
2511  // Check whether the registered module points to current CopasiUI
2512  if (CommandLine.compare(0, Self.length(), Self) == 0)
2513  {
2514  // Check whether the versions match
2515  if (ServiceName != "COPASI " + CVersion::VERSION.getVersion())
2516  {
2517  // We transparently update the registration information
2518  sbwUnregister(ModuleName);
2519  return sbwRegister();
2520  }
2521 
2522  IsSBWRegistered = true;
2523  continue;
2524  }
2525  else
2526  {
2527  // Check whether the CommandLine is still valid
2528  std::string::size_type Length = CommandLine.find(" -sbwmodule");
2529 
2530  if (Length != std::string::npos)
2531  {
2532  CommandLine = CommandLine.substr(0, Length);
2533  }
2534 
2535  if (!CDirEntry::exist(CommandLine))
2536  {
2537  sbwUnregister(ModuleName);
2538  continue;
2539  }
2540  }
2541  }
2542 
2543  SortedNames[FROM_UTF8(MenuName)] = i++;
2544  ModuleList.append(FROM_UTF8(ModuleName));
2545  ServiceList.append(FROM_UTF8(ServiceName));
2546  }
2547 
2548  // Add the option to register in SBW
2549  if (!IsSBWRegistered)
2550  {
2551  QAction* pAction = new QAction("Register", mpSBWActionGroup);
2552  mpSBWMenu->addAction(pAction);
2553  mSBWActionMap[pAction] = SortedNames.size();
2554 
2555  mpSBWMenu->addSeparator();
2556  }
2557 
2558  QMap< QString, int >::const_iterator itMap = SortedNames.begin();
2559  QMap< QString, int >::const_iterator endMap = SortedNames.end();
2560 
2561  for (i = 0; itMap != endMap; ++itMap, i++)
2562  {
2563  mSBWAnalyzerModules.append(ModuleList[itMap.value()]);
2564  mSBWAnalyzerServices.append(ServiceList[itMap.value()]);
2565 
2566  QAction* pAction = new QAction(itMap.key(), mpSBWActionGroup);
2567  mpSBWMenu->addAction(pAction);
2568  mSBWActionMap[pAction] = i;
2569  }
2570 
2571  if (mSBWAnalyzerModules.empty())
2572  Visible = false;
2573  }
2574 
2575  catch (...)
2576  {
2577  Visible = false;
2578  }
2579 
2580  if (!Visible)
2581  mpTools->removeAction(mpSBWAction);
2582 
2583  return;
2584 }
2585 
2586 void CopasiUI3Window::sbwSlotMenuTriggered(QAction * pAction)
2587 {
2589 
2590  mSBWActionId = mSBWActionMap[pAction];
2591 
2592  if (mSBWActionId == mSBWAnalyzerModules.size())
2593  {
2594  sbwRegister();
2595  }
2596  else
2597  {
2598  connect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(sbwSlotMenuTriggeredFinished(bool)));
2599  exportSBMLToString(mSBWDocumentString);
2600  }
2601 }
2602 
2603 void CopasiUI3Window::sbwSlotMenuTriggeredFinished(bool success)
2604 {
2605  disconnect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(sbwSlotMenuTriggeredFinished(bool)));
2606 
2607  if (success)
2608  {
2609  try
2610  {
2611  int nModule = SBWLowLevel::getModuleInstance(TO_UTF8(mSBWAnalyzerModules[mSBWActionId]));
2612  int nService = SBWLowLevel::moduleFindServiceByName(nModule, TO_UTF8(mSBWAnalyzerServices[mSBWActionId]));
2613  int nMethod = SBWLowLevel::serviceGetMethod(nModule, nService, "void doAnalysis(string)");
2614 
2615  DataBlockWriter args;
2616  args << mSBWDocumentString;
2617  SBWLowLevel::methodSend(nModule, nService, nMethod, args);
2618  }
2619 
2620  catch (SBWException * pE)
2621  {
2622  CQMessageBox::critical(this, "SBW Error",
2623  FROM_UTF8(pE->getMessage()),
2624  QMessageBox::Ok | QMessageBox::Default,
2625  QMessageBox::NoButton);
2626  }
2627  }
2628 
2629  mSBWDocumentString = "";
2630 }
2631 
2632 std::vector< DataBlockReader > CopasiUI3Window::sbwFindServices(const std::string & category,
2633  const bool & recursive)
2634 {
2635  std::vector< DataBlockReader > result;
2636 
2637  try
2638  {
2639  DataBlockWriter oArguments;
2640  oArguments.add(category);
2641  oArguments.add(recursive);
2642 
2643  Module oModule = SBW::getModuleInstance("BROKER");
2644  Service oService = oModule.findServiceByName("BROKER");
2645  oService.getMethod("{}[] findServices(string, boolean)").call(oArguments) >> result;
2646  }
2647 
2648  catch (...)
2649  {
2650  result.clear();
2651  }
2652 
2653  return result;
2654 }
2655 
2656 // Here we get an SBML document
2657 SystemsBiologyWorkbench::DataBlockWriter CopasiUI3Window::sbwAnalysis(SystemsBiologyWorkbench::Module /*from*/, SystemsBiologyWorkbench::DataBlockReader reader)
2658 {
2659  try
2660  {
2661  std::string sSBMLModel;
2662  reader >> sSBMLModel;
2663 
2664  QSBWSBMLEvent *event = new QSBWSBMLEvent(sSBMLModel);
2665  QApplication::postEvent(this, event);
2666  }
2667 
2668  catch (...)
2669  {
2670  throw new SystemsBiologyWorkbench::SBWApplicationException("Error in doAnalysis");
2671  }
2672 
2673  // and yes ... every SBW method has to return something
2674  return SystemsBiologyWorkbench::DataBlockWriter();
2675 }
2676 
2677 SystemsBiologyWorkbench::DataBlockWriter CopasiUI3Window::sbwGetSBML(SystemsBiologyWorkbench::Module /*from*/, SystemsBiologyWorkbench::DataBlockReader /*reader*/)
2678 {
2679  connect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(sbwSlotGetSBMLFinished(bool)));
2680 
2681  QMutexLocker Locker(&mSBWMutex);
2682  mSBWCallFinished = false;
2683 
2684  mpDataModelGUI->exportSBMLToString(mSBWDocumentString);
2685 
2686  if (!mSBWCallFinished)
2687  {
2688  mSBWWaitSlot.wait(&mSBWMutex);
2689  }
2690 
2691  SystemsBiologyWorkbench::DataBlockWriter result;
2692 
2693  if (mSBWSuccess)
2694  {
2695  try
2696  {
2697  // write the current model as SBML and return it
2698  result << mSBWDocumentString;
2699  mSBWDocumentString = "";
2700 
2701  return result;
2702  }
2703 
2704  catch (...)
2705  {
2706  throw new SystemsBiologyWorkbench::SBWApplicationException("Error getting the SBML.");
2707  }
2708  }
2709 
2710  throw new SystemsBiologyWorkbench::SBWApplicationException("Error getting the SBML.");
2711 
2712  // This will never be reached.
2713  return result;
2714 }
2715 
2716 void CopasiUI3Window::sbwSlotGetSBMLFinished(bool success)
2717 {
2718  QMutexLocker Locker(&mSBWMutex);
2719 
2720  mSBWCallFinished = true;
2721  mSBWSuccess = success;
2722 
2723  mSBWWaitSlot.wakeAll();
2724 }
2725 #else
2726 //void CopasiUI3Window::slotSBWMenuTriggered(QAction * /* pAction */) {}
2727 void CopasiUI3Window::customEvent(QEvent * /* event */) {}
2728 
2729 #endif // COPASI_SBW_INTEGRATION
2730 #include <QtCore/QUrl>
2731 void CopasiUI3Window::dragEnterEvent(QDragEnterEvent *event)
2732 {
2733  if (event->mimeData()->hasFormat("text/uri-list"))
2734  event->acceptProposedAction();
2735 }
2736 
2737 /**
2738  * Utility function for guessing whether the file might
2739  * be an SBML file. If so it should contain an SBML tag in the
2740  * first couple of lines.
2741  */
2742 bool isProabablySBML(QString &fileName)
2743 {
2744  QFile file(fileName);
2745 
2746  if (!file.open(QIODevice::ReadOnly))
2747  return false;
2748 
2749  for (int i = 0; i < 5; ++i)
2750  {
2751  QByteArray array = file.readLine();
2752 
2753  if (QString(array).contains("<sbml"))
2754  return true;
2755  }
2756 
2757  file.close();
2758 
2759  return false;
2760 }
2761 
2762 void CopasiUI3Window::dropEvent(QDropEvent *event)
2763 {
2764  QList<QUrl> urls = event->mimeData()->urls();
2765 
2766  if (urls.isEmpty())
2767  return;
2768 
2769  QString fileName = urls.first().toLocalFile();
2770 
2771  if (fileName.isEmpty())
2772  return;
2773 
2774  if (isProabablySBML(fileName))
2775  slotImportSBML(fileName);
2776 
2777 #ifdef COPASI_SEDML
2778  else if (isProabablySBML(fileName))
2779  slotImportSEDML(fileName);
2780 
2781 #endif
2782  else
2783  slotFileOpen(fileName);
2784 }
2785 /**
2786  * The slider dialog has to be disabled before
2787  * a task is run and reenabled afterwards.
2788  * Actually the methods stores the state
2789  * when the value true is passed and restores that
2790  * state when the value false is passed.
2791  */
2793 {
2794  if (disable)
2795  {
2796  this->mSliderDialogEnabled = this->mpSliders->isEnabled();
2797  this->mpSliders->setEnabled(false);
2798  }
2799  else
2800  {
2801  this->mpSliders->setEnabled(this->mSliderDialogEnabled);
2802  this->mpSliders->updateAllSliders();
2803  }
2804 }
2805 
2806 //TODO SEDML
2807 #ifdef COPASI_SEDML
2808 
2809 /**
2810  * Utility function for guessing whether the file might
2811  * be an SEDML file. If soit should contain an SEDML tag in the
2812  * first couple of lines.
2813  */
2814 bool isProabablySEDML(QString &fileName)
2815 {
2816  QFile file(fileName);
2817 
2818  if (!file.open(QIODevice::ReadOnly))
2819  return false;
2820 
2821  for (int i = 0; i < 5; ++i)
2822  {
2823  QByteArray array = file.readLine();
2824 
2825  if (QString(array).contains("<sedML"))
2826  return true;
2827  }
2828 
2829  file.close();
2830 
2831  return false;
2832 }
2833 
2834 void CopasiUI3Window::slotFileExamplesSEDMLFiles(QString file)
2835 {
2836  CopasiFileDialog::openExampleDir(); //Sets CopasiFileDialog::LastDir
2837  slotImportSEDML(file);
2838 }
2839 void CopasiUI3Window::slotImportSEDMLFromStringFinished(bool success)
2840 {
2841  disconnect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(slotImportSEDMLFromStringFinished(bool)));
2842  unsetCursor();
2843  mCommitRequired = true;
2844 
2845  if (!success)
2846  {
2847  QString Message = "Error while importing SED-ML model!\n\n";
2848  Message += FROM_UTF8(CCopasiMessage::getLastMessage().getText());
2849 
2850  CQMessageBox::critical(this, QString("Import Error"), Message,
2851  QMessageBox::Ok, QMessageBox::Ok);
2853 
2855  }
2856 
2857  /* still check for warnings.
2858  * Maybe events or rules were ignored while reading
2859  * the file.
2860  */
2861  if (success)
2862  {
2863  this->checkPendingMessages();
2864  }
2865 
2867  (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getKey());
2868 
2869  //if (!bobject_browser_open)
2870  // mpFileMenu->setItemEnabled(nsaveas_menu_id, true);
2871  // msave_button->setEnabled(true);
2872  // mpFileMenu->setItemEnabled(nsave_menu_id, true);
2873 
2875  CQTabWidget *widget = dynamic_cast<CQTabWidget *>(mpListView->getCurrentWidget());
2876 
2877  if (widget != NULL)
2878  widget->selectTab(0);
2879 
2880  updateTitle();
2881 
2882  mSaveAsRequired = true;
2883 }
2884 
2885 void CopasiUI3Window::slotImportSEDMLFinished(bool success)
2886 {
2887  disconnect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(slotImportSEDMLFinished(bool)));
2888  unsetCursor();
2889  mCommitRequired = true;
2890 
2891  if (!success)
2892  {
2893  QString Message = "Error while loading file " + mNewFile + QString("!\n\n");
2894  Message += FROM_UTF8(CCopasiMessage::getLastMessage().getText());
2895 
2896  CQMessageBox::critical(this, QString("File Error"), Message,
2897  QMessageBox::Ok, QMessageBox::Ok);
2898 
2900  }
2901  else
2902  // We check in all case for warnings. This will help also for unsuccessful imports
2903  this->checkPendingMessages();
2904 
2906  (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getKey());
2907 
2908  mpaSave->setEnabled(true);
2909  mpaSaveAs->setEnabled(true);
2910  mpaExportSEDML->setEnabled(true);
2911 // mpaExportODE->setEnabled(true);
2912 
2914  CQTabWidget *widget = dynamic_cast<CQTabWidget *>(mpListView->getCurrentWidget());
2915 
2916  if (widget != NULL)
2917  widget->selectTab(0);
2918 
2919  refreshRecentSEDMLFileMenu();
2920 
2921  updateTitle();
2922 
2923  mSaveAsRequired = true;
2924 
2925  mNewFile = "";
2926 }
2927 void CopasiUI3Window::slotImportSEDML(QString file)
2928 {
2929  disconnect(this, SIGNAL(signalLoadFile(QString)), this, SLOT(slotImportSEDML(QString)));
2930 
2931  if (mCommitRequired)
2932  {
2934  }
2935 
2936  QString SEDMLFile;
2937 
2938  if (file == "")
2939  SEDMLFile =
2940  CopasiFileDialog::getOpenFileName(this, "Open File Dialog",
2941  QString::null, "SED-ML files (*.sedml *.xml);;All Files (*)",
2942  "Choose a file");
2943  else
2944  SEDMLFile = file;
2945 
2946  if (!SEDMLFile.isNull())
2947  {
2948  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
2949 
2950  if (mpDataModelGUI && ((*CCopasiRootContainer::getDatamodelList())[0]->isChanged() || this->mpSliders->isChanged()))
2951  {
2952  switch (CQMessageBox::question(this, "COPASI",
2953  "The document contains unsaved changes\n"
2954  "Do you want to save the changes before exiting?",
2955  QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
2956  QMessageBox::Save))
2957  {
2958  case QMessageBox::Save:
2959  connect(this, SIGNAL(signalLoadFile(QString)), this, SLOT(slotImportSEDML(QString)));
2960 
2961  mNewFile = SEDMLFile;
2962  mCommitRequired = false;
2963 
2964  slotFileSave();
2965  return;
2966  break;
2967 
2968  case QMessageBox::Discard:
2969  break;
2970 
2971  case QMessageBox::Cancel:
2972  default:
2973  return;
2974  break;
2975  }
2976  }
2977 
2979  (*CCopasiRootContainer::getDatamodelList())[0]->getModel()->getKey());
2980 
2982 
2983  if (this->mpSliders) this->mpSliders->reset();
2984 
2985  if (!mpDataModelGUI)
2986  {
2987  mpDataModelGUI = new DataModelGUI(this); // create a new data model
2988  }
2989 
2990  setCursor(Qt::WaitCursor);
2991  connect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(slotImportSEDMLFinished(bool)));
2992 
2993  mNewFile = SEDMLFile;
2994  mpDataModelGUI->importSEDML(TO_UTF8(SEDMLFile));
2995  }
2996 }
2997 
2998 void CopasiUI3Window::refreshRecentSEDMLFileMenu()
2999 {
3000  mpMenuRecentSEDMLFiles->clear();
3001 
3002  mRecentSEDMLFilesActionMap.clear();
3003 
3004  if (mpRecentSEDMLFilesActionGroup != NULL)
3005  {
3006  disconnect(mpRecentSEDMLFilesActionGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotOpenRecentSEDMLFile(QAction *)));
3007  mpRecentSEDMLFilesActionGroup->deleteLater();
3008  mpRecentSEDMLFilesActionGroup = NULL;
3009  }
3010 
3011  mpRecentSEDMLFilesActionGroup = new QActionGroup(this);
3012  connect(mpRecentSEDMLFilesActionGroup, SIGNAL(triggered(QAction *)), this, SLOT(slotOpenRecentSEDMLFile(QAction *)));
3013 
3014  QAction * pAction;
3015 
3020 
3021  C_INT Index = 0;
3022 
3023  for (; it != end; ++it, ++Index)
3024  {
3025  pAction = new QAction(FROM_UTF8(*(*it)->getValue().pSTRING), mpRecentSEDMLFilesActionGroup);
3026  mpMenuRecentSEDMLFiles->addAction(pAction);
3027  mRecentSEDMLFilesActionMap[pAction] = Index;
3028  }
3029 }
3030 
3031 //TODO
3032 void CopasiUI3Window::exportSEDMLToString(std::string & SEDML)
3033 {
3035 
3036  if (mpDataModelGUI)
3037  {
3038  setCursor(Qt::WaitCursor);
3039  connect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(slotExportSEDMLToStringFinished(bool)));
3040 
3041  mpDataModelGUI->exportSEDMLToString(SEDML);
3042  }
3043 }
3044 
3045 void CopasiUI3Window::slotExportSEDMLToStringFinished(bool success)
3046 {
3047  unsetCursor();
3048  disconnect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(slotExportSEDMLToStringFinished(bool)));
3049 
3050  if (!success)
3051  {
3052  QString Message = "Error while exporting SED-ML model!\n\n";
3053  Message += FROM_UTF8(CCopasiMessage::getLastMessage().getText());
3054 
3055  CQMessageBox::critical(this, QString("File Error"), Message,
3056  QMessageBox::Ok, QMessageBox::Ok);
3058  }
3059 }
3060 
3061 void CopasiUI3Window::slotExportSEDMLFinished(bool /* success */)
3062 {
3063  disconnect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(slotExportSEDMLFinished(bool)));
3064  unsetCursor();
3065 
3067  refreshRecentSEDMLFileMenu();
3068 }
3069 
3070 void CopasiUI3Window::slotExportSEDML()
3071 {
3073 
3074  C_INT32 Answer = QMessageBox::No;
3075  QString tmp;
3076  bool exportIncomplete = false;
3077  int sedmlLevel = 1;
3078  int sedmlVersion = 2;
3079 
3080  while (Answer == QMessageBox::No)
3081  {
3082  QString Default = QString::null;
3083  assert(CCopasiRootContainer::getDatamodelList()->size() > 0);
3084 
3085  if ((*CCopasiRootContainer::getDatamodelList())[0]->getFileName() != "")
3086  Default
3090  + ".sedml");
3091  else
3092  {
3093  Default = "untitled.sedml";
3094  }
3095 
3096  // if there already is an SBML model, we present the user with the Level
3097  // and Version of that document as the selected Level and Version to
3098  // export to.
3099  if ((*CCopasiRootContainer::getDatamodelList())[0]->getCurrentSEDMLDocument() != NULL)
3100  {
3101  sedmlLevel = (*CCopasiRootContainer::getDatamodelList())[0]->getCurrentSEDMLDocument()->getLevel();
3102  sedmlVersion = (*CCopasiRootContainer::getDatamodelList())[0]->getCurrentSEDMLDocument()->getVersion();
3103  }
3104 
3105  std::pair<QString, std::pair<unsigned C_INT32, unsigned C_INT32> > nameAndVersion =
3106  CQSEDMLFileDialog::getSaveFileName(this, "Export SED-ML Dialog", Default,
3107  "Choose a filename and SED-ML version for SED-ML export.",
3108  sedmlLevel,
3109  sedmlVersion);
3110  tmp = nameAndVersion.first;
3111  sedmlLevel = nameAndVersion.second.first;
3112  sedmlVersion = nameAndVersion.second.second;
3113 
3114  if (tmp.isEmpty()) return;
3115 
3116  // Checks whether the file exists
3117  Answer = checkSelection(tmp);
3118 
3119  if (Answer == QMessageBox::Cancel) return;
3120  }
3121 
3122  if (mpDataModelGUI && !tmp.isNull())
3123  {
3124  setCursor(Qt::WaitCursor);
3125  connect(mpDataModelGUI, SIGNAL(finished(bool)), this, SLOT(slotExportSEDMLFinished(bool)));
3126  mpDataModelGUI->exportSEDML(TO_UTF8(tmp), true, sedmlLevel, sedmlVersion, exportIncomplete);
3127  }
3128 }
3129 
3130 void CopasiUI3Window::slotOpenRecentSEDMLFile(QAction * pAction)
3131 {
3132  int index = mRecentSEDMLFilesActionMap[pAction];
3133 
3134  std::string FileName =
3136 
3137  slotImportSEDML(FROM_UTF8(FileName));
3138 }
3139 #endif
ListViews * mpListView
ObjectBrowserDialog * mpObjectBrowser
#define C_INT
Definition: copasi.h:115
static const CCopasiMessage & peekLastMessage()
const QList< QPointer< QMainWindow > > & getWindows() const
static bool remove(const std::string &path)
Definition: CDirEntry.cpp:275
QActionGroup * mpWindowsActionGroup
static const char * getLicenseHTML()
virtual QMenu * getWindowMenu() const =0
QAction * mpaUpdateInitialState
void slotFileOpen(QString file=QString::null)
#define pdelete(p)
Definition: copasi.h:215
static void setMIRIAMResources(const CMIRIAMResources *pResources)
Definition: CConstants.cpp:81
void importSBML(const std::string &fileName)
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
CopasiWidget * getCurrentWidget()
Definition: listviews.cpp:995
void listViewsFolderChanged(const QModelIndex &index)
QAction * mpaFontSelectionDialog
QMenu * mpMenuRecentFiles
void setFramework(int index)
void switchToOtherWidget(const size_t &id, const std::string &key)
Definition: listviews.cpp:926
bool updateMIRIAM(CMIRIAMResources &miriamResources)
QActionGroup * mpRecentSBMLFilesActionGroup
void loadFunctionDB(const std::string &fileName)
bool notify(ListViews::ObjectType objectType, ListViews::Action action, const std::string &key="")
SliderDialog * mpSliders
QAction * mpaFunctionDBLoad
void setFilteredText(const QString &text)
QAction * mpaOpenSBMLFiles
void suspendAutoSave(const bool &suspend)
QAction * mpaCapture
QSharedPointer< QFont > getFont(const CLText *item, const CLGroup *group, const CLRenderResolver *, const CLBoundingBox *pBB)
virtual void setCopasiMainWindow(QWidget *copasiMainWindow)
Definition: wizard.cpp:170
static bool isMainThread()
const std::string & getText() const
void loadModel(const std::string &fileName)
void slotExportMathModelFinished(bool success)
void slotFunctionDBSave(QString str=QString::null)
void slotShowSliders(bool flag)
static std::pair< QString, std::pair< unsigned C_INT32, unsigned C_INT32 > > getSaveFileName(QWidget *parent, const char *name, const QString &startWith, const QString &caption, unsigned int sedmlLevel=1, unsigned int sedmlVersion=2)
void updateNonSimulatedValues(void)
Definition: CModel.cpp:1892
QComboBox * mpBoxSelectFramework
void setInitialState(const CState &state)
Definition: CModel.cpp:1774
const std::string getApplicationFont() const
static std::string getAllMessageText(const bool &chronological=true)
const size_t & getNumber() const
virtual void closeEvent(QCloseEvent *e)
QTimer * mpAutoSaveTimer
void openInitialDocument(const QString &file)
QMenu * mpMenuRecentSBMLFiles
void exportSBML(const std::string &fileName, bool overwriteFile, int sbmlLevel, int sbmlVersion, bool exportIncomplete, bool exportCOPASIMIRIAM=true)
void selectTab(int index) const
void disableSliders(bool disable)
index_iterator endIndex() const
CRecentFiles & getRecentFiles()
QAction * mpaObjectBrowser
QAction * mpaCloseAllWindows
static bool removeFiles(const std::string &pattern, const std::string &dir)
Definition: CDirEntry.cpp:290
static StandardButton information(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
QAction * mpaImportSBML
QAction * mpaFunctionDBSave
void importSBMLFromString(const std::string &sbmlDocumentText)
QActionGroup * mpRecentFilesActionGroup
#define C_INT32
Definition: copasi.h:90
void slotObjectBrowserDialogWasClosed()
QAction * mpaSliders
static CopasiUI3Window * getMainWindow()
static std::string baseName(const std::string &path)
Definition: CDirEntry.cpp:98
void applyInitialValues()
Definition: CModel.cpp:1236
void refreshRecentSBMLFileMenu()
void slotOpenRecentSBMLFile(QAction *pAction)
void setText(const QString &text)
static void clearDeque()
#define MCCopasiMessage
static CopasiUI3Window * pMainWindow
void slotFunctionDBLoad(QString str=QString::null)
static std::string dirName(const std::string &path)
Definition: CDirEntry.cpp:135
static void openExampleDir()
void setCurrentFolderId(size_t id)
void addWindow(QMainWindow *pWindow)
void slotFileSaveAs(QString str=QString::null)
const std::string & getFileName() const
static const nonOptionType & getNonOptions()
Definition: COptions.cpp:251
void slotExportSBMLFinished(bool success)
static StandardButton warning(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
static CConfigurationFile * getConfiguration()
void slotOpenRecentFile(QAction *pAction)
#define AutoSaveInterval
static bool compareValue(const std::string &name, const CType &value)
Definition: COptions.h:128
static CopasiUI3Window * create()
void slotActivateWindowTriggered(QAction *action)
const CCopasiMessage::Type & getType() const
void slotImportSBMLFromStringFinished(bool success)
void saveFunctionDB(const std::string &fileName)
static bool exist(const std::string &path)
Definition: CDirEntry.cpp:78
void slotFileOpenFinished(bool success)
static const std::string Separator
Definition: CDirEntry.h:34
struct MESSAGES Message
bool isProabablySBML(QString &fileName)
index_iterator beginIndex() const
Header file of class AboutDialog.
C_INT32 checkSelection(const QString &file)
static size_t size()
static const QIcon & icon(const IconID &id)
void setChanged(bool changed)
void customEvent(QEvent *)
void setFramework(int framework)
void setParentWindow(CopasiUI3Window *pPW)
static CCopasiVector< CCopasiDataModel > * getDatamodelList()
QAction * mpaExportODE
static bool isWritable(const std::string &path)
Definition: CDirEntry.cpp:95
static QString getOpenFileName(QWidget *parent=0, const char *name=0, const QString &startWith=QString::null, const QString &filter=QString::null, const QString &caption=QString::null, QString *pSelectedFilter=NULL, QFileDialog::Options options=0)
CRecentFiles & getRecentSBMLFiles()
CRecentFiles & getRecentSEDMLFiles()
void setApplicationFont(const std::string &applicationFont)
bool isChanged() const
QAction * mpaCheckModel
QMainWindow * getWindowByTitle(const QList< QPointer< QMainWindow > > &list, const QString &title)
void deregisterListView(ListViews *pListView)
void slotFileSaveFinished(bool success)
static void getValue(const std::string &name, CType &value)
Definition: COptions.h:124
QMap< QAction *, int > mRecentFilesActionMap
bool createModel()
long int flag
Definition: f2c.h:52
void saveModel(const std::string &fileName, bool overwriteFile=false)
void adjustTable()
Definition: TaskWidget.cpp:293
QAction * mpaExpandModel
const bool & messageShown() const
QAction * mpaOpenCopasiFiles
static StandardButton critical(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
void exportSBMLToString(std::string &sbmlDocumentText)
void slotQuitFinished(bool success)
bool compileIfNecessary(CProcessReport *pProcessReport)
Definition: CModel.cpp:612
void exportSBMLToString(std::string &SBML)
void dropEvent(QDropEvent *event)
void slotConvertToIrreversible()
QAction * mpaApplyInitialState
void slotFileExamplesCopasiFiles(QString file=QString::null)
QAction * mpaExportSBML
QAction * mpaUpdateMIRIAM
static CCopasiMessage getLastMessage()
ListViews * getMainWidget()
void registerListView(ListViews *pListView)
#define TO_UTF8(__x)
Definition: qtUtilities.h:74
void signalLoadFile(QString newFile)
DataModelGUI * mpDataModelGUI
bool updateInitialValues()
Definition: CModel.cpp:1461
const CCopasiParameter::Value & getValue(const std::string &name) const
DataModelGUI * getDataModel()
void slotFileExamplesSBMLFiles(QString file=QString::null)
void setMessageShown(const bool &shown)
static const char * text
Definition: AboutDialog.h:41
QMap< QAction *, int > mRecentSBMLFilesActionMap
Definition: CModel.h:50
void importSBMLFromString(const std::string &sbmlDocumentText)
bool convert2NonReversible()
Definition: CModel.cpp:3205
CCopasiParameterGroup * getGroup(const std::string &name)
void slotFrameworkChanged(int index)
void exportMathModel(const std::string &fileName, const std::string &filter, bool overwriteFile=false)
const CState & getState() const
Definition: CModel.cpp:1771
static CLocaleString fromUtf8(const std::string &utf8)
void slotExportSBMLToStringFinished(bool success)
static std::pair< QString, std::pair< unsigned C_INT32, unsigned C_INT32 > > getSaveFileName(QWidget *parent, const char *name, const QString &startWith, const QString &caption, unsigned int sbmlLevel=2, unsigned int sbmlVersion=4)
void slotUpdateMIRIAMFinished(bool)
void updateMIRIAMResourceContents()
void dragEnterEvent(QDragEnterEvent *event)
void writeReport(std::ostream &os, bool rt, bool verbose) const
parameterGroup::iterator index_iterator
void slotImportSBML(QString file=QString::null)
static std::string suffix(const std::string &path)
Definition: CDirEntry.cpp:159
virtual void updateAllSliders()
void slotShowObjectBrowserDialog(bool flag)
QThread * mpMainThread
void slotImportSBMLFinished(bool success)
static StandardButton question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
static QString getSaveFileName(QWidget *parent=0, const char *name=0, const QString &startWith=QString::null, const QString &filter=QString::null, const QString &caption=QString::null, QString *pSelectedFilter=NULL, QFileDialog::Options options=0)
size_t getCurrentItemId()
Definition: listviews.cpp:938
void removeWindow(QMainWindow *pWindow)
QList< QPointer< QMainWindow > > mWindows
static const CVersion VERSION
Definition: CVersion.h:164