rm laps tools

This commit is contained in:
Michael James 2018-06-08 12:49:38 -06:00
parent 596fe93fa1
commit 3616ee1184
7 changed files with 2 additions and 2110 deletions

View file

@ -20,10 +20,11 @@
--> -->
<menuTemplate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <menuTemplate xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!--
<contribute xsi:type="command" <contribute xsi:type="command"
commandId="com.raytheon.viz.awipstools.lapstools" commandId="com.raytheon.viz.awipstools.lapstools"
menuText="LAPS tools..." id="lapsTools" /> menuText="LAPS tools..." id="lapsTools" />
-->
<!-- example arbitrary command below, commandAction parameter is required, <!-- example arbitrary command below, commandAction parameter is required,
the others default to false if undefined. If captureOutput is true then after the others default to false if undefined. If captureOutput is true then after
the launched command closes a dialog box will show the contents printed to the launched command closes a dialog box will show the contents printed to

View file

@ -70,10 +70,6 @@
<command <command
id="com.raytheon.viz.awipstools.home" id="com.raytheon.viz.awipstools.home"
name="Home"> name="Home">
</command>
<command
id="com.raytheon.viz.awipstools.lapstools"
name="LAPS tools">
</command> </command>
<command <command
id="com.raytheon.viz.awipstools.unitscalculator" id="com.raytheon.viz.awipstools.unitscalculator"
@ -142,10 +138,6 @@
class="com.raytheon.viz.awipstools.ui.action.HomeToolAction" class="com.raytheon.viz.awipstools.ui.action.HomeToolAction"
commandId="com.raytheon.viz.awipstools.home"> commandId="com.raytheon.viz.awipstools.home">
</handler> </handler>
<handler
class="com.raytheon.viz.awipstools.ui.action.LapsToolsAction"
commandId="com.raytheon.viz.awipstools.lapstools">
</handler>
<handler <handler
class="com.raytheon.viz.awipstools.ui.action.UnitsCalculatorAction" class="com.raytheon.viz.awipstools.ui.action.UnitsCalculatorAction"
commandId="com.raytheon.viz.awipstools.unitscalculator"> commandId="com.raytheon.viz.awipstools.unitscalculator">

View file

@ -1,117 +0,0 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.viz.awipstools.ui.action;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import com.raytheon.uf.common.status.IUFStatusHandler;
import com.raytheon.uf.common.status.UFStatus;
import com.raytheon.uf.common.status.UFStatus.Priority;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.viz.awipstools.ui.dialog.LAPSToolsDlg;
import com.raytheon.viz.ui.EditorUtil;
/**
* TODO Add Description
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* May 2009 # bsteffen Initial creation
* Nov 2013 # mccaslin Only one GUI dialog at a time
* Oct 2014 # mccaslin Improved error handeling
*
* </pre>
*
* @author bsteffen
* @version 1.0
*/
public class LapsToolsAction extends AbstractHandler {
private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(LapsToolsAction.class);
/**
* LAPS Tools dialog.
*/
private static LAPSToolsDlg lapsToolsDlg = null;
public static LAPSToolsDlg getLapsToolsDlg() {
return lapsToolsDlg;
}
public Object execute(ExecutionEvent arg0) throws ExecutionException {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getShell();
if (lapsToolsDlg == null) {
try {
lapsToolsDlg = new LAPSToolsDlg(shell);
lapsToolsDlg.addListener(SWT.Dispose, new Listener() {
@Override
public void handleEvent(Event event) {
lapsToolsDlg = null;
}
});
if (lapsToolsDlg.isLapsInstalled()) {
lapsToolsDlg.open();
} else {
String whatLapsIs = "LAPS is not installed. ";
// Note: Go through the LAPS v2.0 Scripting Interface first,
// if you find that LAPS is not installed.
MessageBox mb = new MessageBox(EditorUtil.getActiveEditor()
.getSite().getShell(), SWT.ICON_ERROR | SWT.OK);
mb.setText("Cannot open the LAPS tool");
mb.setMessage(whatLapsIs);
mb.open();
lapsToolsDlg = null;
// int val = mb.open();
// if (val == SWT.OK) {
// AlertViz Customization Update
// return false;
// }
}
} catch (VizException e) {
statusHandler.handle(Priority.PROBLEM,
"Error: Cannot open LAPS V2.0 Tools GUI", e);
}
}
return null;
}
}

