From e972fa293eef396fd8c6acec4e078c6ee68c4182 Mon Sep 17 00:00:00 2001
From: Lewin Probst <info@emirror.de>
Date: Fri, 22 Nov 2019 12:06:07 +0100
Subject: [PATCH] Added getSoundsourcesWithAppliedToa function. Bugfixes.

---
 .../applySoundSourceToSelectedPoints.m        |  2 +-
 .../+controller/+track/+parameter/open.m      | 18 +++------------
 .../+controller/+track/+parameter/updateGui.m |  6 ++---
 .../+track/+trajectoryOutput/plot.m           |  3 +++
 .../tableGeneratedTracksSelect.m              |  3 +++
 .../+track/getInvolvedSoundsources.m          | 22 +++++++++----------
 .../getSoundsourcesWithAppliedToa.m           | 21 ++++++++++++++++++
 lib/+artoa/+gui/+track/trajectoryOutput.m     |  3 +++
 .../+trajectory/plotTimeDivergenceToGps.m     |  3 +++
 9 files changed, 50 insertions(+), 31 deletions(-)
 create mode 100644 lib/+artoa/+controller/getSoundsourcesWithAppliedToa.m

diff --git a/lib/+artoa/+controller/+edit/+timeOfArrival/applySoundSourceToSelectedPoints.m b/lib/+artoa/+controller/+edit/+timeOfArrival/applySoundSourceToSelectedPoints.m
index 1d1bbc9..f3d9d71 100644
--- a/lib/+artoa/+controller/+edit/+timeOfArrival/applySoundSourceToSelectedPoints.m
+++ b/lib/+artoa/+controller/+edit/+timeOfArrival/applySoundSourceToSelectedPoints.m
@@ -38,7 +38,7 @@ artoaWorkspace.toaData.soundSource( ...
 ) = soundsources(index);
 
 
-% Update status to selected
+%% Update status to selected
 artoa.controller.edit.timeOfArrival.applyStatusToSelectedPoints(1);
 
 %% Update duplicate toa table
diff --git a/lib/+artoa/+controller/+track/+parameter/open.m b/lib/+artoa/+controller/+track/+parameter/open.m
index d5a2e26..aab05a9 100644
--- a/lib/+artoa/+controller/+track/+parameter/open.m
+++ b/lib/+artoa/+controller/+track/+parameter/open.m
@@ -42,25 +42,13 @@ artoa.gui.track.parameter( ...
     artoaWorkspace.defaults.soundspeedMethods ...
 );
 
-%% Get involved
-soundsourceNames = fieldnames(artoaWorkspace.filteredSoundsources);
-appliedSoundsources = {};
-involvedSoundsources = struct();
-for i = 1:length(soundsourceNames)
-    if artoa.soundsources.hasAppliedToa(soundsourceNames{i}, artoaWorkspace.toaData.soundSource)
-        extracted = artoa.data.extractSoundsourcesFromStruct( ...
-            soundsourceNames{i}, ...
-            artoaWorkspace.filteredSoundsources ...
-        );
-        involvedSoundsources.(soundsourceNames{i}) = extracted;
-        clear extracted;
-    end
-end
+%% Get sources with applied toa
+soundsourcesWithAppliedToa = artoa.controller.getSoundsourcesWithAppliedToa();
 
 %% Setup sound source offsets table
 % initialize sound source offsets
 artoaGui.trackParameter.tableSoundSourceOffsets.RowName = fieldnames( ...
-    involvedSoundsources ...
+    soundsourcesWithAppliedToa ...
 );
 
 
diff --git a/lib/+artoa/+controller/+track/+parameter/updateGui.m b/lib/+artoa/+controller/+track/+parameter/updateGui.m
index 501be77..cf03a6b 100644
--- a/lib/+artoa/+controller/+track/+parameter/updateGui.m
+++ b/lib/+artoa/+controller/+track/+parameter/updateGui.m
@@ -38,9 +38,9 @@ for i = 1:length(fieldNames)
         case 'soundsourceOffsets'
             artoaGui.trackParameter.tableSoundSourceOffsets.Data = ...
                 artoa.soundsources.createOffsetsCell( ...
-                currentValue, ...
-                artoaGui.trackParameter.tableSoundSourceOffsets.RowName ...
-            );
+                    currentValue, ...
+                    artoaGui.trackParameter.tableSoundSourceOffsets.RowName ...
+                );
         case 'soundsourceCombinations'
             artoaGui.trackParameter.tableSoundSourceCombinations.Data = artoa.soundsources.createCombinationsCell(currentValue);
         case 'floatOffsetBegin'
diff --git a/lib/+artoa/+controller/+track/+trajectoryOutput/plot.m b/lib/+artoa/+controller/+track/+trajectoryOutput/plot.m
index ab7404c..94a4b9e 100644
--- a/lib/+artoa/+controller/+track/+trajectoryOutput/plot.m
+++ b/lib/+artoa/+controller/+track/+trajectoryOutput/plot.m
@@ -119,6 +119,9 @@ for i = 1:length(trajectories)
         ~trajectories{i}.hidden ...
     );
     if ~trajectories{i}.hidden
