1 package org.opentrafficsim.road.network.factory.vissim;
2
3 import java.io.Serializable;
4 import java.net.URI;
5 import java.net.URISyntaxException;
6
7 import org.djunits.unit.SpeedUnit;
8 import org.djunits.value.vdouble.scalar.Speed;
9 import org.opentrafficsim.core.network.NetworkException;
10 import org.opentrafficsim.core.network.factory.xml.units.Distributions;
11 import org.opentrafficsim.core.units.distributions.ContinuousDistDoubleScalar;
12 import org.opentrafficsim.road.network.factory.vissim.CrossSectionElementTag.ElementType;
13 import org.w3c.dom.NamedNodeMap;
14 import org.w3c.dom.Node;
15 import org.xml.sax.SAXException;
16
17
18
19
20
21
22
23
24
25
26 class ListGeneratorTag implements Serializable
27 {
28
29 private static final long serialVersionUID = 20150723L;
30
31
32 @SuppressWarnings("checkstyle:visibilitymodifier")
33 URI uri = null;
34
35
36 @SuppressWarnings("checkstyle:visibilitymodifier")
37 String positionStr = null;
38
39
40 @SuppressWarnings("checkstyle:visibilitymodifier")
41 GTUTag gtuTag = null;
42
43
44 @SuppressWarnings("checkstyle:visibilitymodifier")
45 GTUMixTag gtuMixTag = null;
46
47
48 @SuppressWarnings("checkstyle:visibilitymodifier")
49 ContinuousDistDoubleScalar.Rel<Speed, SpeedUnit> initialSpeedDist = null;
50
51
52 @SuppressWarnings("checkstyle:visibilitymodifier")
53 String gtuColorer;
54
55
56
57
58
59
60
61
62
63 @SuppressWarnings("checkstyle:needbraces")
64 static void parseListGenerator(final Node node, final VissimNetworkLaneParser parser, final LinkTag linkTag)
65 throws SAXException, NetworkException
66 {
67 NamedNodeMap attributes = node.getAttributes();
68 ListGeneratorTag listGeneratorTag = new ListGeneratorTag();
69
70 if (attributes.getNamedItem("URI") == null)
71 {
72 throw new SAXException("LISTGENERATOR: missing attribute URI" + " for link " + linkTag.name);
73 }
74 String uriStr = attributes.getNamedItem("URI").getNodeValue().trim();
75 try
76 {
77 listGeneratorTag.uri = new URI(uriStr);
78 }
79 catch (URISyntaxException exception)
80 {
81 throw new NetworkException("LISTGENERATOR: URI " + uriStr + " is not valid", exception);
82 }
83
84 if (attributes.getNamedItem("LANE") == null)
85 {
86 throw new SAXException("LISTGENERATOR: missing attribute LANE" + " for link " + linkTag.name);
87 }
88 String laneName = attributes.getNamedItem("LANE").getNodeValue().trim();
89 if (linkTag.roadLayoutTag == null)
90 {
91 throw new NetworkException("LISTGENERATOR: LANE " + laneName + " no ROADTYPE for link " + linkTag.name);
92 }
93 CrossSectionElementTag cseTag = linkTag.roadLayoutTag.cseTags.get(laneName);
94 if (cseTag == null)
95 {
96 throw new NetworkException("LISTGENERATOR: LANE " + laneName + " not found in elements of link " + linkTag.name
97 + " - roadtype " + linkTag.roadLayoutTag.name);
98 }
99 if (cseTag.elementType != ElementType.LANE)
100 {
101 throw new NetworkException("LISTGENERATOR: LANE " + laneName + " not a real GTU lane for link " + linkTag.name
102 + " - roadtype " + linkTag.roadLayoutTag.name);
103 }
104 if (linkTag.generatorTags.containsKey(laneName))
105 {
106 throw new SAXException("LISTGENERATOR for LANE with NAME " + laneName + " defined twice");
107 }
108
109 Node position = attributes.getNamedItem("POSITION");
110 if (position == null)
111 {
112 throw new NetworkException("LISTGENERATOR: POSITION element not found in elements of link " + linkTag.name
113 + " - roadtype " + linkTag.roadLayoutTag.name);
114 }
115 listGeneratorTag.positionStr = position.getNodeValue().trim();
116
117 if (attributes.getNamedItem("GTU") != null)
118 {
119 String gtuName = attributes.getNamedItem("GTU").getNodeValue().trim();
120 if (!parser.getGtuTags().containsKey(gtuName))
121 {
122 throw new NetworkException(
123 "LISTGENERATOR: LANE " + laneName + " GTU " + gtuName + " in link " + linkTag.name + " not defined");
124 }
125 listGeneratorTag.gtuTag = parser.getGtuTags().get(gtuName);
126 }
127
128 if (attributes.getNamedItem("GTUMIX") != null)
129 {
130 String gtuMixName = attributes.getNamedItem("GTUMIX").getNodeValue().trim();
131 if (!parser.getGtuMixTags().containsKey(gtuMixName))
132 {
133 throw new NetworkException("LISTGENERATOR: LANE " + laneName + " GTUMIX " + gtuMixName + " in link "
134 + linkTag.name + " not defined");
135 }
136 listGeneratorTag.gtuMixTag = parser.getGtuMixTags().get(gtuMixName);
137 }
138
139 if (listGeneratorTag.gtuTag == null && listGeneratorTag.gtuMixTag == null)
140 {
141 throw new SAXException("LISTGENERATOR: missing attribute GTU or GTUMIX for Lane with NAME " + laneName + " of link "
142 + linkTag.name);
143 }
144
145 if (listGeneratorTag.gtuTag != null && listGeneratorTag.gtuMixTag != null)
146 {
147 throw new SAXException("LISTGENERATOR: both attribute GTU and GTUMIX defined for Lane with NAME " + laneName
148 + " of link " + linkTag.name);
149 }
150
151 Node initialSpeed = attributes.getNamedItem("INITIALSPEED");
152 if (initialSpeed == null)
153 {
154 throw new SAXException("LISTGENERATOR: missing attribute INITIALSPEED");
155 }
156 listGeneratorTag.initialSpeedDist = Distributions.parseSpeedDist(initialSpeed.getNodeValue());
157
158
159
160 linkTag.listGeneratorTags.put(laneName, listGeneratorTag);
161 }
162
163
164 @Override
165 public final String toString()
166 {
167 return "ListGeneratorTag [uri=" + this.uri + ", positionStr=" + this.positionStr + ", gtuTag=" + this.gtuTag
168 + ", gtuMixTag=" + this.gtuMixTag + ", initialSpeedDist=" + this.initialSpeedDist + ", gtuColorer="
169 + this.gtuColorer + "]";
170 }
171 }