NIXMLEdgesHandler Class Reference

#include <NIXMLEdgesHandler.h>

Inheritance diagram for NIXMLEdgesHandler:

SUMOSAXHandler GenericSAXHandler

Detailed Description

Importer for network edges stored in XML.

This SAX-handler parses edge information and stores it in the given container.

Todo:
revalidate node retrieval

Definition at line 60 of file NIXMLEdgesHandler.h.


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 throw ()
 returns the current file name
 NIXMLEdgesHandler (NBNodeCont &nc, NBEdgeCont &ec, NBTypeCont &tc, NBDistrictCont &dc, OptionsCont &options) throw ()
 Constructor.
void registerParent (const SumoXMLTag tag, GenericSAXHandler *handler)
 Assigning a parent handler which is enabled when the specified tag is closed.
void setFileName (const std::string &name) throw ()
 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.
 ~NIXMLEdgesHandler () throw ()
 Destructor.
SAX ErrorHandler callbacks
void error (const SAXParseException &exception) throw (ProcessError)
 Handler for XML-errors.
void fatalError (const SAXParseException &exception) throw (ProcessError)
 Handler for XML-errors.
void warning (const SAXParseException &exception) throw ()
 Handler for XML-warnings.

Protected Member Functions

std::string buildErrorMessage (const SAXParseException &exception) throw ()
 Builds an error message.
virtual void myCharacters (SumoXMLTag element, const std::string &chars) throw (ProcessError)
 Callback method for characters to implement by derived classes.
inherited from GenericSAXHandler
void myEndElement (SumoXMLTag element) throw (ProcessError)
 Called when a closing tag occurs.
void myStartElement (SumoXMLTag element, const SUMOSAXAttributes &attrs) throw (ProcessError)
 Called on the opening of a tag;.

Private Member Functions

NBNodeinsertNodeChecking (const Position2D &pos, const std::string &name, const std::string &dir)
 NIXMLEdgesHandler (const NIXMLEdgesHandler &s)
 invalid copy constructor
NIXMLEdgesHandleroperator= (const NIXMLEdgesHandler &s)
 invalid assignment operator
void parseSplitLanes (const std::string &val) throw (ProcessError)
 Parses the given string as lanes to keep, storing them.
bool setNodes (const SUMOSAXAttributes &attrs) throw ()
 Sets from/to node information of the currently parsed edge.
SUMOReal tryGetPosition (const SUMOSAXAttributes &attrs, SumoXMLAttr attrID, const std::string &attrName)
 tries to parse one of the node's positions Which position has to be parsed is defined by the given call variables
Position2DVector tryGetShape (const SUMOSAXAttributes &attrs) throw ()
 Tries to parse the shape definition.

Private Attributes

NBEdgemyCurrentEdge
 The currently processed edge.
std::string myCurrentID
 The current edge's id.
int myCurrentLaneNo
 The current edge's number of lanes.
int myCurrentPriority
 The current edge's priority.
SUMOReal myCurrentSpeed
 The current edge's maximum speed.
std::string myCurrentType
 The current edge's type.
NBDistrictContmyDistrictCont
 The districts container (needed if an edge must be split).
NBEdgeContmyEdgeCont
 The edges container (for insertion of build edges).
NBNodemyFromNode
 The nodes the edge starts and ends at.
bool myHaveReportedAboutFunctionDeprecation
 Information whether at least one edge with a function-attribute occured and was reported.
bool myHaveReportedAboutOverwriting
 Information whether at least one edge's attributes were overwritten.
bool myIsUpdate
 Whether this edge definition is an update of a previously inserted edge.
NBEdge::LaneSpreadFunction myLanesSpread
 Information about how to spread the lanes.
SUMOReal myLength
 The current edge's length.
NBNodeContmyNodeCont
 The nodes container (for retrieval of referenced nodes).
OptionsContmyOptions
 A reference to the program's options.
Position2DVector myShape
 The shape of the edge.
std::vector< SplitmySplits
 The list of this edge's splits.
NBNodemyToNode
NBTypeContmyTypeCont
 The types container (for retrieval of type defaults).

Data Structures

struct  Split
 A structure which describes changes of lane number along the road. More...
class  split_by_pos_finder
 Finds a split at the given position. More...
class  split_sorter
 Sorts splits by their position (increasing). More...

Constructor & Destructor Documentation

NIXMLEdgesHandler::NIXMLEdgesHandler ( NBNodeCont nc,
NBEdgeCont ec,
NBTypeCont tc,
NBDistrictCont dc,
OptionsCont options 
) throw ()

Constructor.

Parameters:
[in] nc The nodes container (for retrieval of referenced nodes)
[in] ec The edges container (for insertion of build edges)
[in] tc The types container (for retrieval of type defaults)
[in] dc The districts container (needed if an edge must be split)
[in] options The options to use while building edges

Definition at line 66 of file NIXMLEdgesHandler.cpp.

00071         : SUMOSAXHandler("xml-edges - file"),
00072         myOptions(options),
00073         myNodeCont(nc), myEdgeCont(ec), myTypeCont(tc), myDistrictCont(dc),
00074         myCurrentEdge(0),
00075         myHaveReportedAboutFunctionDeprecation(false) {}

NIXMLEdgesHandler::~NIXMLEdgesHandler (  )  throw ()

Destructor.

Definition at line 78 of file NIXMLEdgesHandler.cpp.

00078 {}

NIXMLEdgesHandler::NIXMLEdgesHandler ( const NIXMLEdgesHandler s  )  [private]

invalid copy constructor


Member Function Documentation

std::string SUMOSAXHandler::buildErrorMessage ( const SAXParseException &  exception  )  throw () [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] exception The name of the currently processed file
Returns:
A string describing the given exception

Definition at line 55 of file SUMOSAXHandler.cpp.

References GenericSAXHandler::getFileName().

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

