#include <NLTriggerBuilder.h>

Called on the occurence of a "trigger"-element, "buildTrigger" parses what kind of a trigger object shall be built and calls an appropriate parsing and building method.
This parsing/building method retrieves the parameter needed to build the trigger, checks them, and, if they are ok, calls the appropriate building method.
The building methods may be overridden, to build guisim-instances of the triggers, for example.
Definition at line 73 of file NLTriggerBuilder.h.
Public Member Functions | |
| void | buildTrigger (MSNet &net, const SUMOSAXAttributes &attrs, const std::string &base) throw (InvalidArgument) |
| builds the specified trigger | |
| void | buildVaporizer (const SUMOSAXAttributes &attrs) throw () |
| Builds a vaporization. | |
| NLTriggerBuilder () throw () | |
| Constructor. | |
| void | setHandler (NLHandler *handler) throw () |
| Sets the parent handler to use for nested parsing. | |
| virtual | ~NLTriggerBuilder () throw () |
| Destructor. | |
parsing methods | |
These methods parse the attributes for each of the described trigger and call the according methods to build the trigger | |
| void | parseAndBuildBusStop (MSNet &net, const SUMOSAXAttributes &attrs) throw (InvalidArgument) |
| Parses his values and builds a bus stop. | |
| void | parseAndBuildCalibrator (MSNet &net, const SUMOSAXAttributes &attrs, const std::string &base) throw (InvalidArgument) |
| Parses his values and builds a mesoscopic or microscopic calibrator. | |
| void | parseAndBuildLaneEmitTrigger (MSNet &net, const SUMOSAXAttributes &attrs, const std::string &base) throw (InvalidArgument) |
| Parses his values and builds an emitter. | |
| void | parseAndBuildLaneSpeedTrigger (MSNet &net, const SUMOSAXAttributes &attrs, const std::string &base) throw (InvalidArgument) |
| Parses his values and builds a lane speed trigger. | |
| void | parseAndBuildRerouter (MSNet &net, const SUMOSAXAttributes &attrs, const std::string &base) throw (InvalidArgument) |
| Parses his values and builds a rerouter. | |
Protected Member Functions | |
building methods | |
Called with parsed values, these methods build the trigger. These methods should be overriden for the gui loader in order to build visualizable versions of the triggers.
In most cases, these methods only call the constructor. | |
| virtual void | buildBusStop (MSNet &net, const std::string &id, const std::vector< std::string > &lines, MSLane *lane, SUMOReal frompos, SUMOReal topos) throw () |
| Builds a bus stop. | |
| virtual void | buildLaneCalibrator (MSNet &net, const std::string &id, MSLane *destLane, SUMOReal pos, const std::string &file) throw () |
| builds a calibrator for online simulation | |
| virtual void | buildLaneEmitTrigger (MSNet &net, const std::string &id, MSLane *destLane, SUMOReal pos, const std::string &file) throw () |
| Builds an emitter. | |
| virtual MSLaneSpeedTrigger * | buildLaneSpeedTrigger (MSNet &net, const std::string &id, const std::vector< MSLane * > &destLanes, const std::string &file) throw (ProcessError) |
| Builds a lane speed trigger. | |
| virtual void | buildRerouter (MSNet &net, const std::string &id, std::vector< MSEdge * > &edges, SUMOReal prob, const std::string &file, bool off) throw () |
| builds an rerouter | |
helper method for obtaining and checking values | |
| std::string | getFileName (const SUMOSAXAttributes &attrs, const std::string &base, const bool allowEmpty=false) throw (InvalidArgument) |
| Helper method to obtain the filename. | |
| MSLane * | getLane (const SUMOSAXAttributes &attrs, const std::string &tt, const std::string &tid) throw (InvalidArgument) |
| Returns the lane defined by attribute "lane". | |
| SUMOReal | getPosition (const SUMOSAXAttributes &attrs, MSLane *lane, const std::string &tt, const std::string &tid) throw (InvalidArgument) |
| returns the position on the lane checking it | |
Protected Attributes | |
| NLHandler * | myHandler |
| The parent handler to set for subhandlers. | |
| bool | myHaveInformedAboutDeprecatedEmitter |
| Information whether an emitter shall be built (is deprecated). | |
| bool | myHaveInformedAboutDeprecatedTriggerDefinition |
| Information whether a deprecated trigger definition has occured and was reported. | |
| NLTriggerBuilder::NLTriggerBuilder | ( | ) | throw () |
Constructor.
Definition at line 60 of file NLTriggerBuilder.cpp.
00061 : myHaveInformedAboutDeprecatedTriggerDefinition(false), 00062 myHaveInformedAboutDeprecatedEmitter(false), myHandler(0) {}
| NLTriggerBuilder::~NLTriggerBuilder | ( | ) | throw () [virtual] |
| void NLTriggerBuilder::buildBusStop | ( | MSNet & | net, | |
| const std::string & | id, | |||
| const std::vector< std::string > & | lines, | |||
| MSLane * | lane, | |||
| SUMOReal | frompos, | |||
| SUMOReal | topos | |||
| ) | throw () [protected, virtual] |
Builds a bus stop.
Simply calls the MSBusStop constructor.
| [in] | net | The net the bus stop belongs to |
| [in] | id | The id of the bus stop |
| [in] | lines | Names of the bus lines that halt on this bus stop |
| [in] | lane | The lane the bus stop is placed on |
| [in] | frompos | Begin position of the bus stop on the lane |
| [in] | topos | End position of the bus stop on the lane |
Reimplemented in GUITriggerBuilder.
Definition at line 380 of file NLTriggerBuilder.cpp.
Referenced by parseAndBuildBusStop().
00382 { 00383 net.addBusStop(new MSBusStop(id, lines, *lane, frompos, topos)); 00384 }
| void NLTriggerBuilder::buildLaneCalibrator | ( | MSNet & | net, | |
| const std::string & | id, | |||
| MSLane * | destLane, | |||
| SUMOReal | pos, | |||
| const std::string & | file | |||
| ) | throw () [protected, virtual] |
builds a calibrator for online simulation
Simply calls the MSCalibrator constructor.
| [in] | net | The net the calibrator belongs to |
| [in] | id | The id of the calibrator |
| [in] | destLane | The lane the calibrator is placed on |
| [in] | pos | Position of the calibrator on the given lane |
| [in] | file | Name of the file to read the calibration definitions from |
Definition at line 352 of file NLTriggerBuilder.cpp.
Referenced by parseAndBuildCalibrator().
00354 { 00355 new MSCalibrator(id, net, destLane, pos, file); 00356 }
| void NLTriggerBuilder::buildLaneEmitTrigger | ( | MSNet & | net, | |
| const std::string & | id, | |||
| MSLane * | destLane, | |||
| SUMOReal | pos, | |||
| const std::string & | file | |||
| ) | throw () [protected, virtual] |
Builds an emitter.
Simply calls the MSEmitter constructor.
| [in] | net | The net the emitter belongs to |
| [in] | id | The id of the emitter |
| [in] | destLane | The lane the emitter is placed on |
| [in] | pos | Position of the emitter on the given lane |
| [in] | file | Name of the file to read the emission definitions from |
Reimplemented in GUITriggerBuilder.
Definition at line 344 of file NLTriggerBuilder.cpp.
Referenced by parseAndBuildLaneEmitTrigger().
00346 { 00347 new MSEmitter(id, net, destLane, pos, file); 00348 }
| MSLaneSpeedTrigger * NLTriggerBuilder::buildLaneSpeedTrigger | ( | MSNet & | net, | |
| const std::string & | id, | |||
| const std::vector< MSLane * > & | destLanes, | |||
| const std::string & | file | |||
| ) | throw (ProcessError) [protected, virtual] |
Builds a lane speed trigger.
Simply calls the MSLaneSpeedTrigger constructor.
| [in] | net | The net the lane speed trigger belongs to |
| [in] | id | The id of the lane speed trigger |
| [in] | destLanes | List of lanes affected by this speed trigger |
| [in] | file | Name of the file to read the speeds to set from |
| ProcessError | If the XML definition file is errornous |
Reimplemented in GUITriggerBuilder.
Definition at line 336 of file NLTriggerBuilder.cpp.
Referenced by parseAndBuildLaneSpeedTrigger().
00338 { 00339 return new MSLaneSpeedTrigger(id, destLanes, file); 00340 }
| void NLTriggerBuilder::buildRerouter | ( | MSNet & | net, | |
| const std::string & | id, | |||
| std::vector< MSEdge * > & | edges, | |||
| SUMOReal | prob, | |||
| const std::string & | file, | |||
| bool | off | |||
| ) | throw () [protected, virtual] |
builds an rerouter
Simply calls the MSTriggeredRerouter constructor.
| [in] | net | The net the rerouter belongs to |
| [in] | id | The id of the rerouter |
| [in] | edges | The edges the rerouter is placed at |
| [in] | prob | The probability the rerouter reoutes vehicles with |
| [in] | file | The file to read the reroute definitions from |
Reimplemented in GUITriggerBuilder.
Definition at line 372 of file NLTriggerBuilder.cpp.
Referenced by parseAndBuildRerouter().
00374 { 00375 new MSTriggeredRerouter(id, edges, prob, file, off); 00376 }
| void NLTriggerBuilder::buildTrigger | ( | MSNet & | net, | |
| const SUMOSAXAttributes & | attrs, | |||
| const std::string & | base | |||
| ) | throw (InvalidArgument) |
builds the specified trigger
Determines the type of the trigger to build using a combination of "objecttype" and "attr" - attributes from the supplied attributes, first.
Build the proper trigger using protected member helper methods.
| [in] | net | The network the trigger shall belong to |
| [in] | attrs | SAX-attributes which define the trigger |
| [in] | base | The base path |
| InvalidArgument | If a parameter is not valid |
Definition at line 74 of file NLTriggerBuilder.cpp.
References MsgHandler::getWarningInstance(), MsgHandler::inform(), myHaveInformedAboutDeprecatedTriggerDefinition, parseAndBuildBusStop(), parseAndBuildCalibrator(), parseAndBuildLaneEmitTrigger(), parseAndBuildLaneSpeedTrigger(), parseAndBuildRerouter(), SUMO_ATTR_ATTR, and SUMO_ATTR_OBJECTTYPE.
Referenced by NLHandler::addSource(), and NLHandler::addTrigger().
00076 { 00077 bool ok = true; 00078 std::string type = attrs.getStringReporting(SUMO_ATTR_OBJECTTYPE, 0, 0, ok); 00079 std::string attr = attrs.getOptStringReporting(SUMO_ATTR_ATTR, 0, 0, ok, ""); 00080 // check which type of a trigger shall be build 00081 if (type=="lane"&&attr=="speed") { 00082 parseAndBuildLaneSpeedTrigger(net, attrs, base); 00083 } else if (type=="emitter") { 00084 parseAndBuildLaneEmitTrigger(net, attrs, base); 00085 } else if (type=="rerouter") { 00086 parseAndBuildRerouter(net, attrs, base); 00087 } else if (type=="bus_stop") { 00088 parseAndBuildBusStop(net, attrs); 00089 } else if (type=="calibrator") { 00090 parseAndBuildCalibrator(net, attrs, base); 00091 } 00092 if (!myHaveInformedAboutDeprecatedTriggerDefinition) { 00093 MsgHandler::getWarningInstance()->inform("Defining '" + type + "' using a trigger definition is deprecated."); 00094 myHaveInformedAboutDeprecatedTriggerDefinition = true; 00095 } 00096 }
| void NLTriggerBuilder::buildVaporizer | ( | const SUMOSAXAttributes & | attrs | ) | throw () |
Builds a vaporization.
Parses the attributes, reporting errors if the time values are false or the edge is not known. Instatiates events for enabling and disabling the vaporization otherwise.
| [in] | attrs | SAX-attributes which define the vaporizer throwing the exception |
Definition at line 101 of file NLTriggerBuilder.cpp.
References MSEventControl::ADAPT_AFTER_EXECUTION, MSEventControl::addEvent(), MSEdge::decVaporization(), MSEdge::dictionary(), MSNet::getBeginOfTimestepEvents(), MsgHandler::getErrorInstance(), MSNet::getInstance(), OptionsCont::getOptions(), MSEdge::incVaporization(), MsgHandler::inform(), string2time(), SUMO_ATTR_BEGIN, and SUMO_ATTR_END.
Referenced by NLHandler::myStartElement().
00101 { 00102 // get the id, throw if not given or empty... 00103 std::string id; 00104 if (!attrs.setIDFromAttributes("vaporizer", id, false)) { 00105 MsgHandler::getErrorInstance()->inform("Missing or empty id in a vaporizer-object."); 00106 return; 00107 } 00108 MSEdge *e = MSEdge::dictionary(id); 00109 if (e==0) { 00110 MsgHandler::getErrorInstance()->inform("Unknown edge ('" + id + "') referenced in a vaporizer."); 00111 return; 00112 } 00113 bool ok = true; 00114 SUMOTime begin = attrs.getSUMOTimeReporting(SUMO_ATTR_BEGIN, "vaporizer", 0, ok); 00115 SUMOTime end = attrs.getSUMOTimeReporting(SUMO_ATTR_END, "vaporizer", 0, ok); 00116 if (!ok) { 00117 return; 00118 } 00119 if (begin<0) { 00120 MsgHandler::getErrorInstance()->inform("A vaporization begin time is negative (edge id='" + id + "')."); 00121 return; 00122 } 00123 if (begin>=end) { 00124 MsgHandler::getErrorInstance()->inform("A vaporization ends before it starts (edge id='" + id + "')."); 00125 return; 00126 } 00127 if (end>=string2time(OptionsCont::getOptions().getString("begin"))) { 00128 Command* cb = new WrappingCommand< MSEdge >(e, &MSEdge::incVaporization); 00129 MSNet::getInstance()->getBeginOfTimestepEvents().addEvent(cb, begin, MSEventControl::ADAPT_AFTER_EXECUTION); 00130 Command* ce = new WrappingCommand< MSEdge >(e, &MSEdge::decVaporization); 00131 MSNet::getInstance()->getBeginOfTimestepEvents().addEvent(ce, end, MSEventControl::ADAPT_AFTER_EXECUTION); 00132 } 00133 }
| std::string NLTriggerBuilder::getFileName | ( | const SUMOSAXAttributes & | attrs, | |
| const std::string & | base, | |||
| const bool | allowEmpty = false | |||
| ) | throw (InvalidArgument) [protected] |
Helper method to obtain the filename.
Retrieves "file" from attributes, checks whether it is absolute and extends it by the given base path if not. Returns this information.
| [in] | attrs | The attributes to obtain the file name from |
| [in] | base | The base path (the path the loaded additional file lies in) |
Definition at line 390 of file NLTriggerBuilder.cpp.
References FileHelpers::getConfigurationRelative(), FileHelpers::isAbsolute(), and SUMO_ATTR_FILE.
Referenced by parseAndBuildCalibrator(), parseAndBuildLaneEmitTrigger(), parseAndBuildLaneSpeedTrigger(), and parseAndBuildRerouter().
00392 { 00393 // get the file name to read further definitions from 00394 bool ok = true; 00395 std::string file = attrs.getOptStringReporting(SUMO_ATTR_FILE, 0, 0, ok, ""); 00396 if (file == "") { 00397 if (allowEmpty) { 00398 return file; 00399 } 00400 throw InvalidArgument("No filename given."); 00401 } 00402 // check whether absolute or relative filenames are given 00403 if (!FileHelpers::isAbsolute(file)) { 00404 return FileHelpers::getConfigurationRelative(base, file); 00405 } 00406 return file; 00407 }
| MSLane * NLTriggerBuilder::getLane | ( | const SUMOSAXAttributes & | attrs, | |
| const std::string & | tt, | |||
| const std::string & | tid | |||
| ) | throw (InvalidArgument) [protected] |
Returns the lane defined by attribute "lane".
Retrieves the lane id from the given attrs. Tries to retrieve the lane, throws an InvalidArgument if it does not exist.
| [in] | attrs | The attributes to obtain the lane id from |
| [in] | tt | The trigger type (for user output) |
| [in] | tid | The trigger id (for user output) |
| InvalidArgument | If the named lane does not exist or a lane is not named |
Definition at line 411 of file NLTriggerBuilder.cpp.
References MSLane::dictionary(), MsgHandler::getWarningInstance(), MsgHandler::inform(), SUMO_ATTR_LANE, and SUMO_ATTR_OBJECTID.
Referenced by parseAndBuildBusStop(), parseAndBuildCalibrator(), and parseAndBuildLaneEmitTrigger().
00413 { 00414 bool ok = true; 00415 std::string objectid; 00416 if (attrs.hasAttribute(SUMO_ATTR_LANE)) { 00417 objectid = attrs.getStringReporting(SUMO_ATTR_LANE, tt.c_str(), tid.c_str(), ok); 00418 } else { 00419 if (attrs.hasAttribute(SUMO_ATTR_OBJECTID)) { 00420 objectid = attrs.getStringReporting(SUMO_ATTR_OBJECTID, tt.c_str(), tid.c_str(), ok); 00421 MsgHandler::getWarningInstance()->inform("Defining the lane using 'objectid' within " + tt + " is deprecated, use 'lane' instead."); 00422 } 00423 } 00424 MSLane *lane = MSLane::dictionary(objectid); 00425 if (lane==0) { 00426 throw InvalidArgument("The lane " + objectid + " to use within the " + tt + " '" + tid + "' is not known."); 00427 } 00428 return lane; 00429 }
| SUMOReal NLTriggerBuilder::getPosition | ( | const SUMOSAXAttributes & | attrs, | |
| MSLane * | lane, | |||
| const std::string & | tt, | |||
| const std::string & | tid | |||
| ) | throw (InvalidArgument) [protected] |
returns the position on the lane checking it
This method extracts the position, checks whether it shall be mirrored and checks whether it is within the lane. If not, an error is reported and a InvalidArgument is thrown.
| [in] | attrs | The attributes to obtain the position from |
| [in] | lane | The lane the position shall be valid for |
| [in] | tt | The trigger type (for user output) |
| [in] | tid | The trigger id (for user output) |
| InvalidArgument | If the position is beyond the lane |
Definition at line 433 of file NLTriggerBuilder.cpp.
References SUMO_ATTR_FRIENDLY_POS, SUMO_ATTR_POSITION, and SUMOReal.
Referenced by parseAndBuildCalibrator(), and parseAndBuildLaneEmitTrigger().
00435 { 00436 bool ok = true; 00437 SUMOReal pos = attrs.getSUMORealReporting(SUMO_ATTR_POSITION, 0, 0, ok); 00438 bool friendlyPos = attrs.getOptBoolReporting(SUMO_ATTR_FRIENDLY_POS, 0, 0, ok, false); 00439 if (!ok) { 00440 throw InvalidArgument("Error on parsing a position information."); 00441 } 00442 if (pos<0) { 00443 pos = lane->getLength() + pos; 00444 } 00445 if (pos>lane->getLength()) { 00446 if (friendlyPos) { 00447 pos = lane->getLength() - (SUMOReal) 0.1; 00448 } else { 00449 throw InvalidArgument("The position of " + tt + " '" + tid + "' lies beyond the lane's '" + lane->getID() + "' length."); 00450 } 00451 } 00452 return pos; 00453 }
| void NLTriggerBuilder::parseAndBuildBusStop | ( | MSNet & | net, | |
| const SUMOSAXAttributes & | attrs | |||
| ) | throw (InvalidArgument) |
Parses his values and builds a bus stop.
| [in] | net | The network the bus stop belongs to |
| [in] | attrs | SAX-attributes which define the trigger |
| InvalidArgument | If a parameter (lane/position) is not valid |
Definition at line 205 of file NLTriggerBuilder.cpp.
References buildBusStop(), getLane(), MSLane::getLength(), MsgHandler::getWarningInstance(), MsgHandler::inform(), MAX2(), SUMOSAXAttributes::parseStringVector(), SUMO_ATTR_FRIENDLY_POS, SUMO_ATTR_FROM, SUMO_ATTR_LINES, SUMO_ATTR_TO, and SUMOReal.
Referenced by buildTrigger(), and NLHandler::myStartElement().
00205 { 00206 // get the id, throw if not given or empty... 00207 std::string id; 00208 if (!attrs.setIDFromAttributes("bus stop", id, false)) { 00209 throw InvalidArgument("A bus stop does not contain an id"); 00210 } 00211 // get the lane 00212 MSLane *lane = getLane(attrs, "bus_stop", id); 00213 // get the positions 00214 bool ok = true; 00215 SUMOReal frompos = attrs.getSUMORealReporting(SUMO_ATTR_FROM, "busstop", id.c_str(), ok); 00216 SUMOReal topos = attrs.getSUMORealReporting(SUMO_ATTR_TO, "busstop", id.c_str(), ok); 00217 bool friendlyPos = attrs.getOptBoolReporting(SUMO_ATTR_FRIENDLY_POS, "busstop", id.c_str(), ok, false); 00218 if (!ok) { 00219 throw InvalidArgument("Error on parsing a bus stop."); 00220 } 00221 if (frompos<0) { 00222 frompos = lane->getLength() + frompos; 00223 } 00224 if (topos<0) { 00225 topos = lane->getLength() + topos; 00226 } 00227 // check positions 00228 if (topos<0 || topos>lane->getLength()) { 00229 if (!friendlyPos) { 00230 throw InvalidArgument("Bus stop '" + id + "' ends after the lane's end."); 00231 } else { 00232 MsgHandler::getWarningInstance()->inform("Bus stop '" + id + "' ends after the lane's end (moving to the end)."); 00233 topos = lane->getLength() - (SUMOReal) .1; 00234 } 00235 } 00236 if (frompos<0 || frompos>lane->getLength()) { 00237 if (!friendlyPos) { 00238 throw InvalidArgument("Bus stop '" + id + "' begins after the lane's end."); 00239 } else { 00240 MsgHandler::getWarningInstance()->inform("Bus stop '" + id + "' begins after the lane's end (moving to the begin-10m)."); 00241 frompos = MAX2(SUMOReal(0), SUMOReal(topos-10.)); 00242 } 00243 } 00244 if (topos<frompos) { 00245 throw InvalidArgument("Bus stop's '" + id + "' end is in front of its begin."); 00246 } 00247 // get the lines 00248 std::vector<std::string> lines; 00249 SUMOSAXAttributes::parseStringVector(attrs.getOptStringReporting(SUMO_ATTR_LINES, "busstop", id.c_str(), ok, ""), lines); 00250 // build the bus stop 00251 buildBusStop(net, id, lines, lane, frompos, topos); 00252 }
| void NLTriggerBuilder::parseAndBuildCalibrator | ( | MSNet & | net, | |
| const SUMOSAXAttributes & | attrs, | |||
| const std::string & | base | |||
| ) | throw (InvalidArgument) |
Parses his values and builds a mesoscopic or microscopic calibrator.
| [in] | net | The network the calibrator belongs to |
| [in] | attrs | SAX-attributes which define the trigger |
| [in] | base | The base path |
| InvalidArgument | If a parameter (edge/position) is not valid |
Definition at line 256 of file NLTriggerBuilder.cpp.
References buildLaneCalibrator(), DELTA_T, MSLane::getEdge(), getFileName(), getLane(), getPosition(), myHandler, SUMO_ATTR_FREQUENCY, SUMO_ATTR_OUTPUT, SUMO_TAG_CALIBRATOR, and SUMOReal.
Referenced by buildTrigger(), and NLHandler::myStartElement().
00257 { 00258 // get the id, throw if not given or empty... 00259 std::string id; 00260 if (!attrs.setIDFromAttributes("calibrator", id, false)) { 00261 throw InvalidArgument("A calibrator does not contain an id"); 00262 } 00263 // get the file name to read further definitions from 00264 MSLane *lane = getLane(attrs, "calibrator", id); 00265 SUMOReal pos = getPosition(attrs, lane, "calibrator", id); 00266 bool ok = true; 00267 SUMOTime freq = attrs.getOptSUMOTimeReporting(SUMO_ATTR_FREQUENCY, "meandata_lane", id.c_str(), ok, DELTA_T); // !!! no error handling 00268 #ifdef HAVE_MESOSIM 00269 if (MSGlobals::gUseMesoSim) { 00270 std::string file = getFileName(attrs, base, true); 00271 bool ok = true; 00272 std::string outfile = attrs.getOptStringReporting(SUMO_ATTR_OUTPUT, 0, 0, ok, ""); 00273 METriggeredCalibrator* trigger = buildCalibrator(net, id, &lane->getEdge(), pos, file, outfile, freq); 00274 if (file == "") { 00275 trigger->registerParent(SUMO_TAG_CALIBRATOR, myHandler); 00276 } 00277 } else { 00278 #endif 00279 std::string file = getFileName(attrs, base); 00280 buildLaneCalibrator(net, id, lane, pos, file); 00281 #ifdef HAVE_MESOSIM 00282 } 00283 #endif 00284 }
| void NLTriggerBuilder::parseAndBuildLaneEmitTrigger | ( | MSNet & | net, | |
| const SUMOSAXAttributes & | attrs, | |||
| const std::string & | base | |||
| ) | throw (InvalidArgument) |
Parses his values and builds an emitter.
| [in] | net | The network the emitter belongs to |
| [in] | attrs | SAX-attributes which define the trigger |
| [in] | base | The base path |
| InvalidArgument | If a parameter (lane/position) is not valid |
Definition at line 185 of file NLTriggerBuilder.cpp.
References buildLaneEmitTrigger(), getFileName(), getLane(), getPosition(), MsgHandler::getWarningInstance(), MsgHandler::inform(), myHaveInformedAboutDeprecatedEmitter, and SUMOReal.
Referenced by buildTrigger(), and NLHandler::myStartElement().
00186 { 00187 if (!myHaveInformedAboutDeprecatedEmitter) { 00188 myHaveInformedAboutDeprecatedEmitter = true; 00189 MsgHandler::getWarningInstance()->inform("Emitter are deprecated; use departpos/departspeed within routes instead."); 00190 } 00191 // get the id, throw if not given or empty... 00192 std::string id; 00193 if (!attrs.setIDFromAttributes("emitter", id, false)) { 00194 throw InvalidArgument("An emitter does not contain an id"); 00195 } 00196 // get the file name to read further definitions from 00197 std::string file = getFileName(attrs, base); 00198 MSLane *lane = getLane(attrs, "emitter", id); 00199 SUMOReal pos = getPosition(attrs, lane, "emitter", id); 00200 buildLaneEmitTrigger(net, id, lane, pos, file); 00201 }
| void NLTriggerBuilder::parseAndBuildLaneSpeedTrigger | ( | MSNet & | net, | |
| const SUMOSAXAttributes & | attrs, | |||
| const std::string & | base | |||
| ) | throw (InvalidArgument) |
Parses his values and builds a lane speed trigger.
If one of the declaration values is errornous, an InvalidArgument is thrown.
If the XML-file parsed during initialisation is errornous, and the MSLaneSpeedTrigger-constructor throws a ProcessError due to this, this exception is catched and an InvalidArgument with the message given in the ProcessError is thrown.
| [in] | net | The network the lane speed trigger belongs to |
| [in] | attrs | SAX-attributes which define the trigger |
| [in] | base | The base path |
| InvalidArgument | If a parameter (lane/position) is not valid or the read definition is errornous |
Definition at line 138 of file NLTriggerBuilder.cpp.
References buildLaneSpeedTrigger(), MSLane::dictionary(), getFileName(), MsgHandler::getWarningInstance(), MsgHandler::inform(), myHandler, SUMOSAXAttributes::parseStringVector(), GenericSAXHandler::registerParent(), SUMO_ATTR_LANES, SUMO_ATTR_OBJECTID, and SUMO_TAG_VSS.
Referenced by buildTrigger(), and NLHandler::myStartElement().
00139 { 00140 // get the id, throw if not given or empty... 00141 std::string id; 00142 if (!attrs.setIDFromAttributes("lane speed trigger", id, false)) { 00143 throw InvalidArgument("A lane speed trigger definition does not contain an id"); 00144 } 00145 // get the file name to read further definitions from 00146 std::string file = getFileName(attrs, base, true); 00147 std::string objectid; 00148 bool ok = true; 00149 if (attrs.hasAttribute(SUMO_ATTR_LANES)) { 00150 objectid = attrs.getStringReporting(SUMO_ATTR_LANES, "vss", id.c_str(), ok); 00151 } else { 00152 if (attrs.hasAttribute(SUMO_ATTR_OBJECTID)) { 00153 objectid = attrs.getStringReporting(SUMO_ATTR_OBJECTID, "vss", id.c_str(), ok); 00154 MsgHandler::getWarningInstance()->inform("Defining the lanes using 'objectid' within a variable speed sign is deprecated, use 'lanes' instead."); 00155 } 00156 } 00157 if (!ok) { 00158 throw InvalidArgument("The lanes to use within MSLaneSpeedTrigger '" + id + "' are not known."); 00159 } 00160 std::vector<MSLane*> lanes; 00161 std::vector<std::string> laneIDs; 00162 SUMOSAXAttributes::parseStringVector(objectid, laneIDs); 00163 for (std::vector<std::string>::iterator i=laneIDs.begin(); i!=laneIDs.end(); ++i) { 00164 MSLane *lane = MSLane::dictionary(*i); 00165 if (lane==0) { 00166 throw InvalidArgument("The lane to use within MSLaneSpeedTrigger '" + id + "' is not known."); 00167 } 00168 lanes.push_back(lane); 00169 } 00170 if (lanes.size()==0) { 00171 throw InvalidArgument("No lane defined for MSLaneSpeedTrigger '" + id + "'."); 00172 } 00173 try { 00174 MSLaneSpeedTrigger* trigger = buildLaneSpeedTrigger(net, id, lanes, file); 00175 if (file == "") { 00176 trigger->registerParent(SUMO_TAG_VSS, myHandler); 00177 } 00178 } catch (ProcessError &e) { 00179 throw InvalidArgument(e.what()); 00180 } 00181 }
| void NLTriggerBuilder::parseAndBuildRerouter | ( | MSNet & | net, | |
| const SUMOSAXAttributes & | attrs, | |||
| const std::string & | base | |||
| ) | throw (InvalidArgument) |
Parses his values and builds a rerouter.
| [in] | net | The network the rerouter belongs to |
| [in] | attrs | SAX-attributes which define the trigger |
| [in] | base | The base path |
| InvalidArgument | If a parameter (edge) is not valid |
Definition at line 288 of file NLTriggerBuilder.cpp.
References buildRerouter(), MSEdge::dictionary(), getFileName(), MsgHandler::getWarningInstance(), MsgHandler::inform(), SUMOSAXAttributes::parseStringVector(), SUMO_ATTR_EDGES, SUMO_ATTR_OBJECTID, SUMO_ATTR_OFF, SUMO_ATTR_PROB, and SUMOReal.
Referenced by buildTrigger(), and NLHandler::myStartElement().
00289 { 00290 // get the id, throw if not given or empty... 00291 std::string id; 00292 if (!attrs.setIDFromAttributes("rerouter", id, false)) { 00293 throw InvalidArgument("A rerouter does not contain an id"); 00294 } 00295 // get the file name to read further definitions from 00296 std::string file = getFileName(attrs, base); 00297 std::string objectid; 00298 bool ok = true; 00299 if (attrs.hasAttribute(SUMO_ATTR_EDGES)) { 00300 objectid = attrs.getStringReporting(SUMO_ATTR_EDGES, "rerouter", id.c_str(), ok); 00301 } else { 00302 if (attrs.hasAttribute(SUMO_ATTR_OBJECTID)) { 00303 objectid = attrs.getStringReporting(SUMO_ATTR_OBJECTID, "rerouter", id.c_str(), ok); 00304 MsgHandler::getWarningInstance()->inform("Defining the edges using 'objectid' within a rerouter is deprecated, use 'edges' instead."); 00305 } 00306 } 00307 if (!ok) { 00308 throw InvalidArgument("The edge to use within MSTriggeredRerouter '" + id + "' is not known."); 00309 } 00310 std::vector<MSEdge*> edges; 00311 std::vector<std::string> edgeIDs; 00312 SUMOSAXAttributes::parseStringVector(objectid, edgeIDs); 00313 for (std::vector<std::string>::iterator i=edgeIDs.begin(); i!=edgeIDs.end(); ++i) { 00314 MSEdge *edge = MSEdge::dictionary(*i); 00315 if (edge==0) { 00316 throw InvalidArgument("The edge to use within MSTriggeredRerouter '" + id + "' is not known."); 00317 } 00318 edges.push_back(edge); 00319 } 00320 if (edges.size()==0) { 00321 throw InvalidArgument("No edges found for MSTriggeredRerouter '" + id + "'."); 00322 } 00323 SUMOReal prob = attrs.getOptSUMORealReporting(SUMO_ATTR_PROB, "rerouter", id.c_str(), ok, 1); 00324 bool off = attrs.getOptBoolReporting(SUMO_ATTR_OFF, "rerouter", id.c_str(), ok, false); 00325 if (!ok) { 00326 throw InvalidArgument("Could not parse MSTriggeredRerouter '" + id + "'."); 00327 } 00328 buildRerouter(net, id, edges, prob, file, off); 00329 }
| void NLTriggerBuilder::setHandler | ( | NLHandler * | handler | ) | throw () |
Sets the parent handler to use for nested parsing.
| [in] | handler | The netload handler to set |
Definition at line 68 of file NLTriggerBuilder.cpp.
References myHandler.
Referenced by load(), and GUILoadThread::run().
00068 { 00069 myHandler = handler; 00070 }
NLHandler* NLTriggerBuilder::myHandler [protected] |
The parent handler to set for subhandlers.
Definition at line 358 of file NLTriggerBuilder.h.
Referenced by parseAndBuildCalibrator(), parseAndBuildLaneSpeedTrigger(), and setHandler().
Information whether an emitter shall be built (is deprecated).
Definition at line 355 of file NLTriggerBuilder.h.
Referenced by parseAndBuildLaneEmitTrigger().
Information whether a deprecated trigger definition has occured and was reported.
Definition at line 352 of file NLTriggerBuilder.h.
Referenced by buildTrigger().
1.5.6