Line data Source code
1 : /****************************************************************************/ 2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo 3 : // Copyright (C) 2001-2024 German Aerospace Center (DLR) and others. 4 : // This program and the accompanying materials are made available under the 5 : // terms of the Eclipse Public License 2.0 which is available at 6 : // https://www.eclipse.org/legal/epl-2.0/ 7 : // This Source Code may also be made available under the following Secondary 8 : // Licenses when the conditions for such availability set forth in the Eclipse 9 : // Public License 2.0 are satisfied: GNU General Public License, version 2 10 : // or later which is available at 11 : // https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html 12 : // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later 13 : /****************************************************************************/ 14 : /// @file NLHandler.h 15 : /// @author Daniel Krajzewicz 16 : /// @author Jakob Erdmann 17 : /// @author Clemens Honomichl 18 : /// @author Michael Behrisch 19 : /// @date Sept 2002 20 : /// 21 : // The XML-Handler for network loading 22 : /****************************************************************************/ 23 : #pragma once 24 : #include <config.h> 25 : 26 : #include <utils/geom/Boundary.h> 27 : #include <utils/shapes/ShapeHandler.h> 28 : #include <microsim/MSRouteHandler.h> 29 : #include "NLDiscreteEventBuilder.h" 30 : 31 : 32 : // =========================================================================== 33 : // class declarations 34 : // =========================================================================== 35 : class NLContainer; 36 : class NLDetectorBuilder; 37 : class NLEdgeControlBuilder; 38 : class NLJunctionControlBuilder; 39 : class NLTriggerBuilder; 40 : class MSTrafficLightLogic; 41 : class MSRailSignal; 42 : 43 : 44 : // =========================================================================== 45 : // class definitions 46 : // =========================================================================== 47 : 48 : 49 : /** 50 : * @class NLShapeHandler 51 : * @brief The XML-Handler for shapes loading network loading 52 : * 53 : * This subclasses ShapeHandler with MSLane specific function 54 : */ 55 : class NLShapeHandler : public ShapeHandler { 56 : public: 57 20391 : NLShapeHandler(const std::string& file, ShapeContainer& sc) : 58 20391 : ShapeHandler(file, sc) {} 59 : 60 : /// @brief Destructor 61 20391 : virtual ~NLShapeHandler() {} 62 : 63 : Position getLanePos(const std::string& poiID, const std::string& laneID, double lanePos, bool friendlyPos, double lanePosLat); 64 : 65 642 : virtual bool addLanePosParams() { 66 642 : return true; 67 : } 68 : }; 69 : 70 : 71 : /** 72 : * @class NLHandler 73 : * @brief The XML-Handler for network loading 74 : * 75 : * The SAX2-handler responsible for parsing networks and routes to load. 76 : * This is an extension of the MSRouteHandler as routes and vehicles may also 77 : * be loaded from network descriptions. 78 : */ 79 : class NLHandler : public MSRouteHandler { 80 : public: 81 : /// @brief Definition of a lane vector 82 : typedef std::vector<MSLane*> LaneVector; 83 : 84 : public: 85 : /** @brief Constructor 86 : * 87 : * @param[in] file Name of the parsed file 88 : * @param[in, out] net The network to fill 89 : * @param[in] detBuilder The detector builder to use 90 : * @param[in] triggerBuilder The trigger builder to use 91 : * @param[in] edgeBuilder The builder of edges to use 92 : * @param[in] junctionBuilder The builder of junctions to use 93 : */ 94 : NLHandler(const std::string& file, MSNet& net, 95 : NLDetectorBuilder& detBuilder, NLTriggerBuilder& triggerBuilder, 96 : NLEdgeControlBuilder& edgeBuilder, 97 : NLJunctionControlBuilder& junctionBuilder); 98 : 99 : 100 : /// @brief Destructor 101 : virtual ~NLHandler(); 102 : 103 : bool haveSeenInternalEdge() const { 104 5255 : return myHaveSeenInternalEdge; 105 : } 106 : 107 : bool hasJunctionHigherSpeeds() const { 108 34665 : return myHaveJunctionHigherSpeeds; 109 : } 110 : 111 : bool haveSeenDefaultLength() const { 112 2696 : return myHaveSeenDefaultLength; 113 : } 114 : 115 : bool haveSeenNeighs() const { 116 : return myHaveSeenNeighs; 117 : } 118 : 119 : bool haveSeenAdditionalSpeedRestrictions() const { 120 20391 : return myHaveSeenAdditionalSpeedRestrictions; 121 : } 122 : 123 : bool haveSeenMesoEdgeType() const { 124 2690 : return myHaveSeenMesoEdgeType; 125 : } 126 : 127 : MMVersion networkVersion() const { 128 104075 : return myNetworkVersion; 129 : } 130 : 131 : static Parameterised* addPredecessorConstraint(int element, const SUMOSAXAttributes& attrs, MSRailSignal* rs); 132 : 133 : protected: 134 : /// @name inherited from GenericSAXHandler 135 : //@{ 136 : 137 : /** @brief Called on the opening of a tag; 138 : * 139 : * @param[in] element ID of the currently opened element 140 : * @param[in] attrs Attributes within the currently opened element 141 : * @exception ProcessError If something fails 142 : * @see GenericSAXHandler::myStartElement 143 : * @todo Refactor/describe 144 : */ 145 : virtual void myStartElement(int element, 146 : const SUMOSAXAttributes& attrs); 147 : 148 : 149 : /** @brief Called when a closing tag occurs 150 : * 151 : * @param[in] element ID of the currently opened element 152 : * @exception ProcessError If something fails 153 : * @see GenericSAXHandler::myEndElement 154 : * @todo Refactor/describe 155 : */ 156 : virtual void myEndElement(int element); 157 : //@} 158 : 159 : 160 : protected: 161 : void addParam(const SUMOSAXAttributes& attrs); 162 : 163 : /** @brief Builds an e1 detector using the given specification 164 : * @param[in] attrs The attributes that define the detector 165 : */ 166 : virtual void addE1Detector(const SUMOSAXAttributes& attrs); 167 : 168 : /** @brief Builds an e1 detector using the given specification 169 : * @param[in] attrs The attributes that define the detector 170 : */ 171 : virtual void addInstantE1Detector(const SUMOSAXAttributes& attrs); 172 : 173 : /** @brief Builds an e2 detector using the given specification 174 : * @param[in] attrs The attributes that define the detector 175 : */ 176 : virtual void addE2Detector(const SUMOSAXAttributes& attrs); 177 : 178 : /** @brief Starts building of an e3 detector using the given specification 179 : * @param[in] attrs The attributes that define the detector 180 : */ 181 : void beginE3Detector(const SUMOSAXAttributes& attrs); 182 : 183 : /** @brief Adds an entry to the currently processed e3 detector 184 : * @param[in] attrs The attributes that define the entry 185 : */ 186 : void addE3Entry(const SUMOSAXAttributes& attrs); 187 : 188 : /** @brief Adds an exit to the currently processed e3 detector 189 : * @param[in] attrs The attributes that define the exit 190 : */ 191 : void addE3Exit(const SUMOSAXAttributes& attrs); 192 : 193 : /// Builds of an e3 detector using collected values 194 : virtual void endE3Detector(); 195 : 196 : /** @brief Builds a vtype-detector using the given specification 197 : * @param[in] attrs The attributes that define the detector 198 : */ 199 : virtual void addVTypeProbeDetector(const SUMOSAXAttributes& attrs); 200 : 201 : /** @brief Builds a routeProbe-detector using the given specification 202 : * @param[in] attrs The attributes that define the detector 203 : */ 204 : virtual void addRouteProbeDetector(const SUMOSAXAttributes& attrs); 205 : 206 : /** @brief Builds edge or lane base mean data collector using the given specification 207 : * @param[in] attrs The attributes that define the detector 208 : * @param[in] objecttype The type (lane/edge) of the parsed mean data definition 209 : */ 210 : virtual void addEdgeLaneMeanData(const SUMOSAXAttributes& attrs, int objecttype); 211 : 212 : /** @brief Loads edge type specific meso parameters 213 : * @param[in] attrs The attributes that hold the parameters 214 : */ 215 : virtual void addMesoEdgeType(const SUMOSAXAttributes& attrs); 216 : 217 : /// Closes the process of building an edge 218 : virtual void closeEdge(); 219 : 220 : private: 221 : /// begins the processing of an edge 222 : void beginEdgeParsing(const SUMOSAXAttributes& attrs); 223 : 224 : /// adds a lane to the previously opened edge 225 : void addLane(const SUMOSAXAttributes& attrs); 226 : 227 : /// adds a request item to the current junction logic 228 : void addRequest(const SUMOSAXAttributes& attrs); 229 : 230 : /// begins the reading of a junction row logic 231 : void initJunctionLogic(const SUMOSAXAttributes& attrs); 232 : 233 : /// begins the reading of a traffic lights logic 234 : void initTrafficLightLogic(const SUMOSAXAttributes& attrs); 235 : 236 : /// adds a phase to the traffic lights logic currently build 237 : void addPhase(const SUMOSAXAttributes& attrs); 238 : 239 : /// adds a switching condition to the traffic lights logic currently build 240 : void addCondition(const SUMOSAXAttributes& attrs); 241 : 242 : /// adds a switching condition assignment to the traffic lights logic currently build 243 : void addAssignment(const SUMOSAXAttributes& attrs); 244 : 245 : /// adds a switching condition function to the traffic lights logic currently build 246 : void addFunction(const SUMOSAXAttributes& attrs); 247 : 248 : /// adds a switching condition function to the traffic lights logic currently build 249 : void closeFunction(); 250 : 251 : /// opens a junction for processing 252 : virtual void openJunction(const SUMOSAXAttributes& attrs); 253 : 254 : void parseLanes(const std::string& junctionID, const std::string& def, std::vector<MSLane*>& into, bool& ok); 255 : 256 : /// adds a connection 257 : void addConnection(const SUMOSAXAttributes& attrs); 258 : 259 : void addConflict(const SUMOSAXAttributes& attrs); 260 : 261 : virtual void openWAUT(const SUMOSAXAttributes& attrs); 262 : void addWAUTSwitch(const SUMOSAXAttributes& attrs); 263 : void addWAUTJunction(const SUMOSAXAttributes& attrs); 264 : 265 : /// Parses network location description 266 : void setLocation(const SUMOSAXAttributes& attrs); 267 : 268 : /** @begin Parses a district and creates a pseudo edge for it 269 : * 270 : * Called on the occurrence of a "district" element, this method 271 : * retrieves the id of the district and creates a district type 272 : * edge with this id. 273 : * 274 : * @param[in] attrs The attributes (of the "district"-element) to parse 275 : * @exception ProcessError If an edge given in district@edges is not known 276 : */ 277 : void addDistrict(const SUMOSAXAttributes& attrs); 278 : 279 : 280 : /** @begin Parses a district edge and connects it to the district 281 : * 282 : * Called on the occurrence of a "dsource" or "dsink" element, this method 283 : * retrieves the id of the approachable edge. If this edge is known 284 : * and valid, the approaching edge is informed about it. 285 : * 286 : * @param[in] attrs The attributes to parse 287 : * @param[in] isSource whether a "dsource or a "dsink" was given 288 : * @todo No exception? 289 : */ 290 : void addDistrictEdge(const SUMOSAXAttributes& attrs, bool isSource); 291 : 292 : /** @begin Parses a roundabout and sets flags for the edges 293 : * @param[in] attrs The attributes to parse 294 : */ 295 : void addRoundabout(const SUMOSAXAttributes& attrs); 296 : 297 : 298 : void closeWAUT(); 299 : 300 : /// @brief Parses the given character into an enumeration typed link direction 301 : LinkDirection parseLinkDir(const std::string& dir); 302 : 303 : /// @brief Parses the given character into an enumeration typed link state 304 : LinkState parseLinkState(const std::string& state); 305 : 306 : protected: 307 : /// @brief The net to fill (preinitialised) 308 : MSNet& myNet; 309 : 310 : /// @brief A builder for object actions 311 : NLDiscreteEventBuilder myActionBuilder; 312 : 313 : /// @brief Information whether the currently parsed edge is internal and not wished, here 314 : bool myCurrentIsInternalToSkip; 315 : 316 : 317 : /// @brief The detector builder to use 318 : NLDetectorBuilder& myDetectorBuilder; 319 : 320 : /// @brief The trigger builder to use 321 : NLTriggerBuilder& myTriggerBuilder; 322 : 323 : /// @brief The edge builder to use 324 : NLEdgeControlBuilder& myEdgeControlBuilder; 325 : 326 : /// @brief The junction builder to use 327 : NLJunctionControlBuilder& myJunctionControlBuilder; 328 : 329 : /// The id of the current district 330 : std::string myCurrentDistrictID; 331 : 332 : /// internal information whether a tls-logic is currently read 333 : bool myAmParsingTLLogicOrJunction; 334 : 335 : /// The id of the currently processed WAUT 336 : std::string myCurrentWAUTID; 337 : 338 : /// The id of the currently processed edge type 339 : std::string myCurrentTypeID; 340 : 341 : /// The network offset 342 : Position myNetworkOffset; 343 : 344 : /// The network's boundaries 345 : Boundary myOrigBoundary, myConvBoundary; 346 : 347 : bool myCurrentIsBroken; 348 : 349 : bool myHaveWarnedAboutInvalidTLType; 350 : 351 : Parameterised myLastEdgeParameters; 352 : std::vector<Parameterised*> myLastParameterised; 353 : 354 : /// @brief whether the loaded network contains internal lanes 355 : bool myHaveSeenInternalEdge; 356 : 357 : /// @brief Whether the network was built with higher speed on junctions 358 : bool myHaveJunctionHigherSpeeds; 359 : 360 : /// @brief whether the loaded network contains edges with default lengths 361 : bool myHaveSeenDefaultLength; 362 : 363 : /// @brief whether the loaded network contains explicit neighbor lanes 364 : bool myHaveSeenNeighs; 365 : 366 : /// @brief whether additional files contained type-specific speed limits 367 : bool myHaveSeenAdditionalSpeedRestrictions; 368 : 369 : /// @brief whether edge type specific meso paramters were loaded 370 : bool myHaveSeenMesoEdgeType; 371 : 372 : /// @brief the loaded network version 373 : MMVersion myNetworkVersion; 374 : 375 : /// @brief whether the location element was already loadee 376 : bool myNetIsLoaded; 377 : 378 : /// @brief rail signal for which constraints are being loaded 379 : MSRailSignal* myConstrainedSignal; 380 : 381 : /// @brief the link element for the connection currently being parsed 382 : MSLink* myCurrentLink = nullptr; 383 : 384 : /// @brief temporary data for building the junction graph after network parsing is finished 385 : typedef std::map<std::string, std::pair<std::string, std::string> > JunctionGraph; 386 : JunctionGraph myJunctionGraph; 387 : 388 : int myPreviousEdgeIdx = 0; 389 : 390 : private: 391 : /** invalid copy constructor */ 392 : NLHandler(const NLHandler& s); 393 : 394 : /** invalid assignment operator */ 395 : NLHandler& operator=(const NLHandler& s); 396 : 397 : };