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-2016 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 #ifdef CHECK_MEMORY_LEAKS
59 #include <foreign/nvwa/debug_new.h>
60 #endif // CHECK_MEMORY_LEAKS
61 
62 
63 // ===========================================================================
64 // member method definitions
65 // ===========================================================================
67  FXSingleEventThread(app, mw), myParent(mw), myEventQue(eq),
68  myEventThrow(ev) {
73 }
74 
75 
77  delete myErrorRetriever;
78  delete myMessageRetriever;
79  delete myWarningRetriever;
80 }
81 
82 
83 FXint
85  // register message callbacks
89 
90  GNENet* net = 0;
91 
92  // try to load the given configuration
94  oc.clear();
95  if (!initOptions()) {
97  return 0;
98  }
100  if (!(NIFrame::checkOptions() &&
103  // options are not valid
104  WRITE_ERROR("Invalid Options. Nothing loaded");
105  submitEndAndCleanup(net);
106  return 0;
107  }
111 
113  if (!GeoConvHelper::init(oc)) {
114  WRITE_ERROR("Could not build projection!");
115  submitEndAndCleanup(net);
116  return 0;
117  }
118  XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"));
119  // this netbuilder instance becomes the responsibility of the GNENet
120  NBNetBuilder* netBuilder = new NBNetBuilder();
121 
122  netBuilder->applyOptions(oc);
123 
124  if (myNewNet) {
125  // create new network
126  net = new GNENet(netBuilder);
127  } else {
128  NILoader nl(*netBuilder);
129  try {
130  nl.load(oc);
131 
132  if (!myLoadNet) {
133  WRITE_MESSAGE("Performing initial computation ...\n");
134  // perform one-time processing (i.e. edge removal)
135  netBuilder->compute(oc);
136  // @todo remove one-time processing options!
137  } else {
138  // make coordinate conversion usable before first netBuilder->compute()
140  }
141 
142  if (oc.getBool("ignore-errors")) {
144  }
145 
146  // check whether any errors occured
147  if (MsgHandler::getErrorInstance()->wasInformed()) {
148  throw ProcessError();
149  } else {
150  net = new GNENet(netBuilder);
151  }
152 
153  // enable load additionals after creation of net if was specified in the command line
154  if (myAdditionalFile != "") {
156  }
157 
158  // Set additionals output file
159  if (myAdditionalOutputFile != "") {
161  }
162  } catch (ProcessError& e) {
163  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
164  WRITE_ERROR(e.what());
165  }
166  WRITE_ERROR("Failed to build network.");
167  delete net;
168  delete netBuilder;
169  net = 0;
170  } catch (std::exception& e) {
171  WRITE_ERROR(e.what());
172 #ifdef _DEBUG
173  throw;
174 #endif
175  delete net;
176  delete netBuilder;
177  net = 0;
178  }
179  }
180  // only a single setting file is supported
181  submitEndAndCleanup(net, oc.getString("gui-settings-file"), oc.getBool("registry-viewport"));
182  return 0;
183 }
184 
185 
186 
187 void
188 GNELoadThread::submitEndAndCleanup(GNENet* net, const std::string& guiSettingsFile, const bool viewportFromRegistry) {
189  // remove message callbacks
193  // inform parent about the process
194  GUIEvent* e = new GNEEvent_NetworkLoaded(net, myFile, guiSettingsFile, viewportFromRegistry);
195  myEventQue.add(e);
197 }
198 
199 
200 void
202  oc.clear();
203  oc.addCallExample("", "start plain GUI with empty net");
204  oc.addCallExample("-c <CONFIGURATION>", "edit net with options read from file");
205 
206  SystemFrame::addConfigurationOptions(oc); // this subtopic is filled here, too
207  oc.addOptionSubTopic("Input");
208  oc.addOptionSubTopic("Output");
210  oc.addOptionSubTopic("TLS Building");
211  oc.addOptionSubTopic("Ramp Guessing");
212  oc.addOptionSubTopic("Edge Removal");
213  oc.addOptionSubTopic("Unregulated Nodes");
214  oc.addOptionSubTopic("Processing");
215  oc.addOptionSubTopic("Building Defaults");
216  oc.addOptionSubTopic("Visualisation");
217 
218  oc.doRegister("new", new Option_Bool(false)); // !!!
219  oc.addDescription("new", "Input", "Start with a new network");
220 
221  oc.doRegister("sumo-additionals-file", new Option_String());
222  oc.addDescription("sumo-additionals-file", "Input", "load additionals");
223 
224  oc.doRegister("disable-laneIcons", new Option_Bool(false));
225  oc.addDescription("disable-laneIcons", "Visualisation", "Disable icons of special lanes");
226 
227  oc.doRegister("disable-textures", 'T', new Option_Bool(false)); // !!!
228  oc.addDescription("disable-textures", "Visualisation", "");
229 
230  oc.doRegister("gui-settings-file", new Option_FileName());
231  oc.addDescription("gui-settings-file", "Visualisation", "Load visualisation settings from FILE");
232 
233  oc.doRegister("registry-viewport", new Option_Bool(false));
234  oc.addDescription("registry-viewport", "Visualisation", "Load current viewport from registry");
235 
236  oc.doRegister("window-size", new Option_String());
237  oc.addDescription("window-size", "Visualisation", "Create initial window with the given x,y size");
238 
239  oc.doRegister("additionals-output", new Option_String());
240  oc.addDescription("additionals-output", "Output", "default value for additionals output file");
241 
242  SystemFrame::addReportOptions(oc); // this subtopic is filled here, too
243 
245  NBFrame::fillOptions(false);
246  NWFrame::fillOptions(false);
248 }
249 
250 
251 void
253  oc.set("offset.disable-normalization", "true"); // preserve the given network as far as possible
254  oc.set("no-turnarounds", "true"); // otherwise it is impossible to manually removed turn-arounds
255 }
256 
257 
258 bool
261  fillOptions(oc);
262  if (myFile != "") {
263  if (myLoadNet) {
264  oc.set("sumo-net-file", myFile);
265  } else {
266  oc.set("configuration-file", myFile);
267  }
268  }
269  setDefaultOptions(oc);
270  try {
272  if (!oc.isSet("output-file")) {
273  oc.set("output-file", oc.getString("sumo-net-file"));
274  }
275  return true;
276  } catch (ProcessError& e) {
277  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
278  WRITE_ERROR(e.what());
279  }
280  WRITE_ERROR("Failed to parse options.");
281  }
282  return false;
283 }
284 
285 
286 void
287 GNELoadThread::loadConfigOrNet(const std::string& file, bool isNet, bool useStartupOptions, bool newNet) {
288  myFile = file;
289  myLoadNet = isNet;
290 
291  const OptionsCont& OC = OptionsCont::getOptions();
292  if (OC.isSet("sumo-additionals-file")) {
293  myAdditionalFile = OC.getString("sumo-additionals-file");
294  }
295  if (OC.isSet("additionals-output")) {
296  myAdditionalOutputFile = OC.getString("additionals-output");
297  }
298 
299  if (myFile != "" && !useStartupOptions) {
300  OptionsIO::setArgs(0, 0);
301  }
302  myNewNet = newNet;
303  start();
304 }
305 
306 
307 void
308 GNELoadThread::retrieveMessage(const MsgHandler::MsgType type, const std::string& msg) {
309  GUIEvent* e = new GUIEvent_Message(type, msg);
310  myEventQue.add(e);
312 }
313 
314 /****************************************************************************/
315 
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
Definition: MsgHandler.cpp:71
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:86
FXEX::FXThreadEvent & myEventThrow
event throw
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:80
static void insertRandOptions()
Initialises the given options container with random number options.
Definition: RandHelper.cpp:53
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NWFrame.cpp:111
OutputDevice * myWarningRetriever
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NBFrame.cpp:428
static void getOptions(const bool commandLineOnly=false)
Parses the command line arguments and loads the configuration.
Definition: OptionsIO.cpp:72
static void addReportOptions(OptionsCont &oc)
Adds reporting options to the given container.
Definition: SystemFrame.cpp:75
static void setValidation(const std::string &validationScheme, const std::string &netValidationScheme)
Enables or disables validation.
Definition: XMLSubSys.cpp:69
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
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:59
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:87
void addRetriever(OutputDevice *retriever)
Adds a further retriever to the instance responsible for a certain msg type.
Definition: MsgHandler.cpp:161
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:50
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:65
std::string myAdditionalOutputFile
filename for the additionals output
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:69
static void initRandGlobal(MTRand *which=0)
Reads the given random number options and initialises the random number generator in accordance...
Definition: RandHelper.cpp:68
Perfoms network import.
Definition: NILoader.h:59
static void setDefaultOptions(OptionsCont &oc)
sets required options for proper functioning
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.
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:175
static MsgHandler * getMessageInstance()
Returns the instance to add normal messages to.
Definition: MsgHandler.cpp:62
void load(OptionsCont &oc)
Definition: NILoader.cpp:87
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
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:277
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
void setAdditionalsOutputFile(const std::string &additionalOutputFile)
set additionals File
Definition: GNENet.cpp:1181
void setAdditionalsFile(const std::string &additionalFile)
set additionals File
Definition: GNENet.cpp:1175
#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
std::string myAdditionalFile
filename with additionals input
Instance responsible for building networks.
Definition: NBNetBuilder.h:112
OutputDevice * myMessageRetriever
A storage for options typed value containers)
Definition: OptionsCont.h:99
std::string myFile
the path to load the simulation from
Definition: GNELoadThread.h:99
static void fillOptions(bool forNetgen)
Inserts options used by the network converter.
Definition: NBFrame.cpp:61
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:63
void clear()
Clears information whether an error occured previously.
Definition: MsgHandler.cpp:149
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:201
static void initOutputOptions()
Definition: MsgHandler.cpp:197
static void fillOptions(OptionsCont &oc)
clears and initializes the OptionsCont
The message is an error.
Definition: MsgHandler.h:66
virtual ~GNELoadThread()
destructor