1 package org.opentrafficsim.road.network.factory.vissim;
2
3 import java.io.Serializable;
4
5 import org.djunits.unit.LengthUnit;
6 import org.djunits.unit.SpeedUnit;
7 import org.djunits.value.vdouble.scalar.Length;
8 import org.djunits.value.vdouble.scalar.Speed;
9 import org.opentrafficsim.core.gtu.GTUException;
10 import org.opentrafficsim.core.gtu.GTUType;
11 import org.opentrafficsim.core.network.NetworkException;
12 import org.opentrafficsim.core.network.factory.xml.units.Distributions;
13 import org.opentrafficsim.core.units.distributions.ContinuousDistDoubleScalar;
14 import org.w3c.dom.NamedNodeMap;
15 import org.w3c.dom.Node;
16 import org.w3c.dom.NodeList;
17 import org.xml.sax.SAXException;
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 class GTUTag implements Serializable
45 {
46
47 private static final long serialVersionUID = 20150723L;
48
49
50 @SuppressWarnings("checkstyle:visibilitymodifier")
51 String name = null;
52
53
54 @SuppressWarnings("checkstyle:visibilitymodifier")
55 GTUType gtuType = null;
56
57
58 @SuppressWarnings("checkstyle:visibilitymodifier")
59 ContinuousDistDoubleScalar.Rel<Length, LengthUnit> lengthDist = null;
60
61
62 @SuppressWarnings("checkstyle:visibilitymodifier")
63 ContinuousDistDoubleScalar.Rel<Length, LengthUnit> widthDist = null;
64
65
66 @SuppressWarnings("checkstyle:visibilitymodifier")
67 ContinuousDistDoubleScalar.Rel<Speed, SpeedUnit> maxSpeedDist = null;
68
69
70
71
72
73
74
75
76 @SuppressWarnings("checkstyle:needbraces")
77 static void parseGTUs(final NodeList nodeList, final VissimNetworkLaneParser parser)
78 throws SAXException, NetworkException, GTUException
79 {
80 for (Node node : XMLParser.getNodes(nodeList, "GTU"))
81 {
82 NamedNodeMap attributes = node.getAttributes();
83 GTUTag gtuTag = new GTUTag();
84
85 Node name = attributes.getNamedItem("NAME");
86 if (name == null)
87 {
88 throw new SAXException("GTU: missing attribute NAME");
89 }
90 gtuTag.name = name.getNodeValue().trim();
91 if (parser.getGtuTags().keySet().contains(gtuTag.name))
92 {
93 throw new SAXException("GTU: NAME " + gtuTag.name + " defined twice");
94 }
95
96 Node gtuType = attributes.getNamedItem("GTUTYPE");
97 if (gtuType == null)
98 {
99 throw new SAXException("GTU: missing attribute GTUTYPE");
100 }
101 if (!parser.getGtuTypes().containsKey(gtuType.getNodeValue().trim()))
102 {
103 throw new SAXException("GTU: GTUTYPE " + gtuType.getNodeValue().trim() + " not defined");
104 }
105 gtuTag.gtuType = parser.getGtuTypes().get(gtuType.getNodeValue().trim());
106
107 Node length = attributes.getNamedItem("LENGTH");
108 if (length == null)
109 {
110 throw new SAXException("GTU: missing attribute LENGTH");
111 }
112 gtuTag.lengthDist = Distributions.parseLengthDist(length.getNodeValue());
113
114 Node width = attributes.getNamedItem("WIDTH");
115 if (width == null)
116 {
117 throw new SAXException("GTU: missing attribute WIDTH");
118 }
119 gtuTag.widthDist = Distributions.parseLengthDist(width.getNodeValue());
120
121 Node maxSpeed = attributes.getNamedItem("MAXSPEED");
122 if (maxSpeed == null)
123 {
124 throw new SAXException("GTU: missing attribute LENGTH");
125 }
126 gtuTag.maxSpeedDist = Distributions.parseSpeedDist(maxSpeed.getNodeValue());
127
128 parser.getGtuTags().put(gtuTag.name, gtuTag);
129 }
130 }
131
132
133 @Override
134 public final String toString()
135 {
136 return "GTUTag [name=" + this.name + ", gtuType=" + this.gtuType + ", lengthDist=" + this.lengthDist + ", widthDist="
137 + this.widthDist + ", followingModel=" + ", maxSpeedDist=" + this.maxSpeedDist + "]";
138 }
139
140 }