Eclipse SUMO - Simulation of Urban MObility
guisim_main.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
18 // Main for GUISIM
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #ifdef HAVE_VERSION_H
28 #include <version.h>
29 #endif
30 
31 #include <ctime>
32 #include <signal.h>
33 #include <iostream>
34 #include <microsim/MSFrame.h>
35 #include <microsim/MSNet.h>
36 #include <utils/options/Option.h>
44 #include <utils/xml/XMLSubSys.h>
49 
50 
51 // ===========================================================================
52 // main function
53 // ===========================================================================
54 int
55 main(int argc, char** argv) {
56  // make the output aware of threading
58  // get the options
60  // give some application descriptions
61  oc.setApplicationDescription("GUI version of the microscopic, multi-modal traffic simulation SUMO.");
62  oc.setApplicationName("sumo-gui", "Eclipse SUMO GUI Version " VERSION_STRING);
63  gSimulation = true;
64  int ret = 0;
65  try {
66  // initialise subsystems
69  OptionsIO::setArgs(argc, argv);
71  if (oc.processMetaOptions(false)) {
73  return 0;
74  }
75  // Make application
76  FXApp application("SUMO GUI", "Eclipse");
77  // Open display
78  application.init(argc, argv);
79  int minor, major;
80  if (!FXGLVisual::supported(&application, major, minor)) {
81  throw ProcessError("This system has no OpenGL support. Exiting.");
82  }
83 
84  // build the main window
85  GUIApplicationWindow* window =
86  new GUIApplicationWindow(&application, "*.sumo.cfg,*.sumocfg");
87  gSchemeStorage.init(&application);
88  window->dependentBuild();
89  // Create app
90  application.addSignal(SIGINT, window, MID_HOTKEY_CTRL_Q_CLOSE);
91  application.create();
92  // Load configuration given on command line
93  if (argc > 1) {
94  window->loadOnStartup();
95  }
96  // Run
97  ret = application.run();
98  } catch (const ProcessError& e) {
99  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
100  WRITE_ERROR(e.what());
101  }
102  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
103  ret = 1;
104 #ifndef _DEBUG
105  } catch (const std::exception& e) {
106  if (std::string(e.what()) != std::string("")) {
107  WRITE_ERROR(e.what());
108  }
109  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
110  ret = 1;
111  } catch (...) {
112  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
113  ret = 1;
114 #endif
115  }
118  return ret;
119 }
120 
121 
122 /****************************************************************************/
Main window closes.
Definition: GUIAppEnum.h:96
void init(FXApp *app, bool netedit=false)
Initialises the storage with some default settings.
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:48
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:81
GUICompleteSchemeStorage gSchemeStorage
static void getOptions(const bool commandLineOnly=false)
Parses the command line arguments and loads the configuration.
Definition: OptionsIO.cpp:76
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
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:55
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
bool gSimulation
Definition: StdDefs.cpp:30
static void fillOptions()
Inserts options used by the simulation into the OptionsCont-singleton.
Definition: MSFrame.cpp:61
static void close()
request termination of connection
static MsgHandler * create(MsgType type)
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
#define VERSION_STRING
Definition: config.h:207
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:245
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:118
A storage for options typed value containers)
Definition: OptionsCont.h:90
static void setFactory(Factory func)
Sets the factory function to use for new MsgHandlers.
Definition: MsgHandler.h:69
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.
int main(int argc, char **argv)
Definition: guisim_main.cpp:55
The main window of the SUMO-gui.