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-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
17 // The thread that performs the loading of a Netedit-net (adapted from
18 // GUILoadThread)
19 /****************************************************************************/
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 
31 #include <iostream>
32 #include <ctime>
33 #include <utils/xml/XMLSubSys.h>
43 #include <utils/options/Option.h>
46 #include <netbuild/NBFrame.h>
47 #include <netimport/NILoader.h>
48 #include <netimport/NIFrame.h>
49 #include <netwrite/NWFrame.h>
50 #include <netbuild/NBFrame.h>
51 
52 #include "GNELoadThread.h"
53 #include "GNENet.h"
54 #include "GNEEvent_NetworkLoaded.h"
55 #include "GNEAdditionalHandler.h"
56 
57 
58 // ===========================================================================
59 // member method definitions
60 // ===========================================================================
62  FXSingleEventThread(app, mw), myParent(mw), myEventQue(eq),
63  myEventThrow(ev) {
68 }
69 
70 
72  delete myErrorRetriever;
73  delete myMessageRetriever;
74  delete myWarningRetriever;
75 }
76 
77 
78 FXint
80  // register message callbacks
84 
85  GNENet* net = 0;
86 
87  // try to load the given configuration
89  oc.clear();
90  if (!initOptions()) {
92  return 0;
93  }
95  if (!(NIFrame::checkOptions() &&
99  // options are not valid
100  WRITE_ERROR("Invalid Options. Nothing loaded");
101  submitEndAndCleanup(net);
102  return 0;
103  }
107 
109  if (!GeoConvHelper::init(oc)) {
110  WRITE_ERROR("Could not build projection!");
111  submitEndAndCleanup(net);
112  return 0;
113  }
114  XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"));
115  // this netbuilder instance becomes the responsibility of the GNENet
116  NBNetBuilder* netBuilder = new NBNetBuilder();
117 
118  netBuilder->applyOptions(oc);
119 
120  if (myNewNet) {
121  // create new network
122  net = new GNENet(netBuilder);
123  } else {
124  NILoader nl(*netBuilder);
125  try {
126  nl.load(oc);
127 
128  if (!myLoadNet) {
129  WRITE_MESSAGE("Performing initial computation ...\n");
130  // perform one-time processing (i.e. edge removal)
131  netBuilder->compute(oc);
132  // @todo remove one-time processing options!
133  } else {
134  // make coordinate conversion usable before first netBuilder->compute()
136  }
137 
138  if (oc.getBool("ignore-errors")) {
140  }
141 
142  // check whether any errors occured
143  if (MsgHandler::getErrorInstance()->wasInformed()) {
144  throw ProcessError();
145  } else {
146  net = new GNENet(netBuilder);
147  if (oc.getBool("lefthand")) {
148  // force initial geometry computation without volatile options because the net will look strange otherwise
149  net->computeAndUpdate(oc, false);
150  }
151  }
152 
153  } catch (ProcessError& e) {
154  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
155  WRITE_ERROR(e.what());
156  }
157  WRITE_ERROR("Failed to build network.");
158  delete net;
159  delete netBuilder;
160  net = 0;
161  } catch (std::exception& e) {
162  WRITE_ERROR(e.what());
163 #ifdef _DEBUG
164  throw;
165 #endif
166  delete net;
167  delete netBuilder;
168  net = 0;
169  }
170  }
171  // only a single setting file is supported
172  submitEndAndCleanup(net, oc.getString("gui-settings-file"), oc.getBool("registry-viewport"));
173  return 0;
174 }
175 
176 
177 
178 void
179 GNELoadThread::submitEndAndCleanup(GNENet* net, const std::string& guiSettingsFile, const bool viewportFromRegistry) {
180  // remove message callbacks
184  // inform parent about the process
185  GUIEvent* e = new GNEEvent_NetworkLoaded(net, myFile, guiSettingsFile, viewportFromRegistry);
186  myEventQue.add(e);
188 }
189 
190 
191 void
193  oc.clear();
194  oc.addCallExample("", "start plain GUI with empty net");
195  oc.addCallExample("-c <CONFIGURATION>", "edit net with options read from file");
196 
197  SystemFrame::addConfigurationOptions(oc); // this subtopic is filled here, too
198  oc.addOptionSubTopic("Input");
199  oc.addOptionSubTopic("Output");
201  oc.addOptionSubTopic("TLS Building");
202  oc.addOptionSubTopic("Ramp Guessing");
203  oc.addOptionSubTopic("Edge Removal");
204  oc.addOptionSubTopic("Unregulated Nodes");
205  oc.addOptionSubTopic("Processing");
206  oc.addOptionSubTopic("Building Defaults");
207  oc.addOptionSubTopic("Visualisation");
208 
209  oc.doRegister("new", new Option_Bool(false)); // !!!
210  oc.addDescription("new", "Input", "Start with a new network");
211 
212  oc.doRegister("sumo-additionals-file", new Option_String());
213  oc.addDescription("sumo-additionals-file", "Input", "file in which additionals are loaded");
214 
215  oc.doRegister("additionals-output", new Option_String());
216  oc.addDescription("additionals-output", "Output", "file in which additionals must be saved");
217 
218  oc.doRegister("sumo-shapes-file", new Option_String());
219  oc.addDescription("sumo-shapes-file", "Input", "file in which shapes are loaded");
220 
221  oc.doRegister("shapes-output", new Option_String());
222  oc.addDescription("shapes-output", "Output", "file in which shapes must be saved");
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("window-pos", new Option_String());
240  oc.addDescription("window-pos", "Visualisation", "Create initial window at the given x,y position");
241 
242  oc.doRegister("gui-testing", new Option_Bool(false));
243  oc.addDescription("gui-testing", "Visualisation", "Enable ovelay for screen recognition");
244 
245  oc.doRegister("gui-testing-debug", new Option_Bool(false));
246  oc.addDescription("gui-testing-debug", "Visualisation", "Enable output messages during GUI-Testing");
247 
248  SystemFrame::addReportOptions(oc); // this subtopic is filled here, too
249 
251  NBFrame::fillOptions(false);
252  NWFrame::fillOptions(false);
254 }
255 
256 
257 void
259  oc.set("offset.disable-normalization", "true"); // preserve the given network as far as possible
260  oc.set("no-turnarounds", "true"); // otherwise it is impossible to manually removed turn-arounds
261 }
262 
263 
264 bool
267  fillOptions(oc);
268  if (myFile != "") {
269  if (myLoadNet) {
270  oc.set("sumo-net-file", myFile);
271  } else {
272  oc.set("configuration-file", myFile);
273  }
274  }
275  setDefaultOptions(oc);
276  try {
278  if (!oc.isSet("output-file")) {
279  oc.set("output-file", oc.getString("sumo-net-file"));
280  }
281  return true;
282  } catch (ProcessError& e) {
283  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
284  WRITE_ERROR(e.what());
285  }
286  WRITE_ERROR("Failed to parse options.");
287  }
288  return false;
289 }
290 
291 
292 void
293 GNELoadThread::loadConfigOrNet(const std::string& file, bool isNet, bool useStartupOptions, bool newNet) {
294  myFile = file;
295  myLoadNet = isNet;
296  if (myFile != "" && !useStartupOptions) {
297  OptionsIO::setArgs(0, 0);
298  }
299  myNewNet = newNet;
300  start();
301 }
302 
303 
304 void
305 GNELoadThread::retrieveMessage(const MsgHandler::MsgType type, const std::string& msg) {
306  GUIEvent* e = new GUIEvent_Message(type, msg);
307  myEventQue.add(e);
309 }
310 
311 /****************************************************************************/
312 
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
Definition: MsgHandler.cpp:66
The message is only something to show.
Definition: MsgHandler.h:61
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:81
FXEX::FXThreadEvent & myEventThrow
event throw
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:75
static void insertRandOptions()
Initialises the given options container with random number options.
Definition: RandHelper.cpp:47
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NWFrame.cpp:131
OutputDevice * myWarningRetriever
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NBFrame.cpp:461
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:71
static void setValidation(const std::string &validationScheme, const std::string &netValidationScheme)
Enables or disables validation.
Definition: XMLSubSys.cpp:64
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:58
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:55
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:91
void addRetriever(OutputDevice *retriever)
Adds a further retriever to the instance responsible for a certain msg type.
Definition: MsgHandler.cpp:156
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:46
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:61
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:64
Perfoms network import.
Definition: NILoader.h:58
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:170
static MsgHandler * getMessageInstance()
Returns the instance to add normal messages to.
Definition: MsgHandler.cpp:57
void load(OptionsCont &oc)
Definition: NILoader.cpp:79
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:299
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:205
The message is a warning.
Definition: MsgHandler.h:63
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:98
static void initRandGlobal(std::mt19937 *which=0)
Reads the given random number options and initialises the random number generator in accordance...
Definition: RandHelper.cpp:76
std::string myFile
the path to load the simulation from
Definition: GNELoadThread.h:98
void computeAndUpdate(OptionsCont &oc, bool volatileOptions)
recompute the network and update lane geometries
Definition: GNENet.cpp:2302
static void fillOptions(bool forNetgen)
Inserts options used by the network converter.
Definition: NBFrame.cpp:55
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:58
void clear()
Clears information whether an error occured previously.
Definition: MsgHandler.cpp:144
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:200
static void initOutputOptions()
Definition: MsgHandler.cpp:192
static void fillOptions(OptionsCont &oc)
clears and initializes the OptionsCont
The message is an error.
Definition: MsgHandler.h:65
virtual ~GNELoadThread()
destructor