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 METypeHandler.cpp
15 : /// @author Jakob Erdmann
16 : /// @date Jan 2026
17 : ///
18 : // The XML-Handler for loading meso edge types
19 : // This is a dedicated handler because meso types must be loaded from additional
20 : // files before any other objects are loaded from them
21 : /****************************************************************************/
22 : #include <config.h>
23 :
24 : #include <string>
25 : #include "METypeHandler.h"
26 : #include <utils/xml/SUMOXMLDefinitions.h>
27 : #include <utils/xml/SUMOSAXHandler.h>
28 : #include <microsim/MSNet.h>
29 : #include <mesosim/MESegment.h>
30 :
31 :
32 : // ===========================================================================
33 : // method definitions
34 : // ===========================================================================
35 3244 : METypeHandler::METypeHandler(const std::string& file, MSNet& net) :
36 : SUMOSAXHandler(file),
37 3244 : myNet(net),
38 6488 : myHaveSeenMesoEdgeType(false)
39 : {
40 3244 : }
41 :
42 :
43 3244 : METypeHandler::~METypeHandler() {}
44 :
45 :
46 : void
47 53921 : METypeHandler::myStartElement(int element,
48 : const SUMOSAXAttributes& attrs) {
49 : try {
50 53921 : switch (element) {
51 46 : case SUMO_TAG_TYPE: {
52 46 : bool ok = true;
53 92 : myCurrentTypeID = attrs.get<std::string>(SUMO_ATTR_ID, nullptr, ok);
54 : break;
55 : }
56 24 : case SUMO_TAG_MESO: {
57 24 : addMesoEdgeType(attrs);
58 : break;
59 : }
60 : default:
61 : break;
62 : }
63 0 : } catch (InvalidArgument& e) {
64 0 : WRITE_ERROR(e.what());
65 0 : }
66 53921 : }
67 :
68 :
69 : void
70 53919 : METypeHandler::myEndElement(int element) {
71 53919 : switch (element) {
72 46 : case SUMO_TAG_TYPE:
73 46 : myCurrentTypeID = "";
74 : break;
75 : default:
76 : break;
77 : }
78 53919 : }
79 :
80 :
81 :
82 : void
83 24 : METypeHandler::addMesoEdgeType(const SUMOSAXAttributes& attrs) {
84 24 : bool ok = true;
85 24 : MESegment::MesoEdgeType edgeType = myNet.getMesoType(""); // init defaults
86 24 : edgeType.tauff = attrs.getOptSUMOTimeReporting(SUMO_ATTR_MESO_TAUFF, myCurrentTypeID.c_str(), ok, edgeType.tauff);
87 24 : edgeType.taufj = attrs.getOptSUMOTimeReporting(SUMO_ATTR_MESO_TAUFJ, myCurrentTypeID.c_str(), ok, edgeType.taufj);
88 24 : edgeType.taujf = attrs.getOptSUMOTimeReporting(SUMO_ATTR_MESO_TAUJF, myCurrentTypeID.c_str(), ok, edgeType.taujf);
89 24 : edgeType.taujj = attrs.getOptSUMOTimeReporting(SUMO_ATTR_MESO_TAUJJ, myCurrentTypeID.c_str(), ok, edgeType.taujj);
90 24 : edgeType.jamThreshold = attrs.getOpt<double>(SUMO_ATTR_JAM_DIST_THRESHOLD, myCurrentTypeID.c_str(), ok, edgeType.jamThreshold);
91 24 : edgeType.junctionControl = attrs.getOpt<bool>(SUMO_ATTR_MESO_JUNCTION_CONTROL, myCurrentTypeID.c_str(), ok, edgeType.junctionControl);
92 24 : edgeType.tlsPenalty = attrs.getOpt<double>(SUMO_ATTR_MESO_TLS_PENALTY, myCurrentTypeID.c_str(), ok, edgeType.tlsPenalty);
93 24 : edgeType.tlsFlowPenalty = attrs.getOpt<double>(SUMO_ATTR_MESO_TLS_FLOW_PENALTY, myCurrentTypeID.c_str(), ok, edgeType.tlsFlowPenalty);
94 24 : edgeType.minorPenalty = attrs.getOptSUMOTimeReporting(SUMO_ATTR_MESO_MINOR_PENALTY, myCurrentTypeID.c_str(), ok, edgeType.minorPenalty);
95 24 : edgeType.overtaking = attrs.getOpt<bool>(SUMO_ATTR_MESO_OVERTAKING, myCurrentTypeID.c_str(), ok, edgeType.overtaking);
96 24 : edgeType.edgeLength = attrs.getOpt<double>(SUMO_ATTR_MESO_EDGELENGHT, myCurrentTypeID.c_str(), ok, edgeType.edgeLength);
97 :
98 24 : if (ok) {
99 24 : myNet.addMesoType(myCurrentTypeID, edgeType);
100 : }
101 24 : myHaveSeenMesoEdgeType = true;
102 24 : }
103 :
104 :
105 : /****************************************************************************/
|