+        if ~artoa.data.hasMember(artoaWorkspace, {'trajectoryOutput', 'showPositionDates'})
+            artoaWorkspace.trajectoryOutput.showPositionDates = true;
+        end
         artoa.controller.setPlotHandleVisibility( ...
             { ...
                 artoaGui.trajectoryOutput.trajectoryHandles{i}.textPositions ...
diff --git a/lib/+artoa/+controller/+track/+trajectoryOutput/tableGeneratedTracksSelect.m b/lib/+artoa/+controller/+track/+trajectoryOutput/tableGeneratedTracksSelect.m
index 6e0717c..92d4ed8 100644
--- a/lib/+artoa/+controller/+track/+trajectoryOutput/tableGeneratedTracksSelect.m
+++ b/lib/+artoa/+controller/+track/+trajectoryOutput/tableGeneratedTracksSelect.m
@@ -80,6 +80,9 @@ artoa.controller.track.trajectoryOutput.showLeftSidebarPlots();
 );
 
 %% Replace track parameter
+if ~artoa.data.hasMember(artoaWorkspace, {'trajectoryOutput', 'updateTrackParameterWindow'})
+    artoaWorkspace.trajectoryOutput.updateTrackParameterWindow = false;
+end
 if artoaWorkspace.trajectoryOutput.updateTrackParameterWindow
     artoaWorkspace.trackParameter = ...
         artoaWorkspace.trajectoryOutput.trajectories{selectedRow}.trackParameter;
diff --git a/lib/+artoa/+controller/+track/getInvolvedSoundsources.m b/lib/+artoa/+controller/+track/getInvolvedSoundsources.m
index 60eabc0..316a539 100644
--- a/lib/+artoa/+controller/+track/getInvolvedSoundsources.m
+++ b/lib/+artoa/+controller/+track/getInvolvedSoundsources.m
@@ -4,18 +4,16 @@ function [involvedSoundsources, involvedSoundsourceNames] = getInvolvedSoundsour
 
 global artoaWorkspace;
 
-involvedSoundsourceNames = fieldnames(artoaWorkspace.filteredSoundsources);
-involvedSoundsources = struct();
-for i = 1:length(involvedSoundsourceNames)
-    if artoa.soundsources.hasAppliedToa(involvedSoundsourceNames{i}, artoaWorkspace.toaData.soundSource)
-        extracted = artoa.data.extractSoundsourcesFromStruct( ...
-            involvedSoundsourceNames{i}, ...
-            artoaWorkspace.filteredSoundsources ...
-        );
-        involvedSoundsources.(involvedSoundsourceNames{i}) = extracted;
-        clear extracted;
-    end
-end
+involvedSoundsourceNames = ...
+    unique(flatten( ...
+        cellfun( ...
+            @strsplit, strtrim(artoaWorkspace.trackParameter.soundsourceCombinations.soundsources), 'UniformOutput', false ...
+        ) ...
+    ));
+involvedSoundsources = artoa.data.extractSoundsourcesFromStruct( ...
+    involvedSoundsourceNames, ...
+    artoaWorkspace.filteredSoundsources ...
+);
 
 end
 
diff --git a/lib/+artoa/+controller/getSoundsourcesWithAppliedToa.m b/lib/+artoa/+controller/getSoundsourcesWithAppliedToa.m
new file mode 100644
index 0000000..c7811e2
--- /dev/null
+++ b/lib/+artoa/+controller/getSoundsourcesWithAppliedToa.m
@@ -0,0 +1,21 @@
+function [involvedSoundsources] = getSoundsourcesWithAppliedToa()
+%GETINVOLVEDSOUNDSOURCES Summary of this function goes here
+%   Detailed explanation goes here
+
+global artoaWorkspace;
+
+involvedSoundsourceNames = fieldnames(artoaWorkspace.filteredSoundsources);
+involvedSoundsources = struct();
+for i = 1:length(involvedSoundsourceNames)
+    if artoa.soundsources.hasAppliedToa(involvedSoundsourceNames{i}, artoaWorkspace.toaData.soundSource)
+        extracted = artoa.data.extractSoundsourcesFromStruct( ...
+            involvedSoundsourceNames{i}, ...
+            artoaWorkspace.filteredSoundsources ...
+        );
+        involvedSoundsources.(involvedSoundsourceNames{i}) = extracted;
+        clear extracted;
+    end
+end
+
+end
+
diff --git a/lib/+artoa/+gui/+track/trajectoryOutput.m b/lib/+artoa/+gui/+track/trajectoryOutput.m
index d03a72b..e41ec19 100644
--- a/lib/+artoa/+gui/+track/trajectoryOutput.m
+++ b/lib/+artoa/+gui/+track/trajectoryOutput.m
@@ -50,6 +50,9 @@ leftSidebarWidth = .2;
 leftSidebarLeft = .015;
 
 %% Setup axes
+if ~artoa.data.hasMember(artoaWorkspace, {'trajectoryOutput', 'enableMercatorProjection'})
+    artoaWorkspace.trajectoryOutput.enableMercatorProjection = false;
+end
 artoa.controller.track.trajectoryOutput.setupTrajectoryAxes( ...
     artoaWorkspace.trajectoryOutput.enableMercatorProjection ...
 );
diff --git a/lib/+artoa/+trajectory/plotTimeDivergenceToGps.m b/lib/+artoa/+trajectory/plotTimeDivergenceToGps.m
index 9813f6c..16ed8ef 100644
--- a/lib/+artoa/+trajectory/plotTimeDivergenceToGps.m
+++ b/lib/+artoa/+trajectory/plotTimeDivergenceToGps.m
@@ -16,6 +16,9 @@ cla(pAxesHandle);
 hold(pAxesHandle, 'on');
 for i = 1:length(fnames)
     current =  pTrajectory.timeDivergenceToGps.(fnames{i});
+    if isempty(current)
+        continue;
+    end
     x = current(:, 1);
     y = current(:, 2);
     handleTimeDivergenceToGps.(fnames{i}) = plot(pAxesHandle, x, y, '.-');
-- 
GitLab