SUMO - Simulation of Urban MObility
GNELoadThread.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-2018 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
15 // The thread that performs the loading of a Netedit-net (adapted from
16 // GUILoadThread)
17 /****************************************************************************/
18 
19 
20 // ===========================================================================
21 // included modules
22 // ===========================================================================
23 #include <netbuild/NBFrame.h>
24 #include <netbuild/NBNetBuilder.h>
25 #include <netimport/NIFrame.h>
26 #include <netimport/NILoader.h>
27 #include <netwrite/NWFrame.h>
34 #include <utils/xml/XMLSubSys.h>
35 
36 #include "GNEEvent_NetworkLoaded.h"
37 #include "GNELoadThread.h"
38 #include "GNENet.h"
39 
40 
41 // ===========================================================================
42 // member method definitions
43 // ===========================================================================
45  FXSingleEventThread(app, mw), myParent(mw), myEventQue(eq),
46  myEventThrow(ev) {
52  MsgHandler::getErrorInstance()->addRetriever(myErrorRetriever);
53 }
54 
55 
57  delete myDebugRetriever;
58  delete myGLDebugRetriever;
59  delete myErrorRetriever;
60  delete myMessageRetriever;
61  delete myWarningRetriever;
62 }
63 
64 
65 FXint
67  // register message callbacks
73 
74  GNENet* net = nullptr;
75 
76  // try to load the given configuration
78  if (myFile != "" || oc.getString("sumo-net-file") != "") {
79  oc.clear();
80  if (!initOptions()) {
82  return 0;
83  }
84  }
86  if (!(NIFrame::checkOptions() &&
90  // options are not valid
91  WRITE_ERROR("Invalid Options. Nothing loaded");
93  return 0;
94  }
100 
102  if (!GeoConvHelper::init(oc)) {
103  WRITE_ERROR("Could not build projection!");
104  submitEndAndCleanup(net);
105  return 0;
106  }
107  XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"));
108  // check if Debug has to be enabled
109  MsgHandler::enableDebugMessages(oc.getBool("gui-testing-debug"));
110  // check if GL Debug has to be enabled
111  MsgHandler::enableDebugGLMessages(oc.getBool("gui-testing-debug-gl"));
112  // this netbuilder instance becomes the responsibility of the GNENet
113  NBNetBuilder* netBuilder = new NBNetBuilder();
114 
115  netBuilder->applyOptions(oc);
116 
117  if (myNewNet) {
118  // create new network
119  net = new GNENet(netBuilder);
120  } else {
121  NILoader nl(*netBuilder);
122  try {
123  nl.load(oc);
124 
125  if (!myLoadNet) {
126  WRITE_MESSAGE("Performing initial computation ...\n");
127  // perform one-time processing (i.e. edge removal)
128  netBuilder->compute(oc);
129  // @todo remove one-time processing options!
130  } else {
131  // make coordinate conversion usable before first netBuilder->compute()
133  }
134 
135  if (oc.getBool("ignore-errors")) {
137  }
138 
139  // check whether any errors occurred
140  if (MsgHandler::getErrorInstance()->wasInformed()) {
141  throw ProcessError();
142  } else {
143  net = new GNENet(netBuilder);
144  if (oc.getBool("lefthand")) {
145  // force initial geometry computation without volatile options because the net will look strange otherwise
146  net->computeAndUpdate(oc, false);
147  }
148  }
149  if (myFile == "") {
150  if (oc.isSet("configuration-file")) {
151  myFile = oc.getString("configuration-file");
152  } else if (oc.isSet("sumo-net-file")) {
153  myFile = oc.getString("sumo-net-file");
154  }
155  }
156 
157  } catch (ProcessError& e) {
158  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
159  WRITE_ERROR(e.what());
160  }
161  WRITE_ERROR("Failed to build network.");
162  delete net;
163  delete netBuilder;
164  net = nullptr;
165  } catch (std::exception& e) {
166  WRITE_ERROR(e.what());
167 #ifdef _DEBUG
168  throw;
169 #endif
170  delete net;
171  delete netBuilder;
172  net = nullptr;
173  }
174  }
175  // only a single setting file is supported
176  submitEndAndCleanup(net, oc.getString("gui-settings-file"), oc.getBool("registry-viewport"));
177  return 0;
178 }
179 
180 
181 
182 void
183 GNELoadThread::submitEndAndCleanup(GNENet* net, const std::string& guiSettingsFile, const bool viewportFromRegistry) {
184  // remove message callbacks
190  // inform parent about the process
191  GUIEvent* e = new GNEEvent_NetworkLoaded(net, myFile, guiSettingsFile, viewportFromRegistry);
192  myEventQue.add(e);
194 }
195 
196 
197 void
199  oc.clear();
200  oc.addCallExample("--new", "start plain GUI with empty net");
201  oc.addCallExample("-s <SUMO_NET>", "edit SUMO network");
202  oc.addCallExample("-c <CONFIGURATION>", "edit net with options read from file");
203 
204  SystemFrame::addConfigurationOptions(oc); // this subtopic is filled here, too
205  oc.addOptionSubTopic("Input");
206  oc.addOptionSubTopic("Output");
208  oc.addOptionSubTopic("Processing");
209  oc.addOptionSubTopic("Building Defaults");
210  oc.addOptionSubTopic("TLS Building");
211  oc.addOptionSubTopic("Ramp Guessing");
212  oc.addOptionSubTopic("Edge Removal");
213  oc.addOptionSubTopic("Unregulated Nodes");
214  oc.addOptionSubTopic("Junctions");
215  oc.addOptionSubTopic("Pedestrian");
216  oc.addOptionSubTopic("Railway");
217  oc.addOptionSubTopic("Formats");
218  oc.addOptionSubTopic("Netedit");
219  oc.addOptionSubTopic("Visualisation");
220 
221  oc.doRegister("new", new Option_Bool(false)); // !!!
222  oc.addDescription("new", "Input", "Start with a new network");
223 
224  oc.doRegister("sumo-additionals-file", 'a', new Option_String());
225  oc.addDescription("sumo-additionals-file", "Netedit", "file in which additionals are loaded");
226 
227  oc.doRegister("additionals-output", new Option_String());
228  oc.addDescription("additionals-output", "Netedit", "file in which additionals must be saved");
229 
230  oc.doRegister("sumo-shapes-file", new Option_String());
231  oc.addDescription("sumo-shapes-file", "Netedit", "file in which shapes are loaded");
232 
233  oc.doRegister("shapes-output", new Option_String());
234  oc.addDescription("shapes-output", "Netedit", "file in which shapes must be saved");
235 
236  oc.doRegister("TLSPrograms-output", new Option_String());
237  oc.addDescription("TLSPrograms-output", "Netedit", "file in which TLS Programs must be saved");
238 
239  oc.doRegister("disable-laneIcons", new Option_Bool(false));
240  oc.addDescription("disable-laneIcons", "Visualisation", "Disable icons of special lanes");
241 
242  oc.doRegister("disable-textures", 'T', new Option_Bool(false)); // !!!
243  oc.addDescription("disable-textures", "Visualisation", "");
244 
245  oc.doRegister("gui-settings-file", 'g', new Option_FileName());
246  oc.addDescription("gui-settings-file", "Visualisation", "Load visualisation settings from FILE");
247 
248  oc.doRegister("registry-viewport", new Option_Bool(false));
249  oc.addDescription("registry-viewport", "Visualisation", "Load current viewport from registry");
250 
251  oc.doRegister("window-size", new Option_String());
252  oc.addDescription("window-size", "Visualisation", "Create initial window with the given x,y size");
253 
254  oc.doRegister("window-pos", new Option_String());
255  oc.addDescription("window-pos", "Visualisation", "Create initial window at the given x,y position");
256 
257  oc.doRegister("gui-testing", new Option_Bool(false));
258  oc.addDescription("gui-testing", "Visualisation", "Enable overlay for screen recognition");
259 
260  oc.doRegister("gui-testing-debug", new Option_Bool(false));
261  oc.addDescription("gui-testing-debug", "Visualisation", "Enable output messages during GUI-Testing");
262 
263  oc.doRegister("gui-testing-debug-gl", new Option_Bool(false));
264  oc.addDescription("gui-testing-debug-gl", "Visualisation", "Enable output messages during GUI-Testing specific of gl functions");
265 
266  SystemFrame::addReportOptions(oc); // this subtopic is filled here, too
267 
269  NBFrame::fillOptions(false);
270  NWFrame::fillOptions(false);
272 }
273 
274 
275 void
277  oc.set("offset.disable-normalization", "true"); // preserve the given network as far as possible
278  oc.set("no-turnarounds", "true"); // otherwise it is impossible to manually removed turn-arounds
279 }
280 
281 
282 bool
285  // fill all optiones
286  fillOptions(oc);
287  // set manually the net file
288  if (myFile != "") {
289  if (myLoadNet) {
290  oc.set("sumo-net-file", myFile);
291  } else {
292  oc.set("configuration-file", myFile);
293  }
294  }
295  // set default options defined in GNELoadThread::setDefaultOptions(...)
296  setDefaultOptions(oc);
297  try {
298  // set all values writables, because certain attributes already setted can be updated throught console
299  oc.resetWritable();
300  // load options from console
302  // if output file wasn't defined in the command line manually, set value of "sumo-net-file"
303  if (!oc.isSet("output-file")) {
304  oc.set("output-file", oc.getString("sumo-net-file"));
305  }
306  return true;
307  } catch (ProcessError& e) {
308  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
309  WRITE_ERROR(e.what());
310  }
311  WRITE_ERROR("Failed to parse options.");
312  return false;
313  }
314 }
315 
316 
317 void
318 GNELoadThread::loadConfigOrNet(const std::string& file, bool isNet, bool useStartupOptions, bool newNet) {
319  myFile = file;
320  myLoadNet = isNet;
321  if (myFile != "" && !useStartupOptions) {
322  OptionsIO::setArgs(0, nullptr);
323  }
324  myNewNet = newNet;
325  start();
326 }
327 
328 
329 void
330 GNELoadThread::retrieveMessage(const MsgHandler::MsgType type, const std::string& msg) {
331  GUIEvent* e = new GUIEvent_Message(type, msg);
332  myEventQue.add(e);
334 }
335 
336 /****************************************************************************/
337 
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
Definition: MsgHandler.cpp:67
The message is only something to show.
Definition: MsgHandler.h:55
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:75
FXEX::FXThreadEvent & myEventThrow
event throw
Definition: GNELoadThread.h:99
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:76
static void insertRandOptions()
Initialises the given options container with random number options.
Definition: RandHelper.cpp:43
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NWFrame.cpp:125
OutputDevice * myWarningRetriever
Definition: GNELoadThread.h:93
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NBFrame.cpp:536
static void getOptions(const bool commandLineOnly=false)
Parses the command line arguments and loads the configuration.
Definition: OptionsIO.cpp:76
void resetWritable()
Resets all options to be writeable.
static void addReportOptions(OptionsCont &oc)
Adds reporting options to the given container.
Definition: SystemFrame.cpp:65
static MsgHandler * getGLDebugInstance()
Returns the instance to add GLdebug to.
Definition: MsgHandler.cpp:94
OutputDevice * myGLDebugRetriever
Definition: GNELoadThread.h:93
static void setValidation(const std::string &validationScheme, const std::string &netValidationScheme)
Enables or disables validation.
Definition: XMLSubSys.cpp:59
void loadConfigOrNet(const std::string &file, bool isNet, bool useStartupOptions, bool newNet=false)
begins the loading of a netconvert configuration or a a network
void add(T what)
Definition: MFXEventQue.h:52
static void computeFinal(bool lefthand=false)
compute the location attributes which will be used for output based on the loaded location data...
void addCallExample(const std::string &example, const std::string &desc)
Add a call example.
bool initOptions()
init options
OutputDevice * myErrorRetriever
The instances of message retriever encapsulations Needed to be deleted from the handler later on...
Definition: GNELoadThread.h:93
static void fillOptions()
Inserts options used by the network importer and network building modules.
Definition: NIFrame.cpp:49
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:77
void addRetriever(OutputDevice *retriever)
Adds a further retriever to the instance responsible for a certain msg type.
Definition: MsgHandler.cpp:185
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static void addConfigurationOptions(OptionsCont &oc)
Adds configuration options to the given container.
Definition: SystemFrame.cpp:40
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:55
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
Perfoms network import.
Definition: NILoader.h:52
static void setDefaultOptions(OptionsCont &oc)
sets required options for proper functioning
OutputDevice * myDebugRetriever
Definition: GNELoadThread.h:93
bool myNewNet
if true, a new net is created
bool myLoadNet
Information whether only the network shall be loaded.
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
void clear()
Removes all information from the container.
static MsgHandler * getDebugInstance()
Returns the instance to add debug to.
Definition: MsgHandler.cpp:85
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
static bool init(OptionsCont &oc)
Initialises the processing and the final instance using the given options.
void removeRetriever(OutputDevice *retriever)
Removes the retriever from the handler.
Definition: MsgHandler.cpp:199
static MsgHandler * getMessageInstance()
Returns the instance to add normal messages to.
Definition: MsgHandler.cpp:58
void load(OptionsCont &oc)
Definition: NILoader.cpp:74
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
static bool checkOptions()
checks shared options and sets StdDefs
GNELoadThread(FXApp *app, MFXInterThreadEventClient *mw, MFXEventQue< GUIEvent *> &eq, FXEX::FXThreadEvent &ev)
constructor
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NIFrame.cpp:322
static void addProjectionOptions(OptionsCont &oc)
Adds projection options to the given container.
FXint run()
starts the thread. The thread ends after the net has been loaded
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:247
The message is a warning.
Definition: MsgHandler.h:57
Encapsulates an object&#39;s method for using it as a message retriever.
bool set(const std::string &name, const std::string &value)
Sets the given value for the named option.
MFXEventQue< GUIEvent * > & myEventQue
event Queue
Definition: GNELoadThread.h:96
Instance responsible for building networks.
Definition: NBNetBuilder.h:109
OutputDevice * myMessageRetriever
Definition: GNELoadThread.h:93
A storage for options typed value containers)
Definition: OptionsCont.h:92
static void initRandGlobal(std::mt19937 *which=0)
Reads the given random number options and initialises the random number generator in accordance...
Definition: RandHelper.cpp:72
std::string myFile
the path to load the network from
Definition: GNELoadThread.h:90
void computeAndUpdate(OptionsCont &oc, bool volatileOptions)
recompute the network and update lane geometries
Definition: GNENet.cpp:2431
The message is an debug.
Definition: MsgHandler.h:61
static void fillOptions(bool forNetgen)
Inserts options used by the network converter.
Definition: NBFrame.cpp:49
static void enableDebugGLMessages(bool enable)
enable/disable gl-debug messages
Definition: MsgHandler.cpp:108
static void enableDebugMessages(bool enable)
enable/disable debug messages
Definition: MsgHandler.cpp:103
void submitEndAndCleanup(GNENet *net, const std::string &guiSettingsFile="", const bool viewportFromRegistry=false)
Closes the loading process.
void retrieveMessage(const MsgHandler::MsgType type, const std::string &msg)
Retrieves messages from the loading module.
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
static void fillOptions(bool forNetgen)
Inserts options used by the network writer.
Definition: NWFrame.cpp:52
void clear()
Clears information whether an error occurred previously.
Definition: MsgHandler.cpp:173
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:242
static void initOutputOptions()
init output options
Definition: MsgHandler.cpp:239
The message is an debug.
Definition: MsgHandler.h:63
static void fillOptions(OptionsCont &oc)
clears and initializes the OptionsCont
The message is an error.
Definition: MsgHandler.h:59
virtual ~GNELoadThread()
destructor