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-2019 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 /****************************************************************************/
14 // The thread that performs the loading of a Netedit-net (adapted from
15 // GUILoadThread)
16 /****************************************************************************/
17 
18 
19 // ===========================================================================
20 // included modules
21 // ===========================================================================
22 #include <netbuild/NBFrame.h>
23 #include <netbuild/NBNetBuilder.h>
24 #include <netimport/NIFrame.h>
25 #include <netimport/NILoader.h>
26 #include <netwrite/NWFrame.h>
33 #include <utils/xml/XMLSubSys.h>
34 
35 #include "GNEEvent_NetworkLoaded.h"
36 #include "GNELoadThread.h"
37 #include "GNENet.h"
38 
39 
40 // ===========================================================================
41 // member method definitions
42 // ===========================================================================
44  FXSingleEventThread(app, mw), myParent(mw), myEventQue(eq),
45  myEventThrow(ev) {
52 }
53 
54 
56  delete myDebugRetriever;
57  delete myGLDebugRetriever;
58  delete myErrorRetriever;
59  delete myMessageRetriever;
60  delete myWarningRetriever;
61 }
62 
63 
64 FXint
66  // register message callbacks
72 
73  GNENet* net = nullptr;
74 
75  // try to load the given configuration
77  if (myFile != "" || oc.getString("sumo-net-file") != "") {
78  oc.clear();
79  if (!initOptions()) {
81  return 0;
82  }
83  }
84  if (oc.isDefault("aggregate-warnings")) {
85  oc.set("aggregate-warnings", "5");
86  }
88  if (!(NIFrame::checkOptions() &&
92  // options are not valid
93  WRITE_ERROR("Invalid Options. Nothing loaded");
95  return 0;
96  }
102 
104  if (!GeoConvHelper::init(oc)) {
105  WRITE_ERROR("Could not build projection!");
106  submitEndAndCleanup(net);
107  return 0;
108  }
109  XMLSubSys::setValidation(oc.getString("xml-validation"), oc.getString("xml-validation.net"));
110  // check if Debug has to be enabled
111  MsgHandler::enableDebugMessages(oc.getBool("gui-testing-debug"));
112  // check if GL Debug has to be enabled
113  MsgHandler::enableDebugGLMessages(oc.getBool("gui-testing-debug-gl"));
114  // this netbuilder instance becomes the responsibility of the GNENet
115  NBNetBuilder* netBuilder = new NBNetBuilder();
116 
117  netBuilder->applyOptions(oc);
118 
119  if (myNewNet) {
120  // create new network
121  net = new GNENet(netBuilder);
122  } else {
123  NILoader nl(*netBuilder);
124  try {
125  nl.load(oc);
126 
127  if (!myLoadNet) {
128  WRITE_MESSAGE("Performing initial computation ...\n");
129  // perform one-time processing (i.e. edge removal)
130  netBuilder->compute(oc);
131  // @todo remove one-time processing options!
132  } else {
133  // make coordinate conversion usable before first netBuilder->compute()
135  }
136 
137  if (oc.getBool("ignore-errors")) {
139  }
140 
141  // check whether any errors occurred
142  if (MsgHandler::getErrorInstance()->wasInformed()) {
143  throw ProcessError();
144  } else {
145  net = new GNENet(netBuilder);
146  if (oc.getBool("lefthand")) {
147  // force initial geometry computation without volatile options because the net will look strange otherwise
148  net->computeAndUpdate(oc, false);
149  }
150  }
151  if (myFile == "") {
152  if (oc.isSet("configuration-file")) {
153  myFile = oc.getString("configuration-file");
154  } else if (oc.isSet("sumo-net-file")) {
155  myFile = oc.getString("sumo-net-file");
156  }
157  }
158 
159  } catch (ProcessError& e) {
160  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
161  WRITE_ERROR(e.what());
162  }
163  WRITE_ERROR("Failed to build network.");
164  delete net;
165  delete netBuilder;
166  net = nullptr;
167  } catch (std::exception& e) {
168  WRITE_ERROR(e.what());
169 #ifdef _DEBUG
170  throw;
171 #endif
172  delete net;
173  delete netBuilder;
174  net = nullptr;
175  }
176  }
177  // only a single setting file is supported
178  submitEndAndCleanup(net, oc.getString("gui-settings-file"), oc.getBool("registry-viewport"));
179  return 0;
180 }
181 
182 
183 
184 void
185 GNELoadThread::submitEndAndCleanup(GNENet* net, const std::string& guiSettingsFile, const bool viewportFromRegistry) {
186  // remove message callbacks
192  // inform parent about the process
193  GUIEvent* e = new GNEEvent_NetworkLoaded(net, myFile, guiSettingsFile, viewportFromRegistry);
196 }
197 
198 
199 void
201  oc.clear();
202  oc.addCallExample("--new", "start plain GUI with empty net");
203  oc.addCallExample("-s <SUMO_NET>", "edit SUMO network");
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("Processing");
211  oc.addOptionSubTopic("Building Defaults");
212  oc.addOptionSubTopic("TLS Building");
213  oc.addOptionSubTopic("Ramp Guessing");
214  oc.addOptionSubTopic("Edge Removal");
215  oc.addOptionSubTopic("Unregulated Nodes");
216  oc.addOptionSubTopic("Junctions");
217  oc.addOptionSubTopic("Pedestrian");
218  oc.addOptionSubTopic("Bicycle");
219  oc.addOptionSubTopic("Railway");
220  oc.addOptionSubTopic("Formats");
221  oc.addOptionSubTopic("Netedit");
222  oc.addOptionSubTopic("Visualisation");
223  oc.addOptionSubTopic("Time");
224 
225  oc.doRegister("new", new Option_Bool(false)); // !!!
226  oc.addDescription("new", "Input", "Start with a new network");
227 
228  oc.doRegister("additional-files", 'a', new Option_FileName());
229  oc.addSynonyme("additional-files", "additional");
230  oc.addDescription("additional-files", "Netedit", "Load additional and shapes descriptions from FILE(s)");
231 
232  oc.doRegister("additionals-output", new Option_String());
233  oc.addDescription("additionals-output", "Netedit", "file in which additionals must be saved");
234 
235  oc.doRegister("route-files", 'r', new Option_FileName());
236  oc.addSynonyme("route-files", "routes");
237  oc.addDescription("route-files", "Netedit", "Load demand elements descriptions from FILE(s)");
238 
239  oc.doRegister("demandelements-output", new Option_String());
240  oc.addDescription("demandelements-output", "Netedit", "file in which demand elements must be saved");
241 
242  oc.doRegister("TLSPrograms-output", new Option_String());
243  oc.addDescription("TLSPrograms-output", "Netedit", "file in which TLS Programs must be saved");
244 
245  oc.doRegister("disable-laneIcons", new Option_Bool(false));
246  oc.addDescription("disable-laneIcons", "Visualisation", "Disable icons of special lanes");
247 
248  oc.doRegister("disable-textures", 'T', new Option_Bool(false)); // !!!
249  oc.addDescription("disable-textures", "Visualisation", "");
250 
251  oc.doRegister("gui-settings-file", 'g', new Option_FileName());
252  oc.addDescription("gui-settings-file", "Visualisation", "Load visualisation settings from FILE");
253 
254  oc.doRegister("registry-viewport", new Option_Bool(false));
255  oc.addDescription("registry-viewport", "Visualisation", "Load current viewport from registry");
256 
257  oc.doRegister("window-size", new Option_StringVector());
258  oc.addDescription("window-size", "Visualisation", "Create initial window with the given x,y size");
259 
260  oc.doRegister("window-pos", new Option_StringVector());
261  oc.addDescription("window-pos", "Visualisation", "Create initial window at the given x,y position");
262 
263  // testing
264 
265  oc.doRegister("gui-testing", new Option_Bool(false));
266  oc.addDescription("gui-testing", "Visualisation", "Enable overlay for screen recognition");
267 
268  oc.doRegister("gui-testing-debug", new Option_Bool(false));
269  oc.addDescription("gui-testing-debug", "Visualisation", "Enable output messages during GUI-Testing");
270 
271  oc.doRegister("gui-testing-debug-gl", new Option_Bool(false));
272  oc.addDescription("gui-testing-debug-gl", "Visualisation", "Enable output messages during GUI-Testing specific of gl functions");
273 
274  oc.doRegister("gui-testing.setting-output", new Option_FileName());
275  oc.addDescription("gui-testing.setting-output", "Visualisation", "Save gui settings in the given settings-output file");
276 
277  // register the simulation settings (needed for GNERouteHandler)
278  oc.doRegister("begin", new Option_String("0", "TIME"));
279  oc.addDescription("begin", "Time", "Defines the begin time in seconds; The simulation starts at this time");
280 
281  oc.doRegister("end", new Option_String("-1", "TIME"));
282  oc.addDescription("end", "Time", "Defines the end time in seconds; The simulation ends at this time");
283 
284  oc.doRegister("default.action-step-length", new Option_Float(0.0));
285  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.");
286 
287  SystemFrame::addReportOptions(oc); // this subtopic is filled here, too
288 
289  NIFrame::fillOptions(true);
290  NBFrame::fillOptions(false);
291  NWFrame::fillOptions(false);
293 }
294 
295 
296 void
298  oc.resetWritable();
299  oc.set("offset.disable-normalization", "true"); // preserve the given network as far as possible
300  oc.set("no-turnarounds", "true"); // otherwise it is impossible to manually removed turn-arounds
301 }
302 
303 
304 bool
307  // fill all optiones
308  fillOptions(oc);
309  // set manually the net file
310  if (myFile != "") {
311  if (myLoadNet) {
312  oc.set("sumo-net-file", myFile);
313  } else {
314  oc.set("configuration-file", myFile);
315  }
316  }
317  // set default options defined in GNELoadThread::setDefaultOptions(...)
318  setDefaultOptions(oc);
319  try {
320  // set all values writables, because certain attributes already setted can be updated throught console
321  oc.resetWritable();
322  // load options from console
324  // if output file wasn't defined in the command line manually, set value of "sumo-net-file"
325  if (!oc.isSet("output-file")) {
326  oc.set("output-file", oc.getString("sumo-net-file"));
327  }
328  return true;
329  } catch (ProcessError& e) {
330  if (std::string(e.what()) != std::string("Process Error") && std::string(e.what()) != std::string("")) {
331  WRITE_ERROR(e.what());
332  }
333  WRITE_ERROR("Failed to parse options.");
334  return false;
335  }
336 }
337 
338 
339 void
340 GNELoadThread::loadConfigOrNet(const std::string& file, bool isNet, bool useStartupOptions, bool newNet) {
341  myFile = file;
342  myLoadNet = isNet;
343  if (myFile != "" && !useStartupOptions) {
344  OptionsIO::setArgs(0, nullptr);
345  }
346  myNewNet = newNet;
347  start();
348 }
349 
350 
351 void
352 GNELoadThread::retrieveMessage(const MsgHandler::MsgType type, const std::string& msg) {
353  GUIEvent* e = new GUIEvent_Message(type, msg);
356 }
357 
358 
359 /****************************************************************************/
OptionsCont::isSet
bool isSet(const std::string &name, bool failOnNonExistant=true) const
Returns the information whether the named option is set.
Definition: OptionsCont.cpp:135
MsgHandler::MsgType
MsgType
Definition: MsgHandler.h:45
MsgHandler::MT_ERROR
@ MT_ERROR
The message is an error.
Definition: MsgHandler.h:51
SystemFrame::addConfigurationOptions
static void addConfigurationOptions(OptionsCont &oc)
Adds configuration options to the given container.
Definition: SystemFrame.cpp:39
NWFrame.h
MFXInterThreadEventClient
Definition: MFXInterThreadEventClient.h:27
MsgHandler::initOutputOptions
static void initOutputOptions()
init output options
Definition: MsgHandler.cpp:216
GNELoadThread::myErrorRetriever
OutputDevice * myErrorRetriever
The instances of message retriever encapsulations Needed to be deleted from the handler later on.
Definition: GNELoadThread.h:92
Option_Bool
Definition: Option.h:538
NBNetBuilder
Instance responsible for building networks.
Definition: NBNetBuilder.h:109
OptionsCont.h
MsgHandler::MT_MESSAGE
@ MT_MESSAGE
The message is only something to show.
Definition: MsgHandler.h:47
OptionsCont::resetWritable
void resetWritable()
Resets all options to be writeable.
Definition: OptionsCont.cpp:441
GNELoadThread::run
FXint run()
starts the thread. The thread ends after the net has been loaded
Definition: GNELoadThread.cpp:65
OptionsCont::set
bool set(const std::string &name, const std::string &value)
Sets the given value for the named option.
Definition: OptionsCont.cpp:241
GNELoadThread::myLoadNet
bool myLoadNet
Information whether only the network shall be loaded.
Definition: GNELoadThread.h:101
GNENet
A NBNetBuilder extended by visualisation and editing capabilities.
Definition: GNENet.h:77
MsgRetrievingFunction
Encapsulates an object's method for using it as a message retriever.
Definition: MsgRetrievingFunction.h:41
MsgHandler::MT_WARNING
@ MT_WARNING
The message is a warning.
Definition: MsgHandler.h:49
OptionsCont::getString
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
Definition: OptionsCont.cpp:201
GNELoadThread::retrieveMessage
void retrieveMessage(const MsgHandler::MsgType type, const std::string &msg)
Retrieves messages from the loading module.
Definition: GNELoadThread.cpp:352
OptionsCont::getBool
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
Definition: OptionsCont.cpp:222
GNELoadThread::myGLDebugRetriever
OutputDevice * myGLDebugRetriever
Definition: GNELoadThread.h:92
OptionsCont::getOptions
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:57
NWFrame::fillOptions
static void fillOptions(bool forNetgen)
Inserts options used by the network writer.
Definition: NWFrame.cpp:49
GNELoadThread::myWarningRetriever
OutputDevice * myWarningRetriever
Definition: GNELoadThread.h:92
GUIEvent_Message.h
GNELoadThread::myEventThrow
FXEX::FXThreadEvent & myEventThrow
event throw
Definition: GNELoadThread.h:98
GeoConvHelper::init
static bool init(OptionsCont &oc)
Initialises the processing and the final instance using the given options.
Definition: GeoConvHelper.cpp:200
GNELoadThread::~GNELoadThread
virtual ~GNELoadThread()
destructor
Definition: GNELoadThread.cpp:55
FXEX::FXThreadEvent::signal
void signal()
Definition: FXThreadEvent.cpp:99
SystemFrame::addReportOptions
static void addReportOptions(OptionsCont &oc)
Adds reporting options to the given container.
Definition: SystemFrame.cpp:64
MsgHandler::clear
virtual void clear()
Clears information whether an error occurred previously.
Definition: MsgHandler.cpp:160
NIFrame::checkOptions
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NIFrame.cpp:329
MsgHandler::enableDebugGLMessages
static void enableDebugGLMessages(bool enable)
enable/disable gl-debug messages
Definition: MsgHandler.cpp:113
OptionsCont::addDescription
void addDescription(const std::string &name, const std::string &subtopic, const std::string &description)
Adds a description for an option.
Definition: OptionsCont.cpp:469
NWFrame::checkOptions
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NWFrame.cpp:126
GNEEvent_NetworkLoaded.h
NILoader
Perfoms network import.
Definition: NILoader.h:50
NBFrame::checkOptions
static bool checkOptions()
Checks set options from the OptionsCont-singleton for being valid.
Definition: NBFrame.cpp:591
GNENet::computeAndUpdate
void computeAndUpdate(OptionsCont &oc, bool volatileOptions)
recompute the network and update lane geometries
Definition: GNENet.cpp:3094
SystemFrame.h
GNELoadThread::initOptions
bool initOptions()
init options
Definition: GNELoadThread.cpp:305
XMLSubSys::setValidation
static void setValidation(const std::string &validationScheme, const std::string &netValidationScheme)
Enables or disables validation.
Definition: XMLSubSys.cpp:58
OptionsCont::addSynonyme
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:95
MsgHandler::getWarningInstance
static MsgHandler * getWarningInstance()
Returns the instance to add warnings to.
Definition: MsgHandler.cpp:68
GNELoadThread::myMessageRetriever
OutputDevice * myMessageRetriever
Definition: GNELoadThread.h:92
NIFrame::fillOptions
static void fillOptions(bool forNetedit=false)
Inserts options used by the network importer and network building modules.
Definition: NIFrame.cpp:48
GeoConvHelper::addProjectionOptions
static void addProjectionOptions(OptionsCont &oc)
Adds projection options to the given container.
Definition: GeoConvHelper.cpp:248
NBNetBuilder.h
MsgHandler::getGLDebugInstance
static MsgHandler * getGLDebugInstance()
Returns the instance to add GLdebug to.
Definition: MsgHandler.cpp:99
OptionsCont::doRegister
void doRegister(const std::string &name, Option *v)
Adds an option under the given name.
Definition: OptionsCont.cpp:74
ProcessError
Definition: UtilExceptions.h:39
NBNetBuilder::applyOptions
void applyOptions(OptionsCont &oc)
Initialises the storage by applying given options.
Definition: NBNetBuilder.cpp:65
Option_String
Definition: Option.h:399
OptionsCont
A storage for options typed value containers)
Definition: OptionsCont.h:89
NBFrame::fillOptions
static void fillOptions(bool forNetgen)
Inserts options used by the network converter.
Definition: NBFrame.cpp:48
FXSynchQue< GUIEvent * >
GNELoadThread::loadConfigOrNet
void loadConfigOrNet(const std::string &file, bool isNet, bool useStartupOptions, bool newNet=false)
begins the loading of a netconvert configuration or a a network
Definition: GNELoadThread.cpp:340
OptionsCont::isDefault
bool isDefault(const std::string &name) const
Returns the information whether the named option has still the default value.
Definition: OptionsCont.cpp:163
NILoader::load
void load(OptionsCont &oc)
Definition: NILoader.cpp:72
OptionsCont::addOptionSubTopic
void addOptionSubTopic(const std::string &topic)
Adds an option subtopic.
Definition: OptionsCont.cpp:519
RandHelper::initRandGlobal
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
GNELoadThread.h
GNELoadThread::submitEndAndCleanup
void submitEndAndCleanup(GNENet *net, const std::string &guiSettingsFile="", const bool viewportFromRegistry=false)
Closes the loading process.
Definition: GNELoadThread.cpp:185
OptionsIO::getOptions
static void getOptions(const bool commandLineOnly=false)
Parses the command line arguments and loads the configuration.
Definition: OptionsIO.cpp:75
NILoader.h
GNEEvent_NetworkLoaded
Definition: GNEEvent_NetworkLoaded.h:43
Option_StringVector
Definition: Option.h:720
MsgHandler::getDebugInstance
static MsgHandler * getDebugInstance()
Returns the instance to add debug to.
Definition: MsgHandler.cpp:90
GUIEvent
Definition: GUIEvent.h:76
Option_Float
Definition: Option.h:470
OptionsCont::addCallExample
void addCallExample(const std::string &example, const std::string &desc)
Add a call example.
Definition: OptionsCont.cpp:495
MsgHandler::MT_DEBUG
@ MT_DEBUG
The message is an debug.
Definition: MsgHandler.h:53
MsgHandler::addRetriever
virtual void addRetriever(OutputDevice *retriever)
Adds a further retriever to the instance responsible for a certain msg type.
Definition: MsgHandler.cpp:174
GNELoadThread::setDefaultOptions
static void setDefaultOptions(OptionsCont &oc)
sets required options for proper functioning
Definition: GNELoadThread.cpp:297
OptionsIO::setArgs
static void setArgs(int argc, char **argv)
Stores the command line arguments for later parsing.
Definition: OptionsIO.cpp:54
GeoConvHelper::computeFinal
static void computeFinal(bool lefthand=false)
compute the location attributes which will be used for output based on the loaded location data,...
Definition: GeoConvHelper.cpp:513
NBNetBuilder::compute
void compute(OptionsCont &oc, const std::set< std::string > &explicitTurnarounds=std::set< std::string >(), bool mayAddOrRemove=true)
Performs the network building steps.
Definition: NBNetBuilder.cpp:77
MsgRetrievingFunction.h
FXSynchQue::push_back
void push_back(T what)
Definition: FXSynchQue.h:115
GNELoadThread::fillOptions
static void fillOptions(OptionsCont &oc)
clears and initializes the OptionsCont
Definition: GNELoadThread.cpp:200
NBFrame.h
Option_FileName
Definition: Option.h:783
RandHelper::insertRandOptions
static void insertRandOptions()
Initialises the given options container with random number options.
Definition: RandHelper.cpp:45
RandHelper.h
SystemFrame::checkOptions
static bool checkOptions()
checks shared options and sets StdDefs
Definition: SystemFrame.cpp:120
FXSingleEventThread
Definition: FXSingleEventThread.h:34
MsgHandler::MT_GLDEBUG
@ MT_GLDEBUG
The message is an debug.
Definition: MsgHandler.h:55
GNELoadThread::myNewNet
bool myNewNet
if true, a new net is created
Definition: GNELoadThread.h:104
FXEX::FXThreadEvent
Definition: FXThreadEvent.h:105
MsgHandler::getErrorInstance
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
Definition: MsgHandler.cpp:81
NIFrame.h
GNELoadThread::GNELoadThread
GNELoadThread(FXApp *app, MFXInterThreadEventClient *mw, FXSynchQue< GUIEvent * > &eq, FXEX::FXThreadEvent &ev)
constructor
Definition: GNELoadThread.cpp:43
GNELoadThread::myDebugRetriever
OutputDevice * myDebugRetriever
Definition: GNELoadThread.h:92
OptionsCont::clear
void clear()
Removes all information from the container.
Definition: OptionsCont.cpp:456
WRITE_ERROR
#define WRITE_ERROR(msg)
Definition: MsgHandler.h:283
GUIEvent_Message
Definition: GUIEvent_Message.h:38
WRITE_MESSAGE
#define WRITE_MESSAGE(msg)
Definition: MsgHandler.h:277
GNELoadThread::myEventQue
FXSynchQue< GUIEvent * > & myEventQue
event Queue
Definition: GNELoadThread.h:95
GNENet.h
OptionsIO.h
GNELoadThread::myFile
std::string myFile
the path to load the network from
Definition: GNELoadThread.h:89
XMLSubSys.h
MsgHandler::removeRetriever
virtual void removeRetriever(OutputDevice *retriever)
Removes the retriever from the handler.
Definition: MsgHandler.cpp:182
MsgHandler::enableDebugMessages
static void enableDebugMessages(bool enable)
enable/disable debug messages
Definition: MsgHandler.cpp:108
MsgHandler::getMessageInstance
static MsgHandler * getMessageInstance()
Returns the instance to add normal messages to.
Definition: MsgHandler.cpp:55