Line data Source code
1 : /****************************************************************************/
2 : // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3 : // Copyright (C) 2001-2026 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 25459 : NLShapeHandler(const std::string& file, ShapeContainer& sc) :
58 25459 : ShapeHandler(file, sc) {}
59 :
60 : /// @brief Destructor
61 25459 : virtual ~NLShapeHandler() {}
62 :
63 : Position getLanePos(const std::string& poiID, const std::string& laneID, double lanePos, bool friendlyPos, double lanePosLat);
64 :
65 807 : virtual bool addLanePosParams() {
66 807 : 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 6040 : return myHaveSeenInternalEdge;
105 : }
106 :
107 : bool hasJunctionHigherSpeeds() const {
108 40768 : return myHaveJunctionHigherSpeeds;
109 : }
110 :
111 : bool haveSeenDefaultLength() const {
112 3260 : return myHaveSeenDefaultLength;
113 : }
114 :
115 : bool haveSeenNeighs() const {
116 : return myHaveSeenNeighs;
117 : }
118 :
119 : bool haveSeenAdditionalSpeedRestrictions() const {
120 25459 : return myHaveSeenAdditionalSpeedRestrictions;
121 : }
122 :
123 : bool haveSeenTLSParams() const {
124 5743 : return myHaveSeenTLSParams;
125 : }
126 :
127 : MMVersion networkVersion() const {
128 122616 : 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 deadlock information for preparing additional rail signal checks
213 : * @param[in] attrs The attributes that hold the parameters
214 : */
215 : virtual void addDeadlock(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 : int parseDetectPersons(const std::string& detectPersonsString, const std::string& id, bool& ok);
307 :
308 : protected:
309 : /// @brief The net to fill (preinitialised)
310 : MSNet& myNet;
311 :
312 : /// @brief A builder for object actions
313 : NLDiscreteEventBuilder myActionBuilder;
314 :
315 : /// @brief Information whether the currently parsed edge is internal and not wished, here
316 : bool myCurrentIsInternalToSkip;
317 :
318 :
319 : /// @brief The detector builder to use
320 : NLDetectorBuilder& myDetectorBuilder;
321 :
322 : /// @brief The trigger builder to use
323 : NLTriggerBuilder& myTriggerBuilder;
324 :
325 : /// @brief The edge builder to use
326 : NLEdgeControlBuilder& myEdgeControlBuilder;
327 :
328 : /// @brief The junction builder to use
329 : NLJunctionControlBuilder& myJunctionControlBuilder;
330 :
331 : /// The id of the current district
332 : std::string myCurrentDistrictID;
333 :
334 : /// internal information whether a tls-logic is currently read
335 : bool myAmParsingTLLogicOrJunction;
336 :
337 : /// The id of the currently processed WAUT
338 : std::string myCurrentWAUTID;
339 :
340 : /// The id of the currently processed edge type
341 : std::string myCurrentTypeID;
342 :
343 : /// The network offset
344 : Position myNetworkOffset;
345 :
346 : /// The network's boundaries
347 : Boundary myOrigBoundary, myConvBoundary;
348 :
349 : bool myCurrentIsBroken;
350 :
351 : bool myHaveWarnedAboutInvalidTLType;
352 :
353 : Parameterised myLastEdgeParameters;
354 : std::vector<Parameterised*> myLastParameterised;
355 :
356 : /// @brief whether the loaded network contains internal lanes
357 : bool myHaveSeenInternalEdge;
358 :
359 : /// @brief Whether the network was built with higher speed on junctions
360 : bool myHaveJunctionHigherSpeeds;
361 :
362 : /// @brief whether the loaded network contains edges with default lengths
363 : bool myHaveSeenDefaultLength;
364 :
365 : /// @brief whether the loaded network contains explicit neighbor lanes
366 : bool myHaveSeenNeighs;
367 :
368 : /// @brief whether additional files contained type-specific speed limits
369 : bool myHaveSeenAdditionalSpeedRestrictions;
370 :
371 : /// @brief whether tls params were loaded
372 : bool myHaveSeenTLSParams;
373 :
374 : /// @brief the loaded network version
375 : MMVersion myNetworkVersion;
376 :
377 : /// @brief whether the location element was already loadee
378 : bool myNetIsLoaded;
379 :
380 : /// @brief rail signal for which constraints are being loaded
381 : MSRailSignal* myConstrainedSignal;
382 :
383 : /// @brief the link element for the connection currently being parsed
384 : MSLink* myCurrentLink = nullptr;
385 :
386 : /// @brief temporary data for building the junction graph after network parsing is finished
387 : typedef std::map<std::string, std::pair<std::string, std::string> > JunctionGraph;
388 : JunctionGraph myJunctionGraph;
389 :
390 : int myPreviousEdgeIdx = 0;
391 :
392 : private:
393 : /** invalid copy constructor */
394 : NLHandler(const NLHandler& s);
395 :
396 : /** invalid assignment operator */
397 : NLHandler& operator=(const NLHandler& s);
398 :
399 : };
|