From 0fb217cd69b03654d0a1132e6ed9f6e8a4944d85 Mon Sep 17 00:00:00 2001
From: jacques Grelet <Jacques.Grelet@ird.fr>
Date: Tue, 25 Dec 2018 23:02:05 +0100
Subject: [PATCH] fix #9, add a customize menu to select ship size and color,
 track size fix #10, add menu "toolbar" to display toolbar icons. Notes that
 in R2018b, tools such as the zoom, pan, datatip, etc are no longer at the
 toolbar at the top of the figure window. These buttons are now in an "axes"
 toolbar and only appear when you hover your mouse over the plot. see:
 https://fr.mathworks.com/matlabcentral/answers/419036-what-happened-to-the-figure-toolbar-in-r2018b-why-is-it-an-axes-toolbar-how-can-i-put-the-buttons

---
 ReleaseNotes.md     |   7 ++-
 tsg_util/plot_map.m |  11 ++--
 tsgqc.m             | 125 +++++++++++++++++++++++++++++---------------
 3 files changed, 91 insertions(+), 52 deletions(-)

diff --git a/ReleaseNotes.md b/ReleaseNotes.md
index 2375ab0..0786d5d 100644
--- a/ReleaseNotes.md
+++ b/ReleaseNotes.md
@@ -2,9 +2,14 @@
 
 Contact: <jacques.grelet@ird.fr>
 
+## v1.50RC2 (2018-12-25)
+
++ fix issue #9, add a customize menu to select ship size and color, track size 
++ fix issue #10, add menu "toolbar" to display toolbar icons. Notes that in 
+R2018b, tools such as the zoom, pan, datatip, etc are no longer at the toolbar at the top of the figure window. These buttons are now in an "axes" toolbar and only appear when you hover your mouse over the plot. see: https://fr.mathworks.com/matlabcentral/answers/419036-what-happened-to-the-figure-toolbar-in-r2018b-why-is-it-an-axes-toolbar-how-can-i-put-the-buttons
+
 ## v1.50RC1 (2018-12-05)
 
-v1.50rc1
 + fix #8 Bug in preferencesForm, structure tsg.preference.map_* is now tsg.preference.map.*
 + move climato files to ftp://ftp.ifremer.fr/ifremer/ird/us191/oceano/Climatology/
 + add tsg_climato directory and automatic files downloading from ftp if they are not present
diff --git a/tsg_util/plot_map.m b/tsg_util/plot_map.m
index 1569d14..0fcaa32 100644
--- a/tsg_util/plot_map.m
+++ b/tsg_util/plot_map.m
@@ -258,13 +258,8 @@ if ~isempty( ind )
     m_line(x,y, 'color','k');
   end
   
-  % Plot the ship track - Check if LAT-LON in deg-decimal
-  % -----------------------------------------------------
-  %m_line(lonx, latx, 'TAG', 'TAG_PLOT4_LINE_SHIPTRACK', 'marker','.','markersize',3,'color','b');
-  %   m_line(lonx, latx, 'LineStyle', 'none', 'marker','*','markersize',2,'color','b');
-  
-  % Plot using QC
-  % -------------
+  % Plot ship track with QC color
+  % -----------------------------
   
   % Get list of keys from hashtable tsg.qc.hash, defined inside
   % tsg_initialisation.m
@@ -292,7 +287,7 @@ if ~isempty( ind )
       % ----------------------
       m_line( mod(lonx(ind) + tsg.lonplus, tsg.lonmod) - tsg.lonplus,...
         latx(ind), 'LineStyle', 'none', 'marker','*',...
-        'markersize', 2, 'color', qcColor);
+        'markersize', tsg.preference.map.track.size, 'color', qcColor);
     end
   end
   
