SUMO - Simulation of Urban MObility
GNELoadThread.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // The thread that performs the loading of a Netedit-net (adapted from
8 // GUILoadThread)
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2001-2017 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #ifdef _MSC_VER
27 #include <windows_config.h>
28 #else
29 #include <config.h>
30 #endif
31 
32 #include <iostream>
33 #include <ctime>
34 #include <utils/xml/XMLSubSys.h>
44 #include <utils/options/Option.h>
47 #include <netbuild/NBFrame.h>
48 #include <netimport/NILoader.h>
49 #include <netimport/NIFrame.h>
50 #include <netwrite/NWFrame.h>
51 #include <netbuild/NBFrame.h>
52 
53 #include "GNELoadThread.h"
54 #include "GNENet.h"
55 #include "GNEEvent_NetworkLoaded.h"
56 #include "GNEAdditionalHandler.h"
57 
58 
59 // ===========================================================================
60 // member method definitions
61 // ===========================================================================
63  FXSingleEventThread(app, mw), myParent(mw), myEventQue(eq),
64  myEventThrow(ev) {
69 }
70 
71 
73  delete myErrorRetriever;
74  delete myMessageRetriever;
75  delete myWarningRetriever;
76 }
77 
78 
79 FXint
81  // register message callbacks
85 
86  GNENet* net = 0;
87 
88  // try to load the given configuration
90  oc.clear();
91  if (!initOptions()) {
93  return 0;
94  }
96  if (!(NIFrame::checkOptions() &&
100  // options are not valid
101  WRITE_ERROR("Invalid Options. Nothing loaded");
102  submitEndAndCleanup(net);
103  return 0;
104  }
108 
110  if (!GeoConvHelper::init(oc)) {
111  WRITE_ERROR("Could not build projection!");
112  submitEndAndCleanup(net);
113  return 0;
114  }
115  XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"));
116  // this netbuilder instance becomes the responsibility of the GNENet
117  NBNetBuilder* netBuilder = new NBNetBuilder();
118 
119  netBuilder->applyOptions(oc);
120 
121  if (myNewNet) {
122  // create new network
123  net = new GNENet(netBuilder);
124  } else {
125  NILoader nl(*netBuilder);
126  try {
127  nl.load(oc);
128 
129  if (!myLoadNet) {
130  WRITE_MESSAGE("Performing initial computation ...\n");
131  // perform one-time processing (i.e. edge removal)
132  netBuilder->compute(oc);
133  // @todo remove one-time processing options!
134  } else {
135  // make coordinate conversion usable before first netBuilder->compute()
137  }
138 
139  if (oc.getBool("ignore-errors")) {
141  }
142 
143  // check whether any errors occured
144  if (MsgHandler::getErrorInstance()->wasInformed()) {
145  throw ProcessError();
146  } else {
147  net = new GNENet(netBuilder);
148  if (oc.getBool("lefthand")) {
149  // force initial geometry computation without volatile options because the net will look strange otherwise
150  net->computeAndUpdate(oc, false);
151  }
152  }
153 
154  } catch (ProcessError& e) {
155  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
156  WRITE_ERROR(e.what());
157  }
158  WRITE_ERROR("Failed to build network.");
159  delete net;
160  delete netBuilder;
161  net = 0;
162  } catch (std::exception& e) {
163  WRITE_ERROR(e.what());
164 #ifdef _DEBUG
165  throw;
166 #endif
167  delete net;
168  delete netBuilder;
169  net = 0;
170  }
171  }
172  // only a single setting file is supported
173  submitEndAndCleanup(net, oc.getString("gui-settings-file"), oc.getBool("registry-viewport"));
174  return 0;
175 }
176 
177 
178 
179 void
180 GNELoadThread::submitEndAndCleanup(GNENet* net, const std::string& guiSettingsFile, const bool viewportFromRegistry) {
181  // remove message callbacks
185  // inform parent about the process
186  GUIEvent* e = new GNEEvent_NetworkLoaded(net, myFile, guiSettingsFile, viewportFromRegistry);
187  myEventQue.add(e);
189 }
190 
191 
192 void
194  oc.clear();
195  oc.addCallExample("", "start plain GUI with empty net");
196  oc.addCallExample("-c <CONFIGURATION>", "edit net with options read from file");
197 
198  SystemFrame::addConfigurationOptions(oc); // this subtopic is filled here, too
199  oc.addOptionSubTopic("Input");
200  oc.addOptionSubTopic("Output");
202  oc.addOptionSubTopic("TLS Building");
203  oc.addOptionSubTopic("Ramp Guessing");
204  oc.addOptionSubTopic("Edge Removal");
205  oc.addOptionSubTopic("Unregulated Nodes");
206  oc.addOptionSubTopic("Processing");
207  oc.addOptionSubTopic("Building Defaults");
208  oc.addOptionSubTopic("Visualisation");
209 
210  oc.doRegister("new", new Option_Bool(false)); // !!!
211  oc.addDescription("new", "Input", "Start with a new network");
212 
213  oc.doRegister("sumo-additionals-file", new Option_String());
214  oc.addDescription("sumo-additionals-file", "Input", "file in which additionals are loaded");
215 
216  oc.doRegister("additionals-output", new Option_String());
217  oc.addDescription("additionals-output", "Output", "file in which additionals must be saved");
218 
219  oc.doRegister("sumo-shapes-file", new Option_String());
220  oc.addDescription("sumo-shapes-file", "Input", "file in which shapes are loaded");
221 
222  oc.doRegister("shapes-output", new Option_String());
223  oc.addDescription("shapes-output", "Output", "file in which shapes must be saved");
224 
225  oc.doRegister("disable-laneIcons", new Option_Bool(false));
226  oc.addDescription("disable-laneIcons", "Visualisation", "Disable icons of special lanes");
227 
228  oc.doRegister("disable-textures", 'T', new Option_Bool(false)); // !!!
229  oc.addDescription("disable-textures", "Visualisation", "");
230 
231  oc.doRegister("gui-settings-file", new Option_FileName());
232  oc.addDescription("gui-settings-file", "Visualisation", "Load visualisation settings from FILE");
233 
234  oc.doRegister("registry-viewport", new Option_Bool(false));
235  oc.addDescription("registry-viewport", "Visualisation", "Load current viewport from registry");
236 
237  oc.doRegister("window-size", new Option_String());
238  oc.addDescription("window-size", "Visualisation", "Create initial window with the given x,y size");
239 
240  oc.doRegister("window-pos", new Option_String());
241  oc.addDescription("window-pos", "Visualisation", "Create initial window at the given x,y position");
242 
243  oc.doRegister("gui-testing", new Option_Bool(false));
244  oc.addDescription("gui-testing", "Visualisation", "Enable ovelay for screen recognition");
245 
246  oc.doRegister("gui-testing-debug", new Option_Bool(false));
247  oc.addDescription("gui-testing-debug", "Visualisation", "Enable output messages during GUI-Testing");
248 
249  SystemFrame::addReportOptions(oc); // this subtopic is filled here, too
250 
252  NBFrame::fillOptions(false);
253  NWFrame::fillOptions(false);
255 }
256 
257 
258 void
260  oc.set("offset.disable-normalization", "true"); // preserve the given network as far as possible
261  oc.set("no-turnarounds", "true"); // otherwise it is impossible to manually removed turn-arounds
262 }
263 
264 
265 bool
268  fillOptions(oc);
269  if (myFile != "") {
270  if (myLoadNet) {
271  oc.set("sumo-net-file", myFile);
272  } else {
273  oc.set("configuration-file", myFile);
274  }
275  }
276  setDefaultOptions(oc);
277  try {
279  if (!oc.isSet("output-file")) {
280  oc.set("output-file", oc.getString("sumo-net-file"));
281  }
282  return true;
283  } catch (ProcessError& e) {
284  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
285  WRITE_ERROR(e.what());
286  }
287  WRITE_ERROR("Failed to parse options.");
288  }
289  return false;
290 }
291 
292 
293 void
294 GNELoadThread::loadConfigOrNet(const std::string& file, bool isNet, bool useStartupOptions, bool newNet) {
295  myFile = file;
296  myLoadNet = isNet;
297  if (myFile != "" && !useStartupOptions) {
298  OptionsIO::setArgs(0, 0);
299  }
300  myNewNet = newNet;
301  start();
302 }
303 
304 
305 void
306 GNELoadThread::retrieveMessage(const MsgHandler::MsgType type, const std::string& msg) {
307  GUIEvent* e = new GUIEvent_Message(type, msg);
308  myEventQue.add(e);
310 }
311 
312 /****************************************************************************/
313 
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
Definition: MsgHandler.cpp:67
The message is only something to show.
Definition: MsgHandler.h:62
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:82
FXEX::FXThreadEvent & myEventThrow
event throw
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:48
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NWFrame.cpp:121
OutputDevice * myWarningRetriever
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NBFrame.cpp:459
static void getOptions(const bool commandLineOnly=false)
Parses the command line arguments and loads the configuration.
Definition: OptionsIO.cpp:82
static void addReportOptions(OptionsCont &oc)
Adds reporting options to the given container.
Definition: SystemFrame.cpp:72
GNELoadThread(FXApp *app, MFXInterThreadEventClient *mw, MFXEventQue< GUIEvent * > &eq, FXEX::FXThreadEvent &ev)
constructor
static void setValidation(const std::string &validationScheme, const std::string &netValidationScheme)
Enables or disables validation.
Definition: XMLSubSys.cpp:65
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:59
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
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
OutputDevice * myErrorRetriever
The instances of message retriever encapsulations Needed to be deleted from the handler later on...
static void fillOptions()
Inserts options used by the network importer and network building modules.
Definition: NIFrame.cpp:56
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:92
void addRetriever(OutputDevice *retriever)
Adds a further retriever to the instance responsible for a certain msg type.
Definition: MsgHandler.cpp:157
static void addConfigurationOptions(OptionsCont &oc)
Adds configuration options to the given container.
Definition: SystemFrame.cpp:47
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:62
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:65
Perfoms network import.
Definition: NILoader.h:59
static void setDefaultOptions(OptionsCont &oc)
sets required options for proper functioning
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool myNewNet
if true, a new net is created
bool myLoadNet
Information whether only the network shall be loaded.
void clear()
Removes all information from the container.
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:171
static MsgHandler * getMessageInstance()
Returns the instance to add normal messages to.
Definition: MsgHandler.cpp:58
void load(OptionsCont &oc)
Definition: NILoader.cpp:80
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
static bool checkOptions()
checks shared options and sets StdDefs
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NIFrame.cpp:291
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:206
The message is a warning.
Definition: MsgHandler.h:64
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
Instance responsible for building networks.
Definition: NBNetBuilder.h:115
OutputDevice * myMessageRetriever
A storage for options typed value containers)
Definition: OptionsCont.h:99
static void initRandGlobal(std::mt19937 *which=0)
Reads the given random number options and initialises the random number generator in accordance...
Definition: RandHelper.cpp:77
std::string myFile
the path to load the simulation from
Definition: GNELoadThread.h:99
void computeAndUpdate(OptionsCont &oc, bool volatileOptions)
recompute the network and update lane geometries
Definition: GNENet.cpp:2238
static void fillOptions(bool forNetgen)
Inserts options used by the network converter.
Definition: NBFrame.cpp:56
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:59
void clear()
Clears information whether an error occured previously.
Definition: MsgHandler.cpp:145
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:201
static void initOutputOptions()
Definition: MsgHandler.cpp:193
static void fillOptions(OptionsCont &oc)
clears and initializes the OptionsCont
The message is an error.
Definition: MsgHandler.h:66
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
virtual ~GNELoadThread()
destructor