View file

@ -1,294 +0,0 @@
package com.raytheon.viz.awipstools.ui.action;
import java.awt.geom.Point2D;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Shell;
import org.geotools.referencing.GeodeticCalculator;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Envelope;
public class LapsToolsData {
private Coordinate gridCenter = new Coordinate();
private Integer nx;
private Integer ny;
private Integer nz;
private Double gridSpacing;
private Double lat;
private Double lon;
private Envelope cwaArea;
private Envelope validArea;
private Envelope validAreaOrig;
private Envelope validAreaDefault;
private Envelope gridArea;
private String areaCoverageString;
private Boolean belowLimits;
public Coordinate getGridCenter() {
return gridCenter;
}
public Coordinate getCwaCenter() {
return cwaArea.centre();
}
public Integer getNx() {
return nx;
}
public Integer getNy() {
return ny;
}
public Integer getNz() {
return nz;
}
public Double getGridSpacing() {
return gridSpacing;
}
public String getAreaCoverageString() {
double nxDist = getNx()*getGridSpacing()/1000;
double nyDist = getNy()*getGridSpacing()/1000;
double areaCoverage = nxDist * nyDist;
this.areaCoverageString = String.format("%.1f km by %.1f km = %.2f km2",
nxDist, nyDist, areaCoverage);
double maximumArea = 14140140.;
double minimumArea = 150000.;
if(areaCoverage > maximumArea) {
System.out.print("LAPS Tools Data: problem with this domain exceeding the RUC 236 background\n");
MessageDialog.openWarning(getShell(), "Domain Size Error",
"The size of new domain would exceed the maximum limits \n\tdefined by model background (the RAP40 grid).\n");
} else if(areaCoverage < minimumArea) {
System.out.print("LAPS Tools Data: problem with this domain coverage area being smaller than the CWA coverage area\n");
MessageDialog.openWarning(getShell(), "Domain Size Error",
"The size of new domain area would LESS than the minimum limits \n\tdefined by the CWA coverage area.");
}
return areaCoverageString;
}
private Shell getShell() {
// TODO Auto-generated method stub
return null;
}
public Double getLat() {
return lat;
}
public Double getLon() {
return lon;
}
public Envelope getCwaArea() {
return cwaArea;
}
public void setLimits(Boolean belowLimits) {
this.belowLimits = belowLimits;
}
public Boolean getLimits() {
return belowLimits;
}
public Envelope getValidArea() {
if (validArea == null) {
double buffer = .1; // tenth of a degree buffer around CWA (in km)
double cosBuffer = Math.abs(2*Math.cos(cwaArea.centre().y));
double cwa_dist_lat = Math.abs(cwaArea.getHeight() / 2) + (2 * buffer);
double cwa_dist_lon = Math.abs(cwaArea.getWidth() / 2) + (2 * buffer * cosBuffer);
validArea = new Envelope(cwaArea.centre());
validArea.expandBy(cwa_dist_lon, cwa_dist_lat);
double z = Math.abs(cwaArea.getHeight() / cwaArea.getWidth()) ;
System.out.print("LAPS Tools Data: cwa height = "+cwaArea.getHeight()+"\n");
System.out.print("cwa width = "+cwaArea.getWidth()+"\n");
System.out.print("z ratio = "+z+"\n");
}
return validArea;
}
public Envelope getValidAreaOrig() {
if (validAreaOrig == null) {
double cwa_dist_lat = Math.abs(cwaArea.getHeight() / 2);
double cwa_dist_lon = Math.abs(cwaArea.getWidth() / 2);
validAreaOrig = new Envelope(cwaArea.centre());
validAreaOrig.expandBy(cwa_dist_lon, cwa_dist_lat);
}
return validAreaOrig;
}
public Envelope getValidAreaDefault() {
if (validAreaDefault == null) {
double buffer = 1; // half degree buffer around CWA (in km)
double cosBuffer = Math.abs(2*Math.cos(cwaArea.centre().y));
double cwa_dist_lat = Math.abs(cwaArea.getHeight() / 2) + (2 * buffer);
double cwa_dist_lon = Math.abs(cwaArea.getWidth() / 2) + (2 * buffer * cosBuffer);
validAreaDefault = new Envelope(cwaArea.centre());
validAreaDefault.expandBy(cwa_dist_lon, cwa_dist_lat);
}
return validAreaDefault;
}
public Envelope getGridArea() {
if (gridArea == null) {
double width = getGridSpacing() * nx;
double height = getGridSpacing() * ny;
GeodeticCalculator gc = new GeodeticCalculator();
gc.setStartingGeographicPoint(gridCenter.x, gridCenter.y);
gc.setDirection(0.0, height / 2);
Point2D top = gc.getDestinationGeographicPoint();
gc.setStartingGeographicPoint(gridCenter.x, gridCenter.y);
gc.setDirection(180.0, height / 2);
Point2D bot = gc.getDestinationGeographicPoint();
gc.setStartingGeographicPoint(top);
gc.setDirection(90.0, width / 2);
Point2D NE = gc.getDestinationGeographicPoint();
gc.setStartingGeographicPoint(top);
gc.setDirection(-90.0, width / 2);
Point2D NW = gc.getDestinationGeographicPoint();
gc.setStartingGeographicPoint(bot);
gc.setDirection(90.0, width / 2);
Point2D SE = gc.getDestinationGeographicPoint();
gc.setStartingGeographicPoint(bot);
gc.setDirection(-90.0, width / 2);
Point2D SW = gc.getDestinationGeographicPoint();
gridArea = new Envelope();
gridArea.expandToInclude(NE.getX(), NE.getY());
gridArea.expandToInclude(NW.getX(), NW.getY());
gridArea.expandToInclude(SE.getX(), SE.getY());
gridArea.expandToInclude(SW.getX(), SW.getY());
}
return gridArea;
}
public void setCwaArea(Envelope cwaArea) {
validArea = null;
this.cwaArea = cwaArea;
}
public void setGridCenterLon(double lon) {
gridArea = null;
gridCenter.x = lon;
}
public void setGridCenterLat(double lat) {
gridArea = null;
gridCenter.y = lat;
}
public void setGridCenter(Coordinate gridCenter) {
gridArea = null;
this.gridCenter = gridCenter;
}
public void setNx(Integer nx) {
gridArea = null;
this.nx = nx;
}
public void setNy(Integer ny) {
gridArea = null;
this.ny = ny;
}
public void setGridSpacing(Double gridSpacing) {
gridArea = null;
this.gridSpacing = gridSpacing;
}
public void setNz(Integer nz) {
this.nz = nz;
}
public void setLat(Double lat) {
this.lat = lat;
}
public void setLon(Double lon) {
this.lon = lon;
}
//LAPS domain.xml has <domain> tags and <NX_L> tags, etc
@XmlRootElement(name="domain", namespace="")
public static class LapsDomain {
private Integer nx;
private Integer ny;
private Integer nz;
private Double gridSpacing;
private Double lat;
private Double lon;
public int getNx() {
return nx;
}
@XmlElement(name = "NX_L")
public void setNx(int nx) {
this.nx = nx;
}
public int getNy() {
return ny;
}
@XmlElement(name = "NY_L")
public void setNy(int ny) {
this.ny = ny;
}
public int getNz() {
return nz;
}
@XmlElement(name = "NK_LAPS")
public void setNz(int nz) {
this.nz = nz;
}
public Double getGridSpacing() {
return gridSpacing;
}
@XmlElement(name = "GRID_SPACING_M")
public void setGridSpacing(Double gridSpacing) {
this.gridSpacing = gridSpacing;
}
public Double getGridCenLat() {
return lat;
}
@XmlElement(name = "GRID_CEN_LAT")
public void setGridCenLat(Double lat) {
this.lat = lat;
}
public Double getGridCenLon() {
return lon;
}
@XmlElement(name = "GRID_CEN_LON")
public void setGridCenLon(Double lon) {
this.lon = lon;
}
}
}

