Eclipse 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-2022 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 // The thread that performs the loading of a Netedit-net (adapted from
19 // GUILoadThread)
20 /****************************************************************************/
21 #include <netbuild/NBFrame.h>
22 #include <netbuild/NBNetBuilder.h>
23 #include <netimport/NIFrame.h>
24 #include <netimport/NILoader.h>
25 #include <netwrite/NWFrame.h>
32 #include <utils/xml/XMLSubSys.h>
33 
34 #include "GNEEvent_NetworkLoaded.h"
35 #include "GNELoadThread.h"
36 #include "GNENet.h"
37 
38 
39 // ===========================================================================
40 // member method definitions
41 // ===========================================================================
43  FXSingleEventThread(app, mw), myParent(mw), myEventQue(eq),
44  myEventThrow(ev) {
51 }
52 
53 
55  delete myDebugRetriever;
56  delete myGLDebugRetriever;
57  delete myErrorRetriever;
58  delete myMessageRetriever;
59  delete myWarningRetriever;
60 }
61 
62 
63 FXint
65  // register message callbacks
71 
72  GNENet* net = nullptr;
73 
74  // try to load the given configuration
76  if (myFile != "" || oc.getString("sumo-net-file") != "") {
77  oc.clear();
78  if (!initOptions()) {
80  return 0;
81  }
82  }
83  if (oc.isDefault("aggregate-warnings")) {
84  oc.set("aggregate-warnings", "5");
85  }
87  if (!(NIFrame::checkOptions() &&
91  // options are not valid
92  WRITE_ERROR("Invalid Options. Nothing loaded");
94  return 0;
95  }
101 
103  if (!GeoConvHelper::init(oc)) {
104  WRITE_ERROR("Could not build projection!");
105  submitEndAndCleanup(net);
106  return 0;
107  }
108  XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"), oc.getString("xml-validation.routes"));
109  // check if Debug has to be enabled
110  MsgHandler::enableDebugMessages(oc.getBool("gui-testing-debug"));
111  // check if GL Debug has to be enabled
112  MsgHandler::enableDebugGLMessages(oc.getBool("gui-testing-debug-gl"));
113  // this netbuilder instance becomes the responsibility of the GNENet
114  NBNetBuilder* netBuilder = new NBNetBuilder();
115 
116  netBuilder->applyOptions(oc);
117 
118  if (myNewNet) {
119  // create new network
120  net = new GNENet(netBuilder);
121  } else {
122  NILoader nl(*netBuilder);
123  try {
124  nl.load(oc);
125 
126  if (!myLoadNet) {
127  WRITE_MESSAGE("Performing initial computation ...\n");
128  // perform one-time processing (i.e. edge removal)
129  netBuilder->compute(oc);
130  // @todo remove one-time processing options!
131  } else {
132  // make coordinate conversion usable before first netBuilder->compute()
134  }
135 
136  if (oc.getBool("ignore-errors")) {
138  }
139 
140  // check whether any errors occurred
141  if (MsgHandler::getErrorInstance()->wasInformed()) {
142  throw ProcessError();
143  } else {
144  net = new GNENet(netBuilder);
145  if (oc.getBool("lefthand")) {
146  // force initial geometry computation without volatile options because the net will look strange otherwise
147  net->computeAndUpdate(oc, false);
148  }
149  }
150  if (myFile == "") {
151  if (oc.isSet("configuration-file")) {
152  myFile = oc.getString("configuration-file");
153  } else if (oc.isSet("sumo-net-file")) {
154  myFile = oc.getString("sumo-net-file");
155  }
156  }
157 
158  } catch (ProcessError& e) {
159  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
160  WRITE_ERROR(e.what());
161  }
162  WRITE_ERROR("Failed to build network.");
163  delete net;
164  delete netBuilder;
165  net = nullptr;
166  } catch (std::exception& e) {
167  WRITE_ERROR(e.what());
168  delete net;
169  delete netBuilder;
170  net = nullptr;
171  }
172  }
173  // only a single setting file is supported
174  submitEndAndCleanup(net, myNewNet, oc.getString("gui-settings-file"), oc.getBool("registry-viewport"));
175  return 0;
176 }
177 
178 
179 
180 void
181 GNELoadThread::submitEndAndCleanup(GNENet* net, const bool newNet, const std::string& guiSettingsFile, const bool viewportFromRegistry) {
182  // remove message callbacks
188  // inform parent about the process
189  GUIEvent* e = new GNEEvent_NetworkLoaded(net, newNet, myFile, guiSettingsFile, viewportFromRegistry);
192 }
193 
194 
195 void
197  oc.clear();
198  oc.addCallExample("--new", "start plain GUI with empty net");
199  oc.addCallExample("-s <SUMO_NET>", "edit SUMO network");
200  oc.addCallExample("-c <CONFIGURATION>", "edit net with options read from file");
201 
202  SystemFrame::addConfigurationOptions(oc); // this subtopic is filled here, too
203  oc.addOptionSubTopic("Input");
204  oc.addOptionSubTopic("Output");
206  oc.addOptionSubTopic("Processing");
207  oc.addOptionSubTopic("Building Defaults");
208  oc.addOptionSubTopic("TLS Building");
209  oc.addOptionSubTopic("Ramp Guessing");
210  oc.addOptionSubTopic("Edge Removal");
211  oc.addOptionSubTopic("Unregulated Nodes");
212  oc.addOptionSubTopic("Junctions");
213  oc.addOptionSubTopic("Pedestrian");
214  oc.addOptionSubTopic("Bicycle");
215  oc.addOptionSubTopic("Railway");
216  oc.addOptionSubTopic("Formats");
217  oc.addOptionSubTopic("Netedit");
218  oc.addOptionSubTopic("Visualisation");
219  oc.addOptionSubTopic("Time");
220 
221  oc.doRegister("new", new Option_Bool(false)); // !!!
222  oc.addDescription("new", "Input", "Start with a new network");
223 
224  // files
225 
226  oc.doRegister("additional-files", 'a', new Option_FileName());
227  oc.addSynonyme("additional-files", "additional");
228  oc.addDescription("additional-files", "Netedit", "Load additional and shapes descriptions from FILE(s)");
229 
230  oc.doRegister("additionals-output", new Option_String());
231  oc.addDescription("additionals-output", "Netedit", "file in which additionals must be saved");
232 
233  oc.doRegister("route-files", 'r', new Option_FileName());
234  oc.addSynonyme("route-files", "routes");
235  oc.addDescription("route-files", "Netedit", "Load demand elements descriptions from FILE(s)");
236 
237  oc.doRegister("demandelements-output", new Option_String());
238  oc.addDescription("demandelements-output", "Netedit", "file in which demand elements must be saved");
239 
240  oc.doRegister("data-files", 'd', new Option_FileName());
241  oc.addSynonyme("data-files", "data");
242  oc.addDescription("data-files", "Netedit", "Load data elements descriptions from FILE(s)");
243 
244  oc.doRegister("dataelements-output", new Option_String());
245  oc.addDescription("dataelements-output", "Netedit", "file in which data elements must be saved");
246 
247  oc.doRegister("TLSPrograms-output", new Option_String());
248  oc.addDescription("TLSPrograms-output", "Netedit", "file in which TLS Programs must be saved");
249 
250  oc.doRegister("edgeTypes-output", new Option_String());
251  oc.addDescription("edgeTypes-output", "Netedit", "file in which edgeTypes must be saved");
252 
253  // network prefixes
254 
255  oc.doRegister("node-prefix", new Option_String("J"));
256  oc.addDescription("node-prefix", "Netedit", "prefix for node naming");
257 
258  oc.doRegister("edge-prefix", new Option_String("E"));
259  oc.addDescription("edge-prefix", "Netedit", "prefix for edge naming");
260 
261  oc.doRegister("edge-infix", new Option_String(""));
262  oc.addDescription("edge-infix", "Netedit", "enable edge-infix (<fromNodeID><infix><toNodeID>)");
263 
264  // additional prefixes
265 
266  oc.doRegister("busStop-prefix", new Option_String("bs"));
267  oc.addDescription("busStop-prefix", "Netedit", "prefix for busStop naming");
268 
269  oc.doRegister("trainStop-prefix", new Option_String("ts"));
270  oc.addDescription("trainStop-prefix", "Netedit", "prefix for trainStop naming");
271 
272  oc.doRegister("containerStop-prefix", new Option_String("ct"));
273  oc.addDescription("containerStop-prefix", "Netedit", "prefix for containerStop naming");
274 
275  oc.doRegister("chargingStation-prefix", new Option_String("cs"));
276  oc.addDescription("chargingStation-prefix", "Netedit", "prefix for chargingStation naming");
277 
278  oc.doRegister("parkingArea-prefix", new Option_String("pa"));
279  oc.addDescription("parkingArea-prefix", "Netedit", "prefix for parkingArea naming");
280 
281  oc.doRegister("e1Detector-prefix", new Option_String("e1"));
282  oc.addDescription("e1Detector-prefix", "Netedit", "prefix for e1Detector naming");
283 
284  oc.doRegister("e2Detector-prefix", new Option_String("e2"));
285  oc.addDescription("e2Detector-prefix", "Netedit", "prefix for e2Detector naming");
286 
287  oc.doRegister("e3Detector-prefix", new Option_String("e3"));
288  oc.addDescription("e3Detector-prefix", "Netedit", "prefix for e3Detector naming");
289 
290  oc.doRegister("e1InstantDetector-prefix", new Option_String("e1i"));
291  oc.addDescription("e1InstantDetector-prefix", "Netedit", "prefix for e1InstantDetector naming");
292 
293  oc.doRegister("rerouter-prefix", new Option_String("rr"));
294  oc.addDescription("rerouter-prefix", "Netedit", "prefix for rerouter naming");
295 
296  oc.doRegister("calibrator-prefix", new Option_String("ca"));
297  oc.addDescription("calibrator-prefix", "Netedit", "prefix for calibrator naming");
298 
299  oc.doRegister("routeProbe-prefix", new Option_String("rp"));
300  oc.addDescription("routeProbe-prefix", "Netedit", "prefix for routeProbe naming");
301 
302  oc.doRegister("vss-prefix", new Option_String("vs"));
303  oc.addDescription("vss-prefix", "Netedit", "prefix for vss naming");
304 
305  oc.doRegister("polygon-prefix", new Option_String("po"));
306  oc.addDescription("polygon-prefix", "Netedit", "prefix for polygon naming");
307 
308  oc.doRegister("poi-prefix", new Option_String("poi"));
309  oc.addDescription("poi-prefix", "Netedit", "prefix for poi naming");
310 
311  // demand prefixes
312 
313  oc.doRegister("route-prefix", new Option_String("r"));
314  oc.addDescription("route-prefix", "Netedit", "prefix for route naming");
315 
316  oc.doRegister("vType-prefix", new Option_String("t"));
317  oc.addDescription("vType-prefix", "Netedit", "prefix for vType naming");
318 
319  oc.doRegister("vehicle-prefix", new Option_String("v"));
320  oc.addDescription("vehicle-prefix", "Netedit", "prefix for vehicle naming");
321 
322  oc.doRegister("trip-prefix", new Option_String("t"));
323  oc.addDescription("trip-prefix", "Netedit", "prefix for trip naming");
324 
325  oc.doRegister("flow-prefix", new Option_String("f"));
326  oc.addDescription("flow-prefix", "Netedit", "prefix for flow naming");
327 
328  oc.doRegister("person-prefix", new Option_String("p"));
329  oc.addDescription("person-prefix", "Netedit", "prefix for person naming");
330 
331  oc.doRegister("container-prefix", new Option_String("c"));
332  oc.addDescription("container-prefix", "Netedit", "prefix for container naming");
333 
334  // drawing
335 
336  oc.doRegister("disable-laneIcons", new Option_Bool(false));
337  oc.addDescription("disable-laneIcons", "Visualisation", "Disable icons of special lanes");
338 
339  oc.doRegister("disable-textures", 'T', new Option_Bool(false)); // !!!
340  oc.addDescription("disable-textures", "Visualisation", "");
341 
342  oc.doRegister("gui-settings-file", 'g', new Option_FileName());
343  oc.addDescription("gui-settings-file", "Visualisation", "Load visualisation settings from FILE");
344 
345  oc.doRegister("registry-viewport", new Option_Bool(false));
346  oc.addDescription("registry-viewport", "Visualisation", "Load current viewport from registry");
347 
348  oc.doRegister("window-size", new Option_StringVector());
349  oc.addDescription("window-size", "Visualisation", "Create initial window with the given x,y size");
350 
351  oc.doRegister("window-pos", new Option_StringVector());
352  oc.addDescription("window-pos", "Visualisation", "Create initial window at the given x,y position");
353 
354  // testing
355 
356  oc.doRegister("gui-testing", new Option_Bool(false));
357  oc.addDescription("gui-testing", "Visualisation", "Enable overlay for screen recognition");
358 
359  oc.doRegister("gui-testing-debug", new Option_Bool(false));
360  oc.addDescription("gui-testing-debug", "Visualisation", "Enable output messages during GUI-Testing");
361 
362  oc.doRegister("gui-testing-debug-gl", new Option_Bool(false));
363  oc.addDescription("gui-testing-debug-gl", "Visualisation", "Enable output messages during GUI-Testing specific of gl functions");
364 
365  oc.doRegister("gui-testing.setting-output", new Option_FileName());
366  oc.addDescription("gui-testing.setting-output", "Visualisation", "Save gui settings in the given settings-output file");
367 
368  // register the simulation settings (needed for GNERouteHandler)
369  oc.doRegister("begin", new Option_String("0", "TIME"));
370  oc.addDescription("begin", "Time", "Defines the begin time in seconds; The simulation starts at this time");
371 
372  oc.doRegister("end", new Option_String("-1", "TIME"));
373  oc.addDescription("end", "Time", "Defines the end time in seconds; The simulation ends at this time");
374 
375  oc.doRegister("default.action-step-length", new Option_Float(0.0));
376  oc.addDescription("default.action-step-length", "Processing", "Length of the default interval length between action points for the car-following and lane-change models (in seconds). If not specified, the simulation step-length is used per default. Vehicle- or VType-specific settings override the default. Must be a multiple of the simulation step-length.");
377 
378  NIFrame::fillOptions(true);
379  NBFrame::fillOptions(false);
380  NWFrame::fillOptions(false);
382 }
383 
384 
385 void
387  oc.resetWritable();
388  oc.set("offset.disable-normalization", "true"); // preserve the given network as far as possible
389  oc.set("no-turnarounds", "true"); // otherwise it is impossible to manually removed turn-arounds
390 }
391 
392 
393 bool
396  // fill all optiones
397  fillOptions(oc);
398  // set manually the net file
399  if (myFile != "") {
400  if (myLoadNet) {
401  oc.set("sumo-net-file", myFile);
402  } else {
403  oc.set("configuration-file", myFile);
404  }
405  }
406  // set default options defined in GNELoadThread::setDefaultOptions(...)
407  setDefaultOptions(oc);
408  try {
409  // set all values writables, because certain attributes already setted can be updated throught console
410  oc.resetWritable();
411  // load options from console
413  // if output file wasn't defined in the command line manually, set value of "sumo-net-file"
414  if (!oc.isSet("output-file")) {
415  oc.set("output-file", oc.getString("sumo-net-file"));
416  }
417  return true;
418  } catch (ProcessError& e) {
419  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
420  WRITE_ERROR(e.what());
421  }
422  WRITE_ERROR("Failed to parse options.");
423  return false;
424  }
425 }
426 
427 
428 void
429 GNELoadThread::loadConfigOrNet(const std::string& file, bool isNet, bool useStartupOptions, bool newNet) {
430  myFile = file;
431  myLoadNet = isNet;
432  if (myFile != "" && !useStartupOptions) {
433  OptionsIO::setArgs(0, nullptr);
434  }
435  myNewNet = newNet;
436  start();
437 }
438 
439 
440 void
441 GNELoadThread::retrieveMessage(const MsgHandler::MsgType type, const std::string& msg) {
442  GUIEvent* e = new GUIEvent_Message(type, msg);
445 }
446 
447 
448 /****************************************************************************/
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:282
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:288
void push_back(T what)
Definition: FXSynchQue.h:114
OutputDevice * myErrorRetriever
The instances of message retriever encapsulations Needed to be deleted from the handler later on.
Definition: GNELoadThread.h:90
void retrieveMessage(const MsgHandler::MsgType type, const std::string &msg)
Retrieves messages from the loading module.
FXSynchQue< GUIEvent * > & myEventQue
event Queue
Definition: GNELoadThread.h:93
void loadConfigOrNet(const std::string &file, bool isNet, bool useStartupOptions, bool newNet=false)
begins the loading of a netconvert configuration or a a network
OutputDevice * myWarningRetriever
Definition: GNELoadThread.h:90
bool myNewNet
if true, a new net is created
OutputDevice * myMessageRetriever
Definition: GNELoadThread.h:90
virtual ~GNELoadThread()
destructor
OutputDevice * myGLDebugRetriever
Definition: GNELoadThread.h:90
std::string myFile
the path to load the network from
Definition: GNELoadThread.h:87
OutputDevice * myDebugRetriever
Definition: GNELoadThread.h:90
static void fillOptions(OptionsCont &oc)
clears and initializes the OptionsCont
bool initOptions()
init options
GNELoadThread(FXApp *app, MFXInterThreadEventClient *mw, FXSynchQue< GUIEvent * > &eq, FXEX::FXThreadEvent &ev)
constructor
bool myLoadNet
Information whether only the network shall be loaded.
Definition: GNELoadThread.h:99
static void setDefaultOptions(OptionsCont &oc)
sets required options for proper functioning
FXint run()
starts the thread. The thread ends after the net has been loaded
FXEX::FXThreadEvent & myEventThrow
event throw
Definition: GNELoadThread.h:96
void submitEndAndCleanup(GNENet *net, const bool newNet=false, const std::string &guiSettingsFile="", const bool viewportFromRegistry=false)
Closes the loading process.
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:42
void computeAndUpdate(OptionsCont &oc, bool volatileOptions)
recompute the network and update lane geometries
Definition: GNENet.cpp:2547
static void addProjectionOptions(OptionsCont &oc)
Adds projection options to the given container.
static bool init(OptionsCont &oc)
Initialises the processing and the final instance using the given options.
static void computeFinal(bool lefthand=false)
compute the location attributes which will be used for output based on the loaded location data,...
virtual void addRetriever(OutputDevice *retriever)
Adds a further retriever to the instance responsible for a certain msg type.
Definition: MsgHandler.cpp:186
static MsgHandler * getGLDebugInstance()
Returns the instance to add GLdebug to.
Definition: MsgHandler.cpp:98
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:80
static void enableDebugGLMessages(bool enable)
enable/disable gl-debug messages
Definition: MsgHandler.cpp:112
static void initOutputOptions()
init output options
Definition: MsgHandler.cpp:228
static MsgHandler * getDebugInstance()
Returns the instance to add debug to.
Definition: MsgHandler.cpp:89
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
Definition: MsgHandler.cpp:67
static void enableDebugMessages(bool enable)
enable/disable debug messages
Definition: MsgHandler.cpp:107
virtual void clear(bool resetInformed=true)
Clears information whether an error occurred previously and print aggregated message summary.
Definition: MsgHandler.cpp:162
virtual void removeRetriever(OutputDevice *retriever)
Removes the retriever from the handler.
Definition: MsgHandler.cpp:194
@ MT_GLDEBUG
The message is GL debug output.
@ MT_DEBUG
The message is debug output.
@ MT_MESSAGE
The message is only something to show.
@ MT_ERROR
The message is an error.
@ MT_WARNING
The message is a warning.
static MsgHandler * getMessageInstance()
Returns the instance to add normal messages to.
Definition: MsgHandler.cpp:54
Encapsulates an object's method for using it as a message retriever.
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NBFrame.cpp:670
static void fillOptions(bool forNetgen)
Inserts options used by the network converter.
Definition: NBFrame.cpp:47
Instance responsible for building networks.
Definition: NBNetBuilder.h:107
void applyOptions(OptionsCont &oc)
Initialises the storage by applying given options.
void compute(OptionsCont &oc, const std::set< std::string > &explicitTurnarounds=std::set< std::string >(), bool mayAddOrRemove=true)
Performs the network building steps.
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NIFrame.cpp:368
static void fillOptions(bool forNetedit=false)
Inserts options used by the network importer and network building modules.
Definition: NIFrame.cpp:47
Perfoms network import.
Definition: NILoader.h:48
void load(OptionsCont &oc)
Definition: NILoader.cpp:70
static void fillOptions(bool forNetgen)
Inserts options used by the network writer.
Definition: NWFrame.cpp:48
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NWFrame.cpp:125
A storage for options typed value containers)
Definition: OptionsCont.h:89
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:75
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
bool set(const std::string &name, const std::string &value)
Sets the given value for the named option.
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
void addSynonyme(const std::string &name1, const std::string &name2, bool isDeprecated=false)
Adds a synonyme for an options name (any order)
Definition: OptionsCont.cpp:96
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
void clear()
Removes all information from the container.
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
void resetWritable()
Resets all options to be writeable.
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
void addCallExample(const std::string &example, const std::string &desc)
Add a call example.
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:85
static void insertRandOptions()
Initialises the given options container with random number options.
Definition: RandHelper.cpp:43
static void initRandGlobal(SumoRNG *which=nullptr)
Reads the given random number options and initialises the random number generator in accordance.
Definition: RandHelper.cpp:75
static void addConfigurationOptions(OptionsCont &oc)
Adds configuration options to the given container.
Definition: SystemFrame.cpp:38
static bool checkOptions()
checks shared options and sets StdDefs
static void setValidation(const std::string &validationScheme, const std::string &netValidationScheme, const std::string &routeValidationScheme)
Enables or disables validation.
Definition: XMLSubSys.cpp:65