SUMO - Simulation of Urban MObility
NIImporter_SUMO Class Reference

Importer for networks stored in SUMO format. More...

#include <NIImporter_SUMO.h>

Inheritance diagram for NIImporter_SUMO:
SUMOSAXHandler GenericSAXHandler DefaultHandler

Data Structures

struct  Connection
 A connection description. More...
struct  EdgeAttrs
 Describes the values found in an edge's definition and this edge's lanes. More...
struct  LaneAttrs
 Describes the values found in a lane's definition. More...
struct  Prohibition
 Describes the values found in a prohibition. More...

Public Member Functions

void characters (const XMLCh *const chars, const XERCES3_SIZE_t length)
 The inherited method called when characters occured.
void endElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname)
 The inherited method called when a tag is being closed.
const std::string & getFileName () const
 returns the current file name
void registerParent (const int tag, GenericSAXHandler *handler)
 Assigning a parent handler which is enabled when the specified tag is closed.
void setFileName (const std::string &name)
 Sets the current file name.
void startElement (const XMLCh *const uri, const XMLCh *const localname, const XMLCh *const qname, const Attributes &attrs)
 The inherited method called when a new tag opens.
SAX ErrorHandler callbacks
void warning (const SAXParseException &exception)
 Handler for XML-warnings.
void error (const SAXParseException &exception)
 Handler for XML-errors.
void fatalError (const SAXParseException &exception)
 Handler for XML-errors.

Static Public Member Functions

static void addPhase (const SUMOSAXAttributes &attrs, NBLoadedSUMOTLDef *currentTL)
 adds a phase to the traffic lights logic currently build
static NBLoadedSUMOTLDefinitTrafficLightLogic (const SUMOSAXAttributes &attrs, NBLoadedSUMOTLDef *currentTL)
 begins the reading of a traffic lights logic
static GeoConvHelperloadLocation (const SUMOSAXAttributes &attrs)
 Parses network location description and registers it with GeoConveHelper::setLoaded.
static void loadNetwork (const OptionsCont &oc, NBNetBuilder &nb)
 Loads content of the optionally given SUMO file.

Protected Member Functions

std::string buildErrorMessage (const SAXParseException &exception)
 Builds an error message.
 NIImporter_SUMO (NBNetBuilder &nb)
 Constructor.
 ~NIImporter_SUMO ()
 Destructor.
inherited from GenericSAXHandler
void myStartElement (int element, const SUMOSAXAttributes &attrs)
 Called on the opening of a tag;.
void myCharacters (int element, const std::string &chars)
 Called when characters occure.
void myEndElement (int element)
 Called when a closing tag occurs.

Private Member Functions

void _loadNetwork (const OptionsCont &oc)
 load the network
LaneAttrsgetLaneAttrsFromID (EdgeAttrs *edge, std::string lane_id)
 Parses lane index from lane ID an retrieve lane from EdgeAttrs.
void parseProhibitionConnection (const std::string &attr, std::string &from, std::string &to, bool &ok)
 parses connection string of a prohibition (very old school)
Object instance parsing methods
void addEdge (const SUMOSAXAttributes &attrs)
 Parses an edge and stores the values in "myCurrentEdge".
void addLane (const SUMOSAXAttributes &attrs)
 Parses a lane and stores the values in "myCurrentLane".
void addJunction (const SUMOSAXAttributes &attrs)
 Parses a junction and saves it in the node control.
void addSuccEdge (const SUMOSAXAttributes &attrs)
 (deprecated) Parses a succedge-definition and saves it by assigning "myCurrentEdge" and "myCurrentLane" to the read values
void addSuccLane (const SUMOSAXAttributes &attrs)
 (deprecated) Parses a succlane-definition and saves it into the lane's definition stored in "myCurrentLane"
void addConnection (const SUMOSAXAttributes &attrs)
 Parses a connection and saves it into the lane's definition stored in "myCurrentLane".
void addProhibition (const SUMOSAXAttributes &attrs)
 Parses a prohibition and saves it.

Static Private Member Functions

static void interpretLaneID (const std::string &lane_id, std::string &edge_id, unsigned int &index)
 parses edge-id and index from lane-id
static Position readPosition (const SUMOSAXAttributes &attrs, const std::string &id, bool &ok)
 read position from the given attributes, attribute errors to id
