1 | %'mouse_motion': permanently called by mouse motion over a figure (Callback for 'WindowButtonMotionFcn' of the figure) |
---|
2 | %----------------------------------------------------------------------- |
---|
3 | % |
---|
4 | % function mouse_motion(hObject,eventdata,handles) |
---|
5 | % activated by the command: |
---|
6 | % set(hObject,'WindowButtonMotionFcn',{'mouse_motion',handles}) |
---|
7 | % where hObject is the handle of the figure |
---|
8 | % |
---|
9 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
10 | % Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org. |
---|
11 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
12 | % This file is part of the toolbox UVMAT. |
---|
13 | % |
---|
14 | % UVMAT is free software; you can redistribute it and/or modify |
---|
15 | % it under the terms of the GNU General Public License as published by |
---|
16 | % the Free Software Foundation; either version 2 of the License, or |
---|
17 | % (at your option) any later version. |
---|
18 | % |
---|
19 | % UVMAT is distributed in the hope that it will be useful, |
---|
20 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
21 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
22 | % GNU General Public License (file UVMAT/COPYING.txt) for more details. |
---|
23 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
24 | |
---|
25 | function mouse_motion(hObject,eventdata,handles) |
---|
26 | if ~exist('handles','var') |
---|
27 | return |
---|
28 | end |
---|
29 | test_create=0;%default |
---|
30 | test_edit=0;%default |
---|
31 | test_edit=isfield(handles,'edit') & get(handles.edit,'Value');% edit test for mouse shap: an arrow |
---|
32 | test_zoom=isfield(handles,'zoom')& get(handles.zoom,'Value');% edit test for mouse shap: an arrow |
---|
33 | |
---|
34 | %find the current axe 'haxes' and display the current mouse position or uicontrol tag |
---|
35 | text_displ_1=''; |
---|
36 | text_displ_2=''; |
---|
37 | text_displ_3=''; |
---|
38 | text_displ_4=''; |
---|
39 | |
---|
40 | haxes=[]; |
---|
41 | AxeData=[];%default |
---|
42 | mouse=[]; |
---|
43 | xy=[];%default |
---|
44 | |
---|
45 | pointershape='arrow';% default pointer is an arrow |
---|
46 | currentfig=gcbo;%store gcbo as variable currentfig |
---|
47 | xy_fig=get(currentfig,'CurrentPoint');% current point of the current figure (gcbo) |
---|
48 | hchild=get(currentfig,'Children');%handles of all objects in the current figure |
---|
49 | |
---|
50 | % loop on all the objects in the current figure (selected by the last mouse click) |
---|
51 | for ichild=1:length(hchild) |
---|
52 | obj_pos=get(hchild(ichild),'Position');%position of the object |
---|
53 | if xy_fig(1) >=obj_pos(1) & xy_fig(2) >= obj_pos(2)& xy_fig(1) <=obj_pos(1)+obj_pos(3) & xy_fig(2) <= obj_pos(2)+obj_pos(4); |
---|
54 | htype=get(hchild(ichild),'Type');%type of the crrent child |
---|
55 | %if the mouse is over an axis, look at the data |
---|
56 | if isequal(htype,'axes') |
---|
57 | haxes=hchild(ichild); |
---|
58 | xy=get(haxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates |
---|
59 | mouse.X=xy(1,1); |
---|
60 | mouse.Y=xy(1,2); |
---|
61 | u_mouse=[]; |
---|
62 | v_mouse=[]; |
---|
63 | w_mouse=[]; |
---|
64 | A_mouse=[]; |
---|
65 | c_text=[]; |
---|
66 | f_text=[]; |
---|
67 | ff_text=[]; |
---|
68 | ivec=[]; |
---|
69 | AxeData=get(haxes,'UserData');% data attached to the axis |
---|
70 | if ~test_edit && ~test_zoom |
---|
71 | pointershape='crosshair';%set pointer with cross shape (default when mouse is over an axis) |
---|
72 | % % pointershape='crosshair';%set pointer with cross shape (default over axis) |
---|
73 | end |
---|
74 | if isfield(AxeData,'X') && isfield(AxeData,'Y') && isfield(AxeData,'Mesh')% test on the existence of a vector field in the current axis |
---|
75 | if ~isempty(AxeData.Mesh) |
---|
76 | flag_vec=(AxeData.X<(xy(1,1)+AxeData.Mesh/3) & AxeData.X>(xy(1,1)-AxeData.Mesh/3)) & ...%flagx=1 for the vectors with x position selected by the mouse |
---|
77 | (AxeData.Y<(xy(1,2)+AxeData.Mesh/3) & AxeData.Y>(xy(1,2)-AxeData.Mesh/3));%f |
---|
78 | ivec=find(flag_vec,1);% search the (first) selected vector index ivec |
---|
79 | hhh=findobj(haxes,'Tag','vector_marker'); |
---|
80 | if ~isempty(ivec) |
---|
81 | %ivec=ivec(1);%choice the first selected vector if several are selected |
---|
82 | if ~test_create |
---|
83 | pointershape='arrow'; %mouse indicates the detection of a vector |
---|
84 | if isempty(hhh) |
---|
85 | set(currentfig,'CurrentAxes',haxes) |
---|
86 | rectangle('Curvature',[1 1],... |
---|
87 | 'Position',[AxeData.X(ivec)-AxeData.Mesh AxeData.Y(ivec)/2-AxeData.Mesh/2 AxeData.Mesh AxeData.Mesh],'EdgeColor','m',... |
---|
88 | 'LineStyle','-','Tag','vector_marker'); |
---|
89 | % line(AxeData.X(ivec),AxeData.Y(ivec),'Color','m','Tag','vector_marker','LineStyle','.','Marker','o','MarkerSize',AxeData.Mesh); |
---|
90 | else |
---|
91 | set(hhh,'Position',[AxeData.X(ivec)-AxeData.Mesh/2 AxeData.Y(ivec)-AxeData.Mesh/2 AxeData.Mesh AxeData.Mesh]) |
---|
92 | end |
---|
93 | end |
---|
94 | mouse.X=AxeData.X(ivec); |
---|
95 | mouse.Y=AxeData.Y(ivec); |
---|
96 | u_mouse=AxeData.U(ivec);%displacement |
---|
97 | v_mouse=AxeData.V(ivec); |
---|
98 | w_mouse=0; %default |
---|
99 | if isfield(AxeData,'W') & length(AxeData.W)>=ivec |
---|
100 | w_text=[', w=' num2str(AxeData.W(ivec),3)]; |
---|
101 | else |
---|
102 | w_text=''; |
---|
103 | end |
---|
104 | if ~isfield(AxeData,'CName') |
---|
105 | AxeData.CName='C';%REVOIR |
---|
106 | end |
---|
107 | c_text=[', ' AxeData.CName '=' num2str(AxeData.C(ivec),3)]; |
---|
108 | if isfield(AxeData,'F')&length(AxeData.F)>=ivec |
---|
109 | f_text=[', f=' num2str(AxeData.F(ivec),3)]; |
---|
110 | else |
---|
111 | f_text=''; |
---|
112 | end |
---|
113 | if isfield(AxeData,'FF')&length(AxeData.FF)>=ivec |
---|
114 | ff_text=[', ff=' num2str(AxeData.FF(ivec),3)]; |
---|
115 | else |
---|
116 | ff_text=''; |
---|
117 | end |
---|
118 | else |
---|
119 | if ~isempty(hhh) |
---|
120 | delete(hhh) |
---|
121 | end |
---|
122 | end |
---|
123 | end |
---|
124 | end |
---|
125 | if isfield(AxeData,'Z') |
---|
126 | mouse.Z=AxeData.Z; %generaliser au cas avec angle |
---|
127 | end |
---|
128 | if isfield(AxeData,'ObjectCoord') & size(AxeData.ObjectCoord,2)==3 |
---|
129 | mouse.Z=AxeData.ObjectCoord(1,3); %generaliser au cas avec angle |
---|
130 | end |
---|
131 | testscal= isfield(AxeData,'A')& isfield(AxeData,'AX')& isfield(AxeData,'AY');%test the existence of an image (or scalar represented by an image) |
---|
132 | if testscal |
---|
133 | testscal=~isempty(AxeData.A)&~isempty(AxeData.AX)& ~isempty(AxeData.AY); |
---|
134 | end |
---|
135 | if testscal%test the existence of an image (or scalar represented by an image) |
---|
136 | nxy=size(AxeData.A); |
---|
137 | MaxAY=max(AxeData.AY(1),AxeData.AY(end)); |
---|
138 | MinAY=min(AxeData.AY(1),AxeData.AY(end)); |
---|
139 | if (xy(1,1)>AxeData.AX(1))&(xy(1,1)<AxeData.AX(end))&(xy(1,2)<MaxAY)&(xy(1,2)>MinAY) |
---|
140 | indx0=1+round((nxy(2)-1)*(xy(1,1)-AxeData.AX(1))/(AxeData.AX(end)-AxeData.AX(1)));% index x of pixel |
---|
141 | indy0=1+round((nxy(1)-1)*(xy(1,2)-AxeData.AY(1))/(AxeData.AY(end)-AxeData.AY(1)));% index y of pixel |
---|
142 | if indx0>=1 & indx0<=nxy(2) & indy0>=1 & indy0<=nxy(1) |
---|
143 | A_mouse=AxeData.A(indy0,indx0,:); |
---|
144 | end |
---|
145 | end |
---|
146 | end |
---|
147 | %coordinate transform if proj_coord differs from menu_coord |
---|
148 | if isfield(AxeData,'CoordType') |
---|
149 | mouse.CoordType=AxeData.CoordType; |
---|
150 | end |
---|
151 | if isfield(AxeData,'CoordUnit') |
---|
152 | mouse.CoordUnit=AxeData.CoordUnit; |
---|
153 | end |
---|
154 | if isfield(mouse,'CoordType') |
---|
155 | if isequal(mouse.CoordType,'px') |
---|
156 | mouse.CoordUnit='px'; |
---|
157 | end |
---|
158 | else |
---|
159 | mouse.CoordUnit='';%default |
---|
160 | end |
---|
161 | text_displ_1=['x=' num2str(mouse.X,4) ',y=' num2str(mouse.Y,4)]; |
---|
162 | if isfield(mouse,'Z')&~isempty(mouse.Z) |
---|
163 | text_displ_1=[text_displ_1 ',z=' num2str(mouse.Z,3)]; |
---|
164 | end |
---|
165 | if isfield(mouse,'CoordUnit') |
---|
166 | text_displ_1=[text_displ_1 ' ' mouse.CoordUnit]; |
---|
167 | end |
---|
168 | if ~isempty(ivec) |
---|
169 | text_displ_4=['vec#=' num2str(ivec)]; |
---|
170 | end |
---|
171 | if ~isempty(u_mouse) |
---|
172 | text_displ_3=['u=' num2str(u_mouse,3) ',v=' num2str(v_mouse,3) w_text ]; |
---|
173 | if isfield(mouse,'CoordUnit') |
---|
174 | if isequal(mouse.CoordUnit,'px') |
---|
175 | text_displ_3=[text_displ_3 ' ' mouse.CoordUnit]; |
---|
176 | elseif isfield(AxeData,'TimeUnit') |
---|
177 | text_displ_3=[text_displ_3 ' ' mouse.CoordUnit '/' AxeData.TimeUnit]; |
---|
178 | end |
---|
179 | end |
---|
180 | text_displ_4=[text_displ_4 c_text f_text ff_text]; |
---|
181 | end |
---|
182 | |
---|
183 | if ~isempty(A_mouse) |
---|
184 | text_displ_2=['A=' num2str(double(A_mouse)) ',i=' num2str(indx0) ',j=' num2str(indy0)]; |
---|
185 | end |
---|
186 | elseif isequal(htype,'uicontrol') && isequal(get(hchild(ichild),'Visible'),'on')&& ~isequal(get(hchild(ichild),'Style'),'frame') |
---|
187 | text_displ_1=get(hchild(ichild),'Tag'); |
---|
188 | end |
---|
189 | end |
---|
190 | end |
---|
191 | set(handles.text_display_1,'String',text_displ_1); |
---|
192 | set(handles.text_display_2,'String',text_displ_2); |
---|
193 | set(handles.text_display_3,'String',text_displ_3); |
---|
194 | set(handles.text_display_4,'String',text_displ_4); |
---|
195 | |
---|
196 | %%%%%%%%%%%%%%%%% |
---|
197 | %create or modify an object |
---|
198 | huvmat=findobj(allchild(0),'Name','uvmat');%find the uvmat interface handle |
---|
199 | if ~isempty(huvmat) |
---|
200 | UvData=get(huvmat,'UserData'); |
---|
201 | end |
---|
202 | if ~isempty(huvmat) & isfield(AxeData,'CurrentObject') & ishandle(AxeData.CurrentObject) & isfield(AxeData,'Drawing') & ~isequal(AxeData.Drawing,'off') |
---|
203 | PlotData=get(AxeData.CurrentObject,'UserData'); |
---|
204 | huvmat=findobj(allchild(0),'Name','uvmat');%find the uvmat interface handle |
---|
205 | if ~isempty(huvmat) |
---|
206 | UvData=get(huvmat,'UserData'); |
---|
207 | if ~isfield(PlotData,'IndexObj') |
---|
208 | return |
---|
209 | end |
---|
210 | ObjectData=UvData.Object{PlotData.IndexObj}; |
---|
211 | XYData=AxeData.CurrentOrigin; |
---|
212 | if isequal(AxeData.Drawing,'create') && isfield(AxeData,'CurrentOrigin') && ~isempty(AxeData.CurrentOrigin) |
---|
213 | if isequal(ObjectData.Style,'line')|isequal(ObjectData.Style,'polyline')|isequal(ObjectData.Style,'polygon')|isequal(ObjectData.Style,'points') |
---|
214 | xy(1,3)=0; |
---|
215 | ObjectData.Coord=[ObjectData.Coord ;xy(1,:)]; |
---|
216 | % ObjectData.Coord(end,:)=xy(1,:); |
---|
217 | elseif isequal(ObjectData.Style,'rectangle')|isequal(ObjectData.Style,'ellipse')|isequal(ObjectData.Style,'volume') |
---|
218 | ObjectData.Coord(1,1)=(xy(1,1)+XYData(1))/2;%origin rectangle, x coordinate |
---|
219 | ObjectData.Coord(1,2)=(xy(1,2)+XYData(2))/2; |
---|
220 | ObjectData.RangeX=abs(xy(1,1)-XYData(1))/2;%rectangle width |
---|
221 | ObjectData.RangeY=abs(xy(1,2)-XYData(2))/2;%rectangle height |
---|
222 | elseif isequal(ObjectData.Style,'plane') %case of 'plane' |
---|
223 | DX=(xy(1,1)-ObjectData.Coord(1,1)); |
---|
224 | DY=(xy(1,2)-ObjectData.Coord(1,2)); |
---|
225 | ObjectData.Phi=(angle(DX+i*DY))*180/pi;%rectangle widt |
---|
226 | if isfield(ObjectData,'RangeX') |
---|
227 | XMax=sqrt(DX*DX+DY*DY); |
---|
228 | if XMax>max(ObjectData.RangeX) |
---|
229 | ObjectData.RangeX=[min(ObjectData.RangeX) XMax]; |
---|
230 | end |
---|
231 | end |
---|
232 | end |
---|
233 | plot_object(ObjectData,[],AxeData.CurrentObject,'m'); |
---|
234 | pointershape='crosshair'; |
---|
235 | elseif isequal(AxeData.Drawing,'translate') |
---|
236 | DX=xy(1,1)-XYData(1);%translation from initial position |
---|
237 | DY=xy(1,2)-XYData(2); |
---|
238 | ObjectData.Coord(:,1)=ObjectData.Coord(:,1)+DX; |
---|
239 | ObjectData.Coord(:,2)=ObjectData.Coord(:,2)+DY; |
---|
240 | plot_object(ObjectData,[],AxeData.CurrentObject,'m'); |
---|
241 | pointershape='fleur'; |
---|
242 | elseif isequal(AxeData.Drawing,'deform') |
---|
243 | ind_move=AxeData.CurrentIndex; |
---|
244 | ObjectData.Coord(ind_move,1)=xy(1,1); |
---|
245 | ObjectData.Coord(ind_move,2)=xy(1,2); |
---|
246 | plot_object(ObjectData,[],AxeData.CurrentObject,'m'); |
---|
247 | pointershape='circle'; |
---|
248 | end |
---|
249 | end |
---|
250 | end |
---|
251 | |
---|
252 | %%%%%%%%%%%%% |
---|
253 | %draw a zoom rectangle if no object creation is selected |
---|
254 | if ~isempty(haxes) & isfield(AxeData,'Drawing')& isequal(AxeData.Drawing,'zoom')& isfield(AxeData,'CurrentOrigin')... |
---|
255 | & isequal(get(gcf,'SelectionType'),'normal')% |
---|
256 | xy_rect=AxeData.CurrentOrigin; |
---|
257 | if ~isempty(xy_rect) |
---|
258 | rect(1)=min(xy(1,1),xy_rect(1));%origin rectangle, x coordinate |
---|
259 | rect(2)=min(xy(1,2),xy_rect(2));%origin rectangle, y coordinate |
---|
260 | rect(3)=abs(xy(1,1)-xy_rect(1));%rectangle width |
---|
261 | rect(4)=abs(xy(1,2)-xy_rect(2));%rectangle height |
---|
262 | if rect(3)>0 & rect(4)>0 |
---|
263 | if isfield(AxeData,'CurrentRectZoom')& ishandle(AxeData.CurrentRectZoom) |
---|
264 | set(AxeData.CurrentRectZoom,'Position',rect);%update the rectangle position |
---|
265 | else |
---|
266 | AxeData.CurrentRectZoom=rectangle('Position',rect,'LineStyle',':','Tag','rect_zoom'); |
---|
267 | set(haxes,'UserData',AxeData) |
---|
268 | end |
---|
269 | end |
---|
270 | end |
---|
271 | % end |
---|
272 | % if test_zoom |
---|
273 | pointershape='arrow'; |
---|
274 | end |
---|
275 | |
---|
276 | % detect calibration points if the GUI geometry_calib is opened |
---|
277 | h_geometry_calib=findobj(allchild(0),'Name','geometry_calib'); %find the geomterty_calib GUI |
---|
278 | if ~test_zoom && ~isempty(h_geometry_calib) |
---|
279 | pointershape='crosshair';%default for geometry_calib: ready to create new points |
---|
280 | hh_geometry_calib=guidata(h_geometry_calib); |
---|
281 | if get(hh_geometry_calib.edit_append,'Value') && ~isempty(xy) |
---|
282 | h_ListCoord=hh_geometry_calib.ListCoord; %findobj(h_geometry_calib,'Tag','ListCoord'); |
---|
283 | Coord=get(h_ListCoord,'String'); |
---|
284 | data=read_geometry_calib(Coord);%transform char cell to numbers |
---|
285 | if size(data.Coord,2)>=5 |
---|
286 | XCoord=(data.Coord(:,4)); |
---|
287 | YCoord=(data.Coord(:,5)); |
---|
288 | xy=get(haxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates |
---|
289 | if ~isempty(xy) |
---|
290 | ind_range=10; |
---|
291 | index_point=find((XCoord<xy(1,1)+ind_range) & (XCoord>xy(1,1)-ind_range) & ...%flagx=1 for the vectors with x position selected by the mouse |
---|
292 | (YCoord<xy(1,2)+ind_range) & (YCoord>xy(1,2)-ind_range),1);%find the first calibration point in the neighborhood of the mouse |
---|
293 | if ~isempty(index_point) |
---|
294 | pointershape='arrow';% default pointer is an arrow |
---|
295 | set(h_ListCoord,'Value',index_point)%mrk the point on the GUI geometry_calib |
---|
296 | hh=findobj('Tag','calib_points');%look for handle of calibration points |
---|
297 | if ~isempty(hh) && strcmp(get(hh,'UserData'),'edit_mode') |
---|
298 | XCoord(index_point)=xy(1,1); |
---|
299 | YCoord(index_point)=xy(1,2); |
---|
300 | set(hh,'XData',XCoord) |
---|
301 | set(hh,'YData',YCoord) |
---|
302 | end |
---|
303 | hhh=findobj('Tag','calib_marker');%look for handle of point marker (circle) |
---|
304 | if ~isempty(hhh) |
---|
305 | set(hhh,'XData',XCoord(index_point)) |
---|
306 | set(hhh,'YData',YCoord(index_point)) |
---|
307 | end |
---|
308 | end |
---|
309 | end |
---|
310 | end |
---|
311 | end |
---|
312 | end |
---|
313 | |
---|
314 | %draw ruler |
---|
315 | if ~isempty(huvmat) |
---|
316 | UvData=get(huvmat,'UserData'); |
---|
317 | if isfield(UvData,'MouseAction') && isequal(UvData.MouseAction,'ruler') |
---|
318 | if isfield(UvData,'RulerHandle') |
---|
319 | pointershape='crosshair'; |
---|
320 | RulerCoord=[UvData.RulerCoord ;xy(1,1:2)]; |
---|
321 | set(UvData.RulerHandle,'XData',RulerCoord(:,1)); |
---|
322 | set(UvData.RulerHandle,'YData',RulerCoord(:,2)); |
---|
323 | end |
---|
324 | end |
---|
325 | end |
---|
326 | set(currentfig,'Pointer',pointershape); |
---|