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/****************************************************************************/
18// Main for netedit (adapted from guisim_main)
19/****************************************************************************/
20
21#include <signal.h>
22#include <utils/xml/XMLSubSys.h>
27
28#ifdef HAVE_VERSION_H
29#include <version.h>
30#endif
31
33#include "GNEExternalRunner.h"
34#include "GNELoadThread.h"
36
37
38// #define SECUREEXCEPTION
39
40// ===========================================================================
41// main function
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 " 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 int ret = 0;
57 // run netedit with try-catch if we're in debug-mode
58#ifdef SECUREEXCEPTION
59 try {
60#endif
61 // initialise subsystems
63 // fill options
64 GNELoadThread::fillOptions(neteditOptions);
65 // set default options
67 // create tagPropertiesdatabase
68 const GNETagPropertiesDatabase* tagPropertiesDatabase = new GNETagPropertiesDatabase();
69 // set arguments called through console
70 OptionsIO::setArgs(argc, argv);
72 if (neteditOptions.processMetaOptions(false)) {
74 } else if (neteditOptions.isSet("attribute-help-output")) {
75 // write attribute help in console
76 tagPropertiesDatabase->writeAttributeHelp();
77 } else {
78 // create FX application
79 FXApp application("SUMO netedit", "netedit");
80 // Open display
81 application.init(argc, argv);
82 int minor, major;
83 if (!FXGLVisual::supported(&application, major, minor)) {
84 throw ProcessError(TL("This system has no OpenGL support. Exiting."));
85 } else {
86 // build the main window
87 GNEApplicationWindow* netedit = new GNEApplicationWindow(&application, tagPropertiesDatabase, "*.netc.cfg,*.netccfg");
88 // build external runner
89 GNEExternalRunner* externalRunner = new GNEExternalRunner(netedit);
90 // set language
91 gLanguage = neteditOptions.getString("language");
92 // initialize GUICompleteSchemeStorage
93 gSchemeStorage.init(&application, true);
94 // build dependent elements
95 netedit->dependentBuild();
96 // add signal handler for CTRL+Q
97 application.addSignal(SIGINT, netedit, MID_HOTKEY_CTRL_Q_CLOSE);
98 // Create app
99 application.create();
100 // Load configuration given on command line
101 if (argc > 1) {
102 // Set default options
103 OptionsIO::setArgs(argc, argv);
104 // load options
105 netedit->loadOptionOnStartup();
106 }
107 // focus window at startup
108 netedit->setFocus();
109 // Run
110 ret = application.run();
111 // delete external runner
112 delete externalRunner;
113 // delete netedit
114 delete netedit;
115 }
116 }
117 // delete tagPropertiesDatabase
118 delete tagPropertiesDatabase;
119#ifdef SECUREEXCEPTION
120 } catch (const std::exception& e) {
121 if (std::string(e.what()) != std::string("")) {
122 WRITE_ERROR(e.what());
123 }
124 MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
125 ret = 1;
126 } catch (...) {
127 MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
128 ret = 1;
129 }
130#endif
132 return ret;
133}
134
135/****************************************************************************/
@ MID_HOTKEY_CTRL_Q_CLOSE
Main window closes.
Definition GUIAppEnum.h:115
GUICompleteSchemeStorage gSchemeStorage
#define WRITE_ERROR(msg)
Definition MsgHandler.h:296
#define TL(string)
Definition MsgHandler.h:305
std::string gLanguage
the language for GUI elements and messages
Definition StdDefs.cpp:35
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)