From d1d92c033a6813c4876c0d7c59c7789378577ec7 Mon Sep 17 00:00:00 2001 From: Mike Duff Date: Fri, 21 Jun 2013 13:50:31 -0500 Subject: [PATCH] Issue #2132 - Fix drawing lat/long box for madis point data Change-Id: Ie041c31726f6e51467b9d2730d662c431b42ac96 Former-commit-id: 9d3c4ce7041e791b039c71a3880fb3ca84218fc4 [formerly 7b3d79edc960664c33b815de05ecf571e73104a5] [formerly f685e73bd24a3dc0cec517098e9d9f9b37a6cac4] [formerly 9d3c4ce7041e791b039c71a3880fb3ca84218fc4 [formerly 7b3d79edc960664c33b815de05ecf571e73104a5] [formerly f685e73bd24a3dc0cec517098e9d9f9b37a6cac4] [formerly 14bd577f6c0b4608f0ad1adc73100d4ca347913d [formerly f685e73bd24a3dc0cec517098e9d9f9b37a6cac4 [formerly 380b50d8a3d2a3f80e5a69dd1980e8e863985c2a]]]] Former-commit-id: 14bd577f6c0b4608f0ad1adc73100d4ca347913d Former-commit-id: c1803234178625b8dc95142ecb8350d91c2773a9 [formerly defc6a30803840a170036fe756d1c7d58fff512f] [formerly f7a3f48b1fa32bf56ed18d0e266ac2ee25be2f81 [formerly 65faaadc7cd5deac7afb820898230d58f3b50ce4]] Former-commit-id: 36915698d722a49fcbd05f616829abbe23289698 [formerly a8a4393c8241b91a832075d50db7a555d8271aa3] Former-commit-id: 0e36cab21f8acbc14c5dcd3cc47703dae4bef239 --- .../viz/datadelivery/common/ui/AreaComp.java | 9 +- .../viz/datadelivery/rsc/DrawBoxResource.java | 137 ++++++++++-------- .../datadelivery/registry/EnvelopeUtils.java | 30 +++- 3 files changed, 105 insertions(+), 71 deletions(-) diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/common/ui/AreaComp.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/common/ui/AreaComp.java index 051bf12ab9..26932e75c8 100644 --- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/common/ui/AreaComp.java +++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/common/ui/AreaComp.java @@ -91,6 +91,7 @@ import com.vividsolutions.jts.geom.Coordinate; * Dec 11, 2012 1264 mpduff Fix validaiton of lat/lon text fields. * Mar 21, 2013 1638 mschenke Changed map scales not tied to d2d * Jun 14, 2013 2064 mpduff Reset controls on load. + * Jun 21, 2013 2132 mpduff Swap target and source envelopes. * * * @@ -733,8 +734,8 @@ public class AreaComp extends Composite implements ISubset { // the dialog should always use an envelope in the same crs as the // data. try { - dlgEnvelope = MapUtil.reprojectAndIntersect(dlgEnvelope, - fullEnvelope); + dlgEnvelope = MapUtil.reprojectAndIntersect(fullEnvelope, + dlgEnvelope); } catch (TransformException e) { statusHandler.handle(Priority.PROBLEM, e.getLocalizedMessage(), e); @@ -889,9 +890,9 @@ public class AreaComp extends Composite implements ISubset { Coordinate ul = EnvelopeUtils.getUpperLeftLatLon(envelope); Coordinate lr = EnvelopeUtils.getLowerRightLatLon(envelope); - upperLeftLonTxt.setText(formatter.format(lr.x)); + upperLeftLonTxt.setText(formatter.format(ul.x)); upperLeftLatTxt.setText(formatter.format(ul.y)); - lowerRightLonTxt.setText(formatter.format(ul.x)); + lowerRightLonTxt.setText(formatter.format(lr.x)); lowerRightLatTxt.setText(formatter.format(lr.y)); this.subEnvelope = envelope; diff --git a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/rsc/DrawBoxResource.java b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/rsc/DrawBoxResource.java index ccb75db299..47d5a21f5c 100644 --- a/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/rsc/DrawBoxResource.java +++ b/cave/com.raytheon.uf.viz.datadelivery/src/com/raytheon/uf/viz/datadelivery/rsc/DrawBoxResource.java @@ -44,18 +44,19 @@ import com.vividsolutions.jts.geom.Coordinate; /** * Resource for drawing a bounding box on the Spatial Subset Map Dialog. - * + * *
- *
+ * 
  * SOFTWARE HISTORY
- *
+ * 
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
  * Jan 19, 2012            mpduff      Initial creation.
  * Oct 31, 2012   1278     mpduff      Added functionality for other datasets in NOMADS.
