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