1 package org.opentrafficsim.road.network.factory.opendrive;
2
3 import java.io.Serializable;
4 import java.util.ArrayList;
5 import java.util.HashMap;
6 import java.util.List;
7 import java.util.Map;
8
9 import org.djunits.unit.LengthUnit;
10 import org.djunits.value.vdouble.scalar.Length;
11 import org.opentrafficsim.core.network.NetworkException;
12 import org.opentrafficsim.road.network.lane.Lane;
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 LaneSectionTag implements Serializable
27 {
28
29
30 private static final long serialVersionUID = 20150723L;
31
32
33 @SuppressWarnings("checkstyle:visibilitymodifier")
34 int id = 0;
35
36
37 @SuppressWarnings("checkstyle:visibilitymodifier")
38 Length s = null;
39
40
41 @SuppressWarnings("checkstyle:visibilitymodifier")
42 Map<Integer, LaneTag> leftLaneTags = new HashMap<Integer, LaneTag>();
43
44
45 @SuppressWarnings("checkstyle:visibilitymodifier")
46 Map<Integer, LaneTag> centerLaneTags = new HashMap<Integer, LaneTag>();
47
48
49 @SuppressWarnings("checkstyle:visibilitymodifier")
50 Map<Integer, LaneTag> rightLaneTags = new HashMap<Integer, LaneTag>();
51
52
53 @SuppressWarnings("checkstyle:visibilitymodifier")
54 Map<Integer, Lane> lanes = new HashMap<Integer, Lane>();
55
56
57
58
59
60
61
62
63
64 @SuppressWarnings("checkstyle:needbraces")
65 static LaneSectionTag parseLaneSection(final Node node, final OpenDriveNetworkLaneParser parser)
66 throws SAXException, NetworkException
67 {
68 NamedNodeMap attributes = node.getAttributes();
69 LaneSectionTag laneSectionTag = new LaneSectionTag();
70
71 Node s = attributes.getNamedItem("s");
72 if (s == null)
73 throw new SAXException("LaneSection: missing attribute s");
74 laneSectionTag.s = new Length(Double.parseDouble(s.getNodeValue().trim()), LengthUnit.METER);
75
76 for (Node leftNode : XMLParser.getNodes(node.getChildNodes(), "left"))
77 for (Node laneNode : XMLParser.getNodes(leftNode.getChildNodes(), "lane"))
78 {
79 LaneTag laneTag = LaneTag.parseLane(laneNode, parser);
80 laneSectionTag.leftLaneTags.put(laneTag.id, laneTag);
81 }
82
83 for (Node centerNode : XMLParser.getNodes(node.getChildNodes(), "center"))
84 for (Node laneNode : XMLParser.getNodes(centerNode.getChildNodes(), "lane"))
85 {
86 LaneTag laneTag = LaneTag.parseLane(laneNode, parser);
87 laneSectionTag.centerLaneTags.put(laneTag.id, laneTag);
88 }
89
90 for (Node rightNode : XMLParser.getNodes(node.getChildNodes(), "right"))
91 for (Node laneNode : XMLParser.getNodes(rightNode.getChildNodes(), "lane"))
92 {
93 LaneTag laneTag = LaneTag.parseLane(laneNode, parser);
94 laneSectionTag.rightLaneTags.put(laneTag.id, laneTag);
95 }
96
97 return laneSectionTag;
98 }
99
100
101
102
103
104 public List<Lane> findLanes(String orientation)
105 {
106 List<Lane> lanes1 = new ArrayList<Lane>();
107 for (int key : this.lanes.keySet())
108 {
109 Lane lane = this.lanes.get(key);
110 if (key < 0)
111 {
112 if (orientation.equals("+") && this.rightLaneTags.get(key).type.equals("driving"))
113 lanes1.add(lane);
114 }
115 else if (key > 0)
116 {
117 if (orientation.equals("-") && this.leftLaneTags.get(key).type.equals("driving"))
118 lanes1.add(lane);
119 }
120
121 }
122 if (lanes1.size() != 1)
123 System.err.println("Exception in finding lanes");
124 return lanes1;
125 }
126
127
128 @Override
129 public final String toString()
130 {
131 return "LaneSectionTag [id=" + this.id + ", s=" + this.s + ", leftLaneTags=" + this.leftLaneTags + ", centerLaneTags="
132 + this.centerLaneTags + ", rightLaneTags=" + this.rightLaneTags + ", lanes=" + this.lanes + "]";
133 }
134 }