1 package org.opentrafficsim.road.network.factory.xml;
2
3 import java.io.Serializable;
4
5 import org.djunits.value.vdouble.scalar.Direction;
6 import org.djunits.value.vdouble.scalar.Length;
7 import org.opentrafficsim.core.geometry.OTSPoint3D;
8 import org.opentrafficsim.core.network.NetworkException;
9 import org.opentrafficsim.core.network.factory.xml.units.AngleUnits;
10 import org.opentrafficsim.core.network.factory.xml.units.LengthUnits;
11 import org.w3c.dom.NamedNodeMap;
12 import org.w3c.dom.Node;
13 import org.xml.sax.SAXException;
14
15
16
17
18
19
20
21
22
23
24 class ArcTag implements Serializable
25 {
26
27 private static final long serialVersionUID = 20150724L;
28
29
30 @SuppressWarnings("checkstyle:visibilitymodifier")
31 Direction angle = null;
32
33
34 @SuppressWarnings("checkstyle:visibilitymodifier")
35 Length radius = null;
36
37
38 @SuppressWarnings("checkstyle:visibilitymodifier")
39 ArcDirection direction = null;
40
41
42 @SuppressWarnings("checkstyle:visibilitymodifier")
43 OTSPoint3D center;
44
45
46 @SuppressWarnings("checkstyle:visibilitymodifier")
47 double startAngle;
48
49
50 enum ArcDirection
51 {
52
53 LEFT,
54
55 RIGHT;
56 }
57
58
59
60
61
62
63
64
65
66 @SuppressWarnings("checkstyle:needbraces")
67 static void parseArc(final Node arcNode, final XmlNetworkLaneParser parser, final LinkTag linkTag)
68 throws SAXException, NetworkException
69 {
70 NamedNodeMap arcAttributes = arcNode.getAttributes();
71 linkTag.arcTag = new ArcTag();
72
73 Node radius = arcAttributes.getNamedItem("RADIUS");
74 if (radius == null)
75 throw new SAXException("ARC: missing attribute RADIUS");
76 linkTag.arcTag.radius = LengthUnits.parseLength(radius.getNodeValue());
77
78 Node angle = arcAttributes.getNamedItem("ANGLE");
79 if (angle == null)
80 throw new SAXException("ARC: missing attribute ANGLE");
81 linkTag.arcTag.angle = AngleUnits.parseDirection(angle.getNodeValue());
82
83 Node dirNode = arcAttributes.getNamedItem("DIRECTION");
84 if (dirNode == null)
85 throw new SAXException("ARC: missing attribute DIRECTION");
86 String dir = dirNode.getNodeValue().trim();
87 linkTag.arcTag.direction = (dir.equals("L") || dir.equals("LEFT") || dir.equals("COUNTERCLOCKWISE")) ? ArcDirection.LEFT
88 : ArcDirection.RIGHT;
89
90 }
91
92
93 @Override
94 public final String toString()
95 {
96 return "ArcTag [angle=" + this.angle + ", radius=" + this.radius + ", direction=" + this.direction + ", center="
97 + this.center + ", startAngle=" + this.startAngle + "]";
98 }
99 }