1 | %'mouse_down': function activated when the mouse button is pressed on a figure (callback for 'WindowButtonDownFcn' |
---|
2 | %-------------------------------------------------------------- |
---|
3 | % xy=mouse_down(hObject,eventdata) |
---|
4 | % activated by the command: |
---|
5 | % set(hObject,'WindowButtonDownFcn',{'mouse_down'}), |
---|
6 | % where hObject is the handle of the figure |
---|
7 | % |
---|
8 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
9 | % Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org. |
---|
10 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
11 | % This file is part of the toolbox UVMAT. |
---|
12 | % |
---|
13 | % UVMAT is free software; you can redistribute it and/or modify |
---|
14 | % it under the terms of the GNU General Public License as published by |
---|
15 | % the Free Software Foundation; either version 2 of the License, or |
---|
16 | % (at your option) any later version. |
---|
17 | % |
---|
18 | % UVMAT is distributed in the hope that it will be useful, |
---|
19 | % but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
20 | % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
21 | % GNU General Public License (file UVMAT/COPYING.txt) for more details. |
---|
22 | %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
---|
23 | |
---|
24 | function xy=mouse_down(hObject,eventdata) |
---|
25 | |
---|
26 | MouseAction='none'; %default |
---|
27 | huvmat=findobj(allchild(0),'tag','uvmat');%find the uvmat interface handle which controls theoption of mouse action |
---|
28 | if isempty(huvmat) |
---|
29 | return |
---|
30 | end |
---|
31 | hhuvmat=guidata(huvmat);%handles of elements in uvmat |
---|
32 | guihandles=guidata(hObject); |
---|
33 | UvData=get(huvmat,'UserData'); |
---|
34 | MouseAction='none'; %default |
---|
35 | testzoom=get(guihandles.zoom,'Value');% get the mouse action from the uvmat GUI: options: |
---|
36 | if isfield(UvData,'MouseAction') |
---|
37 | MouseAction=UvData.MouseAction;% get the mouse action from the uvmat GUI: options: |
---|
38 | end |
---|
39 | |
---|
40 | test_create=~testzoom && (isequal(MouseAction,'create_object') || isequal(MouseAction,'create_mask')); |
---|
41 | %test_cal=get(handles.cal,'Value'); |
---|
42 | test_cal=strcmp(MouseAction,'calib'); |
---|
43 | test_ruler=strcmp(MouseAction,'ruler'); |
---|
44 | test_edit=strcmp(MouseAction,'edit_object'); |
---|
45 | test_edit_vect=strcmp(MouseAction,'edit_vect'); |
---|
46 | xdisplay=[];%default |
---|
47 | ydisplay=[];%default |
---|
48 | AxeData=[];%default |
---|
49 | |
---|
50 | %edit an existing point or line if found |
---|
51 | hcurrentobject=gco;% current object handle (selected by the mouse) |
---|
52 | hcurrentfig=hObject;% current figure handle |
---|
53 | fig_tag=get(hcurrentfig,'Tag'); |
---|
54 | tag_obj=get(gco,'Tag'); |
---|
55 | xy=[];%default |
---|
56 | xy_fig=get(hcurrentfig,'CurrentPoint');% current point of the current figure (gcbo) |
---|
57 | hchild=get(hcurrentfig,'Children');%handles of all objects in the current figure |
---|
58 | haxes=[]; |
---|
59 | % loop on all the objects in the current figure (selected by the last mouse click) |
---|
60 | for ichild=1:length(hchild) |
---|
61 | obj_pos=get(hchild(ichild),'Position');%position of the object |
---|
62 | 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); |
---|
63 | htype=get(hchild(ichild),'Type');%type of object child of the current figure |
---|
64 | %if the mouse is over an axis, look at the data |
---|
65 | if isequal(htype,'axes') |
---|
66 | y_lim=get(hchild(ichild),'YLim'); |
---|
67 | x_lim=get(hchild(ichild),'XLim'); |
---|
68 | haxes=hchild(ichild); |
---|
69 | xy=get(haxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates |
---|
70 | if xy(1,1)>x_lim(1) && xy(1,1)<x_lim(2) && xy(1,2)>y_lim(1) && xy(1,2)<y_lim(2) |
---|
71 | AxeData=get(haxes,'UserData');% data attached to the axis |
---|
72 | AxeData.CurrentOrigin=[xy(1,1) xy(1,2)];% The current point set by the mouse becomes the current origin |
---|
73 | if ~isequal(tag_obj,'proj_object') & ~test_create |
---|
74 | x_mouse=xy(1,1);%default |
---|
75 | y_mouse=xy(1,2);%default |
---|
76 | u_mouse=[]; |
---|
77 | v_mouse=[]; |
---|
78 | w_mouse=[]; |
---|
79 | A_mouse=[]; |
---|
80 | c_text=[]; |
---|
81 | f_text=[]; |
---|
82 | ff_text=[]; |
---|
83 | ivec=[]; |
---|
84 | if isfield(AxeData,'X') & isfield(AxeData,'Y') & isfield(AxeData,'Mesh')% test on the existence of a vector field in the current axis |
---|
85 | flag_vec=(AxeData.X<(xy(1,1)+AxeData.Mesh/4) & AxeData.X>(xy(1,1)-AxeData.Mesh/4)) & ...%flagx=1 for the vectors with x position selected by the mouse |
---|
86 | (AxeData.Y<(xy(1,2)+AxeData.Mesh/4) & AxeData.Y>(xy(1,2)-AxeData.Mesh/4));%f |
---|
87 | ivec=find(flag_vec,1);% search the (first) selected vector index ivec |
---|
88 | end |
---|
89 | end |
---|
90 | else |
---|
91 | haxes=[];%mouse out of axes |
---|
92 | end |
---|
93 | end |
---|
94 | end |
---|
95 | end |
---|
96 | test2D=0; |
---|
97 | if isfield(AxeData,'NbDim') |
---|
98 | if isequal(AxeData.NbDim,2) |
---|
99 | test2D=1; |
---|
100 | end |
---|
101 | end |
---|
102 | if ~test2D %desable object creation and vector editing if NbDim different from 2 |
---|
103 | test_create=0; |
---|
104 | test_edit_vect=0; |
---|
105 | end |
---|
106 | %delete the current zoom rectangle |
---|
107 | if isfield(AxeData,'CurrentRectZoom') & ishandle(AxeData.CurrentRectZoom) |
---|
108 | delete(AxeData.CurrentRectZoom) |
---|
109 | AxeData.CurrentRectZoom=[]; |
---|
110 | end |
---|
111 | |
---|
112 | % zoom has first priority |
---|
113 | if testzoom %&& ~test_create && ~test_edit && ~test_edit_vect && exist('xy','var') |
---|
114 | AxeData.Drawing='zoom'; %initiate drawing mode |
---|
115 | AxeData.CurrentObject=[];%unselect objects |
---|
116 | set(haxes,'UserData',AxeData); |
---|
117 | return |
---|
118 | end |
---|
119 | if isempty(huvmat) |
---|
120 | return |
---|
121 | end |
---|
122 | |
---|
123 | %ruler has second priority |
---|
124 | if test_ruler |
---|
125 | UvData.RulerCoord(1,1)=xy(1,1); |
---|
126 | UvData.RulerCoord(1,2)=xy(1,2); |
---|
127 | UvData.RulerHandle=line([xy(1,1) xy(1,1)],[xy(1,2) xy(1,2)],'Color','m','Tag','ruler'); |
---|
128 | set(huvmat,'UserData',UvData) |
---|
129 | AxeData.Drawing='ruler'; |
---|
130 | set(haxes,'UserData',AxeData); |
---|
131 | return |
---|
132 | end |
---|
133 | |
---|
134 | %selection of an existing projection object |
---|
135 | if test_edit && (isequal(tag_obj,'proj_object')||isequal(tag_obj,'DeformPoint')) |
---|
136 | if ~(isfield(AxeData,'Drawing') && isequal(AxeData.Drawing,'create')) |
---|
137 | userdata=get(hcurrentobject,'UserData'); |
---|
138 | if ishandle(userdata)%the selected line depends on a parent line |
---|
139 | AxeData.CurrentObject=userdata;% the parent object becomes the current one |
---|
140 | else |
---|
141 | AxeData.CurrentObject=hcurrentobject;% the selected object becomes the current one |
---|
142 | end |
---|
143 | ObjectData=get(AxeData.CurrentObject,'UserData'); |
---|
144 | if test_edit && isfield(ObjectData,'IndexObj') |
---|
145 | hother=findobj('Tag','proj_object','Type','line');%find all the proj objects |
---|
146 | set(hother,'Color','b');%reset all the proj objects in 'blue' by default |
---|
147 | set(hother,'Selected','off') |
---|
148 | hother=findobj('Tag','proj_object','Type','rectangle'); |
---|
149 | set(hother,'EdgeColor','b'); |
---|
150 | set(hother,'Selected','off'); |
---|
151 | hother=findobj('Tag','proj_object','Type','image'); |
---|
152 | for iobj=1:length(hother) |
---|
153 | Acolor=get(hother(iobj),'CData'); |
---|
154 | Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2)); |
---|
155 | set(hother(iobj),'CData',Acolor); |
---|
156 | end |
---|
157 | hother=findobj('Tag','DeformPoint'); |
---|
158 | set(hother,'Color','b'); |
---|
159 | set(hother,'Selected','off') |
---|
160 | if isequal(get(AxeData.CurrentObject,'Type'),'line') |
---|
161 | set(AxeData.CurrentObject,'Color','m'); %set the selected object to magenta color |
---|
162 | elseif isequal(get(AxeData.CurrentObject,'Type'),'rectangle') |
---|
163 | set(AxeData.CurrentObject,'EdgeColor','m'); %set the selected object to magenta color |
---|
164 | end |
---|
165 | if isfield(ObjectData,'SubObject')& ishandle(ObjectData.SubObject) |
---|
166 | for iobj=1:length(ObjectData.SubObject) |
---|
167 | hsub=ObjectData.SubObject(iobj); |
---|
168 | if isequal(get(hsub,'Type'),'rectangle') |
---|
169 | set(hsub,'EdgeColor','m'); %set the selected object to magenta color |
---|
170 | elseif isequal(get(hsub,'Type'),'image') |
---|
171 | Acolor=get(hsub,'CData'); |
---|
172 | Acolor(:,:,1)=Acolor(:,:,3); |
---|
173 | set(hsub,'CData',Acolor); |
---|
174 | else |
---|
175 | set(hsub,'Color','m') |
---|
176 | end |
---|
177 | end |
---|
178 | end |
---|
179 | if isequal(tag_obj,'DeformPoint') |
---|
180 | set(hcurrentobject,'Color','m'); %set the selected DeformPoint to magenta color |
---|
181 | end |
---|
182 | IndexObj=ObjectData.IndexObj; |
---|
183 | %indicate on the list of the GUI uvmat which object has been selected |
---|
184 | if strcmp(get(hcurrentfig,'tag'),'uvmat') %if the uvmat graph has been selected, object projection is on the other frame view_field |
---|
185 | set(hhuvmat.list_object_2,'Value',IndexObj); |
---|
186 | list_str=get(hhuvmat.list_object_2,'String'); |
---|
187 | UvData.Object{IndexObj}.Name=list_str{IndexObj}; |
---|
188 | else |
---|
189 | set(hhuvmat.list_object_1,'Value',IndexObj); |
---|
190 | list_str=get(hhuvmat.list_object_1,'String'); |
---|
191 | UvData.Object{IndexObj}.Name=list_str{IndexObj}; |
---|
192 | end |
---|
193 | h_set_object=findobj(allchild(0),'Tag','set_object'); |
---|
194 | if ~isempty(h_set_object) |
---|
195 | delete(h_set_object) |
---|
196 | end |
---|
197 | set_object(UvData.Object{IndexObj}) |
---|
198 | axes(haxes);%set back the current axes haxes |
---|
199 | testdeform=0; |
---|
200 | set(gcbo,'Pointer','circle'); |
---|
201 | AxeData.Drawing='deform'; |
---|
202 | if isequal(tag_obj,'DeformPoint') |
---|
203 | if isfield(ObjectData,'DeformPoint') |
---|
204 | set(hcurrentobject,'Selected','on') |
---|
205 | for ipt=1:length(ObjectData.DeformPoint) |
---|
206 | if isequal(ObjectData.DeformPoint(ipt),hcurrentobject) |
---|
207 | AxeData.CurrentIndex=ipt; |
---|
208 | testdeform=1; |
---|
209 | end |
---|
210 | end |
---|
211 | end |
---|
212 | end |
---|
213 | if testdeform==0 |
---|
214 | AxeData.Drawing='translate'; |
---|
215 | set(AxeData.CurrentObject,'Selected','on') |
---|
216 | set(gcbo,'Pointer','fleur'); |
---|
217 | end |
---|
218 | end |
---|
219 | end |
---|
220 | end |
---|
221 | % create new projection object |
---|
222 | if test_create && ~isempty(xy) && ~(isfield(AxeData,'Drawing')&& isequal(AxeData.Drawing,'create')) |
---|
223 | ObjectData=read_set_object(UvData.sethandles); |
---|
224 | ObjectData.Coord=[]; %reset previous object coordinates |
---|
225 | ObjectData.Coord(1,1)=xy(1,1); |
---|
226 | ObjectData.Coord(1,2)=xy(1,2); |
---|
227 | ObjectData.Coord(1,3)=0; |
---|
228 | if isfield(AxeData,'ObjectCoord') & size(AxeData.ObjectCoord,2)==3 |
---|
229 | ObjectData.Coord(1,3)=AxeData.ObjectCoord(1,3); %generaliser au cas avec angle |
---|
230 | end |
---|
231 | AxeData.CurrentObject=plot_object(ObjectData,[],haxes,'m');%draw the object and its handle becomes AxeData.CurrentObject |
---|
232 | if isfield(UvData,'Object') |
---|
233 | IndexObj=length(UvData.Object)+1;% add the object as index IndexObj on the list of the interface |
---|
234 | else |
---|
235 | IndexObj=2; |
---|
236 | end |
---|
237 | UvData.Object{IndexObj}=ObjectData; |
---|
238 | UvData.Object{IndexObj}.HandlesDisplay(1)=AxeData.CurrentObject; |
---|
239 | set(huvmat,'UserData',UvData) |
---|
240 | list_str=get(hhuvmat.list_object_1,'String'); |
---|
241 | object_name=get(UvData.sethandles.TITLE,'String') |
---|
242 | if isempty(object_name)|| strcmp(object_name,'') |
---|
243 | list_str{IndexObj}=[num2str(IndexObj) '-' ObjectData.Style]; |
---|
244 | set(UvData.sethandles.TITLE,'String',list_str{IndexObj}) |
---|
245 | else |
---|
246 | list_str{IndexObj}=object_name; |
---|
247 | end |
---|
248 | set(hhuvmat.list_object_1,'String',list_str) |
---|
249 | list_str{end+1}='...'; |
---|
250 | set(hhuvmat.list_object_2,'String',list_str) |
---|
251 | if strcmp(fig_tag,'view_field')%we are in view_field plot |
---|
252 | set(hhuvmat.list_object_1,'Value',IndexObj)% the projection field will be plotted in uvmat frame |
---|
253 | else%we are in uvmat plot |
---|
254 | set(hhuvmat.list_object_2,'Value',IndexObj) |
---|
255 | end |
---|
256 | PlotData=get(AxeData.CurrentObject,'UserData'); |
---|
257 | PlotData.IndexObj=IndexObj; |
---|
258 | set(AxeData.CurrentObject,'UserData',PlotData); %record the object index in the graph |
---|
259 | AxeData.Drawing='create'; |
---|
260 | end |
---|
261 | |
---|
262 | % create calibration points if the GUI geometry_calib is opened, if the main axes axes3 of uvmat has ben selected |
---|
263 | if ~testzoom && test_cal && ~isempty(haxes) && strcmp(get(haxes,'tag'),'axes3') |
---|
264 | h_geometry_calib=findobj(allchild(0),'Name','geometry_calib'); %find the geomterty_calib GUI |
---|
265 | hh_geometry_calib=guidata(h_geometry_calib); |
---|
266 | h_ListCoord=hh_geometry_calib.ListCoord; %findobj(h_geometry_calib,'Tag','ListCoord'); |
---|
267 | h_edit_append=hh_geometry_calib.edit_append;%findobj(h_geometry_calib,'Tag','edit_append'); |
---|
268 | if isequal(get(h_edit_append,'Value'),1) && ~isempty(haxes) |
---|
269 | coord_value=get(hhuvmat.transform_fct,'Value');% set uvmat to pixel coordinates, run it again if not |
---|
270 | if ~(isequal(coord_value,1)||isequal(coord_value,3)); %active only with no transform or px (no phys) |
---|
271 | set(hhuvmat.transform_fct,'Value',1) |
---|
272 | uvmat('transform_fct_Callback',hObject,eventdata,hhuvmat); %file input with xml reading in uvmat |
---|
273 | set(hhuvmat.FixedLimits,'Value',0)% put FixedLimits option to 'off' |
---|
274 | set(hhuvmat.FixedLimits,'BackgroundColor',[0.7 0.7 0.7]) |
---|
275 | return |
---|
276 | end |
---|
277 | Coord=get(h_ListCoord,'String'); |
---|
278 | data=read_geometry_calib(Coord);%transform char cell to numbers |
---|
279 | xlim=get(haxes,'XLim'); |
---|
280 | ind_range_x=abs((xlim(2)-xlim(1))/50); |
---|
281 | ylim=get(haxes,'YLim'); |
---|
282 | ind_range_y=abs((ylim(2)-ylim(1))/50); |
---|
283 | ind_range=sqrt(ind_range_x*ind_range_y); |
---|
284 | test_newpoint=1; |
---|
285 | if size(data.Coord,2)>=5 %if calibration points already exist |
---|
286 | XCoord=(data.Coord(:,4)); |
---|
287 | YCoord=(data.Coord(:,5)); |
---|
288 | 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 |
---|
289 | (YCoord<xy(1,2)+ind_range) & (YCoord>xy(1,2)-ind_range),1);%find the first calibration point in the neighborhood of the mouse |
---|
290 | test_newpoint=isempty(index_point);%test for no existing calibration point near the mouse position |
---|
291 | end |
---|
292 | val=get(h_ListCoord,'Value'); |
---|
293 | %create a new calib point if we are not close to an existing one |
---|
294 | if test_newpoint |
---|
295 | strline=[ ' | ' ' | ' ' | ' num2str(xy(1,1),4) ' | ' num2str(xy(1,2),4)]; |
---|
296 | |
---|
297 | if length(Coord)>=val |
---|
298 | Coord(val+1:length(Coord)+1)=Coord(val:length(Coord));% push the list forward beyond the current point |
---|
299 | end |
---|
300 | Coord{val}=strline; |
---|
301 | set(h_ListCoord,'String',Coord) |
---|
302 | % set(h_ListCoord,'Value',val+1) |
---|
303 | data=read_geometry_calib(Coord);%transform char cell to numbers |
---|
304 | XCoord=data.Coord(:,4); |
---|
305 | YCoord=data.Coord(:,5); |
---|
306 | end |
---|
307 | hh=findobj('Tag','calib_points');%look for handle of calibration points |
---|
308 | if isempty(hh) |
---|
309 | hh=line(XCoord,YCoord,'Color','m','Tag','calib_points','LineStyle','.','Marker','+'); |
---|
310 | else |
---|
311 | set(hh,'XData',XCoord) |
---|
312 | set(hh,'YData',YCoord) |
---|
313 | end |
---|
314 | set(hh,'UserData',val)% flag the points to edit mode |
---|
315 | hhh=findobj('Tag','calib_marker');%look for handle of point marker (circle) |
---|
316 | if ~isempty(hhh) |
---|
317 | set(hhh,'Position',[xy(1,1)-ind_range/2 xy(1,2)-ind_range/2 ind_range ind_range]) |
---|
318 | else |
---|
319 | rectangle('Curvature',[1 1],... |
---|
320 | 'Position',[xy(1,1)-ind_range/2 xy(1,2)-ind_range/2 ind_range ind_range],'EdgeColor','m',... |
---|
321 | 'LineStyle','-','Tag','calib_marker'); |
---|
322 | % line([xy(1,1) xy(1,1)],[xy(1,2) xy(1,2)],'Color','m','Tag','calib_marker','LineStyle','.','Marker','o','MarkerSize',ind_range); |
---|
323 | end |
---|
324 | AxeData.Drawing='calibration'; |
---|
325 | end |
---|
326 | end |
---|
327 | |
---|
328 | % edit vectors |
---|
329 | if test_edit_vect & ~isempty(ivec) |
---|
330 | if ~(isfield(AxeData,'FF')&& ~isempty(AxeData.FF)) |
---|
331 | AxeData.FF=zeros(size(AxeData.X)); |
---|
332 | end |
---|
333 | if isequal(AxeData.FF(ivec),0) |
---|
334 | AxeData.FF(ivec)=100; %mark vector #ivec as false |
---|
335 | else |
---|
336 | AxeData.FF(ivec)=0; |
---|
337 | end |
---|
338 | PlotParam=read_plot_param(hhuvmat); |
---|
339 | [PlotType,ScalOut]= plot_field(AxeData,haxes,PlotParam,1); |
---|
340 | end |
---|
341 | set(haxes,'UserData',AxeData); |
---|
342 | |
---|