1 package org.opentrafficsim.draw.road;
2
3 import java.awt.Color;
4 import java.awt.Graphics2D;
5 import java.awt.geom.Path2D;
6 import java.awt.image.ImageObserver;
7
8 import org.opentrafficsim.draw.ClickableLocatable;
9 import org.opentrafficsim.draw.DrawLevel;
10 import org.opentrafficsim.draw.OtsRenderable;
11 import org.opentrafficsim.draw.TextAlignment;
12 import org.opentrafficsim.draw.TextAnimation;
13 import org.opentrafficsim.draw.road.GtuGeneratorPositionAnimation.GtuGeneratorPositionData;
14
15 import nl.tudelft.simulation.naming.context.Contextualized;
16
17 /**
18 * Animates a GtuGeneratorPosition.
19 * <p>
20 * Copyright (c) 2022-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
21 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
22 * </p>
23 * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
24 * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
25 * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
26 */
27 public class GtuGeneratorPositionAnimation extends OtsRenderable<GtuGeneratorPositionData>
28 {
29
30 /** */
31 private static final long serialVersionUID = 20230204L;
32
33 /** Chevron path to draw. */
34 private static final Path2D.Float PATH;
35
36 static
37 {
38 PATH = new Path2D.Float();
39 addChevron(PATH, 0);
40 addChevron(PATH, 1);
41 addChevron(PATH, 2);
42 }
43
44 /**
45 * Add chevron to drawing path.
46 * @param path Path2D.Float; path.
47 * @param number number of the chevron.
48 */
49 private static void addChevron(final Path2D.Float path, final int number)
50 {
51 float x = number * 1.5f;
52 path.moveTo(x, -1.0);
53 path.lineTo(x + 1.0, 0.0);
54 path.lineTo(x, 1.0);
55 path.lineTo(x + 0.75, 1.0);
56 path.lineTo(x + 1.75, 0.0);
57 path.lineTo(x + 0.75, -1.0);
58 path.lineTo(x, -1.0);
59 }
60
61 /**
62 * Constructor.
63 * @param source source.
64 * @param contextProvider simulator.
65 */
66 public GtuGeneratorPositionAnimation(final GtuGeneratorPositionData source, final Contextualized contextProvider)
67 {
68 super(source, contextProvider);
69 new Queue(source, contextProvider);
70 }
71
72 @Override
73 public void paint(final Graphics2D graphics, final ImageObserver observer)
74 {
75 graphics.setColor(Color.BLUE);
76 setRendering(graphics);
77 graphics.fill(PATH);
78 resetRendering(graphics);
79 }
80
81 /**
82 * Paints a queue counter with a GtuGeneratorPosition.
83 * <p>
84 * Copyright (c) 2022-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
85 * <br>
86 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
87 * </p>
88 * @author <a href="https://github.com/averbraeck">Alexander Verbraeck</a>
89 * @author <a href="https://github.com/peter-knoppers">Peter Knoppers</a>
90 * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
91 */
92 public class Queue extends TextAnimation<GtuGeneratorPositionData, Queue>
93 {
94 /** */
95 private static final long serialVersionUID = 20230204L;
96
97 /**
98 * Constructor.
99 * @param source source.
100 * @param contextualized context provider
101 */
102 public Queue(final GtuGeneratorPositionData source, final Contextualized contextualized)
103 {
104 super(source, () -> Integer.toString(source.getQueueCount()), 0.0f, 0.0f, TextAlignment.CENTER, Color.BLACK, 3.0f,
105 12.0f, 50f, contextualized, null, TextAnimation.RENDERWHEN10);
106 }
107 }
108
109 /**
110 * GtuGeneratorPositionData provides the information required to draw a GTU generator position.
111 * <p>
112 * Copyright (c) 2023-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
113 * <br>
114 * BSD-style license. See <a href="https://opentrafficsim.org/docs/license.html">OpenTrafficSim License</a>.
115 * </p>
116 * @author <a href="https://github.com/wjschakel">Wouter Schakel</a>
117 */
118 public interface GtuGeneratorPositionData extends ClickableLocatable
119 {
120 /**
121 * Returns the queue count.
122 * @return queue count.
123 */
124 int getQueueCount();
125
126 @Override
127 default double getZ()
128 {
129 return DrawLevel.OBJECT.getZ();
130 }
131 }
132
133 }