diff --git a/tsgqc.m b/tsgqc.m
index d5d387f..e72cbd7 100644
--- a/tsgqc.m
+++ b/tsgqc.m
@@ -924,14 +924,20 @@ hMapShipSizeMenu = uimenu(hMapShipMenu,'Label','Size', ...
 hMapShipColorMenu = uimenu(hMapShipMenu,'Label','Color', ...
   'Tag', 'TAG_UIMENU_MAP_SHIP_COLOR');
 
+uimenu(hMapShipMenu,'Label','Color picker', ...
+  'Checked','off',...
+  'Tag', 'TAG_UIMENU_MAP_SHIP_COLOR_PICKER',...
+  'Enable', 'on',...
+  'Callback', {@mapColorPickerCallback, 'SHIP_COLOR'});
+
 hMapTrackMenu = uimenu(hMapCustomizeMenu,'Label','Track', ...
   'Tag', 'TAG_UIMENU_MAP_TRACK');
 
 hMapTrackSizeMenu = uimenu(hMapTrackMenu,'Label','Size', ...
   'Tag', 'TAG_UIMENU_MAP_TRACK_SIZE');
 
-hMapTrackColorMenu = uimenu(hMapTrackMenu,'Label','Color', ...
-  'Tag', 'TAG_UIMENU_MAP_TRACK_COLOR');
+% hMapTrackColorMenu = uimenu(hMapTrackMenu,'Label','Color', ...
+%   'Tag', 'TAG_UIMENU_MAP_TRACK_COLOR');
 
 uimenu(hMapShipSizeMenu,'Label','4',...
   'Checked','off',...
@@ -961,73 +967,73 @@ uimenu(hMapShipColorMenu,'Label','red',...
   'Checked','off',...
   'Tag','TAG_UIMENU_MAP_SHIP_COLOR_R',...
   'Enable', 'on',...
-  'Callback', {@mapCustomizeCallback, 'r', 'SHIP_SIZE'});
+  'Callback', {@mapCustomizeCallback, 'r', 'SHIP_COLOR'});
 
 uimenu(hMapShipColorMenu,'Label','black',...
   'Checked','off',...
   'Tag','TAG_UIMENU_MAP_SHIP_COLOR_K',...
   'Enable', 'on',...
-  'Callback', {@mapCustomizeCallback, 'k', 'SHIP_SIZE'});
+  'Callback', {@mapCustomizeCallback, 'k', 'SHIP_COLOR'});
 
 uimenu(hMapShipColorMenu,'Label','blue',...
   'Checked','off',...
   'Tag','TAG_UIMENU_MAP_SHIP_COLOR_B',...
   'Enable', 'on',...
-  'Callback', {@mapCustomizeCallback, 'b', 'SHIP_SIZE'});
+  'Callback', {@mapCustomizeCallback, 'b', 'SHIP_COLOR'});
 
 uimenu(hMapShipColorMenu,'Label','green',...
   'Checked','off',...
   'Tag','TAG_UIMENU_MAP_SHIP_COLOR_G',...
   'Enable', 'on',...
-  'Callback', {@mapCustomizeCallback, 'g', 'SHIP_SIZE'});
-
-uimenu(hMapTrackSizeMenu,'Label','4',...
-  'Checked','off',...
-  'Tag','TAG_UIMENU_MAP_TRACK_SIZE_4',...
-  'Enable', 'on',...
-  'Callback', {@mapCustomizeCallback, 4, 'SHIP_SIZE'});
+  'Callback', {@mapCustomizeCallback, 'g', 'SHIP_COLOR'});
 
-uimenu(hMapTrackSizeMenu,'Label','5',...
+uimenu(hMapTrackSizeMenu,'Label','1',...
   'Checked','off',...
-  'Tag','TAG_UIMENU_MAP_TRACK_SIZE_5',...
+  'Tag','TAG_UIMENU_MAP_TRACK_SIZE_1',...
   'Enable', 'on',...
-  'Callback', {@mapCustomizeCallback, 5, 'SHIP_SIZE'});
+  'Callback', {@mapCustomizeCallback, 1, 'TRACK_SIZE'});
 
-uimenu(hMapTrackSizeMenu,'Label','6',...
+uimenu(hMapTrackSizeMenu,'Label','2',...
   'Checked','off',...
-  'Tag','TAG_UIMENU_MAP_TRACK_SIZE_6',...
+  'Tag','TAG_UIMENU_MAP_TRACK_SIZE_2',...
   'Enable', 'on',...
-  'Callback', {@mapCustomizeCallback, 6, 'SHIP_SIZE'});
+  'Callback', {@mapCustomizeCallback, 2, 'TRACK_SIZE'});
 
-uimenu(hMapTrackSizeMenu,'Label','7',...
+uimenu(hMapTrackSizeMenu,'Label','3',...
   'Checked','off',...
-  'Tag','TAG_UIMENU_MAP_TRACK_SIZE_7',...
+  'Tag','TAG_UIMENU_MAP_TRACK_SIZE_3',...
   'Enable', 'on',...
-  'Callback', {@mapCustomizeCallback, 7, 'SHIP_SIZE'});
+  'Callback', {@mapCustomizeCallback, 3, 'TRACK_SIZE'});
 
