source: MML/trunk/machine/SOLEIL/common/toolbox/ezyfit/ezyfit/myginput.m @ 4

Last change on this file since 4 was 4, checked in by zhangj, 10 years ago

Initial import--MML version from SOLEIL@2013

File size: 6.6 KB
Line 
1function [out1,out2,out3] = myginput(arg1,strpointertype)
2%MYGINPUT Graphical input from mouse with custum cursor pointer.
3%   [X,Y] = MYGINPUT(N) gets N points from the current axes and returns
4%   the X- and Y-coordinates in length N vectors X and Y.
5%
6%   [X,Y] = MYGINPUT(N, POINTER) also specifies the cursor pointer, e.g.
7%   'crosshair', 'arrow', 'circle' etc. See "Specifying the Figure Pointer"
8%   in Matlab's documentation  to see the list of available pointers.
9%   
10%   MYGINPUT is strictly equivalent to Matlab's original GINPUT, except
11%   that a second argument specifies the cursor pointer instead of the
12%   default 'fullcrosshair' pointer.
13%
14%   Example:
15%     plot(1:2,1:2,'s');
16%     hold on
17%     [x,y] = myginput(1,'crosshair');
18%     plot(x,y,'o');
19%     hold off
20%
21%   MYGINPUT is copied from Matlab's GINPUT rev. 5.32.4.4.
22%
23%   See also GINPUT.
24
25%   F. Moisy, moisy_at_fast.u-psud.fr
26%   Revision: 1.02,  Date: 2006/10/24
27%   This function is part of the EzyFit Toolbox
28
29% History:
30% 2005/10/31: v1.00, first version, from GINPUT rev. 5.32.4.4.
31% 2005/11/25: v1.01, line 'uisuspend' modified (for compatibility with
32%                    ML7.00)
33% 2006/10/24: v1.02, help text improved
34
35out1 = []; out2 = []; out3 = []; y = [];
36
37if nargin<1     % modified MYGINPUT
38    strpointertype='fullcrosshair'; % default GINPUT pointer
39end
40
41c = computer;
42if ~strcmp(c(1:2),'PC')
43   tp = get(0,'TerminalProtocol');
44else
45   tp = 'micro';
46end
47
48if ~strcmp(tp,'none') & ~strcmp(tp,'x') & ~strcmp(tp,'micro'),
49   if nargout == 1,
50      if nargin == 1,
51         out1 = trmginput(arg1);
52      else
53         out1 = trmginput;
54      end
55   elseif nargout == 2 | nargout == 0,
56      if nargin == 1,
57         [out1,out2] = trmginput(arg1);
58      else
59         [out1,out2] = trmginput;
60      end
61      if  nargout == 0
62         out1 = [ out1 out2 ];
63      end
64   elseif nargout == 3,
65      if nargin == 1,
66         [out1,out2,out3] = trmginput(arg1);
67      else
68         [out1,out2,out3] = trmginput;
69      end
70   end
71else
72   
73   fig = gcf;
74   figure(gcf);
75   
76   if nargin == 0
77      how_many = -1;
78      b = [];
79   else
80      how_many = arg1;
81      b = [];
82      if  isstr(how_many) ...
83            | size(how_many,1) ~= 1 | size(how_many,2) ~= 1 ...
84            | ~(fix(how_many) == how_many) ...
85            | how_many < 0
86         error('Requires a positive integer.')
87      end
88      if how_many == 0
89         ptr_fig = 0;
90         while(ptr_fig ~= fig)
91            ptr_fig = get(0,'PointerWindow');
92         end
93         scrn_pt = get(0,'PointerLocation');
94         loc = get(fig,'Position');
95         pt = [scrn_pt(1) - loc(1), scrn_pt(2) - loc(2)];
96         out1 = pt(1); y = pt(2);
97      elseif how_many < 0
98         error('Argument must be a positive integer.')
99      end
100   end
101   
102   % Suspend axes functions
103       %haxes = findobj(fig,'type','axes');
104        state = uisuspend(fig);
105   %haxes = findobj(fig,'type','axes');
106   %state = uisuspend(haxes);
107   pointer = get(gcf,'pointer');
108   set(gcf,'pointer',strpointertype);  % modified MYGINPUT
109   fig_units = get(fig,'units');
110   char = 0;
111
112   % We need to pump the event queue on unix
113   % before calling WAITFORBUTTONPRESS
114   drawnow
115   
116   while how_many ~= 0
117      % Use no-side effect WAITFORBUTTONPRESS
118      waserr = 0;
119      try
120        keydown = wfbp;
121      catch
122        waserr = 1;
123      end
124      if(waserr == 1)
125         if(ishandle(fig))
126            set(fig,'units',fig_units);
127            uirestore(state);
128            error('Interrupted');
129         else
130            error('Interrupted by figure deletion');
131         end
132      end
133     
134      ptr_fig = get(0,'CurrentFigure');
135      if(ptr_fig == fig)
136         if keydown
137            char = get(fig, 'CurrentCharacter');
138            button = abs(get(fig, 'CurrentCharacter'));
139            scrn_pt = get(0, 'PointerLocation');
140            set(fig,'units','pixels')
141            loc = get(fig, 'Position');
142            pt = [scrn_pt(1) - loc(1), scrn_pt(2) - loc(2)];
143            set(fig,'CurrentPoint',pt);         
144         else
145            button = get(fig, 'SelectionType');
146            if strcmp(button,'open')
147               button = 1;
148            elseif strcmp(button,'normal')
149               button = 1;
150            elseif strcmp(button,'extend')
151               button = 2;
152            elseif strcmp(button,'alt')
153               button = 3;
154            else
155               error('Invalid mouse selection.')
156            end
157         end
158         pt = get(gca, 'CurrentPoint');
159         
160         how_many = how_many - 1;
161         
162         if(char == 13) % & how_many ~= 0)
163            % if the return key was pressed, char will == 13,
164            % and that's our signal to break out of here whether
165            % or not we have collected all the requested data
166            % points. 
167            % If this was an early breakout, don't include
168            % the <Return> key info in the return arrays.
169            % We will no longer count it if it's the last input.
170            break;
171         end
172         
173         out1 = [out1;pt(1,1)];
174         y = [y;pt(1,2)];
175         b = [b;button];
176      end
177   end
178   
179   uirestore(state);
180   set(fig,'units',fig_units);
181   
182   if nargout > 1
183      out2 = y;
184      if nargout > 2
185         out3 = b;
186      end
187   else
188      out1 = [out1 y];
189   end
190   
191end
192
193%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
194function key = wfbp
195%WFBP   Replacement for WAITFORBUTTONPRESS that has no side effects.
196
197fig = gcf;
198current_char = [];
199
200% Now wait for that buttonpress, and check for error conditions
201waserr = 0;
202try
203  h=findall(fig,'type','uimenu','accel','C');   % Disabling ^C for edit menu so the only ^C is for
204  set(h,'accel','');                            % interrupting the function.
205  keydown = waitforbuttonpress;
206  current_char = double(get(fig,'CurrentCharacter')); % Capturing the character.
207  if~isempty(current_char) & (keydown == 1)           % If the character was generated by the
208          if(current_char == 3)                       % current keypress AND is ^C, set 'waserr'to 1
209                  waserr = 1;                             % so that it errors out.
210          end
211  end
212 
213  set(h,'accel','C');                                 % Set back the accelerator for edit menu.
214catch
215  waserr = 1;
216end
217drawnow;
218if(waserr == 1)
219   set(h,'accel','C');                                % Set back the accelerator if it errored out.
220   error('Interrupted');
221end
222
223if nargout>0, key = keydown; end
224%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Note: See TracBrowser for help on using the repository browser.