1 package org.opentrafficsim.road.network.factory.vissim;
2
3 import java.io.Serializable;
4
5 import org.opentrafficsim.core.gtu.RelativePosition;
6 import org.opentrafficsim.core.network.NetworkException;
7 import org.w3c.dom.NamedNodeMap;
8 import org.w3c.dom.Node;
9 import org.w3c.dom.NodeList;
10 import org.xml.sax.SAXException;
11
12
13
14
15
16
17
18
19
20
21 class SensorTag implements Serializable
22 {
23
24 private static final long serialVersionUID = 20150723L;
25
26
27 @SuppressWarnings("checkstyle:visibilitymodifier")
28 String name = null;
29
30
31 @SuppressWarnings("checkstyle:visibilitymodifier")
32 String length = null;
33
34
35 @SuppressWarnings("checkstyle:visibilitymodifier")
36 String laneName = null;
37
38
39 @SuppressWarnings("checkstyle:visibilitymodifier")
40 String linkName = null;
41
42
43 @SuppressWarnings("checkstyle:visibilitymodifier")
44 String no = null;
45
46
47 @SuppressWarnings("checkstyle:visibilitymodifier")
48 String portNo = null;
49
50
51 @SuppressWarnings("checkstyle:visibilitymodifier")
52 String sc = null;
53
54
55 @SuppressWarnings("checkstyle:visibilitymodifier")
56 String type = null;
57
58
59 @SuppressWarnings("checkstyle:visibilitymodifier")
60 String positionStr = null;
61
62
63 @SuppressWarnings("checkstyle:visibilitymodifier")
64 String className = null;
65
66
67 @SuppressWarnings("checkstyle:visibilitymodifier")
68 RelativePosition.TYPE triggerPosition;
69
70
71 Boolean activeOnThisLink = true;
72
73
74
75
76 public SensorTag(SensorTag sensorTag)
77 {
78 this.name = sensorTag.name;
79 this.length = sensorTag.length;
80 this.laneName = sensorTag.laneName;
81 this.linkName = sensorTag.linkName;
82 this.no = sensorTag.no;
83 this.portNo = sensorTag.portNo;
84 this.sc = sensorTag.sc;
85 this.type = sensorTag.type;
86 this.positionStr = sensorTag.positionStr;
87 this.className = sensorTag.className;
88 this.triggerPosition = sensorTag.triggerPosition;
89 }
90
91
92
93
94 public SensorTag()
95 {
96
97 }
98
99
100
101
102
103
104
105
106 @SuppressWarnings("checkstyle:needbraces")
107 static void parseSensor(final NodeList nodeList, final VissimNetworkLaneParser parser) throws SAXException, NetworkException
108 {
109
110 for (Node linksNode : XMLParser.getNodes(nodeList, "detectors"))
111 {
112
113 for (Node node : XMLParser.getNodes(linksNode.getChildNodes(), "detector"))
114 {
115 NamedNodeMap attributes = node.getAttributes();
116
117 SensorTag sensorTag = new SensorTag();
118
119 if (attributes.getNamedItem("name") == null)
120 {
121 throw new SAXException("Sensor: missing attribute: name");
122 }
123 sensorTag.name = attributes.getNamedItem("name").getNodeValue().trim();
124
125 if (attributes.getNamedItem("lane") == null)
126 {
127 throw new SAXException("Sensor: missing attribute: lane");
128 }
129 String laneLink = attributes.getNamedItem("lane").getNodeValue().trim();
130 String[] laneLinkInfo = laneLink.split("\\s+");
131 sensorTag.linkName = laneLinkInfo[0];
132 sensorTag.laneName = laneLinkInfo[1];
133
134 if (attributes.getNamedItem("length") == null)
135 {
136 throw new SAXException("Sensor: missing attribute: length");
137 }
138 sensorTag.length = attributes.getNamedItem("length").getNodeValue().trim();
139
140 if (attributes.getNamedItem("no") == null)
141 {
142 throw new SAXException("Sensor: missing attribute: no");
143 }
144 sensorTag.no = attributes.getNamedItem("no").getNodeValue().trim();
145
146 if (attributes.getNamedItem("portNo") == null)
147 {
148 throw new SAXException("Sensor: missing attribute: portNo");
149 }
150 sensorTag.portNo = attributes.getNamedItem("portNo").getNodeValue().trim();
151
152 if (attributes.getNamedItem("sc") == null)
153 {
154 throw new SAXException("Sensor: missing attribute: sc");
155 }
156 sensorTag.sc = attributes.getNamedItem("sc").getNodeValue().trim();
157
158 if (attributes.getNamedItem("type") == null)
159 {
160 throw new SAXException("Sensor: missing attribute: type");
161 }
162 sensorTag.type = attributes.getNamedItem("type").getNodeValue().trim();
163
164 if (attributes.getNamedItem("pos") == null)
165 {
166 throw new SAXException("Sensor: missing attribute: pos");
167 }
168 sensorTag.positionStr = attributes.getNamedItem("pos").getNodeValue().trim();
169
170 parser.getSensorTags().put(sensorTag.no, sensorTag);
171
172 }
173 }
174
175 }
176
177
178
179
180
181
182
183
184 static RelativePosition.TYPE parseTriggerPosition(final String trigger, final SensorTag sensorTag, final String laneName)
185 throws SAXException
186 {
187 switch (trigger)
188 {
189 case "FRONT":
190 return RelativePosition.FRONT;
191
192 case "CENTER":
193 return RelativePosition.CENTER;
194
195 case "DRIVER":
196 return RelativePosition.DRIVER;
197
198 case "REAR":
199 return RelativePosition.REAR;
200
201 case "REFERENCE":
202 return RelativePosition.REFERENCE;
203
204 default:
205 throw new SAXException("SENSOR: wrong type of TRIGGER for sensor " + sensorTag.name + " on lane " + laneName);
206 }
207 }
208
209
210 @Override
211 public final String toString()
212 {
213 return "SensorTag [name=" + this.name + ", positionStr=" + this.positionStr + ", className=" + this.className
214 + ", triggerPosition=" + this.triggerPosition + "]";
215 }
216 }