00055                                                                             {
00056     std::ostringstream buf;
00057     char *pMsg = XMLString::transcode(exception.getMessage());
00058     buf << pMsg << std::endl;
00059     buf << " In file '" << getFileName() << "'" << std::endl;
00060     buf << " At line/column " << exception.getLineNumber()+1
00061     << '/' << exception.getColumnNumber() << "." << std::endl;
00062     XMLString::release(&pMsg);
00063     return buf.str();
00064 }

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
Todo:
describe characters processing in the class' head

Definition at line 168 of file GenericSAXHandler.cpp.

References GenericSAXHandler::myCharactersVector.

00169                                                            {
00170     myCharactersVector.push_back(TplConvert<XMLCh>::_2str(chars, length));
00171 }

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
Todo:
do not generate and report the string-representation

Definition at line 118 of file GenericSAXHandler.cpp.

References TplConvert< E >::_2str(), GenericSAXHandler::convertTag(), GenericSAXHandler::myCharacters(), GenericSAXHandler::myCharactersVector, GenericSAXHandler::myEndElement(), GenericSAXHandler::myParentHandler, GenericSAXHandler::myParentIndicator, XMLSubSys::setHandler(), SUMO_TAG_INCLUDE, and SUMO_TAG_NOTHING.

00120                                                         {
00121     std::string name = TplConvert<XMLCh>::_2str(qname);
00122     SumoXMLTag element = convertTag(name);
00123     // collect characters
00124     if (myCharactersVector.size()!=0) {
00125         size_t len = 0;
00126         unsigned i;
00127         for (i=0; i<myCharactersVector.size(); ++i) {
00128             len += myCharactersVector[i].length();
00129         }
00130         char *buf = new char[len+1];
00131         size_t pos = 0;
00132         for (i=0; i<myCharactersVector.size(); ++i) {
00133             memcpy((unsigned char*) buf+pos, (unsigned char*) myCharactersVector[i].c_str(),
00134                    sizeof(char)*myCharactersVector[i].length());
00135             pos += myCharactersVector[i].length();
00136         }
00137         buf[pos] = 0;
00138 
00139         // call user handler
00140         try {
00141             myCharacters(element, buf);
00142         } catch (std::runtime_error &) {
00143             delete[] buf;
00144             throw;
00145         }
00146         delete[] buf;
00147     }
00148     if (element != SUMO_TAG_INCLUDE) {
00149         myEndElement(element);
00150         if (myParentHandler && myParentIndicator == element) {
00151             XMLSubSys::setHandler(*myParentHandler);
00152             myParentIndicator = SUMO_TAG_NOTHING;
00153             myParentHandler = 0;
00154         }
00155     }
00156 }

void SUMOSAXHandler::error ( const SAXParseException &  exception  )  throw (ProcessError) [inherited]

Handler for XML-errors.

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

Parameters:
[in] exception The occured exception to process
Exceptions:
ProcessError On any call

Definition at line 74 of file SUMOSAXHandler.cpp.

References SUMOSAXHandler::buildErrorMessage().

00074                                                                             {
00075     throw ProcessError(buildErrorMessage(exception));
00076 }

void SUMOSAXHandler::fatalError ( const SAXParseException &  exception  )  throw (ProcessError) [inherited]

Handler for XML-errors.

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

Exceptions:
ProcessError On any call
Parameters:
[in] exception The occured exception to process

Definition at line 80 of file SUMOSAXHandler.cpp.

References SUMOSAXHandler::buildErrorMessage().

00080                                                                                  {
00081     throw ProcessError(buildErrorMessage(exception));
00082 }

const std::string & GenericSAXHandler::getFileName (  )  const throw () [inherited]

NBNode * NIXMLEdgesHandler::insertNodeChecking ( const Position2D pos,
const std::string &  name,
const std::string &  dir 
) [private]

Definition at line 341 of file NIXMLEdgesHandler.cpp.

References MsgHandler::getErrorInstance(), NBNodeCont::getFreeID(), MsgHandler::inform(), NBNodeCont::insert(), myCurrentID, myNodeCont, NBNodeCont::retrieve(), SUMOXML_INVALID_POSITION, toString(), Position2D::x(), and Position2D::y().

Referenced by setNodes().

00342                                                                                    {
00343     NBNode *ret = 0;
00344     if (name=="" && (pos.x()==SUMOXML_INVALID_POSITION || pos.y()==SUMOXML_INVALID_POSITION)) {
00345         MsgHandler::getErrorInstance()->inform("Neither the name nor the position of the " + dir + "-node is given for edge '" + myCurrentID + "'.");
00346         return ret;
00347     }
00348     if (name!="") {
00349         if (pos.x()!=SUMOXML_INVALID_POSITION && pos.y()!=SUMOXML_INVALID_POSITION) {
00350             // the node is named and it has a position given
00351             if (!myNodeCont.insert(name, pos)) {
00352                 MsgHandler::getErrorInstance()->inform("Position of " + dir + "-node '" + name + "' mismatches previous positions.");
00353                 return 0;
00354             }
00355         }
00356         // the node is given by its name
00357         ret = myNodeCont.retrieve(name);
00358         if (ret==0) {
00359             MsgHandler::getErrorInstance()->inform("Edge's '" + myCurrentID + "' " + dir + "-node '" + name + "' is not known.");
00360         }
00361     } else {
00362         ret = myNodeCont.retrieve(pos);
00363         if (ret==0) {
00364             ret = new NBNode(myNodeCont.getFreeID(), pos);
00365             if (!myNodeCont.insert(ret)) {
00366                 MsgHandler::getErrorInstance()->inform("Could not insert " + dir + "-node at position " + toString(pos) + ".");
00367                 delete ret;
00368                 return 0;
00369             }
00370         }
00371     }
00372     return ret;
00373 }

void GenericSAXHandler::myCharacters ( SumoXMLTag  element,
const std::string &  chars 
) throw (ProcessError) [protected, virtual, inherited]

