AnimationGtuData.java

  1. package org.opentrafficsim.animation.data;

  2. import java.awt.Color;
  3. import java.awt.geom.RectangularShape;

  4. import org.djunits.value.vdouble.scalar.Length;
  5. import org.djutils.draw.bounds.Bounds2d;
  6. import org.djutils.draw.line.Polygon2d;
  7. import org.djutils.draw.point.OrientedPoint2d;
  8. import org.opentrafficsim.animation.gtu.colorer.GtuColorerManager;
  9. import org.opentrafficsim.base.geometry.OtsShape;
  10. import org.opentrafficsim.draw.gtu.DefaultCarAnimation.GtuData;
  11. import org.opentrafficsim.road.gtu.lane.LaneBasedGtu;

  12. /**
  13.  * Animation data of a LaneBasedGtu.
  14.  * <p>
  15.  * Copyright (c) 2023-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  16.  * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
  17.  * </p>
  18.  * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
  19.  */
  20. public class AnimationGtuData implements GtuData
  21. {

  22.     /** GTU colorer. */
  23.     private final GtuColorerManager gtuColorerManager;

  24.     /** Gtu. */
  25.     private final LaneBasedGtu gtu;

  26.     /** Marker. */
  27.     private final GtuMarker marker;

  28.     /**
  29.      * Constructor.
  30.      * @param gtuColorerManager factory.
  31.      * @param gtu GTU.
  32.      * @param marker marker
  33.      */
  34.     public AnimationGtuData(final GtuColorerManager gtuColorerManager, final LaneBasedGtu gtu, final GtuMarker marker)
  35.     {
  36.         this.gtuColorerManager = gtuColorerManager;
  37.         this.gtu = gtu;
  38.         this.marker = marker;
  39.     }

  40.     @Override
  41.     public OrientedPoint2d getLocation()
  42.     {
  43.         return this.gtu.getLocation();
  44.     }

  45.     @Override
  46.     public Polygon2d getContour()
  47.     {
  48.         return this.gtu.getContour();
  49.     }

  50.     @Override
  51.     public Bounds2d getBounds()
  52.     {
  53.         return this.gtu.getBounds();
  54.     }

  55.     @Override
  56.     public OtsShape getShape()
  57.     {
  58.         return this.gtu.getShape();
  59.     }

  60.     @Override
  61.     public String getId()
  62.     {
  63.         return this.gtu.getId();
  64.     }

  65.     @Override
  66.     public Color getColor()
  67.     {
  68.         return this.gtuColorerManager.getColor(this.gtu);
  69.     }

  70.     @Override
  71.     public Length getLength()
  72.     {
  73.         return this.gtu.getLength();
  74.     }

  75.     @Override
  76.     public Length getWidth()
  77.     {
  78.         return this.gtu.getWidth();
  79.     }

  80.     @Override
  81.     public Length getFront()
  82.     {
  83.         return this.gtu.getFront().dx();
  84.     }

  85.     @Override
  86.     public Length getRear()
  87.     {
  88.         return this.gtu.getRear().dx();
  89.     }

  90.     @Override
  91.     public boolean leftIndicatorOn()
  92.     {
  93.         return this.gtu.getTurnIndicatorStatus().isLeftOrBoth();
  94.     }

  95.     @Override
  96.     public boolean rightIndicatorOn()
  97.     {
  98.         return this.gtu.getTurnIndicatorStatus().isRightOrBoth();
  99.     }

  100.     @Override
  101.     public RectangularShape getMarker()
  102.     {
  103.         return this.marker.getShape();
  104.     }

  105.     @Override
  106.     public boolean isBrakingLightsOn()
  107.     {
  108.         return this.gtu.isBrakingLightsOn();
  109.     }

  110.     /**
  111.      * Returns the GTU.
  112.      * @return GTU.
  113.      */
  114.     public LaneBasedGtu getGtu()
  115.     {
  116.         return this.gtu;
  117.     }

  118.     @Override
  119.     public String toString()
  120.     {
  121.         return "Gtu " + this.gtu.getId();
  122.     }

  123. }