Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/src/netedit/netedit_main.cpp
193732 views
1
/****************************************************************************/
2
// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
// Copyright (C) 2001-2026 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
/****************************************************************************/
14
/// @file netedit_main.cpp
15
/// @author Jakob Erdmann
16
/// @author Mirko Barthauer
17
/// @date Feb 2011
18
///
19
// Main for netedit (adapted from guisim_main)
20
/****************************************************************************/
21
22
#include <signal.h>
23
#include <utils/common/SystemFrame.h>
24
#include <utils/foxtools/MsgHandlerSynchronized.h>
25
#include <utils/gui/settings/GUICompleteSchemeStorage.h>
26
#include <utils/options/OptionsIO.h>
27
#include <utils/xml/XMLSubSys.h>
28
#include <netedit/dialogs/GNECrashDialog.h>
29
30
#ifdef HAVE_VERSION_H
31
#include <version.h>
32
#endif
33
34
#include "GNEApplicationWindow.h"
35
#include "GNEExternalRunner.h"
36
#include "GNELoadThread.h"
37
#include "GNETagPropertiesDatabase.h"
38
39
// ===========================================================================
40
// main function
41
// ===========================================================================
42
43
int
44
main(int argc, char** argv) {
45
// make the output aware of threading
46
MsgHandler::setFactory(&MsgHandlerSynchronized::create);
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
63
XMLSubSys::init();
64
// fill options
65
GNELoadThread::fillOptions(neteditOptions);
66
// set default options
67
GNELoadThread::setDefaultOptions(neteditOptions);
68
// set arguments called through console
69
OptionsIO::setArgs(argc, argv);
70
OptionsIO::getOptions(true);
71
if (neteditOptions.processMetaOptions(false)) {
72
SystemFrame::close();
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
151
SystemFrame::close();
152
return ret;
153
}
154
155
/****************************************************************************/
156
157