Callback method for characters to implement by derived classes.

Called by "endElement" (see there).

Parameters:
[in] element The opened element, given as a SumoXMLTag
[in] chars The complete embedded character string ProcessError These method may throw a ProcessError if something fails

Reimplemented in ROJTRTurnDefLoader, MSRouteHandler, NIImporter_OpenDrive, NIImporter_SUMO, NLHandler, PCLoaderXML, PCNetProjectionLoader, and RORDLoader_SUMOBase.

Definition at line 189 of file GenericSAXHandler.cpp.

Referenced by GenericSAXHandler::endElement().

00189 {}

void NIXMLEdgesHandler::myEndElement ( SumoXMLTag  element  )  throw (ProcessError) [protected, virtual]

Called when a closing tag occurs.

Parameters:
[in] element ID of the currently opened element
Exceptions:
ProcessError If something fails
See also:
GenericSAXHandler::myEndElement

Reimplemented from GenericSAXHandler.

Definition at line 421 of file NIXMLEdgesHandler.cpp.

References NBEdge::addLane2LaneConnection(), MsgHandler::getErrorInstance(), NBEdge::getNoLanes(), MsgHandler::getWarningInstance(), NIXMLEdgesHandler::Split::gpos, MsgHandler::inform(), NBNodeCont::insert(), NBEdgeCont::insert(), NBEdge::invalidateConnections(), NBEdge::L2L_VALIDATED, NIXMLEdgesHandler::Split::lanes, MAX2(), Position2DVector::move2side(), myCurrentEdge, myCurrentID, myDistrictCont, myEdgeCont, myIsUpdate, myNodeCont, mySplits, NIXMLEdgesHandler::Split::nameid, NIXMLEdgesHandler::Split::pos, NBEdgeCont::retrieve(), NBEdgeCont::splitAt(), SUMO_const_laneWidthAndOffset, SUMO_TAG_EDGE, SUMOReal, and toString().

00421                                                                       {
00422     if (element==SUMO_TAG_EDGE && myCurrentEdge!=0) {
00423         if (!myIsUpdate) {
00424             try {
00425                 if (!myEdgeCont.insert(myCurrentEdge)) {
00426                     MsgHandler::getErrorInstance()->inform("Duplicate edge occured. ID='" + myCurrentID + "'");
00427                     delete myCurrentEdge;
00428                 }
00429             } catch (InvalidArgument &e) {
00430                 MsgHandler::getErrorInstance()->inform(e.what());
00431                 throw;
00432             } catch (...) {
00433                 MsgHandler::getErrorInstance()->inform("An important information is missing in edge '" + myCurrentID + "'.");
00434             }
00435         }
00436         if (mySplits.size()!=0) {
00437             std::vector<Split>::iterator i, i2;
00438             sort(mySplits.begin(), mySplits.end(), split_sorter());
00439             NBEdge *e = myCurrentEdge;
00440             unsigned int noLanesMax = e->getNoLanes();
00441             // compute the node positions and sort the lanes
00442             for (i=mySplits.begin(); i!=mySplits.end(); ++i) {
00443                 (*i).gpos = e->getGeometry().positionAtLengthPosition((*i).pos);
00444                 sort((*i).lanes.begin(), (*i).lanes.end());
00445                 noLanesMax = MAX2(noLanesMax, (unsigned int)(*i).lanes.size());
00446             }
00447             // split the edge
00448             std::vector<int> currLanes;
00449             for (unsigned int l=0; l<noLanesMax; ++l) {
00450                 currLanes.push_back(l);
00451             }
00452             std::string edgeid = e->getID();
00453             SUMOReal seen = 0;
00454             for (i=mySplits.begin(); i!=mySplits.end(); ++i) {
00455                 const Split &exp = *i;
00456                 assert(exp.lanes.size()!=0);
00457                 if (exp.pos>0 && e->getGeometry().length()+seen>exp.pos) {
00458                     std::string nid = edgeid + "." +  toString(exp.nameid);
00459                     NBNode *rn = new NBNode(nid, exp.gpos);
00460                     if (myNodeCont.insert(rn)) {
00461                         //  split the edge
00462                         std::string nid = myCurrentID + "." +  toString(exp.nameid);
00463                         std::string pid = e->getID();
00464                         myEdgeCont.splitAt(myDistrictCont, e, exp.pos-seen, rn,
00465                                            pid, nid, e->getNoLanes(), (unsigned int) exp.lanes.size());
00466                         seen = exp.pos;
00467                         std::vector<int> newLanes = exp.lanes;
00468                         NBEdge *pe = myEdgeCont.retrieve(pid);
00469                         NBEdge *ne = myEdgeCont.retrieve(nid);
00470                         // reconnect lanes
00471                         pe->invalidateConnections(true);
00472                         //  new on right
00473                         unsigned int rightMostP = currLanes[0];
00474                         unsigned int rightMostN = newLanes[0];
00475                         for (int l=0; l<(int) rightMostP-(int) rightMostN; ++l) {
00476                             pe->addLane2LaneConnection(0, ne, l, NBEdge::L2L_VALIDATED, true);
00477                         }
00478                         //  new on left
00479                         unsigned int leftMostP = currLanes.back();
00480                         unsigned int leftMostN = newLanes.back();
00481                         for (int l=0; l<(int) leftMostN-(int) leftMostP; ++l) {
00482                             pe->addLane2LaneConnection(pe->getNoLanes()-1, ne, leftMostN-l, NBEdge::L2L_VALIDATED, true);
00483                         }
00484                         //  all other connected
00485                         for (unsigned int l=0; l<noLanesMax; ++l) {
00486                             if (find(currLanes.begin(), currLanes.end(), l)==currLanes.end()) {
00487                                 continue;
00488                             }
00489                             if (find(newLanes.begin(), newLanes.end(), l)==newLanes.end()) {
00490                                 continue;
00491                             }
00492                             pe->addLane2LaneConnection(l-rightMostP, ne, l-rightMostN, NBEdge::L2L_VALIDATED, true);
00493                         }
00494                         // move to next
00495                         e = ne;
00496                         currLanes = newLanes;
00497                     } else {
00498                         MsgHandler::getWarningInstance()->inform("Error on parsing a split (edge '" + myCurrentID + "').");
00499                     }
00500                 }  else if (exp.pos==0) {
00501                     e->decLaneNo(e->getNoLanes()-exp.lanes.size());
00502                     currLanes = exp.lanes;
00503                 } else {
00504                     MsgHandler::getWarningInstance()->inform("Split at '" + toString(exp.pos) + "' lies beyond the edge's length (edge '" + myCurrentID + "').");
00505                 }
00506             }
00507             // patch lane offsets
00508             e = myEdgeCont.retrieve(edgeid);
00509             i = mySplits.begin();
00510             if ((*i).pos!=0) {
00511                 e = e->getToNode()->getOutgoingEdges()[0];
00512             }
00513             for (; i!=mySplits.end(); ++i) {
00514                 unsigned int maxLeft = (*i).lanes.back();
00515                 if (maxLeft<noLanesMax) {
00516                     Position2DVector g = e->getGeometry();
00517                     g.move2side(SUMO_const_laneWidthAndOffset*(noLanesMax-1-maxLeft));
00518                     e->setGeometry(g);
00519                 }
00520                 if (e->getToNode()->getOutgoingEdges().size()!=0) {
00521                     e = e->getToNode()->getOutgoingEdges()[0];
00522                 }
00523             }
00524         }
00525     }
00526 }

