1 package org.opentrafficsim.draw.road;
2
3 import java.awt.BasicStroke;
4 import java.awt.Color;
5 import java.awt.Graphics2D;
6 import java.awt.geom.Path2D;
7 import java.awt.image.ImageObserver;
8 import java.util.Set;
9
10 import org.djutils.draw.line.PolyLine2d;
11 import org.opentrafficsim.base.geometry.OtsLocatable;
12 import org.opentrafficsim.draw.ClickableLocatable;
13 import org.opentrafficsim.draw.DrawLevel;
14 import org.opentrafficsim.draw.OtsRenderable;
15 import org.opentrafficsim.draw.PaintPolygons;
16 import org.opentrafficsim.draw.road.CrossSectionElementAnimation.CrossSectionElementData;
17
18 import nl.tudelft.simulation.naming.context.Contextualized;
19
20
21
22
23
24
25
26
27
28
29
30 public class CrossSectionElementAnimation<L extends CrossSectionElementData> extends OtsRenderable<L>
31 {
32
33 private static final long serialVersionUID = 20141017L;
34
35
36 private final Color color;
37
38
39 private final Set<Path2D.Float> paths;
40
41
42
43
44
45
46 public CrossSectionElementAnimation(final L source, final Contextualized contextualized, final Color color)
47 {
48 super(source, contextualized);
49 this.color = color;
50 this.paths = PaintPolygons.getPaths(OtsLocatable.relativeContour(source).getPointList());
51 }
52
53 @Override
54 public void paint(final Graphics2D graphics, final ImageObserver observer)
55 {
56 setRendering(graphics);
57 PaintPolygons.paintPaths(graphics, this.color, this.paths, true);
58
59 double scale = Math.min(Math.max(3.0 / graphics.getTransform().getDeterminant(), 0.1), 0.5);
60 graphics.setStroke(new BasicStroke((float) scale, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER));
61 PaintPolygons.paintPaths(graphics, this.color, this.paths, false);
62 resetRendering(graphics);
63 }
64
65 @Override
66 public String toString()
67 {
68 return "CrossSectionElementAnimation [source = " + getSource().toString() + ", color=" + this.color + "]";
69 }
70
71
72
73
74
75
76
77
78
79
80 public interface CrossSectionElementData extends ClickableLocatable
81 {
82
83
84
85
86 PolyLine2d getCenterLine();
87
88
89
90
91
92 String getLinkId();
93 }
94
95
96
97
98
99
100
101
102
103
104 public interface ShoulderData extends CrossSectionElementData
105 {
106 @Override
107 default double getZ()
108 {
109 return DrawLevel.SHOULDER.getZ();
110 }
111 }
112 }