1 package org.opentrafficsim.road.gtu.lane.object;
2
3 import org.djunits.unit.LengthUnit;
4 import org.djunits.value.vdouble.scalar.Length;
5 import org.opentrafficsim.core.geometry.OTSGeometryException;
6 import org.opentrafficsim.core.geometry.OTSLine3D;
7 import org.opentrafficsim.road.network.lane.CrossSectionElement;
8
9 /**
10 * <p>
11 * Copyright (c) 2013-2016 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
12 * BSD-style license. See <a href="http://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
13 * </p>
14 * $LastChangedDate: 2015-07-24 02:58:59 +0200 (Fri, 24 Jul 2015) $, @version $Revision: 1147 $, by $Author: averbraeck $,
15 * initial version Nov 26, 2015 <br>
16 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
17 * @author <a href="http://www.tudelft.nl/pknoppers">Peter Knoppers</a>
18 */
19 public class TrafficLight extends AbstractTrafficLightNew
20 {
21 /** The GTU colors for a normal traffic light. */
22 public enum TrafficLightColor
23 {
24 /** GTU needs to stop. */
25 RED,
26
27 /** GTU is allowed to continue if it cannot stop anymore. */
28 YELLOW,
29
30 /** GTU is allowed to drive. */
31 GREEN,
32
33 /** Traffic light is not working. */
34 BLACK
35 };
36
37 /** The color of the traffic light. */
38 private TrafficLightColor trafficLightColor;
39
40 /**
41 * @param geometry the geometry of the object
42 * @param height the height of the object
43 * @param initialColor the initial color of the traffic light
44 */
45 public TrafficLight(final OTSLine3D geometry, final Length height, final TrafficLightColor initialColor)
46 {
47 super(geometry, height);
48 this.trafficLightColor = initialColor;
49 }
50
51 /**
52 * @return the trafficLightColor
53 */
54 public final TrafficLightColor getTrafficLightColor()
55 {
56 return this.trafficLightColor;
57 }
58
59 /**
60 * @param trafficLightColor set the trafficLightColor
61 */
62 public final void setTrafficLightColor(final TrafficLightColor trafficLightColor)
63 {
64 this.trafficLightColor = trafficLightColor;
65 }
66
67 /**
68 * @param cse the cross section element, e.g. lane, where the traffic light is located
69 * @param position the relative position on the design line of the link for this traffic light
70 * @param initialColor the initial color of the traffic light
71 * @return a new CrossSectionElementBlock on the right position on the cse
72 * @throws OTSGeometryException in case the position is outside the CSE
73 */
74 public static TrafficLight createTrafficLight(final CrossSectionElement cse, final Length position,
75 final TrafficLightColor initialColor) throws OTSGeometryException
76 {
77 // return new TrafficLight(AbstractCSEObject.createRectangleOnCSE(cse, position, new Length(0.5,
78 // LengthUnit.METER), cse.getWidth(position).multiplyBy(0.8), new Length(0.5, LengthUnit.METER)), new
79 // Length(0.5, LengthUnit.METER),
80 // initialColor);
81 return new TrafficLight(AbstractCSEObject.createRectangleOnCSE(cse, position, new Length(0.5,
82 LengthUnit.METER), cse.getWidth(position).multiplyBy(0.8), new Length(0.5, LengthUnit.METER)),
83 new Length(0.5, LengthUnit.METER), initialColor);
84 }
85 }