SUMO - Simulation of Urban MObility
guisim_main.cpp
Go to the documentation of this file.
1 /****************************************************************************/
10 // Main for GUISIM
11 /****************************************************************************/
12 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
13 // Copyright (C) 2001-2015 DLR (http://www.dlr.de/) and contributors
14 /****************************************************************************/
15 //
16 // This file is part of SUMO.
17 // SUMO is free software: you can redistribute it and/or modify
18 // it under the terms of the GNU General Public License as published by
19 // the Free Software Foundation, either version 3 of the License, or
20 // (at your option) any later version.
21 //
22 /****************************************************************************/
23 
24 
25 // ===========================================================================
26 // included modules
27 // ===========================================================================
28 #ifdef _MSC_VER
29 #include <windows_config.h>
30 #else
31 #include <config.h>
32 #endif
33 
34 #ifdef HAVE_VERSION_H
35 #include <version.h>
36 #endif
37 
38 #include <ctime>
39 #include <signal.h>
40 #include <iostream>
41 #include <microsim/MSFrame.h>
42 #include <microsim/MSNet.h>
43 #include <utils/options/Option.h>
50 #include <utils/xml/XMLSubSys.h>
54 
55 #ifdef CHECK_MEMORY_LEAKS
56 #include <foreign/nvwa/debug_new.h>
57 #endif
58 
59 
60 // ===========================================================================
61 // methods
62 // ===========================================================================
63 /* -------------------------------------------------------------------------
64  * main
65  * ----------------------------------------------------------------------- */
66 int
67 main(int argc, char** argv) {
68  // make the output aware of threading
69  MFXMutex lock;
71  // get the options
73  // give some application descriptions
74  oc.setApplicationDescription("GUI version of the simulation SUMO.");
75  oc.setApplicationName("sumo-gui.exe", "SUMO gui Version " + getBuildName(VERSION_STRING));
76  int ret = 0;
77  try {
78  // initialise subsystems
80  // Make application
81  FXApp application("SUMO GUISimulation", "DLR");
82  // Open display
83  application.init(argc, argv);
84  int minor, major;
85  if (!FXGLVisual::supported(&application, major, minor)) {
86  throw ProcessError("This system has no OpenGL support. Exiting.");
87  }
88 
89  // build the main window
90  GUIApplicationWindow* window =
91  new GUIApplicationWindow(&application, "*.sumo.cfg,*.sumocfg");
92  gSchemeStorage.init(&application);
93  window->dependentBuild();
94  // Create app
95  application.addSignal(SIGINT, window, MID_QUIT);
96  application.create();
97  // Load configuration given on command line
98  if (argc > 1) {
99  OptionsIO::setArgs(argc, argv);
100  window->loadOnStartup();
101  }
102  // Run
103  ret = application.run();
104  } catch (const ProcessError& e) {
105  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
106  WRITE_ERROR(e.what());
107  }
108  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
109  ret = 1;
110 #ifndef _DEBUG
111  } catch (const std::exception& e) {
112  if (std::string(e.what()) != std::string("")) {
113  WRITE_ERROR(e.what());
114  }
115  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
116  ret = 1;
117  } catch (...) {
118  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
119  ret = 1;
120 #endif
121  }
123  return ret;
124 }
125 
126 
127 /****************************************************************************/
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:58
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:80
GUICompleteSchemeStorage gSchemeStorage
Main window closes.
Definition: GUIAppEnum.h:55
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
static void assignLock(AbstractMutex *lock)
Sets the lock to use The lock will not be deleted.
Definition: MsgHandler.cpp:279
static void close()
Closes all of an applications subsystems.
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:64
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:69
const std::string getBuildName(const std::string &version)
attach some build flags to the version string
Definition: StdDefs.cpp:91
#define VERSION_STRING
Definition: config.h:226
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:205
void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:89
A storage for options typed value containers)
Definition: OptionsCont.h:108
void init(FXApp *app)
Initialises the storage with some default settings.
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.
int main(int argc, char **argv)
Definition: guisim_main.cpp:67
The main window of the SUMO-gui.