From bf8dba768a16f266b55fe6b0baba6a47f9dbd1ca Mon Sep 17 00:00:00 2001 From: Ben Steffensmeier Date: Thu, 29 Aug 2013 11:40:55 -0500 Subject: [PATCH] Issue #2281 Fix shear click distance calculations. Change-Id: I67980264723512a4167cf90cfc3adac2c9ba1d08 Former-commit-id: eac729a60aab70e4940c03d8aba5e7dee0072b59 --- .../{ToolsUiUitil.java => ToolsUiUtil.java} | 3 +- .../viz/awipstools/ui/action/ShearAction.java | 13 +-- .../layer/InteractiveBaselineUIManager.java | 19 ++-- .../viz/awipstools/ui/layer/ShearLayer.java | 107 ++++++------------ 4 files changed, 52 insertions(+), 90 deletions(-) rename cave/com.raytheon.viz.awipstools/src/com/raytheon/viz/awipstools/common/{ToolsUiUitil.java => ToolsUiUtil.java} (98%) diff --git a/cave/com.raytheon.viz.awipstools/src/com/raytheon/viz/awipstools/common/ToolsUiUitil.java b/cave/com.raytheon.viz.awipstools/src/com/raytheon/viz/awipstools/common/ToolsUiUtil.java similarity index 98% rename from cave/com.raytheon.viz.awipstools/src/com/raytheon/viz/awipstools/common/ToolsUiUitil.java rename to cave/com.raytheon.viz.awipstools/src/com/raytheon/viz/awipstools/common/ToolsUiUtil.java index 11e9afad74..3ef508d16b 100644 --- a/cave/com.raytheon.viz.awipstools/src/com/raytheon/viz/awipstools/common/ToolsUiUitil.java +++ b/cave/com.raytheon.viz.awipstools/src/com/raytheon/viz/awipstools/common/ToolsUiUtil.java @@ -37,6 +37,7 @@ import com.vividsolutions.jts.geom.GeometryFactory; * * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- + * Aug 29, 2013 2281 bsteffen Rename ToolsUiUitil. * * * @@ -45,7 +46,7 @@ import com.vividsolutions.jts.geom.GeometryFactory; * @version 1.0 */ -public class ToolsUiUitil { +public class ToolsUiUtil { private static final GeometryFactory gf = new GeometryFactory(); diff --git a/cave/com.raytheon.viz.awipstools/src/com/raytheon/viz/awipstools/ui/action/ShearAction.java b/cave/com.raytheon.viz.awipstools/src/com/raytheon/viz/awipstools/ui/action/ShearAction.java index f5072c1108..8af505acd2 100644 --- a/cave/com.raytheon.viz.awipstools/src/com/raytheon/viz/awipstools/ui/action/ShearAction.java +++ b/cave/com.raytheon.viz.awipstools/src/com/raytheon/viz/awipstools/ui/action/ShearAction.java @@ -39,7 +39,8 @@ import com.vividsolutions.jts.geom.Coordinate; * SOFTWARE HISTORY * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * 01/11/2010 mnash + * Jan 11, 2010 mnash + * Aug 29, 2013 2281 bsteffen Fix click distance calculations. * * * @@ -102,11 +103,10 @@ public abstract class ShearAction extends AbstractGenericToolAction lastMouseY = y; if (shearLayer.isEditable()) { - Coordinate c = editor.translateClick(x, y); if (mouseButton == 1) { lineToMove = -1; - coordinateFound = shearLayer.isInsideEndpoint(c); + coordinateFound = shearLayer.isInsideEndpoint(editor, x, y); if (coordinateFound != null) { this.mode = Mode.MOVE_POINT; @@ -114,7 +114,7 @@ public abstract class ShearAction extends AbstractGenericToolAction return true; } - if ((lineToMove = shearLayer.isInsideLine(c)) != -1) { + if ((lineToMove = shearLayer.isInsideLine(editor, x, y)) != -1) { this.mode = Mode.MOVE_LINE; return true; } @@ -201,15 +201,14 @@ public abstract class ShearAction extends AbstractGenericToolAction */ public boolean handleMouseMove(int x, int y) { if (shearLayer.isEditable()) { - Coordinate c = editor.translateClick(x, y); - if (shearLayer.isInsideEndpoint(c) != null) { + if (shearLayer.isInsideEndpoint(editor, x, y) != null) { // Change the cursor to a hand. this.setCursorHand(); return true; } - if (shearLayer.isInsideLine(c) != -1) { + if (shearLayer.isInsideLine(editor, x, y) != -1) { // Change the cursor to crosshairs. this.setCursorCross(); return true; diff --git a/cave/com.raytheon.viz.awipstools/src/com/raytheon/viz/awipstools/ui/layer/InteractiveBaselineUIManager.java b/cave/com.raytheon.viz.awipstools/src/com/raytheon/viz/awipstools/ui/layer/InteractiveBaselineUIManager.java index 67993b2881..a0d2961011 100644 --- a/cave/com.raytheon.viz.awipstools/src/com/raytheon/viz/awipstools/ui/layer/InteractiveBaselineUIManager.java +++ b/cave/com.raytheon.viz.awipstools/src/com/raytheon/viz/awipstools/ui/layer/InteractiveBaselineUIManager.java @@ -33,7 +33,7 @@ import com.raytheon.uf.viz.core.IDisplayPaneContainer; import com.raytheon.uf.viz.core.drawables.IDescriptor; import com.raytheon.uf.viz.core.drawables.IRenderableDisplay; import com.raytheon.viz.awipstools.ToolsDataManager; -import com.raytheon.viz.awipstools.common.ToolsUiUitil; +import com.raytheon.viz.awipstools.common.ToolsUiUtil; import com.raytheon.viz.awipstools.ui.layer.InteractiveBaselinesLayer.Baseline; import com.raytheon.viz.ui.cmenu.IContextMenuContributor; import com.raytheon.viz.ui.cmenu.IContextMenuProvider; @@ -53,6 +53,7 @@ import com.vividsolutions.jts.geom.LineString; * * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- + * Aug 29, 2013 2281 bsteffen Rename ToolsUiUitil. * * * @@ -160,7 +161,7 @@ public class InteractiveBaselineUIManager extends InputAdapter implements Baseline[] lines = baselinesLayer.getCurrentBaselines(); int mouse = SWT.CURSOR_ARROW; for (Baseline line : lines) { - int idx = ToolsUiUitil.closeToCoordinate(container, + int idx = ToolsUiUtil.closeToCoordinate(container, line.line.getCoordinates(), x, y, CLICK_RADIUS_PIX); if (idx >= 0) { // We are close to a point in this line @@ -170,7 +171,7 @@ public class InteractiveBaselineUIManager extends InputAdapter implements hoverCoords = new Coordinate[] { hoverLine.line .getCoordinateN(idx) }; break; - } else if (ToolsUiUitil.closeToLine(container, + } else if (ToolsUiUtil.closeToLine(container, line.line.getCoordinates(), x, y, CLICK_RADIUS_PIX)) { // We are close this this line mouse = SWT.CURSOR_SIZEALL; @@ -434,7 +435,7 @@ public class InteractiveBaselineUIManager extends InputAdapter implements double[] screenLoc = container.translateInverseClick(c); screenLoc[0] += changeX; screenLoc[1] += changeY; - Coordinate translated = ToolsUiUitil.translateClick(container, + Coordinate translated = ToolsUiUtil.translateClick(container, baselinesLayer.getDescriptor(), screenLoc[0], screenLoc[1]); c.x = translated.x; c.y = translated.y; @@ -486,7 +487,7 @@ public class InteractiveBaselineUIManager extends InputAdapter implements // First time we've moved our new line, change to two points firstSelection = false; coords = new Coordinate[] { coords[0], - ToolsUiUitil.translateClick(container, descriptor, x, y) }; + ToolsUiUtil.translateClick(container, descriptor, x, y) }; } else { double[] d1 = container .translateInverseClick(coords[coords.length - 1]); @@ -497,7 +498,7 @@ public class InteractiveBaselineUIManager extends InputAdapter implements Coordinate c = new Coordinate(x, y); if (Angle.angleBetween(c2, c1, c) > (Math.PI / 2)) { coords = Arrays.copyOf(coords, coords.length + 1); - coords[coords.length - 1] = ToolsUiUitil.translateClick( + coords[coords.length - 1] = ToolsUiUtil.translateClick( container, descriptor, c.x, c.y); } else { selectionQueue.add(currentlySelecting); @@ -550,13 +551,13 @@ public class InteractiveBaselineUIManager extends InputAdapter implements Coordinate[] newLine = new Coordinate[hoverCoords.length + 1]; for (int i = 0; i < newLine.length; i++) { if (i < insertionPoint) { - newLine[i] = ToolsUiUitil.translateClick(container, descriptor, + newLine[i] = ToolsUiUtil.translateClick(container, descriptor, screenLocs[i].x, screenLocs[i].y); } else if (i > insertionPoint) { - newLine[i] = ToolsUiUitil.translateClick(container, descriptor, + newLine[i] = ToolsUiUtil.translateClick(container, descriptor, screenLocs[i - 1].x, screenLocs[i - 1].y); } else { - newLine[i] = ToolsUiUitil.translateClick(container, descriptor, + newLine[i] = ToolsUiUtil.translateClick(container, descriptor, screenRefPoint.x, screenRefPoint.y); } } diff --git a/cave/com.raytheon.viz.awipstools/src/com/raytheon/viz/awipstools/ui/layer/ShearLayer.java b/cave/com.raytheon.viz.awipstools/src/com/raytheon/viz/awipstools/ui/layer/ShearLayer.java index b2ff56df61..27e5b0dfba 100644 --- a/cave/com.raytheon.viz.awipstools/src/com/raytheon/viz/awipstools/ui/layer/ShearLayer.java +++ b/cave/com.raytheon.viz.awipstools/src/com/raytheon/viz/awipstools/ui/layer/ShearLayer.java @@ -49,24 +49,23 @@ import com.raytheon.uf.viz.core.rsc.capabilities.EditableCapability; import com.raytheon.uf.viz.core.rsc.capabilities.MagnificationCapability; import com.raytheon.uf.viz.core.rsc.tools.GenericToolsResourceData; import com.raytheon.uf.viz.points.PointsDataManager; +import com.raytheon.viz.awipstools.common.ToolsUiUtil; import com.raytheon.viz.ui.input.EditableManager; import com.vividsolutions.jts.geom.Coordinate; -import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jts.geom.LineString; -import com.vividsolutions.jts.geom.LinearRing; -import com.vividsolutions.jts.operation.buffer.BufferOp; /** - * TODO Add Description + * Interactive resource for rendering the Shear data. * *
  * 
  * SOFTWARE HISTORY
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
- * 15Mar2013	15693	mgamazaychikov	Added magnification capability.
- * 05/02/2013   DR 14587   D. Friedman Use base velocity.
+ * Mar 15, 2013 15693   mgamazaychikov  Added magnification capability.
+ * May 02, 2013 14587      D. Friedman Use base velocity.
+ * Aug 29, 2013 2281       bsteffen    Fix click distance calculations.
  * 
  * 
