NCCOOS Trac Projects: Top | Web | Platforms | Processing | Viz | Sprints | Sandbox | (Wind)

root/gliderproc/trunk/MATLAB/opnml/basics/stretchline.m

Revision 495 (checked in by cbc, 12 years ago)

Initial import of Stark code.

Line 
1 function stretchline(action)
2 % STRETCHLINE creates a line and stretches it following the mouse
3 %
4 % TO USE: set(gcf,'WindowButtonDownFcn','stretchline')
5 %
6 % Written by: Brian Blanton (Dec 98)
7
8 if nargin==0  % Button pushed, initialize
9
10   % Get the current WindowButton*Fcn's, and store globally
11   % for return
12   global WindowButtonDownFcn WindowButtonMotionFcn WindowButtonUpFcn
13   WindowButtonDownFcn = get(gcf,'WindowButtonDownFcn');
14   WindowButtonMotionFcn = get(gcf,'WindowButtonMotionFcn');
15   WindowButtonUpFcn = get(gcf,'WindowButtonUpFcn');
16
17 % Delete any previous text and lines from stretchline
18   delete(findobj(gca,'Tag','Box Lines For stretchline'))
19   delete(findobj(gca,'Tag','Text1 For stretchline'))
20   delete(findobj(gca,'Tag','Text2 For stretchline'))
21
22   % Determine the location of the mouse and create the XData,
23   % YData, and ZData for the line coords.
24   currrentpoint = get(gca,'CurrentPoint');
25   xpos = [currrentpoint(1) currrentpoint(1)];
26   ypos = [currrentpoint(3) currrentpoint(3)];
27   zpos = [0 0];
28  
29   % Add some text that displays the current point
30   tp1 = text(currrentpoint(1),currrentpoint(3),...
31         sprintf('(%8.3f,%8.3f)',currrentpoint(1),currrentpoint(3)), ...
32         'FontWeight','bold','Tag','Text1 For stretchline','HorizontalAlignment','center');
33
34   % Create the initial line object
35   hs = line('XData',xpos,'YData',ypos,'ZData',zpos, ...
36        'Color','r','EraseMode','xor', ...
37        'LineStyle','--','Tag','Box Lines For stretchline','LineWidth',2);
38
39   % Add some text that displays the current point
40   tp2 = text(currrentpoint(1),currrentpoint(3),...
41         sprintf('(%8.3,%8.3f)',currrentpoint(1),currrentpoint(3)), ...
42        'EraseMode','xor','Tag','Text2 For stretchline',...
43        'FontWeight','bold','HorizontalAlignment','center');
44
45   % Set the WindowButtonMotionFcn WindowButtonUpFcn
46   set(gcf,'WindowButtonMotionFcn','stretchline move', ...
47           'WindowButtonDownFcn','stretchline up')
48
49 elseif strcmp(action,'move');  % Mouse moved
50
51   % Get the location of the mouse
52   currrentpoint = get(gca,'CurrentPoint');
53  
54   % Find the handle to the surface plot and text object
55   hs = findobj(gca,'Type','line','Tag','Box Lines For stretchline');
56   tp2 = findobj(gca,'Type','text','Tag','Text2 For stretchline');
57
58   % Update the locations of the line plot and text object #2
59   xpos = get(hs,'XData');
60   ypos = get(hs,'YData');
61   xpos(2) = [currrentpoint(1)];
62   ypos(2) = [currrentpoint(3)];
63   set(hs,'XData',xpos,'YData',ypos)
64   set(tp2,'Position',[currrentpoint(1) currrentpoint(3) 0],...
65           'String',sprintf('(%8.3f,%8.3f)',currrentpoint(1),currrentpoint(3)));
66
67 elseif strcmp(action,'up')   
68 %%%%
69 %%%% Mouse button released
70 %%%
71    % Set the WindowButtonDownFcn WindowButtonMotionFcn, and
72    % WindowButtonUpFcn to original values.
73    global WindowButtonDownFcn WindowButtonMotionFcn WindowButtonUpFcn
74    set(gcf,'WindowButtonDownFcn',WindowButtonDownFcn, ...
75            'WindowButtonMotionFcn',WindowButtonMotionFcn, ...
76            'WindowButtonUpFcn',WindowButtonUpFcn)
77    clear global WindowButtonDownFcn WindowButtonMotionFcn WindowButtonUpFcn
78    hs = findobj(gca,'Type','line','Tag','Box Lines For stretchline');
79    set(hs,'LineWidth',.25)
80
81 end 
82
83 %set(gcf,'WindowButtonDownFcn','', ...
84 %          'WindowButtonMotionFcn','', ...
85 %          'WindowButtonUpFcn','')
Note: See TracBrowser for help on using the browser.