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.core.dsol.OtsSimulatorInterface;
12 import org.opentrafficsim.core.geometry.DirectedPoint;
13 import org.opentrafficsim.core.gtu.GtuGenerator.GtuGeneratorPosition;
14 import org.opentrafficsim.draw.core.TextAlignment;
15 import org.opentrafficsim.draw.core.TextAnimation;
16
17 import nl.tudelft.simulation.dsol.animation.Locatable;
18 import nl.tudelft.simulation.dsol.animation.D2.Renderable2D;
19 import nl.tudelft.simulation.language.d2.Angle;
20
21
22
23
24
25
26
27
28
29
30
31 public class GtuGeneratorPositionAnimation extends Renderable2D<GtuGeneratorPosition>
32 {
33
34
35 private static final long serialVersionUID = 20230204L;
36
37
38 private static final Path2D.Float PATH;
39
40 static
41 {
42 PATH = new Path2D.Float();
43 addChevron(PATH, 0);
44 addChevron(PATH, 1);
45 addChevron(PATH, 2);
46 }
47
48
49
50
51
52
53 private static void addChevron(final Path2D.Float path, final int number)
54 {
55 float x = number * 1.5f;
56 path.moveTo(x, -1.0);
57 path.lineTo(x + 1.0, 0.0);
58 path.lineTo(x, 1.0);
59 path.lineTo(x + 0.75, 1.0);
60 path.lineTo(x + 1.75, 0.0);
61 path.lineTo(x + 0.75, -1.0);
62 path.lineTo(x, -1.0);
63 }
64
65
66
67
68
69
70
71
72 public GtuGeneratorPositionAnimation(final GtuGeneratorPosition source, final OtsSimulatorInterface contextProvider)
73 throws RemoteException, NamingException
74 {
75 super(source, contextProvider);
76 new Queue(source, contextProvider);
77 }
78
79
80 @Override
81 public void paint(final Graphics2D graphics, final ImageObserver observer)
82 {
83 graphics.setColor(Color.BLUE);
84 graphics.fill(PATH);
85 }
86
87
88
89
90
91
92
93
94
95
96
97
98 public class Queue extends TextAnimation
99 {
100
101 private static final long serialVersionUID = 20230204L;
102
103
104
105
106
107
108
109
110 public Queue(final Locatable source, final OtsSimulatorInterface simulator) throws RemoteException, NamingException
111 {
112 super(source, "", 0.0f, 0.0f, TextAlignment.CENTER, Color.BLACK, 3.0f, 12.0f, 50f, simulator, null,
113 TextAnimation.RENDERALWAYS);
114 }
115
116
117 @Override
118 @SuppressWarnings("checkstyle:designforextension")
119 public DirectedPoint getLocation()
120 {
121
122 DirectedPoint p = super.getLocation();
123 double a = Angle.normalizePi(p.getRotZ());
124 if (a > Math.PI / 2.0 || a < -0.99 * Math.PI / 2.0)
125 {
126 a += Math.PI;
127 }
128 return new DirectedPoint(p.x, p.y, Double.MAX_VALUE, 0.0, 0.0, a);
129 }
130
131
132 @Override
133 public void paint(final Graphics2D graphics, final ImageObserver observer)
134 {
135 setText(Integer.toString(((GtuGeneratorPosition) getSource()).getQueueCount()));
136 super.paint(graphics, observer);
137 }
138 }
139
140 }