-uimenu(hMapTrackColorMenu,'Label','red',...
-  'Checked','off',...
-  'Tag','TAG_UIMENU_MAP_TRACK_COLOR_R',...
-  'Enable', 'on',...
-  'Callback', {@mapCustomizeCallback, 'r', 'SHIP_SIZE'});
-
-uimenu(hMapTrackColorMenu,'Label','black',...
-  'Checked','off',...
-  'Tag','TAG_UIMENU_MAP_TRACK_COLOR_K',...
-  'Enable', 'on',...
-  'Callback', {@mapCustomizeCallback, 'k', 'SHIP_SIZE'});
-
-uimenu(hMapTrackColorMenu,'Label','blue',...
-  'Checked','off',...
-  'Tag','TAG_UIMENU_MAP_TRACK_COLOR_B',...
-  'Enable', 'on',...
-  'Callback', {@mapCustomizeCallback, 'b', 'SHIP_SIZE'});
-
-uimenu(hMapTrackColorMenu,'Label','green',...
+uimenu(hMapTrackSizeMenu,'Label','4',...
   'Checked','off',...
-  'Tag','TAG_UIMENU_MAP_TRACK_COLOR_G',...
+  'Tag','TAG_UIMENU_MAP_TRACK_SIZE_4',...
   'Enable', 'on',...
-  'Callback', {@mapCustomizeCallback, 'g', 'SHIP_SIZE'});
+  'Callback', {@mapCustomizeCallback, 4, 'TRACK_SIZE'});
+
+% uimenu(hMapTrackColorMenu,'Label','red',...
+%   'Checked','off',...
+%   'Tag','TAG_UIMENU_MAP_TRACK_COLOR_R',...
+%   'Enable', 'on',...
+%   'Callback', {@mapCustomizeCallback, 'r', 'TRACK_COLOR'});
+% 
+% uimenu(hMapTrackColorMenu,'Label','black',...
+%   'Checked','off',...
+%   'Tag','TAG_UIMENU_MAP_TRACK_COLOR_K',...
+%   'Enable', 'on',...
+%   'Callback', {@mapCustomizeCallback, 'k', 'TRACK_COLOR'});
+% 
+% uimenu(hMapTrackColorMenu,'Label','blue',...
+%   'Checked','off',...
+%   'Tag','TAG_UIMENU_MAP_TRACK_COLOR_B',...
+%   'Enable', 'on',...
+%   'Callback', {@mapCustomizeCallback, 'b', 'TRACK_COLOR'});
+% 
+% uimenu(hMapTrackColorMenu,'Label','green',...
+%   'Checked','off',...
+%   'Tag','TAG_UIMENU_MAP_TRACK_COLOR_G',...
+%   'Enable', 'on',...
+%   'Callback', {@mapCustomizeCallback, 'g', 'TRACK_COLOR'});
 
 % map Print menu
 % --------------------
@@ -4092,7 +4098,10 @@ end
   end
 
 % function mapCustomizeCallback
-% --------------------------------
+% This function is generic for all customization menus. 
+% The tag argument is used to find the handle of the selected menu.
+% We use a regular expression to access and modify the preference structure
+% ----------------------------------------------------------------------
   function mapCustomizeCallback(src, evnt, val, tag)
     
     % get the tsg structure
@@ -4116,6 +4125,29 @@ end
     plot_map(hMainFig, hPlotAxes);
   end
 
+  function mapColorPickerCallback(src, evnt, tag)
+    
+    % get the tsg structure
+    % ---------------------
+    tsg = getappdata( hMainFig, 'tsg_data');
+    
+    hdls = findobj( '-regexp', 'tag', ['TAG_UIMENU_MAP_' tag]);
+    set(hdls, 'Checked', 'off');
+    set(src, 'Checked', 'on');
+    
+    % change the map border from menu on map, dynamically transform
+    % tag to structure member
+    % -------------------------------------------------------------
+    member =  regexp(lower(tag),'(\w+)_(\w+)','tokens');
+    tsg.preference.map.(member{1}{1}).(member{1}{2}) = uisetcolor;
+    setappdata( hMainFig, 'tsg_data', tsg);
+    
+    % redraw map
+    % ------------------------------------------
+    erase_Line( hPlotAxes, 4 );
+    plot_map(hMainFig, hPlotAxes);
+  end
+
 % print map figure from menu
 % ----------------------------
   function mapPrintCallback(src, evnt)
@@ -4132,6 +4164,13 @@ end
     get(hMapFig, 'toolbar')
     if( strcmp(get(hMapFig, 'toolbar'), 'none'))
       set(hMapFig, 'toolbar', 'figure')
+      % see Reverting axes controls in figure toolbar under:
+      % https://undocumentedmatlab.com/blog/reverting-axes-controls-in-figure-toolbar
+      % and Matlab Central:
+      % https://fr.mathworks.com/matlabcentral/answers/419036-what-happened-to-the-figure-toolbar-in-r2018b-why-is-it-an-axes-toolbar-how-can-i-put-the-buttons
+      if ~verLessThan('matlab','9.5')
+        addToolbarExplorationButtons(hMapFig)
+      end
     else
       set(hMapFig, 'toolbar', 'none')
     end
-- 
GitLab