static PositionVector reconstructEdgeShape (const EdgeAttrs *edge, const Position &from, const Position &to)
 reconstructs the edge shape from the node positions and the given lane shapes since we do not know the original LaneSpreadFunction this is only an approximation

Private Attributes

EdgeAttrsmyCurrentEdge
 The currently parsed edge's definition (to add loaded lanes to)
LaneAttrsmyCurrentLane
 The currently parsed lanes's definition (to add the shape to)
NBLoadedSUMOTLDefmyCurrentTL
 The currently parsed traffic light.
std::map< std::string,
EdgeAttrs * > 
myEdges
 Loaded edge definitions.
bool myHaveWarnedAboutDeprecatedMaxSpeed
bool myHaveWarnedAboutDeprecatedSpreadType
GeoConvHelpermyLocation
 The coordinate transformation which was used to build the loaded network.
NBNetBuildermyNetBuilder
 The network builder to fill.
NBNodeContmyNodeCont
 The node container to fill.
std::vector< ProhibitionmyProhibitions
 Loaded prohibitions.
bool mySuspectKeepShape
 whether we suspect a net that was built with xml.keep-shape
NBTrafficLightLogicContmyTLLCont
 The node container to fill.

Detailed Description

Importer for networks stored in SUMO format.

Definition at line 58 of file NIImporter_SUMO.h.


Constructor & Destructor Documentation

Constructor.

Parameters:
[in]ncThe network builder to fill

Definition at line 75 of file NIImporter_SUMO.cpp.

Destructor.

Definition at line 89 of file NIImporter_SUMO.cpp.

References NIImporter_SUMO::EdgeAttrs::lanes, myEdges, and myLocation.


Member Function Documentation

void NIImporter_SUMO::_loadNetwork ( const OptionsCont oc) [private]

load the network

Definition at line 102 of file NIImporter_SUMO.cpp.

References NBLoadedSUMOTLDef::addConnection(), NBEdge::addLane2LaneConnection(), NBNode::addSortedLinkFoes(), NIImporter_SUMO::LaneAttrs::allow, NIImporter_SUMO::EdgeAttrs::builtEdge, NIImporter_SUMO::LaneAttrs::connections, NBEdge::declareConnectionsAsLoaded(), NIImporter_SUMO::LaneAttrs::disallow, EDGEFUNC_INTERNAL, FileHelpers::exists(), NIImporter_SUMO::EdgeAttrs::fromNode, NIImporter_SUMO::EdgeAttrs::func, NBNetBuilder::getEdgeCont(), NBNode::getPosition(), NBTrafficLightLogicCont::getPrograms(), OptionsCont::getStringVector(), NBEdge::getToNode(), NIImporter_SUMO::EdgeAttrs::id, NBEdgeCont::insert(), OptionsCont::isUsableFileList(), NBEdge::L2L_VALIDATED, NIImporter_SUMO::EdgeAttrs::lanes, NIImporter_SUMO::EdgeAttrs::length, NIImporter_SUMO::EdgeAttrs::lsf, NIImporter_SUMO::LaneAttrs::maxSpeed, NIImporter_SUMO::EdgeAttrs::maxSpeed, NIImporter_SUMO::Connection::mayDefinitelyPass, myEdges, myNetBuilder, myNodeCont, myProhibitions, mySuspectKeepShape, myTLLCont, NIImporter_SUMO::LaneAttrs::offset, parseVehicleClasses(), NIImporter_SUMO::EdgeAttrs::priority, PROGRESS_BEGIN_MESSAGE, PROGRESS_DONE_MESSAGE, reconstructEdgeShape(), NBEdgeCont::retrieve(), NBNodeCont::retrieve(), XMLSubSys::runParser(), GenericSAXHandler::setFileName(), NBEdge::setLoadedLength(), NBEdge::setOffset(), NBEdge::setPermissions(), NBEdge::setSpeed(), NBEdge::setWidth(), NIImporter_SUMO::EdgeAttrs::shape, PositionVector::size(), NIImporter_SUMO::EdgeAttrs::streetName, NIImporter_SUMO::Connection::tlID, NIImporter_SUMO::Connection::tlLinkNo, NIImporter_SUMO::Connection::toEdgeID, NIImporter_SUMO::Connection::toLaneIdx, NIImporter_SUMO::EdgeAttrs::toNode, toString(), NIImporter_SUMO::EdgeAttrs::type, NBEdge::UNSPECIFIED_OFFSET, NBEdge::UNSPECIFIED_WIDTH, NIImporter_SUMO::LaneAttrs::width, WRITE_ERROR, and WRITE_WARNING.

