SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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-2016 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 // main function
62 // ===========================================================================
63 int
64 main(int argc, char** argv) {
65  // make the output aware of threading
66  MFXMutex lock;
68  // get the options
70  // give some application descriptions
71  oc.setApplicationDescription("GUI version of the simulation SUMO.");
72  oc.setApplicationName("sumo-gui.exe", "SUMO gui Version " VERSION_STRING);
73  int ret = 0;
74  try {
75  // initialise subsystems
78  OptionsIO::setArgs(argc, argv);
80  if (oc.processMetaOptions(false)) {
82  return 0;
83  }
84  // Make application
85  FXApp application("SUMO GUISimulation", "DLR");
86  // Open display
87  application.init(argc, argv);
88  int minor, major;
89  if (!FXGLVisual::supported(&application, major, minor)) {
90  throw ProcessError("This system has no OpenGL support. Exiting.");
91  }
92 
93  // build the main window
94  GUIApplicationWindow* window =
95  new GUIApplicationWindow(&application, "*.sumo.cfg,*.sumocfg");
96  gSchemeStorage.init(&application);
97  window->dependentBuild();
98  // Create app
99  application.addSignal(SIGINT, window, MID_QUIT);
100  application.create();
101  // Load configuration given on command line
102  if (argc > 1) {
103  window->loadOnStartup();
104  }
105  // Run
106  ret = application.run();
107  } catch (const ProcessError& e) {
108  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
109  WRITE_ERROR(e.what());
110  }
111  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
112  ret = 1;
113 #ifndef _DEBUG
114  } catch (const std::exception& e) {
115  if (std::string(e.what()) != std::string("")) {
116  WRITE_ERROR(e.what());
117  }
118  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
119  ret = 1;
120  } catch (...) {
121  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
122  ret = 1;
123 #endif
124  }
126  return ret;
127 }
128 
129 
130 /****************************************************************************/
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
static void getOptions(const bool commandLineOnly=false)
Parses the command line arguments and loads the configuration.
Definition: OptionsIO.cpp:72
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:65
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:69
static void fillOptions()
Inserts options used by the simulation into the OptionsCont-singleton.
Definition: MSFrame.cpp:69
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
#define VERSION_STRING
Definition: config.h:226
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:206
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:99
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:64
The main window of the SUMO-gui.