View file

@ -1,242 +0,0 @@
package com.raytheon.viz.awipstools.ui.action;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.bind.JAXB;
import com.raytheon.uf.common.dataquery.requests.RequestConstraint;
import com.raytheon.uf.common.geospatial.SpatialException;
import com.raytheon.uf.common.geospatial.SpatialQueryFactory;
import com.raytheon.uf.common.geospatial.SpatialQueryResult;
import com.raytheon.uf.common.localization.ILocalizationFile;
import com.raytheon.uf.common.localization.IPathManager;
import com.raytheon.uf.common.localization.LocalizationContext;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel;
import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType;
import com.raytheon.uf.common.localization.PathManagerFactory;
import com.raytheon.uf.common.localization.SaveableOutputStream;
import com.raytheon.uf.common.localization.exception.LocalizationException;
import com.raytheon.uf.common.time.SimulatedTime;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.localization.LocalizationManager;
import com.raytheon.viz.awipstools.ui.action.LapsToolsData.LapsDomain;
import com.vividsolutions.jts.geom.Envelope;
/**
* This class no longer performs all the file system, server input/output for
* laps. LAPS support scripts now conduct the localization process.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* May 2009 # bsteffen Initial creation
* Nov 2013 # mccaslin New design approach, changed from OS calls to file io, read xml code, etc
* Feb 12, 2016 5242 dgilling Remove calls to deprecated Localization APIs.
*
* </pre>
*
* @author bsteffen
* @version 1.0
*/
public class LapsToolsIO {
private static final String WHATGOTIN_FILE_FRMT = "%s/%s.wgi";
private static File fxaData;
private static File lapsLogs;
private static List<String> whatgotinFiles;
private static List<String> dataChoices;
static {
// TODO all this configuration should be customizable by the user.
// --- For what got in log files ---
if (System.getenv("FXA_DATA") == null) {
fxaData = new File("/data/fxa");
} else {
fxaData = new File(System.getenv("FXA_DATA"));
}
lapsLogs = new File(fxaData + "/laps/log/wgi");
whatgotinFiles = Arrays.asList("sfc", "wind", "lq3driver", "cloud",
"temp");
dataChoices = Arrays.asList("Surface Analysis", "Wind Analysis",
"Humidity Analysis", "Cloud Analysis", "Temperature Analysis");
}
public static Collection<String> getDataChoices() {
return dataChoices;
}
public static String getLogs(String type) throws IOException, VizException {
String wgiFile = String.format(WHATGOTIN_FILE_FRMT, lapsLogs,
whatgotinFiles.get(dataChoices.indexOf(type)));
String resultIO = loadWhatGotInFile(wgiFile, type);
return (resultIO);
}
private static String loadWhatGotInFile(String wfile, String type)
throws IOException {
BufferedReader reader;
StringBuilder output = new StringBuilder();
File file = new File(wfile);
try {
reader = new BufferedReader(new FileReader(file));
} catch (FileNotFoundException e) {
String arg = String
.format("*** Cannot find expected log file for %s."
+ "\n*** File %s ....does not appear to exist.\n\n",
type, file.getAbsolutePath());
output.append(arg);
return output.toString();
}
String line;
int lineNumber = 0;
while ((line = reader.readLine()) != null) {
String arg = String.format("%04d: %s%n", ++lineNumber, line);
output.append(arg);
}
reader.close();
return output.toString();
}
public static LapsToolsData loadData() throws IOException, VizException,
SpatialException {
LapsToolsData data = new LapsToolsData();
if (LapsToolsIO.readXmlFile(data)) {
LapsToolsIO.readCountyWarningArea(data);
} else {
data = null;
}
return data;
}
public static boolean readXmlFile(LapsToolsData data) throws IOException,
VizException {
IPathManager pm = PathManagerFactory.getPathManager();
LocalizationContext lc = pm.getContext(LocalizationType.COMMON_STATIC,
LocalizationLevel.SITE);
ILocalizationFile xmlLocalizationFile = pm.getLocalizationFile(lc,
"LAPS/domain" + ".xml");
if (!xmlLocalizationFile.exists()) {
return false;
}
LapsDomain domain = new LapsDomain();
try (InputStream inStream = xmlLocalizationFile.openInputStream()) {
domain = JAXB.unmarshal(inStream, LapsDomain.class);
} catch (LocalizationException e) {
throw new VizException("xml is unreadable: "
+ e.getLocalizedMessage());
}
data.setNx(domain.getNx());
data.setNy(domain.getNy());
data.setNz(domain.getNz());
data.setGridSpacing(domain.getGridSpacing());
data.setGridCenterLon(domain.getGridCenLon());
data.setGridCenterLat(domain.getGridCenLat());
return true;
}
public static void defaultDomain(LapsToolsData data) throws IOException,
VizException {
double distance = 111; // 111 km per 1 degree
double gridSpacingDefault = 3500.;
double dim = 200;
double N = dim * dim;
Envelope shapeArea = data.getValidAreaOrig();
double widthY = Math.abs(shapeArea.getHeight() * distance);
double widthX = Math.abs((shapeArea.getWidth() * distance)
* (Math.cos(shapeArea.centre().x)));
double aspectRatio = widthY / widthX;
double buffer = 0.5;
int nX = (int) (Math.sqrt(N / aspectRatio) + buffer);
int nY = (int) ((aspectRatio * nX) + buffer);
System.out.print("LAPS Tools IO:\nheight = " + shapeArea.getHeight()
+ " width = " + shapeArea.getWidth());
System.out.print("\naspect ratio = " + aspectRatio);
System.out.print("\nnX = " + nX + ", nY = " + nY + "\n");
LapsDomain domain = new LapsDomain();
domain.setNx(nX);
domain.setNy(nY);
domain.setNz(43);
domain.setGridSpacing(gridSpacingDefault);
domain.setGridCenLon(data.getCwaCenter().x);
domain.setGridCenLat(data.getCwaCenter().y);
data.setNx(domain.getNx());
data.setNy(domain.getNy());
data.setNz(domain.getNz());
data.setGridSpacing(domain.getGridSpacing());
data.setGridCenterLon(data.getCwaCenter().x);
data.setGridCenterLat(data.getCwaCenter().y);
}
private static void readCountyWarningArea(LapsToolsData data)
throws SpatialException {
Map<String, RequestConstraint> map = new HashMap<String, RequestConstraint>();
map.put("cwa", new RequestConstraint(LocalizationManager.getInstance()
.getCurrentSite()));
SpatialQueryResult[] result = SpatialQueryFactory.create().query("cwa",
null, null, map, null);
if (result == null || result.length == 0) {
return;
}
data.setCwaArea(result[0].geometry.getEnvelopeInternal());
}
public static String getWriteXmlQuestion() {
String date = new SimpleDateFormat("HH:mm").format(SimulatedTime
.getSystemTime().getTime());
return String
.format("Are you sure you want write domain.xml?"
+ "\nNote: Its %s and LAPS runs at ~20 minutes after the hour.",
date);
}
public static void writeXmlFile(LapsToolsData data) throws IOException,
InterruptedException, VizException {
IPathManager pm = PathManagerFactory.getPathManager();
LocalizationContext lc = pm.getContext(LocalizationType.COMMON_STATIC,
LocalizationLevel.USER);
ILocalizationFile xmlLocalizationFile = pm.getLocalizationFile(lc,
"LAPS" + IPathManager.SEPARATOR + "domain.xml");
LapsDomain lapsdomain = new LapsDomain();
lapsdomain.setNx(data.getNx());
lapsdomain.setNy(data.getNy());
lapsdomain.setNz(data.getNz());
lapsdomain.setGridSpacing(data.getGridSpacing());
lapsdomain.setGridCenLat(data.getGridCenter().y);
lapsdomain.setGridCenLon(data.getGridCenter().x);
// marshal java object to XML file
try (SaveableOutputStream outStream = xmlLocalizationFile
.openOutputStream()) {
JAXB.marshal(lapsdomain, outStream);
outStream.save();
} catch (LocalizationException e) {
throw new VizException("Unable to save LapsDomain to xml.");
}
}
}

