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 | huvmat=findobj(allchild(0),'tag','uvmat');%find the uvmat interface handle which controls theoption of mouse action |
---|
27 | if isempty(huvmat) |
---|
28 | return |
---|
29 | end |
---|
30 | hhuvmat=guidata(huvmat);%handles of elements in uvmat |
---|
31 | UvData=get(huvmat,'UserData'); |
---|
32 | FigData=get(hObject,'UserData'); |
---|
33 | if ishandle(FigData)% case of a zoom plot, the handle of the parent rectangle is stored in UserData, its parent is the plotting axes of the rectangle |
---|
34 | hcurrentfig=get(get(FigData,'parent'),'parent'); |
---|
35 | else |
---|
36 | hcurrentfig=hObject;%usual plot |
---|
37 | end |
---|
38 | hhcurrentfig=guidata(hcurrentfig); |
---|
39 | test_zoom=get(hhcurrentfig.zoom,'Value');%test for zoom action, first priority |
---|
40 | test_ruler=isequal(get(hhuvmat.MenuRuler,'checked'),'on');%test for ruler action, second priority; |
---|
41 | test_edit=get(hhuvmat.edit_object,'Value');%test for object editing, third priority |
---|
42 | test_edit_vect=get(hhuvmat.edit_vect,'Value');%test for vector editing, priority 4 |
---|
43 | test_create=isequal(get(hhuvmat.MenuObject,'checked'),'on');% test for object creation, priority 5 |
---|
44 | if test_create |
---|
45 | hset_object=findobj(allchild(0),'tag','set_object'); |
---|
46 | test_create=~isempty(hset_object)&&~test_edit; |
---|
47 | end |
---|
48 | test_cal=isequal(get(hhuvmat.MenuCalib,'checked'),'on');% test for calibration |
---|
49 | if test_cal% test for calibration popints, priority 6 |
---|
50 | h_calib=findobj(allchild(0),'tag','geometry_calib'); |
---|
51 | if isempty(h_calib) |
---|
52 | test_cal=0; |
---|
53 | set(hhuvmat.MenuCalib,'checked','off');% test for calibration off |
---|
54 | else |
---|
55 | hh_calib=guidata(h_calib); |
---|
56 | test_cal=get(hh_calib.edit_append,'Value'); |
---|
57 | end |
---|
58 | end |
---|
59 | xdisplay=[];%default |
---|
60 | ydisplay=[];%default |
---|
61 | AxeData=[];%default |
---|
62 | |
---|
63 | %% determine the currently selected items |
---|
64 | hcurrentobject=gco;% current object handle (selected by the mouse) |
---|
65 | %hcurrentfig=hObject;% current figure handle |
---|
66 | fig_tag=get(hcurrentfig,'Tag'); |
---|
67 | tag_obj=get(gco,'Tag');%tag of the currently selected object |
---|
68 | xy=[];%default |
---|
69 | xy_fig=get(hObject,'CurrentPoint');% current point of the current figure (gcbo) |
---|
70 | hchild=get(hObject,'Children');%handles of all objects in the current figure |
---|
71 | haxes=[]; |
---|
72 | |
---|
73 | %% loop on all the objects in the current figure (selected by the last mouse click) |
---|
74 | %CurrentOrigin=get(hObject,'CurrentPoint') |
---|
75 | for ichild=1:length(hchild) |
---|
76 | obj_pos=get(hchild(ichild),'Position');%position of the object |
---|
77 | 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); |
---|
78 | htype=get(hchild(ichild),'Type');%type of object child of the current figure |
---|
79 | %if the mouse is over an axis, look at the data |
---|
80 | if isequal(htype,'axes') |
---|
81 | y_lim=get(hchild(ichild),'YLim'); |
---|
82 | x_lim=get(hchild(ichild),'XLim'); |
---|
83 | haxes=hchild(ichild); |
---|
84 | xy=get(haxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates |
---|
85 | 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) |
---|
86 | AxeData=get(haxes,'UserData');% data attached to the axis |
---|
87 | AxeData.CurrentOrigin=[xy(1,1) xy(1,2)];% The current point set by the mouse becomes the current origin |
---|
88 | if test_edit_vect && ~isequal(tag_obj,'proj_object') & ~test_create |
---|
89 | ivec=[]; |
---|
90 | FigData=get(hcurrentfig,'UserData'); |
---|
91 | tagaxes=get(haxes,'tag'); |
---|
92 | if isfield(FigData,tagaxes) |
---|
93 | eval(['Field=FigData.' tagaxes ';']) |
---|
94 | [CellVarIndex,NbDim,VarType]=find_field_indices(Field);%analyse the physical fields contained in Field |
---|
95 | for icell=1:numel(CellVarIndex)%look for all physical fields |
---|
96 | if NbDim(icell)==2 % select 2D field |
---|
97 | if isfield(Field,'Mesh') && ~isempty(Field.Mesh)&& ~isempty(VarType{icell}.coord_x) && ~isempty(VarType{icell}.coord_y)%case of unstructured data |
---|
98 | eval(['X=Field.' Field.ListVarName{VarType{icell}.coord_x} ';']) |
---|
99 | eval(['Y=Field.' Field.ListVarName{VarType{icell}.coord_y} ';']) |
---|
100 | flag_vec=(X<(xy(1,1)+Field.Mesh/4) & X>(xy(1,1)-Field.Mesh/4)) & ...%flagx=1 for the vectors with x position selected by the mouse |
---|
101 | (Y<(xy(1,2)+Field.Mesh/4) & Y>(xy(1,2)-Field.Mesh/4));%f |
---|
102 | ivec=find(flag_vec,1);% search the (first) selected vector index ivec |
---|
103 | end |
---|
104 | end |
---|
105 | end |
---|
106 | end |
---|
107 | end |
---|
108 | else |
---|
109 | haxes=[];%mouse out of axes |
---|
110 | end |
---|
111 | end |
---|
112 | end |
---|
113 | end |
---|
114 | |
---|
115 | %% desable object creation and vector editing if NbDim different from 2 |
---|
116 | if ~(isfield(AxeData,'NbDim') && isequal(AxeData.NbDim,2)) |
---|
117 | test_create=0; |
---|
118 | test_edit_vect=0; |
---|
119 | end |
---|
120 | |
---|
121 | %% delete the current zoom rectangle |
---|
122 | if isfield(AxeData,'CurrentRectZoom') & ishandle(AxeData.CurrentRectZoom) |
---|
123 | delete(AxeData.CurrentRectZoom) |
---|
124 | AxeData.CurrentRectZoom=[]; |
---|
125 | end |
---|
126 | |
---|
127 | %% zoom has first priority |
---|
128 | if test_zoom %&& ~test_create && ~test_edit && ~test_edit_vect && exist('xy','var') |
---|
129 | AxeData.Drawing='zoom'; %initiate drawing mode |
---|
130 | AxeData.CurrentObject=[];%unselect objects |
---|
131 | set(haxes,'UserData',AxeData); |
---|
132 | return |
---|
133 | end |
---|
134 | if isempty(huvmat)%further options require the uvmat GUI |
---|
135 | return |
---|
136 | end |
---|
137 | |
---|
138 | %% ruler has second priority |
---|
139 | if test_ruler |
---|
140 | AxeData.RulerCoord(1,1)=xy(1,1); |
---|
141 | AxeData.RulerCoord(1,2)=xy(1,2); |
---|
142 | AxeData.RulerHandle=line([xy(1,1) xy(1,1)],[xy(1,2) xy(1,2)],'Color','m','Tag','ruler'); |
---|
143 | AxeData.Drawing='ruler'; |
---|
144 | set(haxes,'UserData',AxeData); |
---|
145 | return |
---|
146 | end |
---|
147 | |
---|
148 | %% selection of an existing projection object (third priority) |
---|
149 | if test_edit && (isequal(tag_obj,'proj_object')||isequal(tag_obj,'DeformPoint')) |
---|
150 | if ~(isfield(AxeData,'Drawing') && isequal(AxeData.Drawing,'create')) |
---|
151 | userdata=get(hcurrentobject,'UserData'); |
---|
152 | if ishandle(userdata)%the selected line depends on a parent line |
---|
153 | AxeData.CurrentObject=userdata;% the parent object becomes the current one |
---|
154 | else |
---|
155 | AxeData.CurrentObject=hcurrentobject;% the selected object becomes the current one |
---|
156 | end |
---|
157 | ObjectData=get(AxeData.CurrentObject,'UserData'); |
---|
158 | if test_edit && isfield(ObjectData,'IndexObj') |
---|
159 | hother=findobj('Tag','proj_object','Type','line');%find all the proj objects |
---|
160 | set(hother,'Color','b');%reset all the proj objects in 'blue' by default |
---|
161 | set(hother,'Selected','off') |
---|
162 | hother=findobj('Tag','proj_object','Type','rectangle'); |
---|
163 | set(hother,'EdgeColor','b'); |
---|
164 | set(hother,'Selected','off'); |
---|
165 | hother=findobj('Tag','proj_object','Type','image'); |
---|
166 | for iobj=1:length(hother) |
---|
167 | Acolor=get(hother(iobj),'CData'); |
---|
168 | Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2)); |
---|
169 | set(hother(iobj),'CData',Acolor); |
---|
170 | end |
---|
171 | hother=findobj('Tag','DeformPoint'); |
---|
172 | set(hother,'Color','b'); |
---|
173 | set(hother,'Selected','off') |
---|
174 | if isequal(get(AxeData.CurrentObject,'Type'),'line') |
---|
175 | set(AxeData.CurrentObject,'Color','m'); %set the selected object to magenta color |
---|
176 | elseif isequal(get(AxeData.CurrentObject,'Type'),'rectangle') |
---|
177 | set(AxeData.CurrentObject,'EdgeColor','m'); %set the selected object to magenta color |
---|
178 | end |
---|
179 | if isfield(ObjectData,'SubObject')& ishandle(ObjectData.SubObject) |
---|
180 | for iobj=1:length(ObjectData.SubObject) |
---|
181 | hsub=ObjectData.SubObject(iobj); |
---|
182 | if isequal(get(hsub,'Type'),'rectangle') |
---|
183 | set(hsub,'EdgeColor','m'); %set the selected object to magenta color |
---|
184 | elseif isequal(get(hsub,'Type'),'image') |
---|
185 | Acolor=get(hsub,'CData'); |
---|
186 | Acolor(:,:,1)=Acolor(:,:,3); |
---|
187 | set(hsub,'CData',Acolor); |
---|
188 | else |
---|
189 | set(hsub,'Color','m') |
---|
190 | end |
---|
191 | end |
---|
192 | end |
---|
193 | if isequal(tag_obj,'DeformPoint') |
---|
194 | set(hcurrentobject,'Color','m'); %set the selected DeformPoint to magenta color |
---|
195 | end |
---|
196 | IndexObj=ObjectData.IndexObj; |
---|
197 | %indicate on the list of the GUI uvmat which object has been selected |
---|
198 | if strcmp(get(hcurrentfig,'tag'),'uvmat') %if the uvmat graph has been selected, object projection is on the other frame view_field |
---|
199 | set(hhuvmat.list_object_2,'Value',IndexObj); |
---|
200 | list_str=get(hhuvmat.list_object_2,'String'); |
---|
201 | UvData.Object{IndexObj}.Name=list_str{IndexObj}; |
---|
202 | else |
---|
203 | set(hhuvmat.list_object_1,'Value',IndexObj); |
---|
204 | list_str=get(hhuvmat.list_object_1,'String'); |
---|
205 | UvData.Object{IndexObj}.Name=list_str{IndexObj}; |
---|
206 | end |
---|
207 | h_set_object=findobj(allchild(0),'Tag','set_object'); |
---|
208 | if ~isempty(h_set_object) |
---|
209 | delete(h_set_object) |
---|
210 | end |
---|
211 | set_object(UvData.Object{IndexObj}) |
---|
212 | axes(haxes);%set back the current axes haxes |
---|
213 | testdeform=0; |
---|
214 | set(gcbo,'Pointer','circle'); |
---|
215 | AxeData.Drawing='deform'; |
---|
216 | if isequal(tag_obj,'DeformPoint') |
---|
217 | if isfield(ObjectData,'DeformPoint') |
---|
218 | set(hcurrentobject,'Selected','on') |
---|
219 | for ipt=1:length(ObjectData.DeformPoint) |
---|
220 | if isequal(ObjectData.DeformPoint(ipt),hcurrentobject) |
---|
221 | AxeData.CurrentIndex=ipt; |
---|
222 | testdeform=1; |
---|
223 | end |
---|
224 | end |
---|
225 | end |
---|
226 | end |
---|
227 | if testdeform==0 |
---|
228 | AxeData.Drawing='translate'; |
---|
229 | set(AxeData.CurrentObject,'Selected','on') |
---|
230 | set(gcbo,'Pointer','fleur'); |
---|
231 | end |
---|
232 | end |
---|
233 | end |
---|
234 | end |
---|
235 | |
---|
236 | %% create new projection object |
---|
237 | if test_create && ~isempty(xy) && ~(isfield(AxeData,'Drawing')&& isequal(AxeData.Drawing,'create')) |
---|
238 | hset_object=findobj(allchild(0),'tag','set_object'); |
---|
239 | if ~isempty(hset_object) |
---|
240 | sethandles=guidata(hset_object); |
---|
241 | ObjectData=read_set_object(sethandles); |
---|
242 | ObjectData.Coord=[]; %reset previous object coordinates |
---|
243 | ObjectData.Coord(1,1)=xy(1,1); |
---|
244 | ObjectData.Coord(1,2)=xy(1,2); |
---|
245 | ObjectData.Coord(1,3)=0; |
---|
246 | if isfield(AxeData,'ObjectCoord') & size(AxeData.ObjectCoord,2)==3 |
---|
247 | ObjectData.Coord(1,3)=AxeData.ObjectCoord(1,3); %generaliser au cas avec angle |
---|
248 | end |
---|
249 | AxeData.CurrentObject=plot_object(ObjectData,[],haxes,'m');%draw the object and its handle becomes AxeData.CurrentObject |
---|
250 | if isfield(UvData,'Object') |
---|
251 | IndexObj=length(UvData.Object)+1;% add the object as index IndexObj on the list of the interface |
---|
252 | else |
---|
253 | IndexObj=2; |
---|
254 | end |
---|
255 | UvData.Object{IndexObj}=ObjectData; |
---|
256 | list_str=get(hhuvmat.list_object_1,'String'); |
---|
257 | object_name=get(sethandles.TITLE,'String'); |
---|
258 | if isempty(object_name)|| strcmp(object_name,'') |
---|
259 | list_str{IndexObj}=[num2str(IndexObj) '-' ObjectData.Style]; |
---|
260 | set(sethandles.TITLE,'String',list_str{IndexObj}) |
---|
261 | else |
---|
262 | list_str{IndexObj}=object_name; |
---|
263 | end |
---|
264 | set(hhuvmat.list_object_1,'String',list_str) |
---|
265 | list_str{end+1}='...'; |
---|
266 | set(hhuvmat.list_object_2,'String',list_str) |
---|
267 | if strcmp(fig_tag,'view_field')%we are in view_field plot |
---|
268 | set(hhuvmat.list_object_1,'Value',IndexObj)% the projection field will be plotted in uvmat frame |
---|
269 | UvData.Object{IndexObj}.DisplayHandle_uvmat=[]; |
---|
270 | UvData.Object{IndexObj}.DisplayHandle_view_field=AxeData.CurrentObject; |
---|
271 | else%we are in uvmat plot |
---|
272 | set(hhuvmat.list_object_2,'Value',IndexObj) |
---|
273 | UvData.Object{IndexObj}.DisplayHandle_uvmat=AxeData.CurrentObject; |
---|
274 | UvData.Object{IndexObj}.DisplayHandle_view_field=[]; |
---|
275 | end |
---|
276 | set(huvmat,'UserData',UvData) |
---|
277 | PlotData=get(AxeData.CurrentObject,'UserData'); |
---|
278 | PlotData.IndexObj=IndexObj; |
---|
279 | set(AxeData.CurrentObject,'UserData',PlotData); %record the object index in the graph |
---|
280 | AxeData.Drawing='create'; |
---|
281 | end |
---|
282 | end |
---|
283 | |
---|
284 | % create calibration points if the GUI geometry_calib is opened, if the main axes axes3 of uvmat has ben selected |
---|
285 | if ~test_zoom && test_cal && ~isempty(haxes) && strcmp(get(haxes,'tag'),'axes3') |
---|
286 | h_geometry_calib=findobj(allchild(0),'Name','geometry_calib'); %find the geomterty_calib GUI |
---|
287 | hh_geometry_calib=guidata(h_geometry_calib); |
---|
288 | h_edit_append=hh_geometry_calib.edit_append;%findobj(h_geometry_calib,'Tag','edit_append'); |
---|
289 | if isequal(get(h_edit_append,'Value'),1) && ~isempty(haxes) |
---|
290 | h_ListCoord=hh_geometry_calib.ListCoord; %findobj(h_geometry_calib,'Tag','ListCoord'); |
---|
291 | coord_value=get(hhuvmat.transform_fct,'Value');% set uvmat to pixel coordinates, run it again if not |
---|
292 | if ~(isequal(coord_value,1)||isequal(coord_value,3)); %active only with no transform or px (no phys) |
---|
293 | set(hhuvmat.transform_fct,'Value',1) |
---|
294 | uvmat('transform_fct_Callback',hObject,eventdata,hhuvmat); %file input with xml reading in uvmat |
---|
295 | set(hhuvmat.FixedLimits,'Value',0)% put FixedLimits option to 'off' |
---|
296 | set(hhuvmat.FixedLimits,'BackgroundColor',[0.7 0.7 0.7]) |
---|
297 | return |
---|
298 | end |
---|
299 | Coord=get(h_ListCoord,'String'); |
---|
300 | data=read_geometry_calib(Coord);%transform char cell to numbers |
---|
301 | xlim=get(haxes,'XLim'); |
---|
302 | ind_range_x=abs((xlim(2)-xlim(1))/50); |
---|
303 | ylim=get(haxes,'YLim'); |
---|
304 | ind_range_y=abs((ylim(2)-ylim(1))/50); |
---|
305 | ind_range=sqrt(ind_range_x*ind_range_y); |
---|
306 | test_newpoint=1; |
---|
307 | if size(data.Coord,2)>=5 %if calibration points already exist |
---|
308 | XCoord=(data.Coord(:,4)); |
---|
309 | YCoord=(data.Coord(:,5)); |
---|
310 | 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 |
---|
311 | (YCoord<xy(1,2)+ind_range) & (YCoord>xy(1,2)-ind_range),1);%find the first calibration point in the neighborhood of the mouse |
---|
312 | test_newpoint=isempty(index_point);%test for no existing calibration point near the mouse position |
---|
313 | end |
---|
314 | val=get(h_ListCoord,'Value'); |
---|
315 | %create a new calib point if we are not close to an existing one |
---|
316 | if test_newpoint |
---|
317 | strline=[ ' | ' ' | ' ' | ' num2str(xy(1,1),4) ' | ' num2str(xy(1,2),4)]; |
---|
318 | |
---|
319 | if length(Coord)>=val |
---|
320 | Coord(val+1:length(Coord)+1)=Coord(val:length(Coord));% push the list forward beyond the current point |
---|
321 | end |
---|
322 | Coord{val}=strline; |
---|
323 | set(h_ListCoord,'String',Coord) |
---|
324 | data=read_geometry_calib(Coord);%transform char cell to numbers |
---|
325 | XCoord=data.Coord(:,4); |
---|
326 | YCoord=data.Coord(:,5); |
---|
327 | end |
---|
328 | hh=findobj('Tag','calib_points');%look for handle of calibration points |
---|
329 | if isempty(hh) |
---|
330 | hh=line(XCoord,YCoord,'Color','m','Tag','calib_points','LineStyle','.','Marker','+'); |
---|
331 | else |
---|
332 | set(hh,'XData',XCoord) |
---|
333 | set(hh,'YData',YCoord) |
---|
334 | end |
---|
335 | set(hh,'UserData',val)% flag the points to edit mode |
---|
336 | hhh=findobj('Tag','calib_marker');%look for handle of point marker (circle) |
---|
337 | if ~isempty(hhh) |
---|
338 | set(hhh,'Position',[xy(1,1)-ind_range/2 xy(1,2)-ind_range/2 ind_range ind_range]) |
---|
339 | else |
---|
340 | rectangle('Curvature',[1 1],... |
---|
341 | 'Position',[xy(1,1)-ind_range/2 xy(1,2)-ind_range/2 ind_range ind_range],'EdgeColor','m',... |
---|
342 | 'LineStyle','-','Tag','calib_marker'); |
---|
343 | % line([xy(1,1) xy(1,1)],[xy(1,2) xy(1,2)],'Color','m','Tag','calib_marker','LineStyle','.','Marker','o','MarkerSize',ind_range); |
---|
344 | end |
---|
345 | AxeData.Drawing='calibration'; |
---|
346 | end |
---|
347 | end |
---|
348 | |
---|
349 | % edit vectors |
---|
350 | if test_edit_vect && ~isempty(ivec) |
---|
351 | %create the error flag FF if it does not exist |
---|
352 | if ~isfield(Field,'FF') |
---|
353 | Field.ListVarName=[Field.ListVarName 'FF']; |
---|
354 | Field.VarDimName=[Field.VarDimName Field.VarDimName{VarType{icell}.coord_x}]; |
---|
355 | nbvar=length(Field.ListVarName); |
---|
356 | Field.VarAttribute{nbvar}.Role='errorflag'; |
---|
357 | Field.FF=zeros(size(Field.X)); |
---|
358 | end |
---|
359 | if isequal(Field.FF(ivec),0) |
---|
360 | Field.FF(ivec)=100; %mark vector #ivec as false |
---|
361 | else |
---|
362 | Field.FF(ivec)=0; |
---|
363 | end |
---|
364 | PlotParam=read_plot_param(hhcurrentfig); |
---|
365 | plot_field(Field,haxes,PlotParam); |
---|
366 | eval(['FigData.' tagaxes '=Field;'])%record the modified field in FigData |
---|
367 | set(hcurrentfig,'UserData',FigData); |
---|
368 | end |
---|
369 | set(haxes,'UserData',AxeData); |
---|
370 | |
---|