Skip to content

Commit

Permalink
Merge branch 'develop' into 4387_video_recording
Browse files Browse the repository at this point in the history
  • Loading branch information
saulhidalgoaular committed Apr 3, 2024
2 parents c568c7c + e41d5b8 commit 1c7d13c
Show file tree
Hide file tree
Showing 11 changed files with 887 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@
import MWC.GUI.Layers;
import MWC.GUI.PlainChart;
import MWC.GUI.Plottable;
import MWC.GUI.ToolParent;
import MWC.GUI.Canvas.MetafileCanvas;
import MWC.GUI.Tools.Chart.HitTester;
import MWC.GUI.Tools.Chart.RightClickEdit;
Expand Down Expand Up @@ -919,11 +920,15 @@ protected void paintBackground(final CanvasType dest) {
// we start plotting the images
proj.toScreen(proj.getDataArea().getCentre());

final BufferedImage img = GeoToolsPainter.drawAwtImage(width, height, gp,
dest.getBackgroundColor());
if (img != null) {
final ImageData swtImage = awtToSwt(img, width + 1, height + 1);
_swtImage = new Image(Display.getCurrent(), swtImage);
try {
final BufferedImage img = GeoToolsPainter.drawAwtImage(width, height, gp,
dest.getBackgroundColor());
if (img != null) {
final ImageData swtImage = awtToSwt(img, width + 1, height + 1);
_swtImage = new Image(Display.getCurrent(), swtImage);
}
} catch (Exception ee) {
CorePlugin.logError(ToolParent.ERROR, "Error creating image", ee);
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion org.mwc.debrief.core/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
<contentTypeBinding contentTypeId="org.mwc.debrief.contenttype.DebriefPlot"/>
<contentTypeBinding contentTypeId="org.mwc.debrief.contenttype.DebriefPlotGPX"/>
<contentTypeBinding contentTypeId="org.mwc.debrief.contenttype.OTH_G_Log"/>
<contentTypeBinding contentTypeId="org.mwc.debrief.contenttype.CLog"/>
</editor>
</extension>

Expand All @@ -57,6 +56,8 @@
<contentTypeBinding contentTypeId="org.mwc.debrief.contenttype.CSV_GZ_LogFile"/>
<contentTypeBinding contentTypeId="org.mwc.debrief.contenttype.SATCTrackFile"/>
<contentTypeBinding contentTypeId="org.mwc.debrief.contenttype.SATCSampleTrackFile"/>
<contentTypeBinding contentTypeId="org.mwc.debrief.contenttype.CLog"/>
<contentTypeBinding contentTypeId="org.mwc.debrief.contenttype.NMEA_Radar"/>
</editor>
</extension>

Expand Down Expand Up @@ -106,6 +107,10 @@
name="CLog file" priority="high">
<describer class="org.mwc.debrief.core.contenttype.CLog_ContentDescriber"/>
</content-type>
<content-type id="org.mwc.debrief.contenttype.NMEA_Radar" file-extensions="txt"
name="CLog file" priority="high">
<describer class="org.mwc.debrief.core.contenttype.NMEA_Radar_ContentDescriber"/>
</content-type>
<content-type id="org.mwc.debrief.contenttype.LogTrackFile" file-extensions="csv"
name="S2087 Context Track File (Log)" priority="normal"> </content-type>
<content-type id="org.mwc.debrief.contenttype.AISTrackFile"
Expand Down Expand Up @@ -207,6 +212,10 @@
<loader class="org.mwc.debrief.core.loaders.CLog_Loader" extensions="txt" first_line="Unknown" name="CLog File"
/>
</extension>
<extension point="org.mwc.debrief.core.DebriefPlotLoader">
<loader class="org.mwc.debrief.core.loaders.NMEA_Radar_Loader" extensions="txt" name="NMEA Radar File"
/>
</extension>
<extension point="org.mwc.debrief.core.DebriefPlotLoader">
<loader class="org.mwc.debrief.core.loaders.CSV_GZ_Loader" extensions="gz" name="Compressed CLog File"
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,115 @@ public IStatus undo(final IProgressMonitor monitor, final IAdaptable info) throw
}
}


private static class SpatialSplitTracksOperation extends CMAPOperation {

/**
* the parent to update on completion
*/
private final Layers _layers;
private final List<TrackWrapper> _tracks;
private final double _factor;
private final HashMap<TrackWrapper, List<TrackSegment>> _trackChanges;

public SpatialSplitTracksOperation(final String title, final Layers theLayers, final List<TrackWrapper> tracks,
final double factor) {
super(title);
_layers = theLayers;
_tracks = tracks;
_factor = factor;
_trackChanges = new HashMap<TrackWrapper, List<TrackSegment>>();
}

@Override
public boolean canRedo() {
return true;
}

@Override
public boolean canUndo() {
return true;
}

@Override
public IStatus execute(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
boolean modified = false;
_trackChanges.clear();

// loop through the tracks
for (final TrackWrapper track : _tracks) {
final List<TrackSegment> newSegments = TrackWrapper_Support.splitTrackAtSpatialJumps(track, _factor);
modified = modified || !newSegments.isEmpty();
_trackChanges.put(track, newSegments);
}

// did anything get changed
if (modified) {
fireModified();
}
return Status.OK_STATUS;
}

private void fireModified() {
_layers.fireExtended();
}

@Override
public IStatus undo(final IProgressMonitor monitor, final IAdaptable info) throws ExecutionException {
int numChanges = 0;

// ok, merge the segments
for (final TrackWrapper track : _trackChanges.keySet()) {
final List<TrackSegment> splits = _trackChanges.get(track);

final TrackSegment target = splits.get(0);

final SegmentList existingSegments = track.getSegments();

int ctr = 0;
for (final TrackSegment segment : splits) {
if (segment != target) {
// check this is an existing segment for this track
// if we've performed several split/merge operations
// the list may now be out of sync
if (existingSegments.contains(segment)) {
// remove the segment
track.removeElement(segment);

final Enumeration<Editable> fixes = segment.elements();
while (fixes.hasMoreElements()) {
final FixWrapper fix = (FixWrapper) fixes.nextElement();
target.addFix(fix);
}
ctr++;
}
}
}

numChanges += ctr;
}

final boolean modified = numChanges > 0;

// did anything get changed
if (modified) {
fireModified();
}
return Status.OK_STATUS;
}
}
public static class TestSplittingTracks extends TestCase {
private static FixWrapper getFix(final long dtg, final double course, final double speed) {
final Fix theFix = new Fix(new HiResDate(dtg), new WorldLocation(2, 2, 2), course,
Conversions.Kts2Yps(speed));
final FixWrapper res = new FixWrapper(theFix);
return res;
}
private static FixWrapper getFix2(final long dtg, final double lat, final double lng) {
final Fix theFix = new Fix(new HiResDate(dtg), new WorldLocation(lat, lng, 0), 0d,0d);
final FixWrapper res = new FixWrapper(theFix);
return res;
}

private static TrackWrapper getOne() {
final TrackWrapper tOne = new TrackWrapper();
Expand Down Expand Up @@ -196,6 +298,24 @@ private static TrackWrapper getTwo() {
return tTwo;
}

private static TrackWrapper getThree() {
final TrackWrapper tThree = new TrackWrapper();
tThree.setName("t-3");
tThree.addFix(getFix2(1000, 22, 33));
tThree.addFix(getFix2(2000, 22, 34));
tThree.addFix(getFix2(2100, 22, 35));
tThree.addFix(getFix2(4000, 22, 36));
tThree.addFix(getFix2(5000, 22, 30));
tThree.addFix(getFix2(8000, 22, 31));
tThree.addFix(getFix2(9000, 22, 32));
tThree.addFix(getFix2(10000, 22, 38));
tThree.addFix(getFix2(11100, 22, 39));
tThree.addFix(getFix2(12000, 22, 38));
tThree.addFix(getFix2(13000, 22, 37));
tThree.addFix(getFix2(14000, 22, 36));
return tThree;
}

public void testSplitOperation() throws ExecutionException {

final TrackWrapper tOne = getOne();
Expand Down Expand Up @@ -234,6 +354,24 @@ public void testSplitOperation() throws ExecutionException {
assertEquals("correct positions", 14, tOne.numFixes());
assertEquals("correct positions", 12, tTwo.numFixes());
}


public void testSpatialSplitOperation1() throws ExecutionException {

final TrackWrapper tThree = getThree();
final List<TrackWrapper> tracks = new ArrayList<TrackWrapper>();
tracks.add(tThree);
List<TrackSegment> segments = TrackWrapper_Support.splitTrackAtSpatialJumps(tThree, 3d);
assertEquals("three legs", 3, segments.size());
}
public void testSpatialSplitOperation2() throws ExecutionException {

final TrackWrapper tTwo = getTwo();
final List<TrackWrapper> tracks = new ArrayList<TrackWrapper>();
tracks.add(tTwo);
List<TrackSegment> segments = TrackWrapper_Support.splitTrackAtSpatialJumps(tTwo, 3d);
assertEquals("three legs", 0, segments.size());
}
}

@Override
Expand Down Expand Up @@ -268,11 +406,12 @@ public void generate(final IMenuManager parent, final Layers theLayers, final La

final String msg = tracks.size() > 1 ? "tracks" : "track";

final String fullMsg = "Split " + msg + " into segments on gaps over...";
final String fullMsg1 = "Split " + msg + " into segments on gaps over...";

final MenuManager listing = new MenuManager(fullMsg);
final MenuManager listing1 = new MenuManager(fullMsg1);

final HashMap<Long, String> choices = new HashMap<Long, String>();
choices.put(10 * 1000L, "10 Seconds");
choices.put(60 * 1000L, "1 Minute");
choices.put(60 * 60 * 1000L, "1 Hour");
choices.put(24 * 60 * 60 * 1000L, "1 Day");
Expand All @@ -291,9 +430,30 @@ public void run() {
CorePlugin.run(theAction);
}
};
listing.add(doMerge);
listing1.add(doMerge);
}
parent.add(listing1);

// now the spatial distance factor
final String fullMsg2 = "Split " + msg + " into segments where distance increases by factor of ...";

final MenuManager listing2 = new MenuManager(fullMsg2);

final long factors[] = {2, 3, 5, 10, 20};
for (final Long factor : factors) {

// create this operation
final Action doMerge = new Action("" + factor) {
@Override
public void run() {
final IUndoableOperation theAction = new SpatialSplitTracksOperation(
"Split tracks where distance increases by factor of " + factor, theLayers, tracks, factor);
CorePlugin.run(theAction);
}
};
listing2.add(doMerge);
}
parent.add(listing);
parent.add(listing2);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*******************************************************************************
* Debrief - the Open Source Maritime Analysis Application
* http://debrief.info
*
* (C) 2000-2020, Deep Blue C Technology Ltd
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the Eclipse Public License v1.0
* (http://www.eclipse.org/legal/epl-v10.html)
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*******************************************************************************/
package org.mwc.debrief.core.contenttype;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.concurrent.atomic.AtomicBoolean;

import org.eclipse.core.internal.content.TextContentDescriber;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.content.IContentDescription;
import org.mwc.cmap.core.CorePlugin;

import Debrief.ReaderWriter.FlatFile.NMEA_Radar_FileImporter;
import MWC.GUI.ErrorLogger;

/**
* import format test for SATC export files
*
* @author ian
*
*/
@SuppressWarnings("restriction")
public class NMEA_Radar_ContentDescriber extends TextContentDescriber {

@Override
public int describe(final InputStream contents, final IContentDescription description) throws IOException {
BufferedReader r = null;
final AtomicBoolean res = new AtomicBoolean();
try {
r = new BufferedReader(new InputStreamReader(contents));
final ErrorLogger logger = CorePlugin.getToolParent();
final boolean canRead = NMEA_Radar_FileImporter.canLoad(logger, r);
res.set(canRead);
} catch (final Exception e) {
CorePlugin.logError(IStatus.ERROR, "NMEA Radar content type error", e);
} finally {
try {
if (r != null)
r.close();
} catch (final IOException e) {
CorePlugin.logError(IStatus.ERROR, "Couldn't close file", e);
}
}
if (res.get()) {
return VALID;
} else {
return super.describe(contents, description);
}
}

}

0 comments on commit 1c7d13c

Please sign in to comment.