From 72c9fb05d9231f6b7fe13e3fcc81322238084d05 Mon Sep 17 00:00:00 2001 From: Ben Steffensmeier Date: Mon, 13 Jul 2015 11:59:56 -0500 Subject: [PATCH] Omaha #4633 Initial implementation of auto transition. Former-commit-id: d9aea4ace2a767d70dff81d44b371949e2f4a7cb --- .../.classpath | 7 + .../.project | 28 ++ .../META-INF/MANIFEST.MF | 16 ++ .../build.properties | 5 + .../plugin.xml | 22 ++ .../auto/transition/AutoTransitionAction.java | 135 ++++++++++ .../auto/transition/AutoTransitionDialog.java | 249 ++++++++++++++++++ .../transition/AutoTransitionResource.java | 130 +++++++++ .../AutoTransitionResourceData.java | 107 ++++++++ .../transition/AverageValueCalculator.java | 231 ++++++++++++++++ .../ConfigureAutoTransitionAction.java | 73 +++++ .../feature.xml | 6 + 12 files changed, 1009 insertions(+) create mode 100644 cave/com.raytheon.uf.viz.auto.transition/.classpath create mode 100644 cave/com.raytheon.uf.viz.auto.transition/.project create mode 100644 cave/com.raytheon.uf.viz.auto.transition/META-INF/MANIFEST.MF create mode 100644 cave/com.raytheon.uf.viz.auto.transition/build.properties create mode 100644 cave/com.raytheon.uf.viz.auto.transition/plugin.xml create mode 100644 cave/com.raytheon.uf.viz.auto.transition/src/com/raytheon/uf/viz/auto/transition/AutoTransitionAction.java create mode 100644 cave/com.raytheon.uf.viz.auto.transition/src/com/raytheon/uf/viz/auto/transition/AutoTransitionDialog.java create mode 100644 cave/com.raytheon.uf.viz.auto.transition/src/com/raytheon/uf/viz/auto/transition/AutoTransitionResource.java create mode 100644 cave/com.raytheon.uf.viz.auto.transition/src/com/raytheon/uf/viz/auto/transition/AutoTransitionResourceData.java create mode 100644 cave/com.raytheon.uf.viz.auto.transition/src/com/raytheon/uf/viz/auto/transition/AverageValueCalculator.java create mode 100644 cave/com.raytheon.uf.viz.auto.transition/src/com/raytheon/uf/viz/auto/transition/ConfigureAutoTransitionAction.java diff --git a/cave/com.raytheon.uf.viz.auto.transition/.classpath b/cave/com.raytheon.uf.viz.auto.transition/.classpath new file mode 100644 index 0000000000..098194ca4b --- /dev/null +++ b/cave/com.raytheon.uf.viz.auto.transition/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/cave/com.raytheon.uf.viz.auto.transition/.project b/cave/com.raytheon.uf.viz.auto.transition/.project new file mode 100644 index 0000000000..b518b5544c --- /dev/null +++ b/cave/com.raytheon.uf.viz.auto.transition/.project @@ -0,0 +1,28 @@ + + + com.raytheon.uf.viz.auto.transition + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/cave/com.raytheon.uf.viz.auto.transition/META-INF/MANIFEST.MF b/cave/com.raytheon.uf.viz.auto.transition/META-INF/MANIFEST.MF new file mode 100644 index 0000000000..01b3a07e51 --- /dev/null +++ b/cave/com.raytheon.uf.viz.auto.transition/META-INF/MANIFEST.MF @@ -0,0 +1,16 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Automatic Transition +Bundle-SymbolicName: com.raytheon.uf.viz.auto.transition;singleton:=true +Bundle-Version: 1.15.0.qualifier +Bundle-Vendor: RAYTHEON +Bundle-RequiredExecutionEnvironment: JavaSE-1.7 +Require-Bundle: com.raytheon.viz.ui;bundle-version="1.15.1", + com.raytheon.uf.viz.core;bundle-version="1.15.1", + com.raytheon.uf.common.time;bundle-version="1.14.0", + com.raytheon.uf.common.geospatial;bundle-version="1.14.2", + org.eclipse.core.runtime;bundle-version="3.8.0", + com.raytheon.uf.viz.core.rsc;bundle-version="1.14.1", + javax.measure;bundle-version="1.0.0", + com.raytheon.uf.common.colormap;bundle-version="1.15.0" +Import-Package: com.raytheon.viz.core.rsc diff --git a/cave/com.raytheon.uf.viz.auto.transition/build.properties b/cave/com.raytheon.uf.viz.auto.transition/build.properties new file mode 100644 index 0000000000..e9863e281e --- /dev/null +++ b/cave/com.raytheon.uf.viz.auto.transition/build.properties @@ -0,0 +1,5 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml diff --git a/cave/com.raytheon.uf.viz.auto.transition/plugin.xml b/cave/com.raytheon.uf.viz.auto.transition/plugin.xml new file mode 100644 index 0000000000..688d75c9d0 --- /dev/null +++ b/cave/com.raytheon.uf.viz.auto.transition/plugin.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + diff --git a/cave/com.raytheon.uf.viz.auto.transition/src/com/raytheon/uf/viz/auto/transition/AutoTransitionAction.java b/cave/com.raytheon.uf.viz.auto.transition/src/com/raytheon/uf/viz/auto/transition/AutoTransitionAction.java new file mode 100644 index 0000000000..a740e8ad7d --- /dev/null +++ b/cave/com.raytheon.uf.viz.auto.transition/src/com/raytheon/uf/viz/auto/transition/AutoTransitionAction.java @@ -0,0 +1,135 @@ +/** + * 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.uf.viz.auto.transition; + +import com.raytheon.uf.common.serialization.SerializationException; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; +import com.raytheon.uf.viz.core.drawables.ResourcePair; +import com.raytheon.uf.viz.core.exception.VizException; +import com.raytheon.uf.viz.core.procedures.ProcedureXmlManager; +import com.raytheon.uf.viz.core.rsc.AbstractVizResource; +import com.raytheon.uf.viz.core.rsc.ResourceGroup; +import com.raytheon.uf.viz.core.rsc.interrogation.Interrogatable; +import com.raytheon.uf.viz.core.time.TimeMatchingJob; +import com.raytheon.viz.core.rsc.BlendedResource; +import com.raytheon.viz.core.rsc.BlendedResourceData; +import com.raytheon.viz.ui.cmenu.AbstractRightClickAction; + +/** + * + * Action which converts a {@link BlendedResource} into a + * {@link AutoTransitionResource}. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jul 09, 2015  4633     bsteffen    Initial creation
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class AutoTransitionAction extends AbstractRightClickAction { + + private static final transient IUFStatusHandler logger = UFStatus + .getHandler(AutoTransitionAction.class); + + public AutoTransitionAction() { + super(AS_CHECK_BOX); + } + + @Override + public boolean isHidden() { + BlendedResource resource = (BlendedResource) selectedRsc.getResource(); + for (ResourcePair pair : resource.getResourceList()) { + if (pair.getResource() instanceof Interrogatable) { + return false; + } + } + return true; + } + + private AutoTransitionResourceData getResourceData() { + if (selectedRsc.getResource() instanceof AutoTransitionResource) { + return ((AutoTransitionResource) selectedRsc.getResource()) + .getResourceData(); + } + return null; + } + + @Override + public boolean isChecked() { + AutoTransitionResourceData data = getResourceData(); + if (data != null) { + return data.isAutomaticSelection(); + } + return false; + } + + + @Override + public String getText() { + return "Automatic Transition"; + } + + @Override + public void run() { + AutoTransitionResourceData data = getResourceData(); + if (data != null) { + data.setAutomaticSelection(!data.isAutomaticSelection()); + return; + } + ProcedureXmlManager jaxb = ProcedureXmlManager.getInstance(); + // Put the base resource in a group so it can be serialized + ResourceGroup group = new ResourceGroup(); + group.getResourceList().add(selectedRsc); + try { + String baseXml = jaxb.marshal(group); + group = jaxb.unmarshal(ResourceGroup.class, baseXml); + } catch (SerializationException e) { + logger.error("Unable to initialize Automatic Transition.", e); + } + ResourcePair pair = group.getResourceList().get(0); + + AbstractVizResource oldResource = selectedRsc.getResource(); + AutoTransitionResourceData resourceData = new AutoTransitionResourceData( + (BlendedResourceData) pair.getResourceData()); + + selectedRsc.setResourceData(resourceData); + selectedRsc.setLoadProperties(pair.getLoadProperties()); + selectedRsc.setResource(null); + try { + selectedRsc.instantiateResource(oldResource.getDescriptor()); + } catch (VizException e) { + logger.error("Unable to initialize Automatic Transition.", e); + selectedRsc.setResource(oldResource); + return; + } + oldResource.dispose(); + TimeMatchingJob.scheduleTimeMatch(oldResource.getDescriptor()); + } + + +} diff --git a/cave/com.raytheon.uf.viz.auto.transition/src/com/raytheon/uf/viz/auto/transition/AutoTransitionDialog.java b/cave/com.raytheon.uf.viz.auto.transition/src/com/raytheon/uf/viz/auto/transition/AutoTransitionDialog.java new file mode 100644 index 0000000000..f22c291c43 --- /dev/null +++ b/cave/com.raytheon.uf.viz.auto.transition/src/com/raytheon/uf/viz/auto/transition/AutoTransitionDialog.java @@ -0,0 +1,249 @@ +/** + * 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.uf.viz.auto.transition; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.layout.RowData; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Layout; +import org.eclipse.swt.widgets.Scale; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +import com.raytheon.uf.common.colormap.prefs.ColorMapParameters; +import com.raytheon.uf.viz.auto.transition.AverageValueCalculator.CalculatorListener; +import com.raytheon.uf.viz.core.VizApp; +import com.raytheon.uf.viz.core.drawables.ResourcePair; +import com.raytheon.uf.viz.core.rsc.capabilities.ColorMapCapability; +import com.raytheon.viz.ui.dialogs.CaveSWTDialog; + +/** + * + * Dialog for configuring a {@link AutoTransitionResource}. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jul 09, 2015  4633     bsteffen    Initial creation
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class AutoTransitionDialog extends CaveSWTDialog implements + CalculatorListener { + + private final AutoTransitionResource resource; + + private int originalControlIndex; + + private double originalThreshold; + + private Combo resourceCombo; + + private Scale thresholdSlider; + + private Text thresholdText; + + private Text currentValueText; + + public AutoTransitionDialog(Shell parentShell,AutoTransitionResource resource) { + super(parentShell); + this.resource = resource; + setText("Configure Automatic Transition"); + } + + @Override + protected void initializeComponents(Shell shell) { + resource.getCalculator().addListener(this); + new Label(shell, SWT.NONE).setText("Control Resource: "); + resourceCombo = new Combo(shell, SWT.READ_ONLY); + for (ResourcePair pair : resource.getResourceList()) { + resourceCombo.add(pair.getResource().getName()); + } + resourceCombo.select(resource.getResourceData().getControlIndex()); + GridData layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false); + layoutData.horizontalSpan = 2; + resourceCombo.setLayoutData(layoutData); + + resourceCombo.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + resourceComboSelected(); + } + }); + + new Label(shell, SWT.NONE).setText("Threshold Value: "); + thresholdSlider = new Scale(shell, SWT.HORIZONTAL); + layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false); + layoutData.minimumWidth = 100; + thresholdSlider.setLayoutData(layoutData); + + originalThreshold = resource.getResourceData() + .getThresholdValue(); + originalControlIndex = resource.getResourceData().getControlIndex(); + + ResourcePair controlPair = resource.getResourceList().get(resource.getResourceData().getControlIndex()); + final ColorMapParameters params = controlPair.getResource().getCapability(ColorMapCapability.class).getColorMapParameters(); + + int sliderSpan = thresholdSlider.getMaximum() + - thresholdSlider.getMinimum(); + double paramSpan = params.getColorMapMax() - params.getColorMapMin(); + + thresholdSlider + .setSelection((int) (thresholdSlider.getMinimum() + sliderSpan + * (originalThreshold - params.getColorMapMin()) + / paramSpan)); + + + thresholdText = new Text(shell, SWT.BORDER | SWT.READ_ONLY); + layoutData = new GridData(SWT.FILL, SWT.CENTER, false, false); + layoutData.widthHint = 50; + thresholdText.setLayoutData(layoutData); + thresholdText.setText(Double.toString(originalThreshold)); + + thresholdSlider.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + sliderSelected(); + } + }); + new Label(shell, SWT.NONE).setText("Current Value: "); + currentValueText = new Text(shell, SWT.BORDER | SWT.READ_ONLY); + currentValueText + .setText(Double.toString(resource.getCalculator().getValue())); + layoutData = new GridData(SWT.LEFT, SWT.CENTER, false, false); + layoutData.widthHint = 50; + currentValueText.setLayoutData(layoutData); + Composite buttonComp = new Composite(shell, SWT.NONE); + layoutData = new GridData(SWT.RIGHT, SWT.CENTER, false, false); + layoutData.horizontalSpan = 3; + buttonComp.setLayoutData(layoutData); + + buttonComp.setLayout(new RowLayout(SWT.HORIZONTAL)); + Button okButton = new Button(buttonComp, SWT.PUSH); + okButton.setText("OK"); + okButton.setLayoutData(new RowData(100, SWT.DEFAULT)); + okButton.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + okPressed(); + } + + }); + + Button cancelButton = new Button(buttonComp, SWT.PUSH); + cancelButton.setText("Cancel"); + cancelButton.setLayoutData(new RowData(100, SWT.DEFAULT)); + cancelButton.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + cancelPressed(); + } + + }); + + } + + protected void resourceComboSelected() { + resource.getResourceData().setControlIndex( + resourceCombo.getSelectionIndex()); + sliderSelected(); + } + + protected void sliderSelected() { + ResourcePair controlPair = resource.getResourceList().get( + resource.getResourceData().getControlIndex()); + final ColorMapParameters params = controlPair.getResource() + .getCapability(ColorMapCapability.class) + .getColorMapParameters(); + + int sliderSpan = thresholdSlider.getMaximum() + - thresholdSlider.getMinimum(); + double paramSpan = params.getColorMapMax() - params.getColorMapMin(); + + double value = params.getColorMapMin() + + paramSpan + * (thresholdSlider.getSelection() - thresholdSlider + .getMinimum()) / sliderSpan; + resource.getResourceData().setThresholdValue(value); + resource.issueRefresh(); + thresholdText.setText(Double.toString(value)); + } + + protected void okPressed() { + close(); + } + + protected void cancelPressed() { + resource.getResourceData().setThresholdValue(originalThreshold); + resource.getResourceData().setControlIndex(originalControlIndex); + resource.issueRefresh(); + close(); + } + + @Override + protected Layout constructShellLayout() { + GridLayout mainLayout = new GridLayout(3, false); + mainLayout.marginHeight = 3; + mainLayout.marginWidth = 3; + return mainLayout; + } + + @Override + protected void disposed() { + super.disposed(); + resource.getCalculator().removeListener(this); + } + + @Override + public void calculationComplete() { + VizApp.runAsync(new Runnable() { + + @Override + public void run() { + if (currentValueText.isDisposed()) { + return; + } + currentValueText + .setText(Double.toString(resource.getCalculator().getValue())); + + } + + }); + } + +} diff --git a/cave/com.raytheon.uf.viz.auto.transition/src/com/raytheon/uf/viz/auto/transition/AutoTransitionResource.java b/cave/com.raytheon.uf.viz.auto.transition/src/com/raytheon/uf/viz/auto/transition/AutoTransitionResource.java new file mode 100644 index 0000000000..03701f84b9 --- /dev/null +++ b/cave/com.raytheon.uf.viz.auto.transition/src/com/raytheon/uf/viz/auto/transition/AutoTransitionResource.java @@ -0,0 +1,130 @@ +/** + * 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.uf.viz.auto.transition; + +import com.raytheon.uf.common.time.DataTime; +import com.raytheon.uf.viz.auto.transition.AverageValueCalculator.CalculatorListener; +import com.raytheon.uf.viz.core.IGraphicsTarget; +import com.raytheon.uf.viz.core.drawables.PaintProperties; +import com.raytheon.uf.viz.core.drawables.PaintStatus; +import com.raytheon.uf.viz.core.exception.VizException; +import com.raytheon.uf.viz.core.rsc.AbstractVizResource; +import com.raytheon.uf.viz.core.rsc.IResourceDataChanged.ChangeType; +import com.raytheon.uf.viz.core.rsc.LoadProperties; +import com.raytheon.uf.viz.core.rsc.capabilities.BlendableCapability; +import com.raytheon.viz.core.rsc.BlendedResource; + +/** + * + * Provides the ability to automatically select which resource to render based + * off the average value of a control resource. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jul 09, 2015  4633     bsteffen    Initial creation
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class AutoTransitionResource extends BlendedResource implements + CalculatorListener { + + private AverageValueCalculator calc = new AverageValueCalculator(); + + private AutoTransitionResourceData resourceData; + + public AutoTransitionResource(AutoTransitionResourceData data, + LoadProperties props) { + super(data, props); + this.resourceData = data; + } + + public AverageValueCalculator getCalculator() { + return calc; + } + + @Override + public void calculationComplete() { + issueRefresh(); + } + + @Override + protected void disposeInternal() { + super.disposeInternal(); + calc.removeListener(this); + } + + @Override + protected void initInternal(IGraphicsTarget target) throws VizException { + super.initInternal(target); + calc.addListener(this); + + } + + @Override + protected void paintInternal(IGraphicsTarget target, + PaintProperties paintProps) throws VizException { + if (resourceData.isAutomaticSelection()) { + int controlIndex = resourceData.getControlIndex(); + AbstractVizResource controller = getResourceList().get( + controlIndex).getResource(); + + DataTime time = paintProps.getFramesInfo().getTimeForResource( + controller); + + if (calc.calculate(controller, time, paintProps.getView() + .getExtent().clone()) == false) { + updatePaintStatus(PaintStatus.INCOMPLETE); + } + double avg = calc.getValue(); + if (!Double.isNaN(avg) && avg >= resourceData.getThresholdValue()) { + getCapability(BlendableCapability.class).toggle( + (controlIndex + 1) % 2); + } else { + getCapability(BlendableCapability.class).toggle(controlIndex); + } + } + super.paintInternal(target, paintProps); + } + + @Override + public AutoTransitionResourceData getResourceData() { + return resourceData; + } + + @Override + protected void resourceDataChanged(ChangeType type, Object updateObject) { + super.resourceDataChanged(type, updateObject); + if (updateObject instanceof BlendableCapability) { + int alphaStep = getCapability(BlendableCapability.class) + .getAlphaStep(); + if (alphaStep > 0 && alphaStep < BlendableCapability.BLEND_MAX) { + resourceData.setAutomaticSelection(false); + } + } + } + +} diff --git a/cave/com.raytheon.uf.viz.auto.transition/src/com/raytheon/uf/viz/auto/transition/AutoTransitionResourceData.java b/cave/com.raytheon.uf.viz.auto.transition/src/com/raytheon/uf/viz/auto/transition/AutoTransitionResourceData.java new file mode 100644 index 0000000000..9ef8ee14c3 --- /dev/null +++ b/cave/com.raytheon.uf.viz.auto.transition/src/com/raytheon/uf/viz/auto/transition/AutoTransitionResourceData.java @@ -0,0 +1,107 @@ +/** + * 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.uf.viz.auto.transition; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElement; + +import com.raytheon.uf.viz.core.drawables.IDescriptor; +import com.raytheon.uf.viz.core.drawables.ResourcePair; +import com.raytheon.uf.viz.core.exception.VizException; +import com.raytheon.uf.viz.core.rsc.LoadProperties; +import com.raytheon.uf.viz.core.rsc.ResourceList; +import com.raytheon.viz.core.rsc.BlendedResourceData; + +/** + * + * Serializable data for {@link AutoTransitionResource} + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jul 09, 2015  4633     bsteffen    Initial creation
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +@XmlAccessorType(XmlAccessType.NONE) +public class AutoTransitionResourceData extends BlendedResourceData { + + @XmlElement + private int controlIndex = 1; + + @XmlElement + private double thresholdValue = 30; + + @XmlElement + private boolean automaticSelection = true; + + public AutoTransitionResourceData() { + + } + + public AutoTransitionResourceData(BlendedResourceData blended) { + this.resourceList = new ResourceList(); + for (ResourcePair pair : blended.getResourceList()) { + ResourcePair newPair = new ResourcePair(); + newPair.setResourceData(pair.getResourceData()); + newPair.setLoadProperties(pair.getLoadProperties()); + newPair.setProperties(pair.getProperties()); + this.resourceList.add(pair); + } + } + + @Override + public AutoTransitionResource construct(LoadProperties loadProperties, + IDescriptor descriptor) throws VizException { + return new AutoTransitionResource(this, loadProperties); + } + + public int getControlIndex() { + return controlIndex; + } + + public void setControlIndex(int controlIndex) { + this.controlIndex = controlIndex; + } + + public double getThresholdValue() { + return thresholdValue; + } + + public void setThresholdValue(double thresholdValue) { + this.thresholdValue = thresholdValue; + } + + public boolean isAutomaticSelection() { + return automaticSelection; + } + + public void setAutomaticSelection(boolean automaticSelection) { + this.automaticSelection = automaticSelection; + } + +} diff --git a/cave/com.raytheon.uf.viz.auto.transition/src/com/raytheon/uf/viz/auto/transition/AverageValueCalculator.java b/cave/com.raytheon.uf.viz.auto.transition/src/com/raytheon/uf/viz/auto/transition/AverageValueCalculator.java new file mode 100644 index 0000000000..82cce3566f --- /dev/null +++ b/cave/com.raytheon.uf.viz.auto.transition/src/com/raytheon/uf/viz/auto/transition/AverageValueCalculator.java @@ -0,0 +1,231 @@ +/** + * 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.uf.viz.auto.transition; + +import java.util.Set; +import java.util.concurrent.CopyOnWriteArraySet; + +import javax.measure.Measure; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; + +import com.raytheon.uf.common.geospatial.ReferencedCoordinate; +import com.raytheon.uf.common.time.DataTime; +import com.raytheon.uf.viz.core.IExtent; +import com.raytheon.uf.viz.core.drawables.IDescriptor; +import com.raytheon.uf.viz.core.rsc.AbstractVizResource; +import com.raytheon.uf.viz.core.rsc.interrogation.Interrogatable; +import com.raytheon.uf.viz.core.rsc.interrogation.Interrogator; +import com.vividsolutions.jts.geom.Coordinate; + +/** + * + * Async calculation of the average value of a resource. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jul 10, 2015  4633     bsteffen    Initial creation
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class AverageValueCalculator extends Job { + + private static final int NUM_POINTS = 5; + + private final Object lock = new Object(); + + private final Set listeners = new CopyOnWriteArraySet<>(); + + private Task nextTask; + + private Task lastTask; + + private double value = Double.NaN; + + public AverageValueCalculator() { + super("Calculating Resource Average Value"); + } + + public boolean calculate(AbstractVizResource resource, DataTime time, + IExtent extent) { + Task newTask = new Task(resource, time, extent); + synchronized (lock) { + if (newTask.equals(lastTask)) { + nextTask = null; + return true; + } else { + nextTask = newTask; + schedule(); + return false; + } + } + } + + public double getValue() { + return value; + } + + @Override + protected IStatus run(IProgressMonitor monitor) { + Task task = null; + synchronized (lock) { + task = nextTask; + } + if (task == null) { + return Status.OK_STATUS; + } + double value = calculateAverage(task.resource, task.time, task.extent); + synchronized (lock) { + if (task.equals(nextTask)) { + this.value = value; + lastTask = task; + nextTask = null; + } + } + for (CalculatorListener listener : listeners) { + listener.calculationComplete(); + } + return Status.OK_STATUS; + } + + public void addListener(CalculatorListener listener) { + listeners.add(listener); + } + + public void removeListener(CalculatorListener listener) { + listeners.remove(listener); + } + + /** + * Calculate the average value of a resource at a particular time for the + * specified area. Currently this just samples 25 points evenly spaced + * throughout the visible area as proposed by Jordan Gerth. + */ + public static double calculateAverage(AbstractVizResource resource, + DataTime time, IExtent extent) { + if (!(resource instanceof Interrogatable)) { + return Double.NaN; + } + Interrogatable interrogatable = (Interrogatable) resource; + IDescriptor descriptor = resource.getDescriptor(); + double sum = 0.0; + int k = 0; + for (int i = 1; i < NUM_POINTS; i++) { + for (int j = 1; j < NUM_POINTS; j++) { + double mx = extent.getMinX() + + (extent.getMaxX() - extent.getMinX()) / NUM_POINTS + * i; + double my = extent.getMinY() + + (extent.getMaxY() - extent.getMinY()) / NUM_POINTS + * j; + double[] p2w = descriptor.pixelToWorld(new double[] { mx, my }); + ReferencedCoordinate coord = new ReferencedCoordinate( + new Coordinate(p2w[0], p2w[1])); + Measure value = Interrogator.interrogateSingle( + interrogatable, coord, time, Interrogator.VALUE); + if (value != null && value.getValue() instanceof Number) { + double measuredValue = ((Number) value.getValue()) + .doubleValue(); + if (!Double.isNaN(measuredValue)) { + sum += measuredValue; + k++; + } + } + } + } + if (k > NUM_POINTS) { + return sum / k; + } else { + return Double.NaN; + } + } + + private static class Task { + + public final AbstractVizResource resource; + + public final DataTime time; + + public final IExtent extent; + + public Task(AbstractVizResource resource, DataTime time, + IExtent extent) { + this.resource = resource; + this.time = time; + this.extent = extent; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + + ((extent == null) ? 0 : extent.hashCode()); + result = prime * result + + ((resource == null) ? 0 : resource.hashCode()); + result = prime * result + ((time == null) ? 0 : time.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Task other = (Task) obj; + if (extent == null) { + if (other.extent != null) + return false; + } else if (!extent.equals(other.extent)) + return false; + if (resource == null) { + if (other.resource != null) + return false; + } else if (!resource.equals(other.resource)) + return false; + if (time == null) { + if (other.time != null) + return false; + } else if (!time.equals(other.time)) + return false; + return true; + } + + } + + public static interface CalculatorListener{ + + public void calculationComplete(); + } + +} diff --git a/cave/com.raytheon.uf.viz.auto.transition/src/com/raytheon/uf/viz/auto/transition/ConfigureAutoTransitionAction.java b/cave/com.raytheon.uf.viz.auto.transition/src/com/raytheon/uf/viz/auto/transition/ConfigureAutoTransitionAction.java new file mode 100644 index 0000000000..20257c9ee0 --- /dev/null +++ b/cave/com.raytheon.uf.viz.auto.transition/src/com/raytheon/uf/viz/auto/transition/ConfigureAutoTransitionAction.java @@ -0,0 +1,73 @@ +/** + * 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.uf.viz.auto.transition; + +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.PlatformUI; + +import com.raytheon.viz.ui.cmenu.AbstractRightClickAction; + +/** + * + * Action which opens the {@link AutoTransitionDialog}. + * + *
+ * 
+ * SOFTWARE HISTORY
+ * 
+ * Date          Ticket#  Engineer    Description
+ * ------------- -------- ----------- --------------------------
+ * Jul 09, 2015  4633     bsteffen    Initial creation
+ * 
+ * 
+ * + * @author bsteffen + * @version 1.0 + */ +public class ConfigureAutoTransitionAction extends AbstractRightClickAction { + + private AutoTransitionResourceData getResourceData() { + if (selectedRsc.getResource() instanceof AutoTransitionResource) { + return ((AutoTransitionResource) selectedRsc.getResource()) + .getResourceData(); + } + return null; + } + + @Override + public boolean isHidden() { + return !getResourceData().isAutomaticSelection(); + } + + @Override + public String getText() { + return "Configure Automatic Transition"; + } + + @Override + public void run() { + AutoTransitionResource resource = (AutoTransitionResource) selectedRsc + .getResource(); + Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow() + .getShell(); + new AutoTransitionDialog(shell, resource).open(); + } + +} diff --git a/cave/com.raytheon.viz.satellite.feature/feature.xml b/cave/com.raytheon.viz.satellite.feature/feature.xml index 2b13b23f1b..c078f81619 100644 --- a/cave/com.raytheon.viz.satellite.feature/feature.xml +++ b/cave/com.raytheon.viz.satellite.feature/feature.xml @@ -35,4 +35,10 @@ install-size="0" version="0.0.0"/> + +