From 3e4dd77908f3e28689471b5ed21103fb23daa92e Mon Sep 17 00:00:00 2001 From: Douglas Gillespie <50671166+douggillespie@users.noreply.github.com> Date: Tue, 19 Dec 2023 16:41:57 +0000 Subject: [PATCH 1/2] Logger form plotting Fixed logger form plotting in Viewer so that points can find their correct GPS position (based on time) --- src/loggerForms/FormDescription.java | 37 ++++++++++++++++++++ src/loggerForms/FormsDataUnit.java | 4 ++- src/loggerForms/FormsLogging.java | 2 +- src/loggerForms/LoggerForm.java | 50 ++++++++++++++-------------- 4 files changed, 66 insertions(+), 27 deletions(-) diff --git a/src/loggerForms/FormDescription.java b/src/loggerForms/FormDescription.java index b3d55501..95b204cb 100644 --- a/src/loggerForms/FormDescription.java +++ b/src/loggerForms/FormDescription.java @@ -38,6 +38,14 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; +import Array.streamerOrigin.GPSOriginMethod; +import Array.streamerOrigin.GPSOriginSystem; +import Array.streamerOrigin.HydrophoneOriginMethod; +import Array.streamerOrigin.HydrophoneOriginMethods; +import Array.streamerOrigin.OriginIterator; +import Array.streamerOrigin.StaticOriginSystem; +import GPS.GpsData; + import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; @@ -49,6 +57,7 @@ import pamScrollSystem.ScrollPaneAddon; import PamView.PamTabPanel; import PamView.panel.PamPanel; import PamView.symbol.StandardSymbolManager; +import PamguardMVC.PamDataBlock; import PamguardMVC.PamDataUnit; import PamController.PamControlledUnitSettings; import PamController.PamController; @@ -2021,4 +2030,32 @@ public class FormDescription implements Cloneable, Comparable { public void setNeedsUDFSave(boolean needsUDFSave) { this.needsUDFSave = needsUDFSave; } + + public GpsData getOriginLatLong(FormsDataUnit formsDataUnit) { + GpsData gps = getOrigin(GPSOriginSystem.class, formsDataUnit); + if (gps != null) { + return gps; + } + gps = getOrigin(StaticOriginSystem.class, formsDataUnit); + return gps; + } + + private GpsData getOrigin(Class originClass, FormsDataUnit formsDataUnit) { + HydrophoneOriginMethods origins = HydrophoneOriginMethods.getInstance(); + HydrophoneOriginMethod origin = origins.getMethod(GPSOriginMethod.class, null, null); + if (origin == null) { + return null; + } + OriginIterator gpsIter = origin.getGpsDataIterator(PamDataBlock.ITERATOR_END); + GpsData prev = null; + while (gpsIter.hasPrevious()) { + prev = gpsIter.previous(); + if (prev.getTimeInMillis() < formsDataUnit.getTimeMilliseconds()) { + break; + } + } + return prev; + } + + } diff --git a/src/loggerForms/FormsDataUnit.java b/src/loggerForms/FormsDataUnit.java index 963c6374..32ab905d 100644 --- a/src/loggerForms/FormsDataUnit.java +++ b/src/loggerForms/FormsDataUnit.java @@ -87,7 +87,9 @@ public class FormsDataUnit extends PamDataUnit { * we want to as a reference, etc. */ if (recalculate || formOriginLatLong == null) { - formOriginLatLong = loggerForm.getOriginLatLong(this); + if (formDescription != null) { + formOriginLatLong = formDescription.getOriginLatLong(this); + } } return formOriginLatLong; } diff --git a/src/loggerForms/FormsLogging.java b/src/loggerForms/FormsLogging.java index 5420f3a9..64e0d8e6 100644 --- a/src/loggerForms/FormsLogging.java +++ b/src/loggerForms/FormsLogging.java @@ -112,7 +112,7 @@ public class FormsLogging extends SQLLogging { // } // } - +// formDescription.getf FormsDataUnit formsDataUnit = new FormsDataUnit(null, timeMilliseconds, formDescription, formData); formsDataUnit.setDatabaseIndex(databaseIndex); diff --git a/src/loggerForms/LoggerForm.java b/src/loggerForms/LoggerForm.java index 11f562a7..58215478 100644 --- a/src/loggerForms/LoggerForm.java +++ b/src/loggerForms/LoggerForm.java @@ -104,7 +104,7 @@ public class LoggerForm{ private CounterControl counter; - private HydrophoneOriginMethods origins = HydrophoneOriginMethods.getInstance(); +// private HydrophoneOriginMethods origins = HydrophoneOriginMethods.getInstance(); /** * @return the hasCounter @@ -911,30 +911,30 @@ public class LoggerForm{ return saveButton; } - public GpsData getOriginLatLong(FormsDataUnit formsDataUnit) { - GpsData gps = getOrigin(GPSOriginSystem.class, formsDataUnit); - if (gps != null) { - return gps; - } - gps = getOrigin(StaticOriginSystem.class, formsDataUnit); - return gps; - } - - private GpsData getOrigin(Class originClass, FormsDataUnit formsDataUnit) { - HydrophoneOriginMethod origin = origins.getMethod(GPSOriginMethod.class, null, null); - if (origin == null) { - return null; - } - OriginIterator gpsIter = origin.getGpsDataIterator(PamDataBlock.ITERATOR_END); - GpsData prev = null; - while (gpsIter.hasPrevious()) { - prev = gpsIter.previous(); - if (prev.getTimeInMillis() < formsDataUnit.getTimeMilliseconds()) { - break; - } - } - return prev; - } +// public GpsData getOriginLatLong(FormsDataUnit formsDataUnit) { +// GpsData gps = getOrigin(GPSOriginSystem.class, formsDataUnit); +// if (gps != null) { +// return gps; +// } +// gps = getOrigin(StaticOriginSystem.class, formsDataUnit); +// return gps; +// } +// +// private GpsData getOrigin(Class originClass, FormsDataUnit formsDataUnit) { +// HydrophoneOriginMethod origin = origins.getMethod(GPSOriginMethod.class, null, null); +// if (origin == null) { +// return null; +// } +// OriginIterator gpsIter = origin.getGpsDataIterator(PamDataBlock.ITERATOR_END); +// GpsData prev = null; +// while (gpsIter.hasPrevious()) { +// prev = gpsIter.previous(); +// if (prev.getTimeInMillis() < formsDataUnit.getTimeMilliseconds()) { +// break; +// } +// } +// return prev; +// } // /** From 639f33607e5fb2619a4d576c21daba50782e1bd3 Mon Sep 17 00:00:00 2001 From: Douglas Gillespie <50671166+douggillespie@users.noreply.github.com> Date: Wed, 20 Dec 2023 09:05:33 +0000 Subject: [PATCH 2/2] Fix small bugs --- src/Acquisition/FolderInputSystem.java | 3 +++ src/Map/MapPanel.java | 1 + src/loggerForms/FormsControl.java | 26 +++++++++++++++++++ src/loggerForms/FormsDataDisplayTable.java | 19 +------------- src/loggerForms/controls/CheckboxControl.java | 3 ++- .../dataselect/FormDataSelector.java | 2 +- 6 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/Acquisition/FolderInputSystem.java b/src/Acquisition/FolderInputSystem.java index f3a33ed4..93107b31 100644 --- a/src/Acquisition/FolderInputSystem.java +++ b/src/Acquisition/FolderInputSystem.java @@ -318,6 +318,9 @@ public class FolderInputSystem extends FileInputSystem implements PamSettings, D } selection = folderInputParameters.getSelectedFiles(); } + if (selection == null) { + return 0; + } if (selection.length > 0) { System.out.println("FolderInputSystem.makeSelFileList(): Searching for sound files in " + selection[0]); } diff --git a/src/Map/MapPanel.java b/src/Map/MapPanel.java index e3122141..225f01ef 100644 --- a/src/Map/MapPanel.java +++ b/src/Map/MapPanel.java @@ -1096,6 +1096,7 @@ public class MapPanel extends JPanelWithPamKey implements PamObserver, ColorMana return; } ds = dataBlock.getDataSelector(simpleMapRef.getUnitName(), false, DATASELECTNAME); +// ds = null; ArrayList dataCopy = dataBlock.getDataCopy(earliestToPlot, now, true, ds); duIterator = dataCopy.listIterator(); while (duIterator.hasNext()) { diff --git a/src/loggerForms/FormsControl.java b/src/loggerForms/FormsControl.java index e88c1343..94cf9112 100644 --- a/src/loggerForms/FormsControl.java +++ b/src/loggerForms/FormsControl.java @@ -614,6 +614,32 @@ public class FormsControl extends PamControlledUnit { return new ModuleStatus(ModuleStatus.STATUS_OK); } + + /** + * Some things that are meant to be boolean are coming out as int or string so + * need to do some type checking. + * @param value + * @return + */ + public static Boolean checkBadBoolean(Object value) { + if (value instanceof Boolean) { + return (Boolean) value; + } + if (value == null) { + return null; + } + if (value instanceof String) { + String str = (String) value; + str = str.strip(); + return str.equals("1") || str.toLowerCase().equals("false"); + } + if (value instanceof Integer) { + int val = (Integer) value; + return val != 0; + } + + return null; + } // @Override // public Serializable getSettingsReference() { // return (Serializable) dummyParams; diff --git a/src/loggerForms/FormsDataDisplayTable.java b/src/loggerForms/FormsDataDisplayTable.java index 97720f23..26e2f5b3 100644 --- a/src/loggerForms/FormsDataDisplayTable.java +++ b/src/loggerForms/FormsDataDisplayTable.java @@ -213,7 +213,7 @@ public class FormsDataDisplayTable { if (getColumnClass(columnIndex) == Boolean.class) { if (value instanceof Boolean == false) { // System.out.println("Bad boolean value: " + value); - return interpretBadBoolean(value); + return FormsControl.checkBadBoolean(value); } } return value; @@ -260,23 +260,6 @@ public class FormsDataDisplayTable { } - public Boolean interpretBadBoolean(Object value) { - if (value == null) { - return null; - } - if (value instanceof String) { - String str = (String) value; - str = str.strip(); - return str.equals("1") || str.toLowerCase().equals("false"); - } - if (value instanceof Integer) { - int val = (Integer) value; - return val != 0; - } - - return null; - } - /** * Called when data have changed in the datablock. diff --git a/src/loggerForms/controls/CheckboxControl.java b/src/loggerForms/controls/CheckboxControl.java index 3be6dd8f..a0ec06e0 100644 --- a/src/loggerForms/controls/CheckboxControl.java +++ b/src/loggerForms/controls/CheckboxControl.java @@ -9,6 +9,7 @@ import NMEA.NMEADataBlock; import NMEA.NMEADataUnit; import PamView.dialog.PamCheckBox; import PamView.dialog.PamLabel; +import loggerForms.FormsControl; import loggerForms.LoggerForm; import loggerForms.controlDescriptions.ControlDescription; @@ -41,7 +42,7 @@ public class CheckboxControl extends LoggerControl { return; } try { - checkBox.setSelected((Boolean) data); + checkBox.setSelected(FormsControl.checkBadBoolean(data)); } catch(ClassCastException e) { e.printStackTrace(); diff --git a/src/loggerForms/dataselect/FormDataSelector.java b/src/loggerForms/dataselect/FormDataSelector.java index de627d29..926e68cb 100644 --- a/src/loggerForms/dataselect/FormDataSelector.java +++ b/src/loggerForms/dataselect/FormDataSelector.java @@ -70,7 +70,7 @@ public class FormDataSelector extends DataSelector { @Override public double scoreData(PamDataUnit pamDataUnit) { if (controlDataSelector == null) { - return 0; + return 1; } Object[] formData = null; if (pamDataUnit instanceof FormsDataUnit) {