1 package org.opentrafficsim.road.network.factory.vissim;
2
3 import java.io.Serializable;
4
5 import org.djunits.value.vdouble.scalar.Length;
6 import org.opentrafficsim.core.geometry.OTSPoint3D;
7 import org.opentrafficsim.core.network.NetworkException;
8 import org.opentrafficsim.core.network.factory.xml.units.Coordinates;
9 import org.xml.sax.SAXException;
10
11
12
13
14
15
16
17
18
19
20 class PolyLineTag implements Serializable
21 {
22
23 private static final long serialVersionUID = 20150724L;
24
25
26 @SuppressWarnings("checkstyle:visibilitymodifier")
27 Length length = null;
28
29
30 OTSPoint3D[] vertices = null;
31
32
33
34
35 public PolyLineTag(PolyLineTag polyLineTag)
36 {
37 if (polyLineTag != null)
38 {
39 this.length = polyLineTag.length;
40 this.vertices = polyLineTag.vertices;
41 }
42 }
43
44
45
46
47
48 public PolyLineTag(Length length, OTSPoint3D[] vertices)
49 {
50 super();
51 this.length = length;
52 this.vertices = vertices;
53 }
54
55
56
57
58 public PolyLineTag()
59 {
60
61 }
62
63
64
65
66
67
68
69
70
71 @SuppressWarnings("checkstyle:needbraces")
72 static void parsePolyLine(final String coords, final VissimNetworkLaneParser parser, final LinkTag linkTag)
73 throws SAXException, NetworkException
74 {
75 linkTag.polyLineTag = new PolyLineTag();
76 linkTag.polyLineTag.vertices = parseVertices(coords);
77 }
78
79
80
81
82
83
84 public static OTSPoint3D[] parseVertices(final String cs)
85 {
86 String cs1 = cs.replaceAll("\\s+", "");
87 String c = cs1.replace(")(", ")split(");
88 String[] cc = c.split("split");
89 OTSPoint3D[] coords = new OTSPoint3D[cc.length - 2];
90
91 int i = 0;
92 int vertexCount = 0;
93 for (String coord : cc)
94 {
95 if (i > 0 && i < cc.length - 1)
96 {
97 coords[vertexCount] = Coordinates.parseCoordinate(coord);
98 vertexCount++;
99 }
100 i++;
101 }
102 return coords;
103 }
104
105
106 @Override
107 public final String toString()
108 {
109 return "PolyLineTag [length=" + this.length + "]";
110 }
111
112 }