1
2 package hep.wired.heprep.representation;
3
4 import java.util.*;
5
6 import org.freehep.graphics2d.VectorGraphics;
7 import hep.graphics.heprep.HepRepInstance;
8 import hep.graphics.heprep.HepRepPoint;
9
10 import hep.wired.heprep.services.GraphicsMode;
11 import hep.wired.heprep.services.Attributes;
12 import hep.wired.heprep.services.Projection;
13 import hep.wired.heprep.services.DrawAs;
14 import hep.wired.heprep.util.Arrow;
15 import hep.wired.services.ViewPort;
16
17 /***
18 * Draws one or more line segments, given by HepRepPoints.
19 *
20 * @author Mark Donszelmann
21 * @version $Id: DrawAsLine.java 653 2005-03-01 01:12:16Z duns $
22 */
23
24 public class DrawAsLine extends AbstractDrawAs {
25
26
27 private double uvw[][] = new double[3][10000];
28
29 public String getKey() {
30 return "line";
31 }
32
33 public String getName() {
34 return "Line";
35 }
36
37 public String getDescription() {
38 return "Draws line segments from point 0 till point n.";
39 }
40
41 public void draw(VectorGraphics graphics, HepRepInstance instance,
42 Attributes atts, GraphicsMode mode,
43 Projection projection, ViewPort viewPort) {
44
45 int n = instance.getPoints(uvw);
46 if (n < 0) {
47 n = 0;
48 for (Iterator i=instance.getPoints().iterator(); i.hasNext(); ) {
49
50 HepRepPoint p = (HepRepPoint)i.next();
51 uvw[U][n] = p.getX();
52 uvw[V][n] = p.getY();
53 uvw[W][n] = p.getZ();
54 n++;
55 }
56 }
57 if (n == 0) return;
58
59 uvw = projection.transform(viewPort, uvw, n);
60 graphics.drawPolyline(uvw[U], uvw[V], n);
61
62
63 if ((atts.hasLineArrow() == atts.ARROW_START) || (atts.hasLineArrow() == atts.ARROW_BOTH)) {
64 graphics.fill(new Arrow(uvw[U][1], uvw[V][1], uvw[U][0], uvw[V][0], 20, 16, 70, false));
65 }
66
67
68 if ((atts.hasLineArrow() == atts.ARROW_END) || (atts.hasLineArrow() == atts.ARROW_BOTH)) {
69 graphics.fill(new Arrow(uvw[U][n-2], uvw[V][n-2], uvw[U][n-1], uvw[V][n-1], 20, 16, 70, false));
70 }
71 }
72
73 public void frame(VectorGraphics graphics, HepRepInstance instance,
74 Attributes atts, GraphicsMode mode,
75 Projection projection, ViewPort viewPort) {
76
77 int n = instance.getPoints(uvw);
78
79 if (n < 0) {
80 n = 0;
81 for (Iterator i=instance.getPoints().iterator(); i.hasNext(); ) {
82
83 HepRepPoint p = (HepRepPoint)i.next();
84 uvw[U][n] = p.getX();
85 uvw[V][n] = p.getY();
86 uvw[W][n] = p.getZ();
87 n++;
88 }
89 }
90 if (n == 0) return;
91
92 uvw = projection.transform(viewPort, uvw, n);
93
94 graphics.setColor(atts.getFrameColor());
95 graphics.setLineWidth(atts.getFrameWidth()*2+atts.getLineWidth());
96 graphics.drawPolyline(uvw[U], uvw[V], n);
97 graphics.setLineWidth(atts.getLineWidth());
98 graphics.setColor(atts.getColor());
99
100
101 }
102 }