View file

@ -1,371 +0,0 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.viz.awipstools.ui.layer;
import java.util.ArrayList;
import java.util.Arrays;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.swt.graphics.RGB;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import com.raytheon.uf.viz.core.DrawableCircle;
import com.raytheon.uf.viz.core.DrawableString;
import com.raytheon.uf.viz.core.IDisplayPaneContainer;
import com.raytheon.uf.viz.core.IExtent;
import com.raytheon.uf.viz.core.IGraphicsTarget;
//import com.raytheon.uf.viz.core.IGraphicsTarget.HorizontalAlignment;
import com.raytheon.uf.viz.core.IGraphicsTarget.LineStyle;
//import com.raytheon.uf.viz.core.IGraphicsTarget.TextStyle;
import com.raytheon.uf.viz.core.drawables.IWireframeShape;
import com.raytheon.uf.viz.core.drawables.PaintProperties;
import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.rsc.LoadProperties;
import com.raytheon.uf.viz.core.rsc.capabilities.ColorableCapability;
import com.raytheon.uf.viz.core.rsc.tools.AbstractMovableToolLayer;
import com.raytheon.uf.viz.core.rsc.tools.GenericToolsResourceData;
import com.raytheon.viz.awipstools.ui.action.LapsToolsData;
import com.raytheon.viz.ui.cmenu.AbstractRightClickAction;
import com.raytheon.viz.ui.cmenu.IContextMenuContributor;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Envelope;
/**
* TODO Add Description
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* bsteffen Intial creation.
* 07-21-14 #3412 mapeters Updated deprecated drawCircle call.
* 07-29-14 #3465 mapeters Updated deprecated drawString() calls.
* Nov 2013 # mccaslin Draw more graphical boxes: for CWA, previous domain, etc
* </pre>
*
* @author bsteffen
* @version 1.0
*/
public class LapsToolLayer extends AbstractMovableToolLayer<Coordinate>
implements IContextMenuContributor {
private LapsToolsData data;
public static final String DEFAULT_NAME = "Laps Relocator";
private final AbstractRightClickAction selectLocationAction;
private final AbstractRightClickAction moveElementAction;
private IWireframeShape validShapeOrig;
private IWireframeShape validShape;
private IWireframeShape gridShape;
private RGB labelColor;
public static String centerLabel = "Center Point";
public LapsToolLayer(GenericToolsResourceData<LapsToolLayer> resourceData,
LoadProperties loadProperties) {
super(resourceData, loadProperties, false);
selectLocationAction = new AbstractRightClickAction() {
@Override
public void run() {
save(null, lastMouseLoc);
}
};
selectLocationAction.setText("Select Location");
moveElementAction = new AbstractRightClickAction() {
@Override
public void run() {
makeSelectedLive();
}
};
moveElementAction.setText("Move Entire Element");
this.rightClickMovesToCoord = true;
resourceData.addChangeListener(this);
}
@Override
protected void disposeInternal() {
if (validShape != null) {
validShape.dispose();
validShape = null;
}
if (gridShape != null) {
gridShape.dispose();
gridShape = null;
}
super.disposeInternal();
}
@Override
protected void initInternal(IGraphicsTarget target) throws VizException {
super.initInternal(target);
setObjects(new ArrayList<Coordinate>(
Arrays.asList(data.getGridCenter())));
}
/*
* (non-Javadoc)
*
* @see
* com.raytheon.viz.awipstools.ui.layer.AbstractMovableToolLayer#paintInternal
* (com.raytheon.uf.viz.core.IGraphicsTarget,
* com.raytheon.uf.viz.core.drawables.PaintProperties)
*/
@Override
protected void paintInternal(IGraphicsTarget target,
PaintProperties paintProps) throws VizException {
super.paintInternal(target, paintProps);
Envelope shapeArea = data.getValidArea();
if (validShape == null) {
validShape = target.createWireframeShape(false, descriptor);
Coordinate[] coords = new Coordinate[5];
coords[0] = new Coordinate(shapeArea.getMinX(), shapeArea.getMinY());
coords[1] = new Coordinate(shapeArea.getMinX(), shapeArea.getMaxY());
coords[2] = new Coordinate(shapeArea.getMaxX(), shapeArea.getMaxY());
coords[3] = new Coordinate(shapeArea.getMaxX(), shapeArea.getMinY());
coords[4] = coords[0];
validShape.addLineSegment(coords);
}
Envelope shapeArea2 = data.getValidAreaOrig();
if (validShapeOrig == null) {
validShapeOrig = target.createWireframeShape(false, descriptor);
Coordinate[] coords = new Coordinate[5];
coords[0] = new Coordinate(shapeArea2.getMinX(), shapeArea2.getMinY());
coords[1] = new Coordinate(shapeArea2.getMinX(), shapeArea2.getMaxY());
coords[2] = new Coordinate(shapeArea2.getMaxX(), shapeArea2.getMaxY());
coords[3] = new Coordinate(shapeArea2.getMaxX(), shapeArea2.getMinY());
coords[4] = coords[0];
validShapeOrig.addLineSegment(coords);
}
Envelope gridArea = data.getGridArea();
if (gridShape == null) {
gridShape = target.createWireframeShape(false, descriptor);
Coordinate[] coords = new Coordinate[5];
coords[0] = new Coordinate(gridArea.getMinX(), gridArea.getMinY());
coords[1] = new Coordinate(gridArea.getMinX(), gridArea.getMaxY());
coords[2] = new Coordinate(gridArea.getMaxX(), gridArea.getMaxY());
coords[3] = new Coordinate(gridArea.getMaxX(), gridArea.getMinY());
coords[4] = coords[0];
gridShape.addLineSegment(coords);
}
//Test domain sizes
data.setLimits(false);
if (gridArea.getMinX() > shapeArea.getMinX()) {
data.setLimits(true);
} if (gridArea.getMaxX() < shapeArea.getMaxX()) {
data.setLimits(true);
} if (gridArea.getMinY() > shapeArea.getMinY()) {
data.setLimits(true);
} if (gridArea.getMaxY() < shapeArea.getMaxY()) {
data.setLimits(true);
}
RGB color = getCapability(ColorableCapability.class).getColor();
RGB color2 = color;
// Projected grid domain too small, below the limits of the CWA...
if (data.getLimits()) {
color2 = new RGB ( 250, 40, 40);
labelColor = color2;
centerLabel = "[Center point]\nFull CWA is NOT covered by domain";
} else {
labelColor = color;
centerLabel = "Center point";
}
target.drawWireframeShape(validShape, color, 1, LineStyle.DASHED_LARGE);
target.drawWireframeShape(gridShape, color2, 1, LineStyle.SOLID);
RGB gray = new RGB ( 90, 90, 90);
target.drawWireframeShape(validShapeOrig, gray, 1, LineStyle.DASH_DOTTED);
}
@Override
protected void paint(IGraphicsTarget target, PaintProperties paintProps,
Coordinate home, SelectionStatus status) throws VizException {
RGB color = getCapability(ColorableCapability.class).getColor();
if (status == SelectionStatus.SELECTED) {
color = GRAY;
}
double radius = (MAGIC_CIRCLE_RADIUS * paintProps.getZoomLevel());
double[] center = descriptor
.worldToPixel(new double[] { home.x, home.y });
DrawableCircle circle = new DrawableCircle();
circle.setCoordinates(center[0], center[1]);
circle.radius = radius;
circle.basics.color = color;
target.drawCircle(circle);
//14.1.1 and earlier: target.drawCircle(center[0], center[1], 0, radius, color, 1);
double labelLoc[] = target.getPointOnCircle(center[0], center[1], 0.0,
radius, 0);
//DrawableString string = new DrawableString("center point", color);
DrawableString string = new DrawableString(centerLabel, labelColor);
string.setCoordinates(labelLoc[0], labelLoc[1]);
target.drawStrings(string);
//14.1.1 and earlier: target.drawString(null, centerLabel, labelLoc[0], labelLoc[1], 0.0,
// TextStyle.NORMAL, labelColor, HorizontalAlignment.LEFT, null);
}
@Override
public String getDefaultName() {
return DEFAULT_NAME;
}
@Override
public void addContextMenuItems(IMenuManager menuManager, int x, int y) {
if (isEditable() && selectedObject != null) {
menuManager.add(moveElementAction);
}
if (isEditable() && data.getValidArea().contains(lastMouseLoc)) {
menuManager.add(selectLocationAction);
}
}
@Override
protected boolean isClicked(IDisplayPaneContainer container,
Coordinate mouseLoc, Coordinate object) {
this.endpointClicked = false;
double[] pointPixel = container.translateInverseClick(object);
double distance = (mouseLoc.x - pointPixel[0])
* (mouseLoc.x - pointPixel[0]) + (mouseLoc.y - pointPixel[1])
* (mouseLoc.y - pointPixel[1]);
if (distance < MAGIC_CLICK_DISTANCE * MAGIC_CLICK_DISTANCE) {
this.endpointClicked = true;
return true;
}
return false;
}
@Override
protected Coordinate makeLive(Coordinate object) {
return new Coordinate(object);
}
@Override
protected Coordinate move(Coordinate lastMouseLoc, Coordinate mouseLoc,
Coordinate object) {
if (mouseLoc != null && data.getValidArea().contains(mouseLoc)) {
return new Coordinate(mouseLoc);
} else {
return object;
}
}
@Override
protected void save(Coordinate oldCoordinate, Coordinate coordinate) {
data.setGridCenterLon(coordinate.x);
data.setGridCenterLat(coordinate.y);
resourceData.fireChangeListeners(ChangeType.DATA_UPDATE, null);
}
public LapsToolsData getData() {
return data;
}
public void setData(LapsToolsData data) {
this.data = data;
}
@Override
public void resourceChanged(ChangeType type, Object object) {
super.resourceChanged(type, object);
if (type == ChangeType.DATA_UPDATE) {
setObjects(new ArrayList<Coordinate>(Arrays.asList(data
.getGridCenter())));
if (validShape != null) {
validShape.dispose();
validShape = null;
}
if (validShapeOrig != null) {
validShapeOrig.dispose();
validShapeOrig = null;
}
if (gridShape != null) {
gridShape.dispose();
gridShape = null;
}
issueRefresh();
}
}
/*
@see
* com.raytheon.uf.viz.core.rsc.AbstractVizResource#project(org.opengis.
* referencing.crs.CoordinateReferenceSystem)
*/
public void project(CoordinateReferenceSystem crs) throws VizException {
if (validShape != null) {
validShape.dispose();
validShape = null;
}
if (validShapeOrig != null) {
validShapeOrig.dispose();
validShapeOrig = null;
}
if (gridShape != null) {
gridShape.dispose();
gridShape = null;
}
issueRefresh();
}
protected void drawUpperLeftCornerLabel(IGraphicsTarget target,
PaintProperties paintProps, String label) throws VizException {
// TODO this screen location code is borrowed from MPELegendResource...
// should it be put into a shared class, possibly a paint
// properties method?
IExtent screenExtent = paintProps.getView().getExtent();
double scale = (screenExtent.getHeight() / paintProps.getCanvasBounds().height);
DrawableString tmpDS = new DrawableString("0", new RGB(100, 100, 100));
tmpDS.font = null;
double textHeight = target.getStringsBounds(tmpDS).getHeight() * scale;
double padding = 3 * scale;
double textSpace = textHeight + padding;
double cmapHeight = textHeight * 1.25;
double legendHeight = cmapHeight + 2.0 * textSpace + 2.0 * padding;
double y1 = screenExtent.getMinY() + legendHeight * 2.5;
double x1 = screenExtent.getMinX() + padding * 10.0;
DrawableString string = new DrawableString(label, this.getCapability(
ColorableCapability.class).getColor());
string.basics.x = x1;
string.basics.y = y1;
string.font = null;
//string.textStyle = IGraphicsTarget.TextStyle.NORMAL;
//string.horizontalAlignment = HorizontalAlignment.LEFT;
target.drawStrings(string);
}
}