Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
netedit_main.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2025 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/****************************************************************************/
19// Main for netedit (adapted from guisim_main)
20/****************************************************************************/
21
22#include <signal.h>
27#include <utils/xml/XMLSubSys.h>
29
30#ifdef HAVE_VERSION_H
31#include <version.h>
32#endif
33
35#include "GNEExternalRunner.h"
36#include "GNELoadThread.h"
38
39// ===========================================================================
40// main function
41// ===========================================================================
42
43int
44main(int argc, char** argv) {
45 // make the output aware of threading
47 // get the options
48 auto& neteditOptions = OptionsCont::getOptions();
49 neteditOptions.setApplicationDescription(TL("Graphical editor for SUMO networks, demand and additional infrastructure."));
50 neteditOptions.setApplicationName("netedit", "Eclipse SUMO netedit " VERSION_STRING);
51 // preload registry from sumo to decide on language
52 FXRegistry reg("SUMO GUI", "sumo-gui");
53 reg.read();
54 // set language
55 gLanguage = reg.readStringEntry("gui", "language", gLanguage.c_str());
56 // declare return value (0 means all ok, 1 means error)
57 int ret = 0;
58 // run netedit with try-catch if we're in release mode
59#ifndef _DEBUG
60 try {
61#endif
62 // initialise subsystems
64 // fill options
65 GNELoadThread::fillOptions(neteditOptions);
66 // set default options
68 // set arguments called through console
69 OptionsIO::setArgs(argc, argv);
71 if (neteditOptions.processMetaOptions(false)) {
73 } else {
74 // create tagPropertiesdatabase
75 const GNETagPropertiesDatabase* tagPropertiesDatabase = new GNETagPropertiesDatabase();
76 // check if we're only printing the attributes in console
77 if (neteditOptions.isSet("attribute-help-output")) {
78 // write attribute help in console
79 tagPropertiesDatabase->writeAttributeHelp();
80 } else {
81 // create FX application
82 FXApp application("SUMO netedit", "netedit");
83 // Open display
84 application.init(argc, argv);
85 int minor, major;
86 if (!FXGLVisual::supported(&application, major, minor)) {
87 throw ProcessError(TL("This system has no OpenGL support. Exiting."));
88 } else {
89 // build the main window
90 GNEApplicationWindow* netedit = new GNEApplicationWindow(&application, tagPropertiesDatabase, "*.netc.cfg,*.netccfg");
91#ifndef _DEBUG
92 try {
93#endif
94 // build external runner
95 GNEExternalRunner* externalRunner = new GNEExternalRunner(netedit);
96 // set language
97 gLanguage = neteditOptions.getString("language");
98 // initialize GUICompleteSchemeStorage
99 gSchemeStorage.init(&application, true);
100 // build dependent elements
101 netedit->dependentBuild();
102 // add signal handler for CTRL+Q
103 application.addSignal(SIGINT, netedit, MID_HOTKEY_CTRL_Q_CLOSE);
104 // Create app
105 application.create();
106 // Load configuration given on command line
107 if (argc > 1) {
108 // Set default options
109 OptionsIO::setArgs(argc, argv);
110 // load options
111 netedit->loadOptionOnStartup();
112 }
113 // focus window at startup
114 netedit->setFocus();
115 // Run
116 ret = application.run();
117 // delete external runner
118 delete externalRunner;
119 // delete netedit
120 delete netedit;
121#ifndef _DEBUG
122 } catch (const ProcessError& e) {
123 // write info
124 if (std::string(e.what()).length() > 0) {
125 WRITE_ERROR(e.what());
126 }
127 MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
128 ret = 1;
129 // open crash dialog with the exception
130 GNECrashDialog(netedit, e);
131 }
132#endif
133 }
134 }
135 // delete tagPropertiesDatabase
136 delete tagPropertiesDatabase;
137 }
138#ifndef _DEBUG
139 } catch (const std::exception& e) {
140 if (std::string(e.what()).length() > 0) {
141 WRITE_ERROR(e.what());
142 }
143 MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
144 ret = 1;
145 } catch (...) {
146 MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
147 ret = 1;
148 }
149#endif
150 // close system frame before return result
152 return ret;
153}
154
155/****************************************************************************/
@ MID_HOTKEY_CTRL_Q_CLOSE
Main window closes.
Definition GUIAppEnum.h:115
GUICompleteSchemeStorage gSchemeStorage
#define WRITE_ERROR(msg)
Definition MsgHandler.h:295
#define TL(string)
Definition MsgHandler.h:304
std::string gLanguage
the language for GUI elements and messages
Definition StdDefs.cpp:38
The main window of Netedit.
void loadOptionOnStartup()
load net on startup
void dependentBuild()
build dependent
static void fillOptions(OptionsCont &neteditOptions)
clears and initializes the OptionsCont
static void setDefaultOptions(OptionsCont &neteditOptions)
sets required options for proper functioning
void writeAttributeHelp() const
write machine readable attribute help to file
void init(FXApp *app, bool netedit=false)
Initialises the storage with some default settings.
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
static void setFactory(Factory func)
Sets the factory function to use for new MsgHandlers.
Definition MsgHandler.h:64
static MsgHandler * create(MsgType type)
static OptionsCont & getOptions()
Retrieves the options.
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 init()
Initialises the xml-subsystem.
Definition XMLSubSys.cpp:56
int main(int argc, char **argv)