void NIXMLEdgesHandler::myStartElement ( SumoXMLTag  element,
const SUMOSAXAttributes attrs 
) throw (ProcessError) [protected, virtual]

Called on the opening of a tag;.

Parameters:
[in] element ID of the currently opened element
[in] attrs Attributes within the currently opened element
Exceptions:
ProcessError If something fails
See also:
GenericSAXHandler::myStartElement

insert the parsed edge into the edges map

Reimplemented from GenericSAXHandler.

Definition at line 82 of file NIXMLEdgesHandler.cpp.

References TplConvert< E >::_2int(), NBEdge::allowVehicleClass(), NBEdge::disallowVehicleClass(), OptionsCont::getBool(), NBTypeCont::getDefaultNoLanes(), NBTypeCont::getDefaultPriority(), NBTypeCont::getDefaultSpeed(), MsgHandler::getErrorInstance(), NBEdge::getGeometry(), MsgHandler::getMessageInstance(), NBTypeCont::getNoLanes(), NBEdge::getNoLanes(), OptionsCont::getOptions(), NBTypeCont::getPriority(), NBEdge::getPriority(), NBTypeCont::getSpeed(), NBEdge::getSpeed(), NBEdge::getTypeID(), getVehicleClassID(), MsgHandler::getWarningInstance(), MsgHandler::inform(), NBTypeCont::knows(), NIXMLEdgesHandler::Split::lanes, NBEdge::LANESPREAD_CENTER, NBEdge::LANESPREAD_RIGHT, Position2DVector::length(), myCurrentEdge, myCurrentID, myCurrentLaneNo, myCurrentPriority, myCurrentSpeed, myCurrentType, myEdgeCont, myFromNode, myHaveReportedAboutFunctionDeprecation, myHaveReportedAboutOverwriting, myIsUpdate, myLanesSpread, myLength, myOptions, myShape, mySplits, myToNode, myTypeCont, NIXMLEdgesHandler::Split::nameid, SUMOSAXAttributes::parseStringVector(), NIXMLEdgesHandler::Split::pos, NBEdge::preferVehicleClass(), NBEdge::reinit(), NBEdgeCont::retrieve(), NBEdge::setLoadedLength(), setNodes(), Position2DVector::size(), SUMO_ATTR_ALLOW, SUMO_ATTR_DISALLOW, SUMO_ATTR_FORCE_LENGTH, SUMO_ATTR_FUNCTION, SUMO_ATTR_ID, SUMO_ATTR_LANES, SUMO_ATTR_LENGTH, SUMO_ATTR_NOLANES, SUMO_ATTR_POSITION, SUMO_ATTR_PREFER, SUMO_ATTR_PRIORITY, SUMO_ATTR_SPEED, SUMO_ATTR_SPREADFUNC, SUMO_ATTR_TYPE, SUMO_TAG_EDGE, SUMO_TAG_LANE, SUMO_TAG_SPLIT, SUMOReal, toString(), and tryGetShape().

