View Javadoc
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   * Animation data of a LaneBasedGtu.
17   * <p>
18   * Copyright (c) 2023-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
19   * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
20   * </p>
21   * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
22   */
23  public class AnimationGtuData implements GtuData
24  {
25  
26      /** GTU colorer. */
27      private final GtuColorer gtuColorer;
28  
29      /** Gtu. */
30      private final LaneBasedGtu gtu;
31  
32      /**
33       * Constructor.
34       * @param gtuColorer GtuColorer; factory.
35       * @param gtu LaneBasedGtu; GTU.
36       */
37      public AnimationGtuData(final GtuColorer gtuColorer, final LaneBasedGtu gtu)
38      {
39          this.gtuColorer = gtuColorer;
40          this.gtu = gtu;
41      }
42  
43      /** {@inheritDoc} */
44      @Override
45      public OrientedPoint2d getLocation()
46      {
47          return this.gtu.getLocation();
48      }
49  
50      /** {@inheritDoc} */
51      @Override
52      public OtsBounds2d getBounds()
53      {
54          return this.gtu.getBounds();
55      }
56  
57      /** {@inheritDoc} */
58      @Override
59      public String getId()
60      {
61          return this.gtu.getId();
62      }
63  
64      /** {@inheritDoc} */
65      @Override
66      public Color getColor()
67      {
68          return this.gtuColorer.getColor(this.gtu);
69      }
70  
71      /** {@inheritDoc} */
72      @Override
73      public Length getLength()
74      {
75          return this.gtu.getLength();
76      }
77  
78      /** {@inheritDoc} */
79      @Override
80      public Length getWidth()
81      {
82          return this.gtu.getWidth();
83      }
84  
85      /** {@inheritDoc} */
86      @Override
87      public Length getFront()
88      {
89          return this.gtu.getFront().dx();
90      }
91  
92      /** {@inheritDoc} */
93      @Override
94      public Length getRear()
95      {
96          return this.gtu.getRear().dx();
97      }
98  
99      /** {@inheritDoc} */
100     @Override
101     public boolean leftIndicatorOn()
102     {
103         return this.gtu.getTurnIndicatorStatus().isLeftOrBoth();
104     }
105 
106     /** {@inheritDoc} */
107     @Override
108     public boolean rightIndicatorOn()
109     {
110         return this.gtu.getTurnIndicatorStatus().isRightOrBoth();
111     }
112 
113     /** {@inheritDoc} */
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     /** {@inheritDoc} */
129     @Override
130     public boolean isBrakingLightsOn()
131     {
132         return this.gtu.isBrakingLightsOn();
133     }
134 
135     /**
136      * Returns the GTU.
137      * @return LaneBasedGtu; GTU.
138      */
139     public LaneBasedGtu getGtu()
140     {
141         return this.gtu;
142     }
143 
144     /** {@inheritDoc} */
145     @Override
146     public String toString()
147     {
148         return "Gtu " + this.gtu.getId();
149     }
150 
151 }