1 package org.opentrafficsim.animation.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.djutils.draw.point.Point2d;
9 import org.opentrafficsim.animation.DrawLevel;
10 import org.opentrafficsim.animation.OtsRenderable;
11 import org.opentrafficsim.animation.RenderableTextSource;
12 import org.opentrafficsim.animation.TextAlignment;
13 import org.opentrafficsim.animation.road.GtuGeneratorPositionAnimation.GtuGeneratorPositionData;
14 import org.opentrafficsim.base.geometry.OtsShape;
15
16 import nl.tudelft.simulation.naming.context.Contextualized;
17
18
19
20
21
22
23
24
25
26
27
28 public class GtuGeneratorPositionAnimation extends OtsRenderable<GtuGeneratorPositionData>
29 {
30
31
32 private static final Path2D.Float PATH;
33
34 static
35 {
36 PATH = new Path2D.Float();
37 addChevron(PATH, 0);
38 addChevron(PATH, 1);
39 addChevron(PATH, 2);
40 }
41
42
43
44
45
46
47 private static void addChevron(final Path2D.Float path, final int number)
48 {
49 float x = number * 1.5f;
50 path.moveTo(x, -1.0);
51 path.lineTo(x + 1.0, 0.0);
52 path.lineTo(x, 1.0);
53 path.lineTo(x + 0.75, 1.0);
54 path.lineTo(x + 1.75, 0.0);
55 path.lineTo(x + 0.75, -1.0);
56 path.lineTo(x, -1.0);
57 }
58
59
60 private final Queue queue;
61
62
63
64
65
66
67 public GtuGeneratorPositionAnimation(final GtuGeneratorPositionData source, final Contextualized contextProvider)
68 {
69 super(source, contextProvider);
70 this.queue = new Queue(source, contextProvider);
71 }
72
73 @Override
74 public synchronized void destroy(final Contextualized contextProvider)
75 {
76 super.destroy(contextProvider);
77 this.queue.destroy(contextProvider);
78 }
79
80 @Override
81 public void paint(final Graphics2D graphics, final ImageObserver observer)
82 {
83 graphics.setColor(Color.BLUE);
84 setRendering(graphics);
85 graphics.fill(PATH);
86 resetRendering(graphics);
87 }
88
89
90
91
92 public static class Queue extends RenderableTextSource<GtuGeneratorPositionData, Queue>
93 {
94
95
96
97
98
99 public Queue(final GtuGeneratorPositionData source, final Contextualized contextualized)
100 {
101 super(source, () -> Integer.toString(source.getQueueCount()), 0.0f, 0.0f, TextAlignment.CENTER, Color.BLACK, 3.0f,
102 12.0f, 50f, contextualized, null, RenderableTextSource.RENDERWHEN10);
103 }
104 }
105
106
107
108
109 public interface GtuGeneratorPositionData extends OtsShape
110 {
111
112
113
114
115 int getQueueCount();
116
117 @Override
118 default double signedDistance(final Point2d point)
119 {
120 return getLocation().distance(point);
121 }
122
123 @Override
124 default double getZ()
125 {
126 return DrawLevel.OBJECT.getZ();
127 }
128 }
129
130 }