00083                                                                                       {
00084     if (element==SUMO_TAG_EDGE) {
00085         myIsUpdate = false;
00086         bool ok = true;
00087         // initialise the edge
00088         myCurrentEdge = 0;
00089         mySplits.clear();
00090         // get the id, report an error if not given or empty...
00091         if (!attrs.setIDFromAttributes("edge", myCurrentID)) {
00092             return;
00093         }
00094         myCurrentEdge = myEdgeCont.retrieve(myCurrentID);
00095         // check deprecated (unused) attributes
00096         if (!myHaveReportedAboutFunctionDeprecation&&attrs.hasAttribute(SUMO_ATTR_FUNCTION)) {
00097             MsgHandler::getWarningInstance()->inform("While parsing edge '" + myCurrentID + "': 'function' is deprecated.\n All occurences are ignored.");
00098             myHaveReportedAboutFunctionDeprecation = true;
00099         }
00100         // use default values, first
00101         myCurrentSpeed = myTypeCont.getDefaultSpeed();
00102         myCurrentPriority = myTypeCont.getDefaultPriority();
00103         myCurrentLaneNo = myTypeCont.getDefaultNoLanes();
00104         // use values from the edge to overwrite if existing, then
00105         if (myCurrentEdge!=0) {
00106             myIsUpdate = true;
00107             if (!myHaveReportedAboutOverwriting) {
00108                 MsgHandler::getMessageInstance()->inform("Duplicate edge id occured ('" + myCurrentID + "'); assuming overwriting is wished.");
00109                 myHaveReportedAboutOverwriting = true;
00110             }
00111             myCurrentSpeed = myCurrentEdge->getSpeed();
00112             myCurrentPriority = myCurrentEdge->getPriority();
00113             myCurrentLaneNo = myCurrentEdge->getNoLanes();
00114             myCurrentType = myCurrentEdge->getTypeID();
00115         }
00116         // check whether a type's values shall be used
00117         myCurrentType = "";
00118         if (attrs.hasAttribute(SUMO_ATTR_TYPE)) {
00119             myCurrentType = attrs.getStringReporting(SUMO_ATTR_TYPE, "edge", myCurrentID.c_str(), ok);
00120             if (!ok) {
00121                 return;
00122             }
00123             if (!myTypeCont.knows(myCurrentType)) {
00124                 MsgHandler::getErrorInstance()->inform("Type '" + myCurrentType + "' used by edge '" + myCurrentID + "' was not defined.");
00125                 return;
00126             }
00127             myCurrentSpeed = myTypeCont.getSpeed(myCurrentType);
00128             myCurrentPriority = myTypeCont.getPriority(myCurrentType);
00129             myCurrentLaneNo = myTypeCont.getNoLanes(myCurrentType);
00130         }
00131         // speed, priority and the number of lanes have now default values;
00132         // try to read the real values from the file
00133         if (attrs.hasAttribute(SUMO_ATTR_SPEED)) {
00134             myCurrentSpeed = attrs.getSUMORealReporting(SUMO_ATTR_SPEED, "edge", myCurrentID.c_str(), ok);
00135         }
00136         if (myOptions.getBool("speed-in-kmh")) {
00137             myCurrentSpeed = myCurrentSpeed / (SUMOReal) 3.6;
00138         }
00139         // try to get the number of lanes
00140         if (attrs.hasAttribute(SUMO_ATTR_NOLANES)) {
00141             myCurrentLaneNo = attrs.getIntReporting(SUMO_ATTR_NOLANES, "edge", myCurrentID.c_str(), ok);
00142         }
00143         // try to get the priority
00144         if (attrs.hasAttribute(SUMO_ATTR_PRIORITY)) {
00145             myCurrentPriority = attrs.getIntReporting(SUMO_ATTR_PRIORITY, "edge", myCurrentID.c_str(), ok);
00146         }
00147 
00148         // try to get the shape
00149         myShape = tryGetShape(attrs);
00150         // and how to spread the lanes
00151         if (attrs.getOptStringReporting(SUMO_ATTR_SPREADFUNC, "edge", myCurrentID.c_str(), ok, "")=="center") {
00152             myLanesSpread = NBEdge::LANESPREAD_CENTER;
00153         } else {
00154             myLanesSpread = NBEdge::LANESPREAD_RIGHT;
00155         }
00156         // try to set the nodes
00157         if (!setNodes(attrs)) {
00158             // return if this failed
00159             return;
00160         }
00161         // get the length or compute it
00162         if (attrs.hasAttribute(SUMO_ATTR_LENGTH)) {
00163             myLength = attrs.getSUMORealReporting(SUMO_ATTR_LENGTH, "edge", myCurrentID.c_str(), ok);
00164         } else {
00165             myLength = 0;
00166         }
00168         if (!ok) {
00169             return;
00170         }
00171         // check whether a previously defined edge shall be overwritten
00172         if (myCurrentEdge!=0) {
00173             myCurrentEdge->reinit(myFromNode, myToNode, myCurrentType, myCurrentSpeed,
00174                                   myCurrentLaneNo, myCurrentPriority, myShape,
00175                                   myLanesSpread);
00176         } else {
00177             // the edge must be allocated in dependence to whether a shape is given
00178             if (myShape.size()==0) {
00179                 myCurrentEdge = new NBEdge(myCurrentID, myFromNode, myToNode, myCurrentType, myCurrentSpeed,
00180                                            myCurrentLaneNo, myCurrentPriority, myLanesSpread);
00181             } else {
00182                 myCurrentEdge = new NBEdge(myCurrentID, myFromNode, myToNode, myCurrentType, myCurrentSpeed,
00183                                            myCurrentLaneNo, myCurrentPriority, myShape,
00184                                            myLanesSpread, OptionsCont::getOptions().getBool("xml.keep-shape"));
00185             }
00186             myCurrentEdge->setLoadedLength(myLength);
00187         }
00188     }
00189     if (element==SUMO_TAG_LANE) {
00190         if (myCurrentEdge==0) {
00191             if (!OptionsCont::getOptions().isInStringVector("remove-edges", myCurrentID)) {
00192                 MsgHandler::getErrorInstance()->inform("Additional lane information could not been set - the edge with id '" + myCurrentID + "' is not known.");
00193             }
00194             return;
00195         }
00196         bool ok = true;
00197         int lane = attrs.getIntReporting(SUMO_ATTR_ID, "lane", 0, ok);
00198         std::vector<std::string> disallowed, allowed, preferred;
00199         SUMOSAXAttributes::parseStringVector(attrs.getOptStringReporting(SUMO_ATTR_DISALLOW, "lane", 0, ok, ""), disallowed);
00200         SUMOSAXAttributes::parseStringVector(attrs.getOptStringReporting(SUMO_ATTR_ALLOW, "lane", 0, ok, ""), allowed);
00201         SUMOSAXAttributes::parseStringVector(attrs.getOptStringReporting(SUMO_ATTR_PREFER, "lane", 0, ok, ""), preferred);
00202         if (!ok) {
00203             return;
00204         }
00205         if (lane<0) {
00206             MsgHandler::getErrorInstance()->inform("Missing lane-id in lane definition (edge '" + myCurrentID + "').");
00207             return;
00208         }
00209         // check whether this lane exists
00210         if (lane>=(int) myCurrentEdge->getNoLanes()) {
00211             MsgHandler::getErrorInstance()->inform("Lane-id is larger than number of lanes (edge '" + myCurrentID + "').");
00212             return;
00213         }
00214         // set information about allowed / disallowed vehicle classes
00215         for (std::vector<std::string>::iterator i=disallowed.begin(); i!=disallowed.end(); ++i) {
00216             myCurrentEdge->disallowVehicleClass(lane, getVehicleClassID(*i));
00217         }
00218         for (std::vector<std::string>::iterator i=allowed.begin(); i!=allowed.end(); ++i) {
00219             myCurrentEdge->allowVehicleClass(lane, getVehicleClassID(*i));
00220         }
00221         for (std::vector<std::string>::iterator i=preferred.begin(); i!=preferred.end(); ++i) {
00222             myCurrentEdge->preferVehicleClass(lane, getVehicleClassID(*i));
00223         }
00224 
00225         // set information about later beginning lanes
00226         if (attrs.hasAttribute(SUMO_ATTR_FORCE_LENGTH)) {
00227             bool ok = true;
00228             int forcedLength = attrs.getIntReporting(SUMO_ATTR_FORCE_LENGTH, "lane", myCurrentID.c_str(), ok); // !!! edge id
00229             if (ok) {
00230                 int nameid = forcedLength;
00231                 forcedLength = (int)(myCurrentEdge->getGeometry().length() - forcedLength);
00232                 std::vector<Split>::iterator i;
00233                 i = find_if(mySplits.begin(), mySplits.end(), split_by_pos_finder((SUMOReal) forcedLength));
00234                 if (i==mySplits.end()) {
00235                     Split e;
00236                     e.pos = (SUMOReal) forcedLength;
00237                     e.nameid = nameid;
00238                     for (unsigned int j=0; j<myCurrentEdge->getNoLanes(); j++) {
00239                         e.lanes.push_back(j);
00240                     }
00241                     mySplits.push_back(e);
00242                 }
00243                 i = find_if(mySplits.begin(), mySplits.end(), split_by_pos_finder((SUMOReal) forcedLength));
00244                 std::vector<int>::iterator k = find((*i).lanes.begin(), (*i).lanes.end(), lane);
00245                 if (k!=(*i).lanes.end()) {
00246                     (*i).lanes.erase(k);
00247                 }
00248             }
00249         }
00250     }
00251     if (element==SUMO_TAG_SPLIT) {
00252         bool ok = true;
00253         Split e;
00254         e.pos = attrs.getSUMORealReporting(SUMO_ATTR_POSITION, "split", 0, ok);
00255         std::vector<Split>::iterator i = find_if(mySplits.begin(), mySplits.end(), split_by_pos_finder(e.pos));
00256         if (i!=mySplits.end()) {
00257             MsgHandler::getErrorInstance()->inform("Edge '" + myCurrentID + "' has already a split at position " + toString(e.pos) + ".");
00258             return;
00259         }
00260         if (e.pos<0) {
00261             e.pos = myCurrentEdge->getGeometry().length() - e.pos;
00262         }
00263         e.nameid = e.pos;
00264         if (ok) {
00265             if (myCurrentEdge==0) {
00266                 if (!OptionsCont::getOptions().isInStringVector("remove-edges", myCurrentID)) {
00267                     MsgHandler::getErrorInstance()->inform("Additional lane information could not been set - the edge with id '" + myCurrentID + "' is not known.");
00268                 }
00269                 return;
00270             }
00271             if (e.pos<0) {
00272                 e.pos = myCurrentEdge->getGeometry().length() + e.pos;
00273             }
00274             std::vector<std::string> lanes;
00275             SUMOSAXAttributes::parseStringVector(attrs.getOptStringReporting(SUMO_ATTR_LANES, "split", 0, ok, ""), lanes);
00276             for (std::vector<std::string>::iterator i=lanes.begin(); i!=lanes.end(); ++i) {
00277                 try {
00278                     int lane = TplConvert<char>::_2int((*i).c_str());
00279                     e.lanes.push_back(lane);
00280                 } catch (NumberFormatException &) {
00281                     MsgHandler::getErrorInstance()->inform("Error on parsing a split (edge '" + myCurrentID + "').");
00282                 } catch (EmptyData &) {
00283                     MsgHandler::getErrorInstance()->inform("Error on parsing a split (edge '" + myCurrentID + "').");
00284                 }
00285             }
00286             if (e.lanes.size()==0) {
00287                 MsgHandler::getErrorInstance()->inform("Missing lane information in split of edge '" + myCurrentID + "'.");
00288             } else {
00289                 mySplits.push_back(e);
00290             }
00291         }
00292     }
00293 }