* @@ -218,24 +217,6 @@ public class ShearLayer extends } } - public LinearRing getCircle(Coordinate coor, double radius) { - - Coordinate circleCoordinates[] = new Coordinate[361]; - Coordinate firstCoor = null; - - for (int i = 0; i < 360; i++) { - circleCoordinates[i] = getCoordinateOnCircle(coor, radius, i); - if (i == 0) { - // save the first coordinate, to add to end, so completes the - // ring. - firstCoor = circleCoordinates[0]; - } - } - circleCoordinates[360] = firstCoor; - - return gf.createLinearRing(circleCoordinates); - } - public Coordinate getCoordinateOnCircle(Coordinate coor, double radius, int angle) { @@ -254,7 +235,7 @@ public class ShearLayer extends return coorOnCircle; } - + protected void drawBaselineLabel(IGraphicsTarget target, Coordinate latLong, String label) throws VizException { @@ -298,18 +279,6 @@ public class ShearLayer extends return getCapability(EditableCapability.class).isEditable(); } - /** - * Checks and returns the coordinate of the endpoint that clicked in. - * - * @param c - * Coordinate of the click. - * @return Coordinate of the endpoint, null if not found. - */ - public Coordinate isInsideEndpoint(Coordinate c) { - - return getEndpointClickedIn(c); - } - public void moveBaseline(Coordinate delta, int index) { for (Coordinate point : baseline.getCoordinates()) { @@ -340,54 +309,46 @@ public class ShearLayer extends } /** - * Returns the endpoint the user clicked in, or null if they didn't click in - * an endpoint. + * Get the closest endpoint to the provided screen location. * - * @param coor - * Coordinate of the click point. - * @return The coordinate of the endpoint they hit on. + * @param container + * display container to use + * @param refX + * x location in screen pixels + * @param refY + * y location in screen pixels + * @return T Coordinate of the endpoint, null if not found. */ - public Coordinate getEndpointClickedIn(Coordinate coor) { - - Coordinate c1 = getBaseline().getCoordinates()[0]; - Coordinate c2 = getBaseline().getCoordinates()[1]; - - if (gf.createPolygon(getCircle(c1, this.endCircleRadius), null) - .contains(gf.createPoint(coor))) { - return c1; - } else if (gf.createPolygon(getCircle(c2, this.endCircleRadius), null) - .contains(gf.createPoint(coor))) { - return c2; + public Coordinate isInsideEndpoint(IDisplayPaneContainer container, int x, + int y) { + Coordinate[] coords = getBaseline().getCoordinates(); + int idx = ToolsUiUtil.closeToCoordinate(container, coords, x, y, 9); + if (idx < 0) { + return null; + } else { + return coords[idx]; } - - return null; } /** * Return the index of the linestring the user clicked in (for move for * instance). * - * @param coor + * @param container + * display container to use + * @param refX + * x location of reference point in screen pixels + * @param refY + * y location of reference point in screen pixels * @return int Index of line they matched on. */ - public int isInsideLine(Coordinate coor) { - - int index = -1; - for (int i = 0; i < getBuffer().length; i++) { - if (getBuffer()[i].contains(gf.createPoint(coor))) { - index = i; - } + public int isInsideLine(IDisplayPaneContainer container, int x, int y) { + Coordinate[] coords = getBaseline().getCoordinates(); + if (ToolsUiUtil.closeToLine(container, coords, x, y, 15)) { + return 0; + } else { + return -1; } - return index; - } - - public Geometry[] getBuffer() { - - Geometry[] buffer = new Geometry[1]; - - buffer[0] = BufferOp.bufferOp(getBaseline(), 0.001); - - return buffer; } /**