View Javadoc

1   // Copyright 2004-2005, FreeHEP.
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.graphicspanel.HepRepGraphicsMode;
13  import hep.wired.heprep.services.Projection;
14  import hep.wired.heprep.services.DrawAs;
15  import hep.wired.services.ViewPort;
16  
17  /***
18   * Draws one or more marker of type "MarkName" and size "MarkSize", centered at HepRepPoints. 
19   *
20   * @author Mark Donszelmann
21   * @version $Id: DrawAsPoint.java 2136 2005-07-30 00:25:21Z duns $
22   */
23  
24  public class DrawAsPoint extends AbstractDrawAs {
25  
26      private double[] uvw = new double[3];
27  
28      public String getKey() {
29          return "point";
30      }
31  
32      public String getName() {
33          return "Point";
34      }
35      
36      public String getDescription() {
37          return "Draws any HepRepPoints as a Marker (square, circle, ...) symbol.";
38      }
39      
40      public void draw(VectorGraphics graphics, HepRepInstance instance,
41                       Attributes atts, GraphicsMode mode, 
42                       Projection projection, ViewPort viewPort) {
43  
44          HepRepGraphicsMode heprepMode = (HepRepGraphicsMode)mode;
45          for (Iterator i=instance.getPoints().iterator(); i.hasNext(); ) {
46  
47              HepRepPoint p = (HepRepPoint)i.next();
48              uvw[U] = p.getX();
49              uvw[V] = p.getY();
50              uvw[W] = p.getZ();
51              
52              uvw = projection.transform(viewPort, uvw);
53              
54              if (atts.isFilled() && heprepMode.fillBoxes) {
55                  graphics.fillAndDrawSymbol(uvw[U], uvw[V],
56                                             atts.getMarkSize()*heprepMode.markSizeMultiplier,
57                                             atts.getMarkSymbol(), atts.getColor());
58              } else {
59                  graphics.drawSymbol(uvw[U], uvw[V],
60                                      atts.getMarkSize()*heprepMode.markSizeMultiplier,
61                                      heprepMode.drawWideLines ? atts.getMarkSymbol() : VectorGraphics.SYMBOL_BOX);
62              }
63          }
64      }
65  
66      public void frame(VectorGraphics graphics, HepRepInstance instance,
67                        Attributes atts, GraphicsMode mode, 
68                        Projection projection, ViewPort viewPort) {
69  
70          HepRepGraphicsMode heprepMode = (HepRepGraphicsMode)mode;
71          graphics.setColor(atts.getFrameColor());
72          for (Iterator i=instance.getPoints().iterator(); i.hasNext(); ) {
73  
74              HepRepPoint p = (HepRepPoint)i.next();
75              uvw[U] = p.getX();
76              uvw[V] = p.getY();
77              uvw[W] = p.getZ();
78              
79              uvw = projection.transform(viewPort, uvw);
80              
81              graphics.fillSymbol(uvw[U], uvw[V],
82                                  atts.getFrameWidth()*2 + atts.getMarkSize()*heprepMode.markSizeMultiplier, 
83                                  atts.getMarkSymbol());
84          }
85          graphics.setColor(atts.getColor());
86      }
87  }