1 package org.opentrafficsim.animation.data;
2
3 import java.awt.Color;
4 import java.awt.geom.Ellipse2D;
5 import java.awt.geom.Rectangle2D;
6 import java.awt.geom.RectangularShape;
7
8 import org.djunits.value.vdouble.scalar.Length;
9 import org.djutils.draw.point.OrientedPoint2d;
10 import org.opentrafficsim.animation.gtu.colorer.GtuColorer;
11 import org.opentrafficsim.base.geometry.OtsBounds2d;
12 import org.opentrafficsim.draw.gtu.DefaultCarAnimation.GtuData;
13 import org.opentrafficsim.road.gtu.lane.LaneBasedGtu;
14
15
16
17
18
19
20
21
22
23 public class AnimationGtuData implements GtuData
24 {
25
26
27 private final GtuColorer gtuColorer;
28
29
30 private final LaneBasedGtu gtu;
31
32
33
34
35
36
37 public AnimationGtuData(final GtuColorer gtuColorer, final LaneBasedGtu gtu)
38 {
39 this.gtuColorer = gtuColorer;
40 this.gtu = gtu;
41 }
42
43
44 @Override
45 public OrientedPoint2d getLocation()
46 {
47 return this.gtu.getLocation();
48 }
49
50
51 @Override
52 public OtsBounds2d getBounds()
53 {
54 return this.gtu.getBounds();
55 }
56
57
58 @Override
59 public String getId()
60 {
61 return this.gtu.getId();
62 }
63
64
65 @Override
66 public Color getColor()
67 {
68 return this.gtuColorer.getColor(this.gtu);
69 }
70
71
72 @Override
73 public Length getLength()
74 {
75 return this.gtu.getLength();
76 }
77
78
79 @Override
80 public Length getWidth()
81 {
82 return this.gtu.getWidth();
83 }
84
85
86 @Override
87 public Length getFront()
88 {
89 return this.gtu.getFront().dx();
90 }
91
92
93 @Override
94 public Length getRear()
95 {
96 return this.gtu.getRear().dx();
97 }
98
99
100 @Override
101 public boolean leftIndicatorOn()
102 {
103 return this.gtu.getTurnIndicatorStatus().isLeftOrBoth();
104 }
105
106
107 @Override
108 public boolean rightIndicatorOn()
109 {
110 return this.gtu.getTurnIndicatorStatus().isRightOrBoth();
111 }
112
113
114 @Override
115 public RectangularShape getMarker()
116 {
117 switch (this.gtu.getType().getMarker())
118 {
119 case CIRCLE:
120 return new Ellipse2D.Double(0, 0, 0, 0);
121 case SQUARE:
122 return new Rectangle2D.Double(0, 0, 0, 0);
123 default:
124 return new Ellipse2D.Double(0, 0, 0, 0);
125 }
126 }
127
128
129 @Override
130 public boolean isBrakingLightsOn()
131 {
132 return this.gtu.isBrakingLightsOn();
133 }
134
135
136
137
138
139 public LaneBasedGtu getGtu()
140 {
141 return this.gtu;
142 }
143
144
145 @Override
146 public String toString()
147 {
148 return "Gtu " + this.gtu.getId();
149 }
150
151 }