diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/IGraphicsTarget.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/IGraphicsTarget.java index c936d755ce..462da293dc 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/IGraphicsTarget.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/IGraphicsTarget.java @@ -23,7 +23,9 @@ package com.raytheon.uf.viz.core; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.io.File; +import java.util.ArrayList; import java.util.Collection; +import java.util.List; import org.eclipse.swt.graphics.RGB; import org.geotools.coverage.grid.GeneralGridGeometry; @@ -84,18 +86,94 @@ public interface IGraphicsTarget extends IImagingExtension { * the target may want to switch default to a different style before drawing */ public static enum LineStyle { - DEFAULT, SOLID, DASHED, DASHED_LARGE, DOTTED, DASH_DOTTED, + DEFAULT, // + SOLID, // + DASHED(4, (short) 0xAAAA), // + DASHED_LARGE(4, (short) 0xEEEE), // + DOTTED(1, (short) 0xAAAA), // + DASH_DOTTED(1, (short) 0xE4E4), // Task 69 : Added for NMAP - SHORT_DASHED, // GEMPAK line type 2 - MEDIUM_DASHED, // GEMPAK line type 3 - LONG_DASH_SHORT_DASH, // GEMPAK line type 4 - LONG_DASHED, // GEMPAK line type 5 - LONG_DASH_THREE_SHORT_DASHES, // GEMPAK line type 6 - LONG_DASH_DOT, // GEMPAK line type 7 - LONG_DASH_THREE_DOTS, // GEMPAK line type 8 - MEDIUM_DASH_DOT, // GEMPAK line type 9 - DOTS - // GEMPAK line type 10 + SHORT_DASHED(8, (short) 0xAAAA), // GEMPAK line type 2 + MEDIUM_DASHED(3, (short) 0xF8F8), // GEMPAK line type 3 + LONG_DASH_SHORT_DASH(3, (short) 0xFC38), // GEMPAK line type 4 + LONG_DASHED(3, (short) 0xFCFC), // GEMPAK line type 5 + LONG_DASH_THREE_SHORT_DASHES(3, (short) 0xFDB6), // GEMPAK line type 6 + LONG_DASH_DOT(2, (short) 0xFFE4), // GEMPAK line type 7 + LONG_DASH_THREE_DOTS(2, (short) 0xFC92), // GEMPAK line type 8 + MEDIUM_DASH_DOT(2, (short) 0xFF88), // GEMPAK line type 9 + DOTS(1, (short) 0x8888); // GEMPAK line type 10 + + private final int factor; + + private final short pattern; + + LineStyle() { + this.factor = 0; + this.pattern = 0; + } + + LineStyle(int factor, short pattern) { + if (factor < 1) { + this.factor = 1; + } else if (factor > 255) { + this.factor = 255; + } else { + this.factor = factor; + } + this.pattern = pattern; + } + + public int getFactor() { + return factor; + } + + public short getPattern() { + return pattern; + } + + public int[] getSWTLineStyle() { + if (this.factor == 0 || this.pattern == 0) { + return null; + } else { + List dashPattern = new ArrayList(); + + int p = this.pattern & 0xFFFF; + + // strip trailing 0s + int prevLsb = p & 1; + while (prevLsb == 0) { + p >>= 1; + prevLsb = p & 1; + } + + int count = 0; + int sum = 0; + while (p != 0) { + int lsb = p & 1; + if (lsb != prevLsb) { + dashPattern.add(count * factor); + sum += count; + count = 0; + prevLsb = lsb; + } + count++; + p >>= 1; + } + if (prevLsb == 1 & count > 0) { + dashPattern.add(count * factor); + sum += count; + } + if (sum < 16) { + dashPattern.add((16 - sum) * factor); + } + + int[] array = new int[dashPattern.size()]; + for (int i = 0; i < dashPattern.size(); i++) { + array[i] = dashPattern.get(i); + } + return array; + } + } } public static enum PointStyle { @@ -732,9 +810,7 @@ public interface IGraphicsTarget extends IImagingExtension { public IView getView(); /** - - /** - * Use drawStrings(DrawableString parameters) + * /** Use drawStrings(DrawableString parameters) */ @Deprecated public abstract void drawString(IFont font, String text, double x, diff --git a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLTarget.java b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLTarget.java index 4e00c74406..9ad596ed53 100644 --- a/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLTarget.java +++ b/cave/com.raytheon.viz.core.gl/src/com/raytheon/viz/core/gl/internal/GLTarget.java @@ -1130,44 +1130,7 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget { if (lineStyle != null && lineStyle != LineStyle.SOLID && lineStyle != LineStyle.DEFAULT) { gl.glEnable(GL.GL_LINE_STIPPLE); - if (lineStyle == LineStyle.DASHED) { - gl.glLineStipple(4, (short) 0xAAAA); - } else if (lineStyle == LineStyle.DASHED_LARGE) { - gl.glLineStipple(4, (short) 0xEEEE); - } else if (lineStyle == LineStyle.DOTTED) { - gl.glLineStipple(1, (short) 0xAAAA); - } else if (lineStyle == LineStyle.DASH_DOTTED) { - gl.glLineStipple(1, (short) 0xE4E4); - } - // NMAP Task 69 to add line styles from GEMPAK - else if (lineStyle == LineStyle.DOTS) { - gl.glLineStipple(1, (short) 0x8888); - } else if (lineStyle == LineStyle.SHORT_DASHED) { - gl.glLineStipple(8, (short) 0xAAAA); - } else if (lineStyle == LineStyle.MEDIUM_DASHED) { - gl.glLineStipple(3, (short) 0xF8F8); - } else if (lineStyle == LineStyle.LONG_DASHED) { - gl.glLineStipple(3, (short) 0xFCFC); - } else if (lineStyle == LineStyle.LONG_DASH_DOT) { - gl.glLineStipple(2, (short) 0xFFE4); - } else if (lineStyle == LineStyle.LONG_DASH_SHORT_DASH) { - gl.glLineStipple(3, (short) 0xFC38); - } else if (lineStyle == LineStyle.LONG_DASH_THREE_DOTS) { - // gl.glLineStipple(2, (short) 0xFFAA); - // gl.glLineStipple(3, (short) 0xFFAA); - gl.glLineStipple(2, (short) 0xFC92); - } else if (lineStyle == LineStyle.LONG_DASH_THREE_SHORT_DASHES) { - // gl.glLineStipple(5, (short) 0xFFAA); - gl.glLineStipple(3, (short) 0xFDB6); - } else if (lineStyle == LineStyle.MEDIUM_DASH_DOT) { - // GEMPAK appears to have a bug where line type 9 draws as 'long - // dash 2 dots' - // This line type will draw a MEDIUM DASH DOT - // gl.glLineStipple(2, (short) 0xFF24 ); // long dash 2 dots as - // drawn by GEMPAK - // gl.glLineStipple(2, (short) 0xFF18); - gl.glLineStipple(2, (short) 0xFF88); - } + gl.glLineStipple(lineStyle.getFactor(), lineStyle.getPattern()); } else { gl.glDisable(GL.GL_LINE_STIPPLE); } @@ -1188,6 +1151,7 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget { * * @see com.raytheon.viz.IGraphicsTarget#init() */ + @Override public void init() { makeContextCurrent(); GLU glu = new GLU(); @@ -1322,6 +1286,7 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget { * * @see com.raytheon.viz.core.gl.IGLTarget#makeContextCurrent() */ + @Override public boolean makeContextCurrent() { return theContext.makeContextCurrent(); } @@ -1332,6 +1297,7 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget { * Do not call outside of gl package * */ + @Override public void releaseContext() { theContext.releaseContext(); } @@ -1475,6 +1441,7 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget { * * @see com.raytheon.uf.viz.core.IGraphicsTarget#getModelView() */ + @Override public double[] getModelView() { double[] modelMatrix = new double[16]; gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, modelMatrix, 0); @@ -1486,6 +1453,7 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget { * * @see com.raytheon.uf.viz.core.IGraphicsTarget#getModelView() */ + @Override public double[] getProjection() { double[] projection = new double[16]; gl.glGetDoublev(GL.GL_PROJECTION_MATRIX, projection, 0); @@ -1497,6 +1465,7 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget { * * @see com.raytheon.uf.viz.core.IGraphicsTarget#getViewPort() */ + @Override public int[] getViewPort() { int[] vp = new int[4]; gl.glGetIntegerv(GL.GL_VIEWPORT, vp, 0); @@ -1509,6 +1478,7 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget { * @param p * @return */ + @Override public double[] project(double[] p) { double[] window = new double[3]; if (!this.glu.gluProject(p[0], p[1], p[2], getModelView(), 0, @@ -1529,6 +1499,7 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget { * screen coordinate * @return pixel value */ + @Override public double[] unproject(double[] pos) { return this.unproject(pos[0], pos[1], pos[2]); } @@ -1569,6 +1540,7 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget { * * @see com.raytheon.viz.core.gl.IDisplayPane#getBounds() */ + @Override public Rectangle getBounds() { if (theCanvas != null && theCanvas.isDisposed()) { return null; @@ -1617,7 +1589,7 @@ public class GLTarget extends AbstractGraphicsTarget implements IGLTarget { */ @Override public void setView(IView view) { - this.targetView = (IView) view.clone(); + this.targetView = view.clone(); this.targetView.setupView(this); } diff --git a/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/cmenu/ChangeLineStyleAction.java b/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/cmenu/ChangeLineStyleAction.java index 4bf3e92d24..e1e5808b79 100644 --- a/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/cmenu/ChangeLineStyleAction.java +++ b/cave/com.raytheon.viz.ui/src/com/raytheon/viz/ui/cmenu/ChangeLineStyleAction.java @@ -162,27 +162,27 @@ public class ChangeLineStyleAction extends AbstractRightClickAction implements super(style.toString()); this.style = style; - int[] dashes = null; - switch (style) { - case DASHED: - dashes = new int[] { 4, 4 }; - break; - case DASHED_LARGE: - dashes = new int[] { 12, 4 }; - break; - case DOTTED: - dashes = new int[] { 1, 1 }; - break; - case DASH_DOTTED: - dashes = new int[] { 3, 2, 1, 2 }; - ; - break; - case DEFAULT: - case SOLID: - default: - dashes = null; - break; - } + int[] dashes = style.getSWTLineStyle(); + // switch (style) { + // case DASHED: + // dashes = new int[] { 4, 4 }; + // break; + // case DASHED_LARGE: + // dashes = new int[] { 12, 4 }; + // break; + // case DOTTED: + // dashes = new int[] { 1, 1 }; + // break; + // case DASH_DOTTED: + // dashes = new int[] { 3, 2, 1, 2 }; + // ; + // break; + // case DEFAULT: + // case SOLID: + // default: + // dashes = null; + // break; + // } boolean selected = style == getTopMostSelectedResource() .getCapability(OutlineCapability.class).getLineStyle();