1 /****************************************************************************/ 2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo 3 // Copyright (C) 2001-2019 German Aerospace Center (DLR) and others. 4 // This program and the accompanying materials 5 // are made available under the terms of the Eclipse Public License v2.0 6 // which accompanies this distribution, and is available at 7 // http://www.eclipse.org/legal/epl-v20.html 8 // SPDX-License-Identifier: EPL-2.0 9 /****************************************************************************/ 10 /// @file NIXMLEdgesHandler.h 11 /// @author Daniel Krajzewicz 12 /// @author Jakob Erdmann 13 /// @author Michael Behrisch 14 /// @author Leonhard Luecken 15 /// @date Tue, 20 Nov 2001 16 /// @version $Id$ 17 /// 18 // Importer for network edges stored in XML 19 /****************************************************************************/ 20 #ifndef NIXMLEdgesHandler_h 21 #define NIXMLEdgesHandler_h 22 23 24 // =========================================================================== 25 // included modules 26 // =========================================================================== 27 #include <config.h> 28 29 #include <utils/common/SUMOVehicleClass.h> 30 #include <utils/geom/PositionVector.h> 31 #include <utils/xml/SUMOSAXHandler.h> 32 #include <netbuild/NBEdge.h> 33 #include <netbuild/NBEdgeCont.h> 34 35 36 // =========================================================================== 37 // class declarations 38 // =========================================================================== 39 class OptionsCont; 40 class NBNode; 41 class NBEdge; 42 class NBNodeCont; 43 class NBTypeCont; 44 class NBDistrictCont; 45 class NBTrafficLightLogicCont; 46 47 // =========================================================================== 48 // class definitions 49 // =========================================================================== 50 /** 51 * @class NIXMLEdgesHandler 52 * @brief Importer for network edges stored in XML 53 * 54 * This SAX-handler parses edge information and stores it in the given 55 * container. 56 * @todo revalidate node retrieval 57 * @todo One day, one should rethink the order of parsing. Now, the handler 58 * is able to load edges, using information from the types, first, and extending 59 * them by given information. In addition, if the read edge is already known, 60 * it's values are also used. Then, defining vehicles allowed per lane, and 61 * additional edge split definitions add some further complexity. This all 62 * works somehow for most of our use cases, but it's definitely not as consistent 63 * that everything what seems to be possible would also work appropriately. 64 */ 65 class NIXMLEdgesHandler : public SUMOSAXHandler { 66 public: 67 /** @brief Constructor 68 * @param[in] nc The nodes container (for retrieval of referenced nodes) 69 * @param[in] ec The edges container (for insertion of build edges) 70 * @param[in] tc The types container (for retrieval of type defaults) 71 * @param[in] dc The districts container (needed if an edge must be split) 72 * @param[in] options The options to use while building edges 73 */ 74 NIXMLEdgesHandler(NBNodeCont& nc, NBEdgeCont& ec, 75 NBTypeCont& tc, NBDistrictCont& dc, 76 NBTrafficLightLogicCont& tlc, 77 OptionsCont& options); 78 79 80 /// @brief Destructor 81 ~NIXMLEdgesHandler(); 82 83 protected: 84 /// @name inherited from GenericSAXHandler 85 //@{ 86 87 /** @brief Called on the opening of a tag; 88 * 89 * @param[in] element ID of the currently opened element 90 * @param[in] attrs Attributes within the currently opened element 91 * @exception ProcessError If something fails 92 * @see GenericSAXHandler::myStartElement 93 */ 94 void myStartElement(int element, 95 const SUMOSAXAttributes& attrs); 96 97 98 /** @brief Called when a closing tag occurs 99 * 100 * @param[in] element ID of the currently opened element 101 * @exception ProcessError If something fails 102 * @see GenericSAXHandler::myEndElement 103 */ 104 void myEndElement(int element); 105 //@} 106 107 108 private: 109 /** @brief Tries to parse the shape definition 110 * 111 * Returns the edge's geometry (may be empty if no one was defined). 112 * Writes an error message if an error occurred. 113 * @param[in] attrs The attributes to read the shape from 114 * @return The edge's shape 115 */ 116 PositionVector tryGetShape(const SUMOSAXAttributes& attrs); 117 118 119 /** @brief Tries to parse the spread type 120 */ 121 LaneSpreadFunction tryGetLaneSpread(const SUMOSAXAttributes& attrs); 122 123 124 /** @brief Sets from/to node information of the currently parsed edge 125 * 126 * If the nodes could be retrieved/built, they are set in myFromNode/myToNode, 127 * respectively, and true is returned. If not, false is returned. 128 * @param[in] attrs The SAX-attributes to parse the nodes from 129 * @return Whether valid nodes exist 130 */ 131 bool setNodes(const SUMOSAXAttributes& attrs); 132 133 134 private: 135 /// @brief A reference to the program's options 136 OptionsCont& myOptions; 137 138 139 /// @name Currently parsed edge's values 140 /// @{ 141 142 /// @brief The current edge's id 143 std::string myCurrentID; 144 145 /// @brief The current edge's maximum speed 146 double myCurrentSpeed; 147 148 /// @brief The current edge's priority 149 int myCurrentPriority; 150 151 /// @brief The current edge's number of lanes 152 int myCurrentLaneNo; 153 154 /// @brief The current edge's lane width 155 double myCurrentWidth; 156 157 /// @brief The current edge's offset till the destination node 158 double myCurrentEndOffset; 159 160 /// @brief The current edge's street name 161 std::string myCurrentStreetName; 162 163 /// @brief The current edge's type 164 std::string myCurrentType; 165 166 /// @brief The nodes the edge starts and ends at 167 NBNode* myFromNode, *myToNode; 168 169 /// @brief The current edge's length 170 double myLength; 171 172 /// @brief The shape of the edge 173 PositionVector myShape; 174 175 /// @brief Information about how to spread the lanes 176 LaneSpreadFunction myLanesSpread; 177 178 /// @brief Information about lane permissions 179 SVCPermissions myPermissions; 180 181 /// @brief Whether the edge shape shall be kept at reinitilization 182 bool myReinitKeepEdgeShape; 183 184 /// @brief The width of the sidewalk that shall be added to the current edge 185 double mySidewalkWidth; 186 187 /// @brief The width of the bike lane that shall be added to the current edge 188 double myBikeLaneWidth; 189 190 /// @} 191 192 193 /// @brief Whether this edge definition is an update of a previously inserted edge 194 bool myIsUpdate; 195 196 197 /// @name Used instance containers (access to nodes, edges, types, etc.) 198 /// @{ 199 200 /// @brief The nodes container (for retrieval of referenced nodes) 201 NBNodeCont& myNodeCont; 202 203 /// @brief The edges container (for insertion of build edges) 204 NBEdgeCont& myEdgeCont; 205 206 /// @brief The types container (for retrieval of type defaults) 207 NBTypeCont& myTypeCont; 208 209 /// @brief The districts container (needed if an edge must be split) 210 NBDistrictCont& myDistrictCont; 211 212 /** @brief The traffic lights container to add built tls to (when 213 * invalidating tls because of splits) */ 214 NBTrafficLightLogicCont& myTLLogicCont; 215 /// @} 216 217 218 /// @brief The currently processed edge 219 NBEdge* myCurrentEdge; 220 221 /// @brief The currently processed lane index 222 int myCurrentLaneIndex; 223 224 /// @brief The list of this edge's splits 225 std::vector<NBEdgeCont::Split> mySplits; 226 227 /** @class split_by_pos_finder 228 * @brief Finds a split at the given position 229 */ 230 class split_by_pos_finder { 231 public: 232 /// @brief Constructor split_by_pos_finder(double pos)233 explicit split_by_pos_finder(double pos) 234 : myPosition(pos) { } 235 236 /// @brief Comparing operator operator()237 bool operator()(const NBEdgeCont::Split& e) { 238 return e.pos == myPosition; 239 } 240 241 private: 242 /// @brief The position to search for 243 double myPosition; 244 245 }; 246 247 248 /// @brief Information whether at least one edge's attributes were overwritten 249 bool myHaveReportedAboutOverwriting; 250 251 /// @brief Information whether at least one edge's type was changed 252 bool myHaveReportedAboutTypeOverride; 253 254 bool myHaveWarnedAboutDeprecatedLaneId; 255 256 /// @brief Whether the edge shape shall be kept generally 257 const bool myKeepEdgeShape; 258 259 /// @brief element to receive parameters 260 std::vector<Parameterised*> myLastParameterised; 261 262 private: 263 264 /** @brief Parses an edge and stores the values in "myCurrentEdge" 265 * @param[in] attrs The attributes to get the edge's values from 266 */ 267 void addEdge(const SUMOSAXAttributes& attrs); 268 269 /** @brief parses delete tag and deletes the specified edge or lane 270 * @param[in] attrs The attributes to get the edge id and the optional lane index from 271 */ 272 void deleteEdge(const SUMOSAXAttributes& attrs); 273 274 /** @brief Parses a lane and modifies myCurrentEdge according to the given 275 * attribures 276 * @param[in] attrs The attributes to get the lanes's values from 277 */ 278 void addLane(const SUMOSAXAttributes& attrs); 279 280 /** @brief Parses a split and stores it in mySplits. Splits are executed Upon reading the end 281 * tag of an edge 282 * @param[in] attrs The attributes to get the splits's values from 283 */ 284 void addSplit(const SUMOSAXAttributes& attrs); 285 286 /** @brief Parses a roundabout and stores it in myEdgeCont. 287 * @param[in] attrs The attributes to get the roundabouts values from 288 */ 289 void addRoundabout(const SUMOSAXAttributes& attrs); 290 291 292 private: 293 /** @brief invalid copy constructor */ 294 NIXMLEdgesHandler(const NIXMLEdgesHandler& s); 295 296 /** @brief invalid assignment operator */ 297 NIXMLEdgesHandler& operator=(const NIXMLEdgesHandler& s); 298 299 }; 300 301 302 #endif 303 304 /****************************************************************************/ 305 306