Referenced by loadNetwork().

void NIImporter_SUMO::addEdge ( const SUMOSAXAttributes attrs) [private]
void NIImporter_SUMO::addSuccEdge ( const SUMOSAXAttributes attrs) [private]

(deprecated) Parses a succedge-definition and saves it by assigning "myCurrentEdge" and "myCurrentLane" to the read values

Parameters:
[in]attrsThe attributes to get the succedge-definition from

Definition at line 466 of file NIImporter_SUMO.cpp.

References getLaneAttrsFromID(), SUMOSAXAttributes::getStringReporting(), myCurrentEdge, myCurrentLane, myEdges, SUMO_ATTR_EDGE, SUMO_ATTR_LANE, and WRITE_ERROR.

Referenced by myStartElement().

std::string GenericSAXHandler::buildErrorMessage ( const SAXParseException &  exception) [protected, inherited]

Builds an error message.

The error message includes the file name and the line/column information as supported by the given SAXParseException

Parameters:
[in]exceptionThe name of the currently processed file
Returns:
A string describing the given exception

Definition at line 193 of file GenericSAXHandler.cpp.

References GenericSAXHandler::getFileName().

Referenced by GenericSAXHandler::error(), GenericSAXHandler::fatalError(), and GenericSAXHandler::warning().

void GenericSAXHandler::characters ( const XMLCh *const  chars,
const XERCES3_SIZE_t  length 
) [inherited]

The inherited method called when characters occured.

The retrieved characters are converted into a string and appended into a private buffer. They are reported as soon as the element ends.

Todo:

recheck/describe what happens with characters when a new element is opened

describe characters processing in the class' head

Definition at line 176 of file GenericSAXHandler.cpp.

References GenericSAXHandler::myCharactersVector.

void GenericSAXHandler::endElement ( const XMLCh *const  uri,
const XMLCh *const  localname,
const XMLCh *const  qname 
) [inherited]

The inherited method called when a tag is being closed.

This method calls the user-implemented methods myCharacters with the previously collected and converted characters.

Then, myEndElement is called, supplying it the qname converted to its enum- and string-representations.

Todo:

recheck/describe encoding of the string-representation

do not generate and report the string-representation

Definition at line 126 of file GenericSAXHandler.cpp.

References GenericSAXHandler::convertTag(), GenericSAXHandler::myCharacters(), GenericSAXHandler::myCharactersVector, GenericSAXHandler::myEndElement(), GenericSAXHandler::myParentHandler, GenericSAXHandler::myParentIndicator, XMLSubSys::setHandler(), SUMO_TAG_INCLUDE, and SUMO_TAG_NOTHING.

void GenericSAXHandler::error ( const SAXParseException &  exception) [inherited]

Handler for XML-errors.

The message is built using buildErrorMessage and thrown within a ProcessError.

Parameters:
[in]exceptionThe occured exception to process
Exceptions:
ProcessErrorOn any call

Definition at line 212 of file GenericSAXHandler.cpp.

References GenericSAXHandler::buildErrorMessage().

Referenced by NLHandler::getLanesFromIndices().

void GenericSAXHandler::fatalError ( const SAXParseException &  exception) [inherited]

Handler for XML-errors.

The message is built using buildErrorMessage and thrown within a ProcessError.

Exceptions:
ProcessErrorOn any call
Parameters:
[in]exceptionThe occured exception to process

Definition at line 218 of file GenericSAXHandler.cpp.

References GenericSAXHandler::buildErrorMessage().

NIImporter_SUMO::LaneAttrs * NIImporter_SUMO::getLaneAttrsFromID ( EdgeAttrs edge,
std::string  lane_id 
) [private]

Parses lane index from lane ID an retrieve lane from EdgeAttrs.

Parameters:
[in]edgeThe EdgeAttrs* which should contain the lane
[in]lane_idThe ID of the lane

Definition at line 551 of file NIImporter_SUMO.cpp.

References NIImporter_SUMO::EdgeAttrs::id, interpretLaneID(), NIImporter_SUMO::EdgeAttrs::lanes, and WRITE_ERROR.

Referenced by addSuccEdge().

void NIImporter_SUMO::interpretLaneID ( const std::string &  lane_id,
std::string &  edge_id,
unsigned int index 
) [static, private]