- *
+ * Jun 21, 2013   2132     mpduff      Convert coordinates to East/West before drawing.
+ * 
  * 
- * + * * @author mpduff * @version 1.0 */ @@ -130,7 +131,7 @@ public class DrawBoxResource extends /* * (non-Javadoc) - * + * * @see com.raytheon.uf.viz.core.rsc.AbstractVizResource#disposeInternal() */ @Override @@ -140,7 +141,7 @@ public class DrawBoxResource extends /* * (non-Javadoc) - * + * * @see * com.raytheon.uf.viz.core.rsc.AbstractVizResource#paintInternal(com.raytheon * .uf.viz.core.IGraphicsTarget, @@ -151,6 +152,8 @@ public class DrawBoxResource extends PaintProperties paintProps) throws VizException { this.target = target; if ((c1 != null) && (c2 != null)) { + c1.x = spatialUtils.convertToEastWest(c1.x); + c2.x = spatialUtils.convertToEastWest(c2.x); double[] ul = descriptor.worldToPixel(new double[] { c1.x, c1.y }); double[] lr = descriptor.worldToPixel(new double[] { c2.x, c2.y }); PixelExtent pe = new PixelExtent(ul[0], lr[0], ul[1], lr[1]); @@ -160,7 +163,7 @@ public class DrawBoxResource extends /* * (non-Javadoc) - * + * * @see * com.raytheon.uf.viz.core.rsc.AbstractVizResource#initInternal(com.raytheon * .uf.viz.core.IGraphicsTarget) @@ -182,7 +185,7 @@ public class DrawBoxResource extends /* * (non-Javadoc) - * + * * @see com.raytheon.uf.viz.core.rsc.AbstractVizResource#getName() */ @Override @@ -204,7 +207,7 @@ public class DrawBoxResource extends /* * (non-Javadoc) - * + * * @see com.raytheon.viz.ui.input.InputAdapter#handleMouseDown(int, int, * int) */ @@ -215,9 +218,12 @@ public class DrawBoxResource extends x1 = x; y1 = y; c1 = getResourceContainer().translateClick(x, y); - c1.x = spatialUtils.convertToEasting(c1.x); - if (spatialUtils.getLongitudinalShift() > 0 && x >= x360) { - c1.x += 360; + if (c1 != null) { + c1.x = spatialUtils.convertToEasting(c1.x); + if (spatialUtils.getLongitudinalShift() > 0 + && x >= x360) { + c1.x += 360; + } } } } else if (mouseButton == 2) { @@ -228,7 +234,7 @@ public class DrawBoxResource extends /* * (non-Javadoc) - * + * * @see com.raytheon.viz.ui.input.InputAdapter#handleMouseDownMove(int, * int, int) */ @@ -238,23 +244,25 @@ public class DrawBoxResource extends drawingBox = true; if (resizingBox) { Coordinate c = getResourceContainer().translateClick(x, y); - if (boxSide == 0) { - c1.y = c.y; - } else if (boxSide == 1) { - c1.x = c.x; - c1.x = spatialUtils.convertToEasting(c1.x); - if (spatialUtils.getLongitudinalShift() > 0 - && x >= x360) { - c1.x += 360; - } - } else if (boxSide == 2) { - c2.y = c.y; - } else if (boxSide == 3) { - c2.x = c.x; - c2.x = spatialUtils.convertToEasting(c2.x); - if (spatialUtils.getLongitudinalShift() > 0 - && x >= x360) { - c2.x += 360; + if (c != null) { + if (boxSide == 0) { + c1.y = c.y; + } else if (boxSide == 1) { + c1.x = c.x; + c1.x = spatialUtils.convertToEasting(c1.x); + if (spatialUtils.getLongitudinalShift() > 0 + && x >= x360) { + c1.x += 360; + } + } else if (boxSide == 2) { + c2.y = c.y; + } else if (boxSide == 3) { + c2.x = c.x; + c2.x = spatialUtils.convertToEasting(c2.x); + if (spatialUtils.getLongitudinalShift() > 0 + && x >= x360) { + c2.x += 360; + } } } } else { @@ -267,6 +275,7 @@ public class DrawBoxResource extends } } } + fireBoxChangedEvent(); createRegions(); target.setNeedsRefresh(true); @@ -279,7 +288,7 @@ public class DrawBoxResource extends /* * (non-Javadoc) - * + * * @see com.raytheon.viz.ui.input.InputAdapter#handleMouseMove(int, int) */ @Override @@ -309,7 +318,7 @@ public class DrawBoxResource extends /* * (non-Javadoc) - * + * * @see com.raytheon.viz.ui.input.InputAdapter#handleMouseUp(int, int, * int) */ @@ -318,38 +327,42 @@ public class DrawBoxResource extends if (mouseButton == 1) { if (resizingBox) { Coordinate c = getResourceContainer().translateClick(x, y); - c.x = spatialUtils.convertToEasting(c.x); - if (spatialUtils.getLongitudinalShift() > 0 && x >= x360) { - c.x += 360; + if (c != null) { + c.x = spatialUtils.convertToEasting(c.x); + if (spatialUtils.getLongitudinalShift() > 0 + && x >= x360) { + c.x += 360; + } + if (boxSide == 0) { + c1.y = c.y; + y1 = y; + } else if (boxSide == 1) { + c1.x = c.x; + x1 = x; + } else if (boxSide == 2) { + c2.y = c.y; + y2 = y; + } else if (boxSide == 3) { + c2.x = c.x; + x2 = x; + } + createRegions(); + fireBoxChangedEvent(); + target.setNeedsRefresh(true); + drawingBox = false; } - if (boxSide == 0) { - c1.y = c.y; - y1 = y; - } else if (boxSide == 1) { - c1.x = c.x; - x1 = x; - } else if (boxSide == 2) { - c2.y = c.y; - y2 = y; - } else if (boxSide == 3) { - c2.x = c.x; - x2 = x; - } - - createRegions(); - fireBoxChangedEvent(); - target.setNeedsRefresh(true); - drawingBox = false; } else { if (drawingBox) { x2 = x; y2 = y; target.setNeedsRefresh(true); c2 = getResourceContainer().translateClick(x, y); - c2.x = spatialUtils.convertToEasting(c2.x); - if (spatialUtils.getLongitudinalShift() > 0 - && x >= x360) { - c2.x += 360; + if (c2 != null) { + c2.x = spatialUtils.convertToEasting(c2.x); + if (spatialUtils.getLongitudinalShift() > 0 + && x >= x360) { + c2.x += 360; + } } createRegions(); @@ -369,7 +382,7 @@ public class DrawBoxResource extends /** * Add a box listener. - * + * * @param listener * the listener to add */ @@ -379,7 +392,7 @@ public class DrawBoxResource extends /** * Remove the box listener. - * + * * @param listener * the listener to remove */ @@ -470,7 +483,7 @@ public class DrawBoxResource extends /** * Set the parent shell. - * + * * @param shell * the parent shell */ @@ -480,7 +493,7 @@ public class DrawBoxResource extends /** * Set the coordinates. - * + * * @param ul * upper left coordinates * @param lr diff --git a/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/EnvelopeUtils.java b/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/EnvelopeUtils.java index 80c8aa542d..6de17bfdd0 100644 --- a/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/EnvelopeUtils.java +++ b/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/EnvelopeUtils.java @@ -45,7 +45,8 @@ import com.vividsolutions.jts.geom.Coordinate; * * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- - * Dec 5, 2012 bsteffen Initial creation + * Dec 5, 2012 bsteffen Initial creation. + * Jun 21, 2013 2132 mpduf createSubEnvelopeFromLatLon now uses East/West direction. * * * @@ -319,10 +320,14 @@ public class EnvelopeUtils { * @return */ public static ReferencedEnvelope createSubenvelopeFromLatLon( - Envelope envelope, Coordinate latLon1, - Coordinate latLon2) { - ReferencedEnvelope result = createEnvelopeFromLatLon(envelope.getCoordinateReferenceSystem(), latLon1, latLon2); - return new ReferencedEnvelope(result.intersection(reference(envelope)), envelope.getCoordinateReferenceSystem()); + Envelope envelope, Coordinate latLon1, Coordinate latLon2) { + latLon1 = EnvelopeUtils.convertToEastWest(latLon1); + latLon2 = EnvelopeUtils.convertToEastWest(latLon2); + + ReferencedEnvelope result = createEnvelopeFromLatLon( + envelope.getCoordinateReferenceSystem(), latLon1, latLon2); + return new ReferencedEnvelope(result.intersection(reference(envelope)), + envelope.getCoordinateReferenceSystem()); } /** @@ -353,4 +358,19 @@ public class EnvelopeUtils { return new ReferencedEnvelope(envelope); } } + + /** + * Convert coordinate value to East/West. + * + * @param coord + * Coordinate to convert + * @return converted coordinate + */ + public static Coordinate convertToEastWest(Coordinate coord) { + if (coord.x > 180) { + coord.x = coord.x - 360; + } + + return coord; + } }