COPASI API  4.16.103
ViewCurrentUI/main.cpp
Go to the documentation of this file.
1 // Copyright (C) 2012 - 2013 by Pedro Mendes, Virginia Tech Intellectual
2 // Properties, Inc., University of Heidelberg, and The University
3 // of Manchester.
4 // All rights reserved.
5 
6 #include <stdexcept>
7 
8 #include <QtGui/QApplication>
9 #include <QtCore/QString>
10 
11 #define COPASI_MAIN
12 
13 #include "copasi.h"
14 
15 #include "UI/CQCopasiApplication.h"
16 #include "UI/copasiui3window.h"
17 #include "UI/DataModelGUI.h"
18 #include "UI/CQMessageBox.h"
19 
22 #include "function/CFunctionDB.h"
23 #include "function/CFunction.h"
25 #include "commandline/COptions.h"
26 
27 #ifdef COPASI_SBW_INTEGRATION
28 // SBW includes
29 #include "SBW/SBW.h"
30 #include <sstream>
31 #endif // COPASI_SBW_INTEGRATION
32 
33 #ifdef Darwin
34 # include <QtCore/QDir>
35 # include "UI/qtUtilities.h"
36 #endif // Darwin
37 
38 #include <worker.h>
39 #include <arguments.h>
40 
41 int main(int argc, char *argv[])
42 {
43  CQCopasiApplication a(argc, argv);
44 
45  // parse args
46  Arguments args(argc, argv);
47 
48  if (args.handleCommandLine())
49  {
50  return 0;
51  }
52 
53  a.setAttribute(Qt::AA_DontShowIconsInMenus, false);
54 
55  Q_INIT_RESOURCE(copasi);
56 
57  // Parse the commandline options
58  try
59  {
60  // Create the root container but don't pass in any args past the executable name
61  CCopasiRootContainer::init(1, argv, true);
62  }
63  catch (copasi::option_error & msg)
64  {
65  CQMessageBox::critical(NULL, "Initialization Error",
66  msg.what(),
67  QMessageBox::Ok , QMessageBox::Ok);
68 
69  return 1;
70  }
71 
72 #ifdef Darwin
73  std::string PluginDir;
74 
75  COptions::getValue("CopasiDir", PluginDir);
76  PluginDir += "/Contents/plugins";
77 
78  QApplication::setLibraryPaths(QStringList(FROM_UTF8(PluginDir)));
79 #endif // Darwin
80 
81  // Create the global data model.
83 
84  // instantiate model and apply all changes
85  args.prepareModel();
86 
87  // Create the main application window.
89  Worker* pWorker = NULL;
90 #ifdef COPASI_SBW_INTEGRATION
91 
92  if (COptions::compareValue("SBWRegister", true))
93  goto finish;
94 
95 #endif // COPASI_SBW_INTEGRATION
96 
97  if (pWindow != NULL)
98  {
99  a.setMainWindow(pWindow);
100 
101  // pass control to the worker
102  if (args.isValid())
103  pWorker = new Worker(pWindow, &args);
104 
105  a.exec();
106  }
107 
108 finish:
109 
110  try // To suppress any access violations during destruction works only under Windows
111  {
112  if (pWorker != NULL)
113  {
114  delete pWorker;
115  pWorker = NULL;
116  }
117 
119  }
120  catch (...)
121  {}
122 
123  return 0;
124 }
Definition: worker.h:18
#define FROM_UTF8(__x)
Definition: qtUtilities.h:73
int main(int argc, char *argv[])
bool handleCommandLine() const
Definition: arguments.cpp:116
void setMainWindow(CopasiUI3Window *pMainWindow)
static bool compareValue(const std::string &name, const CType &value)
Definition: COptions.h:128
static CopasiUI3Window * create()
static void getValue(const std::string &name, CType &value)
Definition: COptions.h:124
static CCopasiDataModel * addDatamodel()
static StandardButton critical(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons=Ok, StandardButton defaultButton=NoButton)
bool isValid() const
Definition: arguments.cpp:315
static void init(int argc, char *argv[], const bool &withGui=false)
std::string prepareModel() const
Definition: arguments.cpp:324