source: trunk/src/mouse_motion.m @ 61

Last change on this file since 61 was 61, checked in by sommeria, 14 years ago

gestion of projection objects improved. Implementation of view_field.fig
introduction of a circle to mark vectors with the mouse
various cleaning and debugging

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