NIXMLEdgesHandler& NIXMLEdgesHandler::operator= ( const NIXMLEdgesHandler s  )  [private]

invalid assignment operator

void NIXMLEdgesHandler::parseSplitLanes ( const std::string &  val  )  throw (ProcessError) [private]

Parses the given string as lanes to keep, storing them.

Parameters:
[in] val The definition of lanes to keep
Exceptions:
ProcessError If the description is malicious

Definition at line 401 of file NIXMLEdgesHandler.cpp.

References TplConvert< E >::_2int(), MsgHandler::getErrorInstance(), MsgHandler::inform(), NIXMLEdgesHandler::Split::lanes, myCurrentID, mySplits, and SUMOSAXAttributes::parseStringVector().

00401                                                                            {
00402     if (mySplits.size()!=0) {
00403         Split &e = mySplits.back();
00404         std::vector<std::string> lanes;
00405         SUMOSAXAttributes::parseStringVector(val, lanes);
00406         for (std::vector<std::string>::iterator i=lanes.begin(); i!=lanes.end(); ++i) {
00407             try {
00408                 int lane = TplConvert<char>::_2int((*i).c_str());
00409                 e.lanes.push_back(lane);
00410             } catch (NumberFormatException &) {
00411                 MsgHandler::getErrorInstance()->inform("Error on parsing a split (edge '" + myCurrentID + "').");
00412             } catch (EmptyData &) {
00413                 MsgHandler::getErrorInstance()->inform("Error on parsing a split (edge '" + myCurrentID + "').");
00414             }
00415         }
00416     }
00417 }

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

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

