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