From 4cead39b33fb5401715226cad34d1aa5e2153f57 Mon Sep 17 00:00:00 2001
From: Jacques Grelet <jacques.grelet@ird.fr>
Date: Thu, 14 Jan 2010 15:03:28 +0000
Subject: [PATCH] improve MouseMotion poisition display

---
 tsgqc.m | 62 ++++++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 42 insertions(+), 20 deletions(-)

diff --git a/tsgqc.m b/tsgqc.m
index ad1575b..dac6252 100644
--- a/tsgqc.m
+++ b/tsgqc.m
@@ -2376,8 +2376,10 @@ hrbInterpCancel = uicontrol( ...
       %    1 - one to desactivate QC when Pan is set to on.
       %    2 - one to reactivate QC once the pan has been used.
       % ---------------------------------------------------------
-      qcState = get(hQCToggletool,   'state' );
-      if strcmp(qcState, 'on' );
+      
+      % if we are in QC mode
+      % ---------------------
+      if strcmp( get(hQCToggletool, 'state' ), 'on' );
 
         % Suppose that Y axes is increasing from the bottom to the top
         % ------------------------------------------------------------
@@ -2393,20 +2395,26 @@ hrbInterpCancel = uicontrol( ...
             pan(hMainFig, 'off');
           catch
           end
-        end
-      end
+          
+        end % end of cursor test location
+        
+      end % end of QC mode test
 
       % Dynamically display data in uicontrol
       % -------------------------------------
       if x > tsg.DAYD(1) && x < tsg.DAYD(end)
 
-        % display cursor in location in text uicontrol
-        % --------------------------------------------
-        indCursor = find( tsg.DAYD > x);
+        % get index of cursor location 
+        % ----------------------------
+        indCursor = find( tsg.DAYD > x, 1, 'first');
+        
+        % display informations of cursor location in text uicontrol
+        % ---------------------------------------------------------
         set( hInfoDateText, 'String',...
           datestr(tsg.DAYD(indCursor(1)),'dd/mm/yyyy   HH:MM'));
-        set( hInfoLatText,  'String', dd2dm(tsg.LATX(indCursor(1)),0));
-        set( hInfoLongText, 'String', dd2dm(mod(tsg.LONX(indCursor(1))+180,360)-180,1));
+        set( hInfoLatText,  'String', dd2dm(tsg.LATX(indCursor(1)), 0) );
+        set( hInfoLongText, 'String', ...
+          dd2dm(mod(tsg.LONX(indCursor) + 180, 360) - 180, 1) );
         if ~isempty(tsg.SSPS)
           set( hInfoSSPSText, 'String', tsg.SSPS(indCursor(1)));
         end
@@ -2431,14 +2439,15 @@ hrbInterpCancel = uicontrol( ...
 
           if isempty( h )   % if no Marker
 
-            if ~isnan( tsg.LONX(indCursor(1)) )
+            if ~isnan( tsg.LONX(indCursor) )
 
               % Plot a Marker (Red point) on the ship track
               % -------------------------------------------
-              hMarker = m_line( mod(tsg.LONX(indCursor(1))+tsg.lonplus,tsg.lonmod)-tsg.lonplus,...
+              hMarker = m_line( mod(tsg.LONX(indCursor(1)) + ...
+                tsg.lonplus, tsg.lonmod) - tsg.lonplus,...
                 tsg.LATX(indCursor(1)),...
-                'Marker','o','MarkerSize',5, ...
-                'Color','r', 'MarkerFaceColor','r');
+                'Marker', 'o', 'MarkerSize', 5, ...
+                'Color', 'r', 'MarkerFaceColor', 'r');
 
               % Put a tag on the Marker - This tag allows to get the handle
               % of the Marker
@@ -2448,15 +2457,15 @@ hrbInterpCancel = uicontrol( ...
 
           else         % a marker exists
 
-            if ~isnan( tsg.LONX(indCursor(1)) )
+            if ~isnan( tsg.LONX(indCursor) )
 
               % Delete the Marker and redraw it
               % -------------------------------
               delete( h);
               hMarker = m_line( ...
-                tsg.LONX(indCursor(1)), tsg.LATX(indCursor(1)),...
-                'Marker','o','MarkerSize',5, ...
-                'Color','r', 'MarkerFaceColor','r');
+                tsg.LONX(indCursor), tsg.LATX(indCursor),...
+                'Marker', 'o', 'MarkerSize', 5, ...
+                'Color', 'r', 'MarkerFaceColor', 'r');
 
               % Put a tag on the Marker - This tag allows to get the handle
               % of the Marker
@@ -2465,10 +2474,23 @@ hrbInterpCancel = uicontrol( ...
             end
           end
 
-        end
+         end % end of map visible
+        
+      else
+        
+        % if cursor is out of valid data, display blank
+        % ---------------------------------------------
+        set( hInfoDateText, 'String', '' );
+        set( hInfoLatText,  'String', '' );
+        set( hInfoLongText, 'String', '' );
+        set( hInfoSSPSText, 'String', '' );
+        set( hInfoSSTPText, 'String', '' );
+        set( hInfoSSJTText, 'String', '' );
       end
-    end
-  end
+      
+    end % end of BuntonMotionOn
+    
+  end % end of mouseMotion function
 
 %% Map_OnMenuCallback
 %---------------------------------------------------------------------
-- 
GitLab