Definition at line 160 of file GenericSAXHandler.cpp.

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

Referenced by NLTriggerBuilder::parseAndBuildLaneSpeedTrigger().

00160                                                                                   {
00161     myParentHandler = handler;
00162     myParentIndicator = tag;
00163     XMLSubSys::setHandler(*this);
00164 }

void GenericSAXHandler::setFileName ( const std::string &  name  )  throw () [inherited]

Sets the current file name.

Parameters:
[in] name The name of the currently processed file
Todo:
Hmmm - this is as unsafe as having a direct access to the variable; recheck

Definition at line 72 of file GenericSAXHandler.cpp.

References GenericSAXHandler::myFileName.

Referenced by PCNetProjectionLoader::loadIfSet(), ROLoader::loadNet(), NIImporter_OpenStreetMap::loadNetwork(), NILoader::loadXMLType(), and traci::TraCIServer::TraCIServer().

00072                                                             {
00073     myFileName = name;
00074 }

bool NIXMLEdgesHandler::setNodes ( const SUMOSAXAttributes attrs  )  throw () [private]

Sets from/to node information of the currently parsed edge.

If the nodes could be retrieved/built, they are set in myFromNode/myToNode, respectively, and true is returned. If not, false is returned.

Parameters:
[in] attrs The SAX-attributes to parse the nodes from
Returns:
Whether valid nodes exist

Definition at line 297 of file NIXMLEdgesHandler.cpp.

References NBEdge::getFromNode(), NBNode::getID(), NBEdge::getToNode(), insertNodeChecking(), myCurrentEdge, myFromNode, myIsUpdate, myToNode, SUMO_ATTR_FROMNODE, SUMO_ATTR_TONODE, SUMO_ATTR_XFROM, SUMO_ATTR_XTO, SUMO_ATTR_YFROM, SUMO_ATTR_YTO, SUMOReal, SUMOXML_INVALID_POSITION, tryGetPosition(), Position2D::x(), GeoConvHelper::x2cartesian(), and Position2D::y().

Referenced by myStartElement().

00297                                                                   {
00298     // the names and the coordinates of the beginning and the end node
00299     // may be found, try
00300     bool ok = true;
00301     std::string begNodeID = myIsUpdate ? myCurrentEdge->getFromNode()->getID() : "";
00302     std::string endNodeID = myIsUpdate ? myCurrentEdge->getToNode()->getID() : "";
00303     begNodeID = attrs.hasAttribute(SUMO_ATTR_FROMNODE) ? attrs.getStringReporting(SUMO_ATTR_FROMNODE, "edge", 0, ok) : begNodeID;
00304     endNodeID = attrs.hasAttribute(SUMO_ATTR_TONODE) ? attrs.getStringReporting(SUMO_ATTR_TONODE, "edge", 0, ok) : endNodeID;
00305     if (!ok) {
00306         return false;
00307     }
00308     // or their positions !!! deprecated
00309     SUMOReal begNodeXPos = tryGetPosition(attrs, SUMO_ATTR_XFROM, "XFrom");
00310     SUMOReal begNodeYPos = tryGetPosition(attrs, SUMO_ATTR_YFROM, "YFrom");
00311     SUMOReal endNodeXPos = tryGetPosition(attrs, SUMO_ATTR_XTO, "XTo");
00312     SUMOReal endNodeYPos = tryGetPosition(attrs, SUMO_ATTR_YTO, "YTo");
00313     if (begNodeXPos!=SUMOXML_INVALID_POSITION&&begNodeYPos!=SUMOXML_INVALID_POSITION) {
00314         Position2D pos(begNodeXPos, begNodeYPos);
00315         GeoConvHelper::x2cartesian(pos);
00316         begNodeXPos = pos.x();
00317         begNodeYPos = pos.y();
00318     }
00319     if (endNodeXPos!=SUMOXML_INVALID_POSITION&&endNodeYPos!=SUMOXML_INVALID_POSITION) {
00320         Position2D pos(endNodeXPos, endNodeYPos);
00321         GeoConvHelper::x2cartesian(pos);
00322         endNodeXPos = pos.x();
00323         endNodeYPos = pos.y();
00324     }
00325     // check the obtained values for nodes
00326     myFromNode = insertNodeChecking(Position2D(begNodeXPos, begNodeYPos), begNodeID, "from");
00327     myToNode = insertNodeChecking(Position2D(endNodeXPos, endNodeYPos), endNodeID, "to");
00328     return myFromNode!=0&&myToNode!=0;
00329 }

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
Todo:
do not generate and report the string-representation

Definition at line 97 of file GenericSAXHandler.cpp.

References TplConvert< E >::_2str(), 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.

00100                                                          {
00101     std::string name = TplConvert<XMLCh>::_2str(qname);
00102     SumoXMLTag element = convertTag(name);
00103     myCharactersVector.clear();
00104     SUMOSAXAttributesImpl_Xerces na(attrs, myPredefinedTags, myPredefinedTagsMML);
00105     if (element == SUMO_TAG_INCLUDE) {
00106         std::string file = na.getString(SUMO_ATTR_HREF);
00107         if (!FileHelpers::isAbsolute(file)) {
00108             file = FileHelpers::getConfigurationRelative(getFileName(), file);
00109         }
00110         XMLSubSys::runParser(*this, file);
00111     } else {
00112         myStartElement(element, na);
00113     }
00114 }