parses edge-id and index from lane-id

Parameters:
[in]lane_idThe lane-id
[out]edge_idID of this lane's edge
[out]indexIndex of this lane

Definition at line 566 of file NIImporter_SUMO.cpp.

References WRITE_ERROR.

Referenced by addSuccLane(), and getLaneAttrsFromID().

void NIImporter_SUMO::loadNetwork ( const OptionsCont oc,
NBNetBuilder nb 
) [static]

Loads content of the optionally given SUMO file.

If the option "sumo-net-file" is set, the file stored therein is read and the network definition stored therein is stored within the given network builder.

If the option "sumo-net-file" is not set, this method simply returns.

The loading is done by parsing the network definition as an XML file using the SAXinterface and handling the incoming data via this class' methods.

Parameters:
[in]ocThe options to use
[in]nbThe network builder to fill

Definition at line 66 of file NIImporter_SUMO.cpp.

References _loadNetwork().

Referenced by NILoader::load().

void NIImporter_SUMO::myCharacters ( int  element,
const std::string &  chars 
) [protected, virtual]

Called when characters occure.

Parameters:
[in]elementID of the last opened element
[in]charsThe read characters (complete)
Exceptions:
ProcessErrorIf something fails
See also:
GenericSAXHandler::myCharacters

Reimplemented from GenericSAXHandler.

Definition at line 292 of file NIImporter_SUMO.cpp.

References UNUSED_PARAMETER.

void NIImporter_SUMO::myStartElement ( int  element,
const SUMOSAXAttributes attrs 
) [protected, virtual]

Called on the opening of a tag;.

In dependence to the obtained type, an appropriate parsing method is called ("addEdge" if an edge encounters, f.e.).

Parameters:
[in]elementID of the currently opened element
[in]attrsAttributes within the currently opened element
Exceptions:
ProcessErrorIf something fails
See also:
GenericSAXHandler::myStartElement

Reimplemented from GenericSAXHandler.

Definition at line 237 of file NIImporter_SUMO.cpp.

References addConnection(), addEdge(), addJunction(), addLane(), addPhase(), addProhibition(), addSuccEdge(), addSuccLane(), initTrafficLightLogic(), loadLocation(), myCurrentTL, myLocation, SUMO_TAG_CONNECTION, SUMO_TAG_EDGE, SUMO_TAG_JUNCTION, SUMO_TAG_LANE, SUMO_TAG_LOCATION, SUMO_TAG_PHASE, SUMO_TAG_PROHIBITION, SUMO_TAG_SUCC, SUMO_TAG_SUCCLANE, SUMO_TAG_TLLOGIC, and SUMO_TAG_TLLOGIC__DEPRECATED.

void NIImporter_SUMO::parseProhibitionConnection ( const std::string &  attr,
std::string &  from,
std::string &  to,
bool ok 
) [private]

parses connection string of a prohibition (very old school)

Parameters:
[in]attrThe connection attribute
[out]fromID of the source edge
[out]toID of the destination edge
[out]okWhether parsing completed successfully

Definition at line 706 of file NIImporter_SUMO.cpp.

References myEdges, and WRITE_ERROR.

Referenced by addProhibition().

Position NIImporter_SUMO::readPosition ( const SUMOSAXAttributes attrs,
const std::string &  id,
bool ok 
) [static, private]

read position from the given attributes, attribute errors to id

Definition at line 694 of file NIImporter_SUMO.cpp.

References SUMOSAXAttributes::getSUMORealReporting(), SUMOSAXAttributes::hasAttribute(), SUMO_ATTR_X, SUMO_ATTR_Y, SUMO_ATTR_Z, and SUMOReal.

Referenced by addJunction().

PositionVector NIImporter_SUMO::reconstructEdgeShape ( const EdgeAttrs edge,
const Position from,
const Position to 
) [static, private]

reconstructs the edge shape from the node positions and the given lane shapes since we do not know the original LaneSpreadFunction this is only an approximation

Parameters:
[in]lanesThe list of lane attributes

Definition at line 630 of file NIImporter_SUMO.cpp.

References Line::extrapolateBy(), NIImporter_SUMO::EdgeAttrs::id, Line::intersects(), Line::intersectsAt(), NBEdge::laneOffset(), NIImporter_SUMO::EdgeAttrs::lanes, NIImporter_SUMO::EdgeAttrs::lsf, PositionVector::push_back(), PositionVector::size(), SUMO_const_laneWidthAndOffset, WRITE_WARNING, Position::x(), and Position::y().

