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 <config.h>
24 
25 #include <iostream>
26 #include <ctime>
27 #include <utils/xml/XMLSubSys.h>
37 #include <utils/options/Option.h>
40 #include <netbuild/NBFrame.h>
41 #include <netimport/NILoader.h>
42 #include <netimport/NIFrame.h>
43 #include <netwrite/NWFrame.h>
44 #include <netbuild/NBFrame.h>
46 
47 #include "GNELoadThread.h"
48 #include "GNENet.h"
49 #include "GNEEvent_NetworkLoaded.h"
50 
51 
52 // ===========================================================================
53 // member method definitions
54 // ===========================================================================
56  FXSingleEventThread(app, mw), myParent(mw), myEventQue(eq),
57  myEventThrow(ev) {
63  MsgHandler::getErrorInstance()->addRetriever(myErrorRetriever);
64 }
65 
66 
68  delete myDebugRetriever;
69  delete myGLDebugRetriever;
70  delete myErrorRetriever;
71  delete myMessageRetriever;
72  delete myWarningRetriever;
73 }
74 
75 
76 FXint
78  // 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  }
109 
111  if (!GeoConvHelper::init(oc)) {
112  WRITE_ERROR("Could not build projection!");
113  submitEndAndCleanup(net);
114  return 0;
115  }
116  XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"));
117  // check if Debug has to be enabled
118  MsgHandler::enableDebugMessages(oc.getBool("gui-testing-debug"));
119  // check if GL Debug has to be enabled
120  MsgHandler::enableDebugGLMessages(oc.getBool("gui-testing-debug-gl"));
121  // this netbuilder instance becomes the responsibility of the GNENet
122  NBNetBuilder* netBuilder = new NBNetBuilder();
123 
124  netBuilder->applyOptions(oc);
125 
126  if (myNewNet) {
127  // create new network
128  net = new GNENet(netBuilder);
129  } else {
130  NILoader nl(*netBuilder);
131  try {
132  nl.load(oc);
133 
134  if (!myLoadNet) {
135  WRITE_MESSAGE("Performing initial computation ...\n");
136  // perform one-time processing (i.e. edge removal)
137  netBuilder->compute(oc);
138  // @todo remove one-time processing options!
139  } else {
140  // make coordinate conversion usable before first netBuilder->compute()
142  }
143 
144  if (oc.getBool("ignore-errors")) {
146  }
147 
148  // check whether any errors occurred
149  if (MsgHandler::getErrorInstance()->wasInformed()) {
150  throw ProcessError();
151  } else {
152  net = new GNENet(netBuilder);
153  if (oc.getBool("lefthand")) {
154  // force initial geometry computation without volatile options because the net will look strange otherwise
155  net->computeAndUpdate(oc, false);
156  }
157  }
158  if (myFile == "") {
159  if (oc.isSet("configuration-file")) {
160  myFile = oc.getString("configuration-file");
161  } else if (oc.isSet("sumo-net-file")) {
162  myFile = oc.getString("sumo-net-file");
163  }
164  }
165 
166  } catch (ProcessError& e) {
167  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
168  WRITE_ERROR(e.what());
169  }
170  WRITE_ERROR("Failed to build network.");
171  delete net;
172  delete netBuilder;
173  net = 0;
174  } catch (std::exception& e) {
175  WRITE_ERROR(e.what());
176 #ifdef _DEBUG
177  throw;
178 #endif
179  delete net;
180  delete netBuilder;
181  net = 0;
182  }
183  }
184  // only a single setting file is supported
185  submitEndAndCleanup(net, oc.getString("gui-settings-file"), oc.getBool("registry-viewport"));
186  return 0;
187 }
188 
189 
190 
191 void
192 GNELoadThread::submitEndAndCleanup(GNENet* net, const std::string& guiSettingsFile, const bool viewportFromRegistry) {
193  // remove message callbacks
199  // inform parent about the process
200  GUIEvent* e = new GNEEvent_NetworkLoaded(net, myFile, guiSettingsFile, viewportFromRegistry);
201  myEventQue.add(e);
203 }
204 
205 
206 void
208  oc.clear();
209  oc.addCallExample("--new", "start plain GUI with empty net");
210  oc.addCallExample("-s <SUMO_NET>", "edit SUMO network");
211  oc.addCallExample("-c <CONFIGURATION>", "edit net with options read from file");
212 
213  SystemFrame::addConfigurationOptions(oc); // this subtopic is filled here, too
214  oc.addOptionSubTopic("Input");
215  oc.addOptionSubTopic("Output");
217  oc.addOptionSubTopic("Processing");
218  oc.addOptionSubTopic("Building Defaults");
219  oc.addOptionSubTopic("TLS Building");
220  oc.addOptionSubTopic("Ramp Guessing");
221  oc.addOptionSubTopic("Edge Removal");
222  oc.addOptionSubTopic("Unregulated Nodes");
223  oc.addOptionSubTopic("Junctions");
224  oc.addOptionSubTopic("Pedestrian");
225  oc.addOptionSubTopic("Railway");
226  oc.addOptionSubTopic("Formats");
227  oc.addOptionSubTopic("Netedit");
228  oc.addOptionSubTopic("Visualisation");
229 
230  oc.doRegister("new", new Option_Bool(false)); // !!!
231  oc.addDescription("new", "Input", "Start with a new network");
232 
233  oc.doRegister("sumo-additionals-file", 'a', new Option_String());
234  oc.addDescription("sumo-additionals-file", "Netedit", "file in which additionals are loaded");
235 
236  oc.doRegister("additionals-output", new Option_String());
237  oc.addDescription("additionals-output", "Netedit", "file in which additionals must be saved");
238 
239  oc.doRegister("sumo-shapes-file", new Option_String());
240  oc.addDescription("sumo-shapes-file", "Netedit", "file in which shapes are loaded");
241 
242  oc.doRegister("shapes-output", new Option_String());
243  oc.addDescription("shapes-output", "Netedit", "file in which shapes must be saved");
244 
245  oc.doRegister("TLSPrograms-output", new Option_String());
246  oc.addDescription("TLSPrograms-output", "Netedit", "file in which TLS Programs must be saved");
247 
248  oc.doRegister("disable-laneIcons", new Option_Bool(false));
249  oc.addDescription("disable-laneIcons", "Visualisation", "Disable icons of special lanes");
250 
251  oc.doRegister("disable-textures", 'T', new Option_Bool(false)); // !!!
252  oc.addDescription("disable-textures", "Visualisation", "");
253 
254  oc.doRegister("gui-settings-file", 'g', new Option_FileName());
255  oc.addDescription("gui-settings-file", "Visualisation", "Load visualisation settings from FILE");
256 
257  oc.doRegister("registry-viewport", new Option_Bool(false));
258  oc.addDescription("registry-viewport", "Visualisation", "Load current viewport from registry");
259 
260  oc.doRegister("window-size", new Option_String());
261  oc.addDescription("window-size", "Visualisation", "Create initial window with the given x,y size");
262 
263  oc.doRegister("window-pos", new Option_String());
264  oc.addDescription("window-pos", "Visualisation", "Create initial window at the given x,y position");
265 
266  oc.doRegister("gui-testing", new Option_Bool(false));
267  oc.addDescription("gui-testing", "Visualisation", "Enable overlay for screen recognition");
268 
269  oc.doRegister("gui-testing-debug", new Option_Bool(false));
270  oc.addDescription("gui-testing-debug", "Visualisation", "Enable output messages during GUI-Testing");
271 
272  oc.doRegister("gui-testing-debug-gl", new Option_Bool(false));
273  oc.addDescription("gui-testing-debug-gl", "Visualisation", "Enable output messages during GUI-Testing specific of gl functions");
274 
275  SystemFrame::addReportOptions(oc); // this subtopic is filled here, too
276 
278  NBFrame::fillOptions(false);
279  NWFrame::fillOptions(false);
281 }
282 
283 
284 void
286  oc.set("offset.disable-normalization", "true"); // preserve the given network as far as possible
287  oc.set("no-turnarounds", "true"); // otherwise it is impossible to manually removed turn-arounds
288 }
289 
290 
291 bool
294  // fill all optiones
295  fillOptions(oc);
296  // set manually the net file
297  if (myFile != "") {
298  if (myLoadNet) {
299  oc.set("sumo-net-file", myFile);
300  } else {
301  oc.set("configuration-file", myFile);
302  }
303  }
304  // set default options defined in GNELoadThread::setDefaultOptions(...)
305  setDefaultOptions(oc);
306  try {
307  // set all values writables, because certain attributes already setted can be updated throught console
308  oc.resetWritable();
309  // load options from console
311  // if output file wasn't defined in the command line manually, set value of "sumo-net-file"
312  if (!oc.isSet("output-file")) {
313  oc.set("output-file", oc.getString("sumo-net-file"));
314  }
315  return true;
316  } catch (ProcessError& e) {
317  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
318  WRITE_ERROR(e.what());
319  }
320  WRITE_ERROR("Failed to parse options.");
321  return false;
322  }
323 }
324 
325 
326 void
327 GNELoadThread::loadConfigOrNet(const std::string& file, bool isNet, bool useStartupOptions, bool newNet) {
328  myFile = file;
329  myLoadNet = isNet;
330  if (myFile != "" && !useStartupOptions) {
331  OptionsIO::setArgs(0, 0);
332  }
333  myNewNet = newNet;
334  start();
335 }
336 
337 
338 void
339 GNELoadThread::retrieveMessage(const MsgHandler::MsgType type, const std::string& msg) {
340  GUIEvent* e = new GUIEvent_Message(type, msg);
341  myEventQue.add(e);
343 }
344 
345 /****************************************************************************/
346 
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
Definition: MsgHandler.cpp:67
The message is only something to show.
Definition: MsgHandler.h:56
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:75
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:43
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NWFrame.cpp:125
OutputDevice * myWarningRetriever
Definition: GNELoadThread.h:95
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NBFrame.cpp:524
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:95
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:95
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:80
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:95
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:320
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:248
The message is a warning.
Definition: MsgHandler.h:58
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:98
Instance responsible for building networks.
Definition: NBNetBuilder.h:109
OutputDevice * myMessageRetriever
Definition: GNELoadThread.h:95
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:92
void computeAndUpdate(OptionsCont &oc, bool volatileOptions)
recompute the network and update lane geometries
Definition: GNENet.cpp:2415
The message is an debug.
Definition: MsgHandler.h:62
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:243
static void initOutputOptions()
init output options
Definition: MsgHandler.cpp:239
The message is an debug.
Definition: MsgHandler.h:64
static void fillOptions(OptionsCont &oc)
clears and initializes the OptionsCont
The message is an error.
Definition: MsgHandler.h:60
virtual ~GNELoadThread()
destructor