[11] | 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 | if ~isfield(handles, 'mouse_coord') |
---|
| 30 | return |
---|
| 31 | end |
---|
| 32 | if ~ishandle(handles.mouse_coord) |
---|
| 33 | return |
---|
| 34 | end |
---|
| 35 | proj_coord=get(handles.mouse_coord,'String'); |
---|
| 36 | choice=get(handles.mouse_coord,'Value'); |
---|
| 37 | if ~isempty(proj_coord); proj_coord=proj_coord{choice};else;proj_coord=[];end; |
---|
| 38 | test_create=0;%default |
---|
| 39 | test_edit=0;%default |
---|
| 40 | if isfield(handles,'VOLUME') % mouse_motion not applied to the uvmat figure, no object creation |
---|
| 41 | test_create=get(handles.create,'Value'); |
---|
| 42 | end |
---|
| 43 | test_edit=isfield(handles,'edit') & get(handles.edit,'Value');% edit test for mouse shap: an arrow |
---|
| 44 | test_zoom=isfield(handles,'zoom')& get(handles.zoom,'Value');% edit test for mouse shap: an arrow |
---|
| 45 | |
---|
| 46 | %find the current axe 'haxes' and display the current mouse position or uicontrol tag |
---|
| 47 | text_displ_1=''; |
---|
| 48 | text_displ_2=''; |
---|
| 49 | text_displ_3=''; |
---|
| 50 | text_displ_4=''; |
---|
| 51 | |
---|
| 52 | haxes=[]; |
---|
| 53 | AxeData=[];%default |
---|
| 54 | mouse=[]; |
---|
| 55 | |
---|
| 56 | pointershape='arrow';% default pointer is an arrow |
---|
| 57 | |
---|
| 58 | xy_fig=get(gcbo,'CurrentPoint');% current point of the current figure (gcbo) |
---|
| 59 | hchild=get(gcbo,'Children');%handles of all objects in the current figure |
---|
| 60 | currentfig=gcbo;%store gcbo as variable currentfig |
---|
| 61 | % loop on all the objects in the current figure (selected by the last mouse click) |
---|
| 62 | for ichild=1:length(hchild) |
---|
| 63 | obj_pos=get(hchild(ichild),'Position');%position of the object |
---|
| 64 | 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); |
---|
| 65 | htype=get(hchild(ichild),'Type');%type of the crrent child |
---|
| 66 | %if the mouse is over an axis, look at the data |
---|
| 67 | if isequal(htype,'axes') |
---|
| 68 | haxes=hchild(ichild); |
---|
| 69 | xy=get(haxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates |
---|
| 70 | mouse.X=xy(1,1); |
---|
| 71 | mouse.Y=xy(1,2); |
---|
| 72 | u_mouse=[]; |
---|
| 73 | v_mouse=[]; |
---|
| 74 | w_mouse=[]; |
---|
| 75 | A_mouse=[]; |
---|
| 76 | c_text=[]; |
---|
| 77 | f_text=[]; |
---|
| 78 | ff_text=[]; |
---|
| 79 | ivec=[]; |
---|
| 80 | AxeData=get(haxes,'UserData');% data attached to the axis |
---|
| 81 | if ~test_edit && ~test_zoom |
---|
| 82 | pointershape='crosshair';%set pointer with cross shape (default when mouse is over an axis) |
---|
| 83 | % % pointershape='crosshair';%set pointer with cross shape (default over axis) |
---|
| 84 | end |
---|
| 85 | if isfield(AxeData,'X') && isfield(AxeData,'Y') && isfield(AxeData,'Mesh')% test on the existence of a vector field in the current axis |
---|
| 86 | if ~isempty(AxeData.Mesh) |
---|
| 87 | 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 |
---|
| 88 | (AxeData.Y<(xy(1,2)+AxeData.Mesh/3) & AxeData.Y>(xy(1,2)-AxeData.Mesh/3));%f |
---|
| 89 | ivec=find(flag_vec);% search the selected vector index ivec |
---|
| 90 | if length(ivec)>0 |
---|
| 91 | if ~test_create |
---|
| 92 | pointershape='arrow'; %mouse indicates the detection of a vector |
---|
| 93 | end |
---|
| 94 | ivec=ivec(1);%choice the first selected vector if several are selected |
---|
| 95 | mouse.X=AxeData.X(ivec); |
---|
| 96 | mouse.Y=AxeData.Y(ivec); |
---|
| 97 | u_mouse=AxeData.U(ivec);%displacement |
---|
| 98 | v_mouse=AxeData.V(ivec); |
---|
| 99 | w_mouse=0; %default |
---|
| 100 | if isfield(AxeData,'W')&length(AxeData.W)>=ivec |
---|
| 101 | w_text=[', w=' num2str(AxeData.W(ivec),3)]; |
---|
| 102 | else |
---|
| 103 | w_text=''; |
---|
| 104 | end |
---|
| 105 | if ~isfield(AxeData,'CName') |
---|
| 106 | AxeData.CName='C';%REVOIR |
---|
| 107 | end |
---|
| 108 | c_text=[', ' AxeData.CName '=' num2str(AxeData.C(ivec),3)]; |
---|
| 109 | if isfield(AxeData,'F')&length(AxeData.F)>=ivec |
---|
| 110 | f_text=[', f=' num2str(AxeData.F(ivec),3)]; |
---|
| 111 | else |
---|
| 112 | f_text=''; |
---|
| 113 | end |
---|
| 114 | if isfield(AxeData,'FF')&length(AxeData.FF)>=ivec |
---|
| 115 | ff_text=[', ff=' num2str(AxeData.FF(ivec),3)]; |
---|
| 116 | else |
---|
| 117 | ff_text=''; |
---|
| 118 | end |
---|
| 119 | end |
---|
| 120 | end |
---|
| 121 | end |
---|
| 122 | if isfield(AxeData,'Z') |
---|
| 123 | mouse.Z=AxeData.Z; %generaliser au cas avec angle |
---|
| 124 | end |
---|
| 125 | if isfield(AxeData,'ObjectCoord') & size(AxeData.ObjectCoord,2)==3 |
---|
| 126 | mouse.Z=AxeData.ObjectCoord(1,3); %generaliser au cas avec angle |
---|
| 127 | end |
---|
| 128 | testscal= isfield(AxeData,'A')& isfield(AxeData,'AX')& isfield(AxeData,'AY');%test the existence of an image (or scalar represented by an image) |
---|
| 129 | if testscal |
---|
| 130 | testscal=~isempty(AxeData.A)&~isempty(AxeData.AX)& ~isempty(AxeData.AY); |
---|
| 131 | end |
---|
| 132 | if testscal%test the existence of an image (or scalar represented by an image) |
---|
| 133 | nxy=size(AxeData.A); |
---|
| 134 | MaxAY=max(AxeData.AY(1),AxeData.AY(end)); |
---|
| 135 | MinAY=min(AxeData.AY(1),AxeData.AY(end)); |
---|
| 136 | if (xy(1,1)>AxeData.AX(1))&(xy(1,1)<AxeData.AX(end))&(xy(1,2)<MaxAY)&(xy(1,2)>MinAY) |
---|
| 137 | indx0=1+round((nxy(2)-1)*(xy(1,1)-AxeData.AX(1))/(AxeData.AX(end)-AxeData.AX(1)));% index x of pixel |
---|
| 138 | indy0=1+round((nxy(1)-1)*(xy(1,2)-AxeData.AY(1))/(AxeData.AY(end)-AxeData.AY(1)));% index y of pixel |
---|
| 139 | if indx0>=1 & indx0<=nxy(2) & indy0>=1 & indy0<=nxy(1) |
---|
| 140 | A_mouse=AxeData.A(indy0,indx0,:); |
---|
| 141 | end |
---|
| 142 | end |
---|
| 143 | end |
---|
| 144 | %coordinate transform if proj_coord differs from menu_coord |
---|
| 145 | if isfield(AxeData,'CoordType') |
---|
| 146 | mouse.CoordType=AxeData.CoordType; |
---|
| 147 | end |
---|
| 148 | if isfield(AxeData,'CoordUnit') |
---|
| 149 | mouse.CoordUnit=AxeData.CoordUnit; |
---|
| 150 | end |
---|
| 151 | if isfield(mouse,'CoordType') &~isequal(mouse.CoordType,proj_coord) |
---|
| 152 | huvmat=findobj(allchild(0),'Tag','uvmat');%find the uvmat interface handle |
---|
| 153 | UvData=get(huvmat,'UserData'); %coord transformed stored in the uvmat interface, updated by file input |
---|
| 154 | if isfield(AxeData,'CoordType') |
---|
| 155 | mouse.CoordType=AxeData.CoordType; |
---|
| 156 | end |
---|
| 157 | if isfield(AxeData,'dt') |
---|
| 158 | mouse.dt=AxeData.dt; |
---|
| 159 | end |
---|
| 160 | % if ~isempty(z_mouse) |
---|
| 161 | % mouse.Z=z_mouse; |
---|
| 162 | % end |
---|
| 163 | if length(ivec)>0 %& isfield(AxeData,'dt') |
---|
| 164 | mouse.U=u_mouse; |
---|
| 165 | mouse.V=v_mouse; |
---|
| 166 | end |
---|
| 167 | mouse=feval(proj_coord,mouse,UvData);%apply transform proj_coord to the position |
---|
| 168 | if length(ivec)>0%& isfield(AxeData,'dt') |
---|
| 169 | u_mouse=mouse.U; |
---|
| 170 | v_mouse=mouse.V; |
---|
| 171 | end |
---|
| 172 | end |
---|
| 173 | if isfield(mouse,'CoordType') |
---|
| 174 | if isequal(mouse.CoordType,'px') |
---|
| 175 | mouse.CoordUnit='px'; |
---|
| 176 | end |
---|
| 177 | else |
---|
| 178 | mouse.CoordUnit='';%default |
---|
| 179 | end |
---|
| 180 | text_displ_1=['x=' num2str(mouse.X,4) ',y=' num2str(mouse.Y,4)]; |
---|
| 181 | if isfield(mouse,'Z')&~isempty(mouse.Z) |
---|
| 182 | text_displ_1=[text_displ_1 ',z=' num2str(mouse.Z,3)]; |
---|
| 183 | end |
---|
| 184 | if isfield(mouse,'CoordUnit') |
---|
| 185 | text_displ_1=[text_displ_1 ' ' mouse.CoordUnit]; |
---|
| 186 | end |
---|
| 187 | if ~isempty(ivec) |
---|
| 188 | text_displ_4=['vec#=' num2str(ivec)]; |
---|
| 189 | end |
---|
| 190 | if ~isempty(u_mouse) |
---|
| 191 | text_displ_3=['u=' num2str(u_mouse,3) ',v=' num2str(v_mouse,3) w_text ]; |
---|
| 192 | if isfield(mouse,'CoordUnit') |
---|
| 193 | if isequal(mouse.CoordUnit,'px') |
---|
| 194 | text_displ_3=[text_displ_3 ' ' mouse.CoordUnit]; |
---|
| 195 | elseif isfield(AxeData,'TimeUnit') |
---|
| 196 | text_displ_3=[text_displ_3 ' ' mouse.CoordUnit '/' AxeData.TimeUnit]; |
---|
| 197 | end |
---|
| 198 | end |
---|
| 199 | text_displ_4=[text_displ_4 c_text f_text ff_text]; |
---|
| 200 | end |
---|
| 201 | |
---|
| 202 | if ~isempty(A_mouse) |
---|
| 203 | text_displ_2=['A=' num2str(double(A_mouse)) ',i=' num2str(indx0) ',j=' num2str(indy0)]; |
---|
| 204 | end |
---|
| 205 | elseif isequal(get(hchild(ichild),'Visible'),'on')& ~isequal(get(hchild(ichild),'Style'),'frame') |
---|
| 206 | text_displ_1=get(hchild(ichild),'Tag'); |
---|
| 207 | end |
---|
| 208 | end |
---|
| 209 | end |
---|
| 210 | set(handles.text_display_1,'String',text_displ_1); |
---|
| 211 | set(handles.text_display_2,'String',text_displ_2); |
---|
| 212 | set(handles.text_display_3,'String',text_displ_3); |
---|
| 213 | set(handles.text_display_4,'String',text_displ_4); |
---|
| 214 | |
---|
| 215 | %%%%%%%%%%%%%%%%% |
---|
| 216 | %create or modify an object |
---|
| 217 | if isfield(AxeData,'CurrentObject') & ishandle(AxeData.CurrentObject) & isfield(AxeData,'Drawing') & ~isequal(AxeData.Drawing,'off') |
---|
| 218 | PlotData=get(AxeData.CurrentObject,'UserData'); |
---|
| 219 | huvmat=findobj(allchild(0),'Name','uvmat');%find the uvmat interface handle |
---|
| 220 | if ~isempty(huvmat) |
---|
| 221 | UvData=get(huvmat,'UserData'); |
---|
| 222 | if ~isfield(PlotData,'IndexObj') |
---|
| 223 | return |
---|
| 224 | end |
---|
| 225 | ObjectData=UvData.Object{PlotData.IndexObj}; |
---|
| 226 | XYData=AxeData.CurrentOrigin; |
---|
| 227 | if isequal(AxeData.Drawing,'create') && isfield(AxeData,'CurrentOrigin') && ~isempty(AxeData.CurrentOrigin) |
---|
| 228 | if isequal(ObjectData.Style,'line')|isequal(ObjectData.Style,'polyline')|isequal(ObjectData.Style,'polygon')|isequal(ObjectData.Style,'points') |
---|
| 229 | xy(1,3)=0; |
---|
| 230 | ObjectData.Coord=[ObjectData.Coord ;xy(1,:)]; |
---|
| 231 | % ObjectData.Coord(end,:)=xy(1,:); |
---|
| 232 | elseif isequal(ObjectData.Style,'rectangle')|isequal(ObjectData.Style,'ellipse')|isequal(ObjectData.Style,'volume') |
---|
| 233 | ObjectData.Coord(1,1)=(xy(1,1)+XYData(1))/2;%origin rectangle, x coordinate |
---|
| 234 | ObjectData.Coord(1,2)=(xy(1,2)+XYData(2))/2; |
---|
| 235 | ObjectData.RangeX=abs(xy(1,1)-XYData(1))/2;%rectangle width |
---|
| 236 | ObjectData.RangeY=abs(xy(1,2)-XYData(2))/2;%rectangle height |
---|
| 237 | elseif isequal(ObjectData.Style,'plane') %case of 'plane' |
---|
| 238 | DX=(xy(1,1)-ObjectData.Coord(1,1)); |
---|
| 239 | DY=(xy(1,2)-ObjectData.Coord(1,2)); |
---|
| 240 | ObjectData.Phi=(angle(DX+i*DY))*180/pi;%rectangle widt |
---|
| 241 | if isfield(ObjectData,'RangeX') |
---|
| 242 | XMax=sqrt(DX*DX+DY*DY); |
---|
| 243 | if XMax>max(ObjectData.RangeX) |
---|
| 244 | ObjectData.RangeX=[min(ObjectData.RangeX) XMax]; |
---|
| 245 | end |
---|
| 246 | end |
---|
| 247 | end |
---|
| 248 | plot_object(ObjectData,[],AxeData.CurrentObject,'m'); |
---|
| 249 | pointershape='crosshair'; |
---|
| 250 | elseif isequal(AxeData.Drawing,'translate') |
---|
| 251 | DX=xy(1,1)-XYData(1);%translation from initial position |
---|
| 252 | DY=xy(1,2)-XYData(2); |
---|
| 253 | ObjectData.Coord(:,1)=ObjectData.Coord(:,1)+DX; |
---|
| 254 | ObjectData.Coord(:,2)=ObjectData.Coord(:,2)+DY; |
---|
| 255 | plot_object(ObjectData,[],AxeData.CurrentObject,'m'); |
---|
| 256 | pointershape='fleur'; |
---|
| 257 | elseif isequal(AxeData.Drawing,'deform') |
---|
| 258 | ind_move=AxeData.CurrentIndex; |
---|
| 259 | ObjectData.Coord(ind_move,1)=xy(1,1); |
---|
| 260 | ObjectData.Coord(ind_move,2)=xy(1,2); |
---|
| 261 | plot_object(ObjectData,[],AxeData.CurrentObject,'m'); |
---|
| 262 | pointershape='circle'; |
---|
| 263 | end |
---|
| 264 | end |
---|
| 265 | end |
---|
| 266 | %%%%%%%%%%%%% |
---|
| 267 | %draw a rectangle if no object creation is selected |
---|
| 268 | if ~isempty(haxes) & isfield(AxeData,'Drawing')& isequal(AxeData.Drawing,'zoom')& isfield(AxeData,'CurrentOrigin')... |
---|
| 269 | & isequal(get(gcf,'SelectionType'),'normal')% |
---|
| 270 | xy_rect=AxeData.CurrentOrigin; |
---|
| 271 | if ~isempty(xy_rect) |
---|
| 272 | rect(1)=min(xy(1,1),xy_rect(1));%origin rectangle, x coordinate |
---|
| 273 | rect(2)=min(xy(1,2),xy_rect(2));%origin rectangle, y coordinate |
---|
| 274 | rect(3)=abs(xy(1,1)-xy_rect(1));%rectangle width |
---|
| 275 | rect(4)=abs(xy(1,2)-xy_rect(2));%rectangle height |
---|
| 276 | if rect(3)>0 & rect(4)>0 |
---|
| 277 | if isfield(AxeData,'CurrentRectZoom')& ishandle(AxeData.CurrentRectZoom) |
---|
| 278 | set(AxeData.CurrentRectZoom,'Position',rect);%update the rectangle position |
---|
| 279 | else |
---|
| 280 | AxeData.CurrentRectZoom=rectangle('Position',rect,'LineStyle',':','Tag','rect_zoom'); |
---|
| 281 | set(haxes,'UserData',AxeData) |
---|
| 282 | end |
---|
| 283 | end |
---|
| 284 | end |
---|
| 285 | end |
---|
| 286 | if test_zoom |
---|
| 287 | pointershape='arrow'; |
---|
| 288 | end |
---|
| 289 | set(currentfig,'Pointer',pointershape); |
---|