SUMOReal NIXMLEdgesHandler::tryGetPosition ( const SUMOSAXAttributes attrs,
SumoXMLAttr  attrID,
const std::string &  attrName 
) [private]

tries to parse one of the node's positions Which position has to be parsed is defined by the given call variables

Definition at line 333 of file NIXMLEdgesHandler.cpp.

References SUMOSAXAttributes::getOptSUMORealReporting(), myCurrentID, and SUMOXML_INVALID_POSITION.

Referenced by setNodes().

00334                                                              {
00335     bool ok = true;
00336     return attrs.getOptSUMORealReporting(attrID, "edge", myCurrentID.c_str(), ok, SUMOXML_INVALID_POSITION);
00337 }

Position2DVector NIXMLEdgesHandler::tryGetShape ( const SUMOSAXAttributes attrs  )  throw () [private]

Tries to parse the shape definition.

Returns the edge's geometry (may be empty if no one was defined). Writes an error message if an error occured.

Parameters:
[in] attrs The attributes to read the shape from
Returns:
The edge's shape

Definition at line 377 of file NIXMLEdgesHandler.cpp.

References MsgHandler::getErrorInstance(), MsgHandler::inform(), myCurrentID, GeomConvHelper::parseShapeReporting(), Position2DVector::push_back(), Position2DVector::size(), SUMO_ATTR_SHAPE, and GeoConvHelper::x2cartesian().

Referenced by myStartElement().

00377                                                                      {
00378     if (!attrs.hasAttribute(SUMO_ATTR_SHAPE)) {
00379         return Position2DVector();
00380     }
00381     // try to build shape
00382     bool ok = true;
00383     std::string shpdef = attrs.getOptStringReporting(SUMO_ATTR_SHAPE, "edge", 0, ok, "");
00384     if (shpdef=="") {
00385         return Position2DVector();
00386     }
00387     Position2DVector shape1 = GeomConvHelper::parseShapeReporting(shpdef, "edge", 0, ok, true);
00388     Position2DVector shape;
00389     for (int i=0; i<(int) shape1.size(); ++i) {
00390         Position2D pos(shape1[i]);
00391         if (!GeoConvHelper::x2cartesian(pos)) {
00392             MsgHandler::getErrorInstance()->inform("Unable to project coordinates for edge '" + myCurrentID + "'.");
00393         }
00394         shape.push_back(pos);
00395     }
00396     return shape;
00397 }

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

Handler for XML-warnings.

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

Parameters:
[in] exception The occured exception to process

Definition at line 68 of file SUMOSAXHandler.cpp.

References SUMOSAXHandler::buildErrorMessage(), MsgHandler::getWarningInstance(), and MsgHandler::inform().


Field Documentation

The currently processed edge.

Definition at line 187 of file NIXMLEdgesHandler.h.

Referenced by myEndElement(), myStartElement(), and setNodes().

std::string NIXMLEdgesHandler::myCurrentID [private]

The current edge's id.

Definition at line 145 of file NIXMLEdgesHandler.h.

Referenced by insertNodeChecking(), myEndElement(), myStartElement(), parseSplitLanes(), tryGetPosition(), and tryGetShape().

The current edge's number of lanes.

Definition at line 154 of file NIXMLEdgesHandler.h.

Referenced by myStartElement().

The current edge's priority.

Definition at line 151 of file NIXMLEdgesHandler.h.

Referenced by myStartElement().

The current edge's maximum speed.

Definition at line 148 of file NIXMLEdgesHandler.h.

Referenced by myStartElement().

std::string NIXMLEdgesHandler::myCurrentType [private]

The current edge's type.

Definition at line 157 of file NIXMLEdgesHandler.h.

Referenced by myStartElement().

The districts container (needed if an edge must be split).

Definition at line 181 of file NIXMLEdgesHandler.h.

Referenced by myEndElement().

The edges container (for insertion of build edges).

Definition at line 175 of file NIXMLEdgesHandler.h.

Referenced by myEndElement(), and myStartElement().

The nodes the edge starts and ends at.

Definition at line 160 of file NIXMLEdgesHandler.h.

Referenced by myStartElement(), and setNodes().

Information whether at least one edge with a function-attribute occured and was reported.

Definition at line 245 of file NIXMLEdgesHandler.h.

Referenced by myStartElement().

Information whether at least one edge's attributes were overwritten.

Definition at line 248 of file NIXMLEdgesHandler.h.

Referenced by myStartElement().

Whether this edge definition is an update of a previously inserted edge.

Definition at line 184 of file NIXMLEdgesHandler.h.

Referenced by myEndElement(), myStartElement(), and setNodes().

Information about how to spread the lanes.

Definition at line 169 of file NIXMLEdgesHandler.h.

Referenced by myStartElement().

SUMOReal NIXMLEdgesHandler::myLength [private]

The current edge's length.

Definition at line 163 of file NIXMLEdgesHandler.h.

Referenced by myStartElement().

The nodes container (for retrieval of referenced nodes).

Definition at line 172 of file NIXMLEdgesHandler.h.

Referenced by insertNodeChecking(), and myEndElement().

A reference to the program's options.

Definition at line 142 of file NIXMLEdgesHandler.h.

Referenced by myStartElement().

The shape of the edge.

Definition at line 166 of file NIXMLEdgesHandler.h.

Referenced by myStartElement().

std::vector<Split> NIXMLEdgesHandler::mySplits [private]

The list of this edge's splits.

Definition at line 205 of file NIXMLEdgesHandler.h.

Referenced by myEndElement(), myStartElement(), and parseSplitLanes().

Definition at line 160 of file NIXMLEdgesHandler.h.

Referenced by myStartElement(), and setNodes().

The types container (for retrieval of type defaults).

Definition at line 178 of file NIXMLEdgesHandler.h.

Referenced by myStartElement().


The documentation for this class was generated from the following files:

Generated on Wed May 5 00:06:56 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6