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-2023 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
21// Main for GUISIM
22/****************************************************************************/
23#include <config.h>
24
25#ifdef HAVE_VERSION_H
26#include <version.h>
27#endif
28
29#include <ctime>
30#include <signal.h>
31#include <iostream>
32#include <microsim/MSFrame.h>
33#include <microsim/MSNet.h>
42#include <utils/xml/XMLSubSys.h>
47
48
49// ===========================================================================
50// main function
51// ===========================================================================
52int
53main(int argc, char** argv) {
54 // make the output aware of threading
57 oc.setApplicationDescription(TL("GUI version of the microscopic, multi-modal traffic simulation SUMO."));
58 oc.setApplicationName("sumo-gui", "Eclipse SUMO GUI Version " VERSION_STRING);
59 gSimulation = true;
60 int ret = 0;
61 try {
62 // initialise subsystems
65 OptionsIO::setArgs(argc, argv);
67 if (oc.processMetaOptions(false)) {
69 return 0;
70 }
71 // Make application
72 FXApp application("SUMO GUI", "sumo-gui");
73 // Open display
74 application.init(argc, argv);
75 int minor, major;
76 if (!FXGLVisual::supported(&application, major, minor)) {
77 throw ProcessError(TL("This system has no OpenGL support. Exiting."));
78 }
79
80 // build the main window
81 GUIApplicationWindow* window = new GUIApplicationWindow(&application, "*.sumo.cfg,*.sumocfg");
82 gLanguage = oc.getString("language");
83 gSchemeStorage.init(&application);
84 window->dependentBuild(false);
85 // Create app
86 application.addSignal(SIGINT, window, MID_HOTKEY_CTRL_Q_CLOSE);
87 application.create();
88 // Load configuration given on command line
89 if (argc > 1) {
90 window->loadOnStartup();
91 }
92 // Run
93 window->setFocus();
94 ret = application.run();
95 } catch (const ProcessError& e) {
96 if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
97 WRITE_ERROR(e.what());
98 }
99 MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
100 ret = 1;
101#ifndef _DEBUG
102 } catch (const std::exception& e) {
103 if (std::string(e.what()) != std::string("")) {
104 WRITE_ERROR(e.what());
105 }
106 MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
107 ret = 1;
108 } catch (...) {
109 MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
110 ret = 1;
111#endif
112 }
115 return ret;
116}
117
118
119/****************************************************************************/
@ MID_HOTKEY_CTRL_Q_CLOSE
Main window closes.
Definition: GUIAppEnum.h:111
GUICompleteSchemeStorage gSchemeStorage
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:276
#define TL(string)
Definition: MsgHandler.h:284
std::string gLanguage
the language for GUI elements and messages
Definition: StdDefs.cpp:33
bool gSimulation
Definition: StdDefs.cpp:30
The main window of the SUMO-gui.
void loadOnStartup(const bool wait=false)
config or net on startup
void dependentBuild(const bool isLibsumo)
build dependt
void init(FXApp *app, bool netedit=false)
Initialises the storage with some default settings.
static void fillOptions()
Inserts options used by the simulation into the OptionsCont-singleton.
Definition: MSFrame.cpp:60
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:80
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:117
static void setFactory(Factory func)
Sets the factory function to use for new MsgHandlers.
Definition: MsgHandler.h:64
static MsgHandler * create(MsgType type)
A storage for options typed value containers)
Definition: OptionsCont.h:89
void setApplicationName(const std::string &appName, const std::string &fullName)
Sets the application name.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
void setApplicationDescription(const std::string &appDesc)
Sets the application description.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:59
bool processMetaOptions(bool missingOptions)
Checks for help and configuration output, returns whether we should exit.
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:58
static void getOptions(const bool commandLineOnly=false)
Parses the command line arguments and loads the configuration.
Definition: OptionsIO.cpp:74
static void close()
Closes all of an applications subsystems.
static void close()
request termination of connection
static void init()
Initialises the xml-subsystem.
Definition: XMLSubSys.cpp:55
int main(int argc, char **argv)
Definition: guisim_main.cpp:53