SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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-sim.org/
13 // Copyright (C) 2001-2014 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 " + (std::string)VERSION_STRING);
76  int ret = 0;
77  try {
78  // initialise subsystems
81  OptionsIO::getOptions(false, argc, argv);
82  if (oc.processMetaOptions(false)) {
84  return 0;
85  }
86  XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"));
87  // Make application
88  FXApp application("SUMO GUISimulation", "DLR");
89  // Open display
90  application.init(argc, argv);
91  int minor, major;
92  if (!FXGLVisual::supported(&application, major, minor)) {
93  throw ProcessError("This system has no OpenGL support. Exiting.");
94  }
95 
96  // build the main window
97  GUIApplicationWindow* window =
98  new GUIApplicationWindow(&application, "*.sumo.cfg,*.sumocfg");
99  window->dependentBuild(oc.getBool("game"));
100  gSchemeStorage.init(&application);
101  // Create app
102  application.addSignal(SIGINT, window, MID_QUIT);
103  application.create();
104  // Load configuration given on command line
105  if (oc.isSet("configuration-file") || oc.isSet("net-file")) {
106  window->loadOnStartup();
107  }
108  // Run
109  ret = application.run();
110  } catch (const ProcessError& e) {
111  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
112  WRITE_ERROR(e.what());
113  }
114  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
115  ret = 1;
116 #ifndef _DEBUG
117  } catch (const std::exception& e) {
118  if (std::string(e.what()) != std::string("")) {
119  WRITE_ERROR(e.what());
120  }
121  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
122  ret = 1;
123  } catch (...) {
124  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
125  ret = 1;
126 #endif
127  }
129  return ret;
130 }
131 
132 
133 /****************************************************************************/
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
static void getOptions(bool loadConfig, int argc=0, char **argv=0)
Parses the command line arguments and loads the configuration optionally.
Definition: OptionsIO.cpp:64
static void setValidation(const std::string &validationScheme, const std::string &netValidationScheme)
Enables or disables validation.
Definition: XMLSubSys.cpp:69
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static void assignLock(AbstractMutex *lock)
Sets the lock to use The lock will not be deleted.
Definition: MsgHandler.cpp:275
static void close()
Closes all of an applications subsystems.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:67
Main window closes.
Definition: GUIAppEnum.h:55
static void fillOptions()
Inserts options used by the simulation into the OptionsCont-singleton.
Definition: MSFrame.cpp:69
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
#define VERSION_STRING
Definition: config.h:227
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:201
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.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
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.