1 package org.opentrafficsim.road.network.lane;
2
3 import java.rmi.RemoteException;
4 import java.util.List;
5 import java.util.Set;
6
7 import javax.naming.NamingException;
8
9 import org.djunits.value.vdouble.scalar.Length;
10 import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
11 import org.opentrafficsim.core.geometry.OTSGeometryException;
12 import org.opentrafficsim.core.gtu.GTUType;
13 import org.opentrafficsim.core.network.LateralDirectionality;
14 import org.opentrafficsim.core.network.NetworkException;
15 import org.opentrafficsim.road.network.animation.StripeAnimation;
16
17
18
19
20
21
22
23
24
25
26
27
28 public class Stripe extends RoadMarkerAlong
29 {
30
31 private static final long serialVersionUID = 20151025L;
32
33
34
35
36
37
38
39
40
41
42 public Stripe(final CrossSectionLink parentLink, final Length lateralCenterPosition, final Length width)
43 throws OTSGeometryException, NetworkException
44 {
45 super(parentLink, lateralCenterPosition, width);
46 }
47
48
49
50
51
52
53
54
55
56
57
58
59
60 public Stripe(final CrossSectionLink parentLink, final Length lateralCenterPosition, final Length width,
61 final Set<GTUType> gtuTypes, final Permeable permeable) throws OTSGeometryException, NetworkException
62 {
63 super(parentLink, lateralCenterPosition, width);
64 for (GTUType gtuType : gtuTypes)
65 {
66 addPermeability(gtuType, permeable);
67 }
68 }
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83 public Stripe(final CrossSectionLink parentLink, final List<CrossSectionSlice> crossSectionSlices,
84 final Permeable permeable) throws OTSGeometryException, NetworkException
85 {
86 super(parentLink, crossSectionSlices);
87 addPermeability(GTUType.ALL, permeable);
88 }
89
90
91
92
93
94
95
96
97
98
99 protected Stripe(final CrossSectionLink newParentLink, final OTSSimulatorInterface newSimulator,
100 final boolean animation, final Stripe cse) throws NetworkException
101 {
102 super(newParentLink, newSimulator, animation, cse);
103 }
104
105
106
107
108
109 public final void addPermeability(final GTUType gtuType, final Permeable permeable)
110 {
111 if (permeable.equals(Permeable.LEFT) || permeable.equals(Permeable.BOTH))
112 {
113 addPermeability(gtuType, LateralDirectionality.LEFT);
114 }
115 if (permeable.equals(Permeable.RIGHT) || permeable.equals(Permeable.BOTH))
116 {
117 addPermeability(gtuType, LateralDirectionality.RIGHT);
118 }
119 }
120
121
122 public enum Permeable
123 {
124
125 LEFT,
126
127 RIGHT,
128
129 BOTH;
130 }
131
132
133 @Override
134 @SuppressWarnings("checkstyle:designforextension")
135 public String toString()
136 {
137 return String.format("Stripe offset %.2fm..%.2fm, width %.2fm..%.2fm", getDesignLineOffsetAtBegin().getSI(),
138 getDesignLineOffsetAtEnd().getSI(), getBeginWidth().getSI(), getEndWidth().getSI());
139 }
140
141
142 @Override
143 @SuppressWarnings("checkstyle:designforextension")
144 public Stripe clone(final CrossSectionLink newParentLink, final OTSSimulatorInterface newSimulator,
145 final boolean animation) throws NetworkException
146 {
147 try
148 {
149 Stripe newStripe = new Stripe(newParentLink, newSimulator, animation, this);
150
151 if (animation)
152 {
153
154 Permeable permeable = null;
155 for (GTUType gtuType : newStripe.getPermeabilityMap().keySet())
156 {
157 for (LateralDirectionality dir : newStripe.getPermeabilityMap().get(gtuType))
158 {
159 if (dir.isLeft())
160 {
161 if (permeable == null)
162 {
163 permeable = Permeable.LEFT;
164 }
165 if (permeable.equals(Permeable.RIGHT))
166 {
167 permeable = Permeable.BOTH;
168 }
169 }
170 if (dir.isRight())
171 {
172 if (permeable == null)
173 {
174 permeable = Permeable.RIGHT;
175 }
176 if (permeable.equals(Permeable.LEFT))
177 {
178 permeable = Permeable.BOTH;
179 }
180 }
181 }
182 }
183 if (permeable == null)
184 {
185 new StripeAnimation(newStripe, newSimulator, StripeAnimation.TYPE.SOLID);
186 }
187 else
188 {
189 switch (permeable)
190 {
191 case BOTH:
192 new StripeAnimation(newStripe, newSimulator, StripeAnimation.TYPE.DASHED);
193 break;
194
195 case LEFT:
196 new StripeAnimation(newStripe, newSimulator, StripeAnimation.TYPE.LEFTONLY);
197 break;
198
199 case RIGHT:
200 new StripeAnimation(newStripe, newSimulator, StripeAnimation.TYPE.RIGHTONLY);
201 break;
202
203 default:
204 break;
205 }
206 }
207 }
208
209 return newStripe;
210 }
211 catch (NamingException | RemoteException | OTSGeometryException exception)
212 {
213 throw new NetworkException(exception);
214 }
215 }
216
217 }