Eclipse SUMO - Simulation of Urban MObility
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-2024 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 #include <config.h>
21 
22 #ifdef HAVE_VERSION_H
23 #include <version.h>
24 #endif
25 
26 #include <signal.h>
33 #include <utils/xml/XMLSubSys.h>
35 
36 #include "GNEApplicationWindow.h"
37 #include "GNELoadThread.h"
38 
39 
40 // ===========================================================================
41 // main function
42 // ===========================================================================
43 int
44 main(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  gLanguage = reg.readStringEntry("gui", "language", gLanguage.c_str());
55  int ret = 0;
56 #ifndef _DEBUG
57  try {
58 #else
59  {
60 #endif
61  // initialise subsystems
63  // fill options
64  GNELoadThread::fillOptions(neteditOptions);
65  // set default options
66  GNELoadThread::setDefaultOptions(neteditOptions);
67  // set arguments called through console
68  OptionsIO::setArgs(argc, argv);
70  if (neteditOptions.processMetaOptions(false)) {
72  return 0;
73  }
74  if (neteditOptions.isSet("attribute-help-output")) {
77  return 0;
78  }
79  // Make application
80  FXApp application("SUMO netedit", "netedit");
81  // Open display
82  application.init(argc, argv);
83  int minor, major;
84  if (!FXGLVisual::supported(&application, major, minor)) {
85  throw ProcessError(TL("This system has no OpenGL support. Exiting."));
86  }
87  // build the main window
88  GNEApplicationWindow* window = new GNEApplicationWindow(&application, "*.netc.cfg,*.netccfg");
89  gLanguage = neteditOptions.getString("language");
90  gSchemeStorage.init(&application, true);
91  window->dependentBuild();
92  // Create app
93  application.addSignal(SIGINT, window, MID_HOTKEY_CTRL_Q_CLOSE);
94  application.create();
95  // Load configuration given on command line
96  if (argc > 1) {
97  // Set default options
98  OptionsIO::setArgs(argc, argv);
99  // load options
100  window->loadOptionOnStartup();
101  }
102  // focus window at startup
103  window->setFocus();
104  // Run
105  ret = application.run();
106 #ifndef _DEBUG
107  } catch (const std::exception& e) {
108  if (std::string(e.what()) != std::string("")) {
109  WRITE_ERROR(e.what());
110  }
111  MsgHandler::getErrorInstance()->inform("Quitting (on error).", false);
112  ret = 1;
113  } catch (...) {
114  MsgHandler::getErrorInstance()->inform("Quitting (on unknown error).", false);
115  ret = 1;
116 #endif
117  }
119  return ret;
120 }
121 
122 
123 /****************************************************************************/
@ MID_HOTKEY_CTRL_Q_CLOSE
Main window closes.
Definition: GUIAppEnum.h:115
GUICompleteSchemeStorage gSchemeStorage
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:304
#define TL(string)
Definition: MsgHandler.h:315
std::string gLanguage
the language for GUI elements and messages
Definition: StdDefs.cpp:33
The main window of Netedit.
void loadOptionOnStartup()
load net on startup
void dependentBuild()
build dependent
static void writeAttributeHelp()
write machine readable attribute help to file
static void fillOptions(OptionsCont &neteditOptions)
clears and initializes the OptionsCont
static void setDefaultOptions(OptionsCont &neteditOptions)
sets required options for proper functioning
void init(FXApp *app, bool netedit=false)
Initialises the storage with some default settings.
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:92
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
Definition: MsgHandler.cpp:154
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.
Definition: OptionsCont.cpp:60
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)