Referenced by _loadNetwork().

void GenericSAXHandler::registerParent ( const int  tag,
GenericSAXHandler handler 
) [inherited]

Assigning a parent handler which is enabled when the specified tag is closed.

Definition at line 168 of file GenericSAXHandler.cpp.

References GenericSAXHandler::myParentHandler, GenericSAXHandler::myParentIndicator, and XMLSubSys::setHandler().

Referenced by NLTriggerBuilder::parseAndBuildLaneSpeedTrigger(), and NLTriggerBuilder::parseAndBuildRerouter().

void GenericSAXHandler::setFileName ( const std::string &  name) [inherited]
void GenericSAXHandler::startElement ( const XMLCh *const  uri,
const XMLCh *const  localname,
const XMLCh *const  qname,
const Attributes &  attrs 
) [inherited]

The inherited method called when a new tag opens.

The method parses the supplied XMLCh*-qname using the internal name/enum-map to obtain the enum representation of the attribute name.

Then, "myStartElement" is called supplying the enumeration value, the string-representation of the name and the attributes.

Todo:

recheck/describe encoding of the string-representation

do not generate and report the string-representation

Definition at line 105 of file GenericSAXHandler.cpp.

References GenericSAXHandler::convertTag(), FileHelpers::getConfigurationRelative(), GenericSAXHandler::getFileName(), SUMOSAXAttributesImpl_Xerces::getString(), FileHelpers::isAbsolute(), GenericSAXHandler::myCharactersVector, GenericSAXHandler::myPredefinedTags, GenericSAXHandler::myPredefinedTagsMML, GenericSAXHandler::myStartElement(), XMLSubSys::runParser(), SUMO_ATTR_HREF, and SUMO_TAG_INCLUDE.

void GenericSAXHandler::warning ( const SAXParseException &  exception) [inherited]

Handler for XML-warnings.

The message is built using buildErrorMessage and reported to the warning-instance of the MsgHandler.

Parameters:
[in]exceptionThe occured exception to process

Definition at line 206 of file GenericSAXHandler.cpp.

References GenericSAXHandler::buildErrorMessage(), and WRITE_WARNING.


Field Documentation

The currently parsed edge's definition (to add loaded lanes to)

Definition at line 290 of file NIImporter_SUMO.h.

Referenced by addEdge(), addLane(), addSuccEdge(), and myEndElement().

The currently parsed lanes's definition (to add the shape to)

Definition at line 293 of file NIImporter_SUMO.h.

Referenced by addLane(), addSuccEdge(), addSuccLane(), and myEndElement().

The currently parsed traffic light.

Definition at line 296 of file NIImporter_SUMO.h.

Referenced by myEndElement(), and myStartElement().

std::map<std::string, EdgeAttrs*> NIImporter_SUMO::myEdges [private]

Loaded edge definitions.

Definition at line 275 of file NIImporter_SUMO.h.

Referenced by _loadNetwork(), addConnection(), addSuccEdge(), myEndElement(), parseProhibitionConnection(), and ~NIImporter_SUMO().

Definition at line 305 of file NIImporter_SUMO.h.

Referenced by addLane().

Definition at line 304 of file NIImporter_SUMO.h.

Referenced by addEdge().

The coordinate transformation which was used to build the loaded network.

Definition at line 299 of file NIImporter_SUMO.h.

Referenced by addEdge(), addJunction(), addLane(), myStartElement(), and ~NIImporter_SUMO().

The network builder to fill.

Definition at line 281 of file NIImporter_SUMO.h.

Referenced by _loadNetwork().

The node container to fill.

Definition at line 284 of file NIImporter_SUMO.h.

Referenced by _loadNetwork(), and addJunction().

Loaded prohibitions.

Definition at line 278 of file NIImporter_SUMO.h.

Referenced by _loadNetwork(), and addProhibition().

whether we suspect a net that was built with xml.keep-shape

Definition at line 302 of file NIImporter_SUMO.h.

Referenced by _loadNetwork(), and addJunction().

The node container to fill.

Definition at line 287 of file NIImporter_SUMO.h.

Referenced by _loadNetwork(), and myEndElement().


The documentation for this class was generated from the following files:
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines