1 package org.opentrafficsim.editor.extensions.map;
2
3 import java.util.List;
4
5 import org.djunits.value.vdouble.scalar.Direction;
6 import org.djunits.value.vdouble.scalar.Length;
7 import org.djutils.draw.line.PolyLine2d;
8 import org.opentrafficsim.base.StripeElement;
9 import org.opentrafficsim.base.StripeElement.StripeLateralSync;
10 import org.opentrafficsim.base.geometry.DirectionalPolyLine;
11 import org.opentrafficsim.base.geometry.OtsLocatable;
12 import org.opentrafficsim.draw.road.StripeAnimation.StripeData;
13 import org.opentrafficsim.editor.XsdTreeNode;
14 import org.opentrafficsim.editor.extensions.map.MapLinkData.MiddleOffset;
15 import org.opentrafficsim.road.network.lane.CrossSectionGeometry;
16
17
18
19
20
21
22
23
24
25 public class MapStripeData extends MapCrossSectionData implements StripeData
26 {
27
28
29 private final Length width;
30
31
32 private Length dashOffset;
33
34
35 private final Length laterealStartOffset;
36
37
38 private final List<StripeElement> elements;
39
40
41 private final StripeLateralSync lateralSync;
42
43
44 private final PolyLine2d linkLine;
45
46
47 private PolyLine2d linkReferenceLine = null;
48
49
50 private final MiddleOffset middleOffset;
51
52
53 private final Direction startDirection;
54
55
56 private final Direction endDirection;
57
58
59 private DirectionalPolyLine centerLine;
60
61
62
63
64
65
66
67
68
69
70
71
72
73 public MapStripeData(final Length dashOffset, final XsdTreeNode linkNode, final CrossSectionGeometry geometry,
74 final List<StripeElement> elements, final StripeLateralSync lateralSync, final PolyLine2d linkLine,
75 final MiddleOffset middleOffset, final Direction startDirection, final Direction endDirection)
76 {
77 super(linkNode, geometry);
78 Length w = Length.ZERO;
79 for (StripeElement element : elements)
80 {
81 w = w.plus(element.width());
82 }
83 this.width = w;
84 this.dashOffset = dashOffset;
85 this.laterealStartOffset = Length.instantiateSI(geometry.offset().apply(0.0));
86 this.elements = elements;
87 this.lateralSync = lateralSync;
88 this.linkLine = linkLine;
89 this.middleOffset = middleOffset;
90 this.startDirection = startDirection;
91 this.endDirection = endDirection;
92 }
93
94 @Override
95 public PolyLine2d getLine()
96 {
97 return OtsLocatable.transformLine(getCenterLine(), getLocation());
98 }
99
100 @Override
101 public Length getWidth(final Length position)
102 {
103 return this.width;
104 }
105
106 @Override
107 public PolyLine2d getReferenceLine()
108 {
109 return this.lateralSync.equals(StripeLateralSync.NONE) ? this.getCenterLine() : getLinkReferenceLine();
110 }
111
112 @Override
113 public DirectionalPolyLine getCenterLine()
114 {
115 if (this.centerLine == null)
116 {
117 this.centerLine = new DirectionalPolyLine(super.getCenterLine(), this.startDirection, this.endDirection);
118 }
119 return this.centerLine;
120 }
121
122
123
124
125
126 private PolyLine2d getLinkReferenceLine()
127 {
128 if (this.linkReferenceLine == null)
129 {
130 this.linkReferenceLine = new DirectionalPolyLine(this.linkLine, this.startDirection, this.endDirection)
131 .directionalOffsetLine(this.middleOffset.getStartOffset(), this.middleOffset.getEndOffset());
132 }
133 return this.linkReferenceLine;
134 }
135
136 @Override
137 public List<StripeElement> getElements()
138 {
139 return this.elements;
140 }
141
142 @Override
143 public Length getDashOffset()
144 {
145 return this.dashOffset;
146 }
147
148
149
150
151
152 public StripeLateralSync getLateralSync()
153 {
154 return this.lateralSync;
155 }
156
157
158
159
160
161 public void setDashOffset(final Length dashOffset)
162 {
163 this.dashOffset = dashOffset;
164 }
165
166
167 @Override
168 public String toString()
169 {
170 return "Stripe " + getLinkId() + " " + this.laterealStartOffset;
171 }
172
173 }