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 | testzoom=0;%default |
---|
26 | MouseAction='none'; %default |
---|
27 | huvmat=findobj(allchild(0),'Name','uvmat');%find the uvmat interface handle which controls theoption of mouse action |
---|
28 | if ~isempty(huvmat) |
---|
29 | hhuvmat=guidata(huvmat);%handles of elements in uvmat |
---|
30 | UvData=get(huvmat,'UserData'); |
---|
31 | testzoom=get(hhuvmat.zoom,'Value');% get the mouse action from the uvmat GUI: options: |
---|
32 | if isfield(UvData,'MouseAction') |
---|
33 | MouseAction=UvData.MouseAction;% get the mouse action from the uvmat GUI: options: |
---|
34 | end |
---|
35 | end |
---|
36 | test_create=~testzoom && (isequal(MouseAction,'create_object') || isequal(MouseAction,'create_mask')); |
---|
37 | %test_cal=get(handles.cal,'Value'); |
---|
38 | test_cal=isequal(MouseAction,'calib'); |
---|
39 | handles_coord=findobj(huvmat,'Tag','menu_coord'); |
---|
40 | menu_coord=get(handles_coord,'String'); |
---|
41 | coord_choice=get(handles_coord,'Value'); |
---|
42 | coord_type=menu_coord{coord_choice}; |
---|
43 | test_edit=isequal(MouseAction,'edit_object'); |
---|
44 | test_edit_vect=isequal(MouseAction,'edit_vect'); |
---|
45 | xdisplay=[];%default |
---|
46 | ydisplay=[];%default |
---|
47 | haxes=[]; |
---|
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=gcbo;% current figure handle |
---|
53 | tag_obj=get(gco,'Tag'); |
---|
54 | xy=[];%default |
---|
55 | xy_fig=get(hcurrentfig,'CurrentPoint');% current point of the current figure (gcbo) |
---|
56 | hchild=get(hcurrentfig,'Children');%handles of all objects in the current figure |
---|
57 | % loop on all the objects in the current figure (selected by the last mouse click) |
---|
58 | for ichild=1:length(hchild) |
---|
59 | obj_pos=get(hchild(ichild),'Position');%position of the object |
---|
60 | 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); |
---|
61 | htype=get(hchild(ichild),'Type');%type of object child of the current figure |
---|
62 | %if the mouse is over an axis, look at the data |
---|
63 | if isequal(htype,'axes') |
---|
64 | haxes=hchild(ichild); |
---|
65 | xy=get(haxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates |
---|
66 | AxeData=get(haxes,'UserData');% data attached to the axis |
---|
67 | AxeData.CurrentOrigin=[xy(1,1) xy(1,2)];% The current point set by the mouse becomes the current origin |
---|
68 | if ~isequal(tag_obj,'proj_object') & ~test_create |
---|
69 | x_mouse=xy(1,1);%default |
---|
70 | y_mouse=xy(1,2);%default |
---|
71 | u_mouse=[]; |
---|
72 | v_mouse=[]; |
---|
73 | w_mouse=[]; |
---|
74 | A_mouse=[]; |
---|
75 | c_text=[]; |
---|
76 | f_text=[]; |
---|
77 | ff_text=[]; |
---|
78 | ivec=[]; |
---|
79 | if isfield(AxeData,'X') & isfield(AxeData,'Y') & isfield(AxeData,'Mesh')% test on the existence of a vector field in the current axis |
---|
80 | 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 |
---|
81 | (AxeData.Y<(xy(1,2)+AxeData.Mesh/4) & AxeData.Y>(xy(1,2)-AxeData.Mesh/4));%f |
---|
82 | ivec=find(flag_vec);% search the selected vector index ivec |
---|
83 | if length(ivec)>0 |
---|
84 | ivec=ivec(1);%choice the first selected vector if several are selected |
---|
85 | end |
---|
86 | end |
---|
87 | end |
---|
88 | elseif isequal(get(hchild(ichild),'Visible'),'on')& ~isequal(get(hchild(ichild),'Style'),'frame') |
---|
89 | %FAIRE UNE OPTION D'AIDE AVEC BOUTON SOURIS DROIT (ALT)?? |
---|
90 | end |
---|
91 | end |
---|
92 | end |
---|
93 | test2D=0; |
---|
94 | if isfield(AxeData,'NbDim') |
---|
95 | if isequal(AxeData.NbDim,2) |
---|
96 | test2D=1; |
---|
97 | end |
---|
98 | end |
---|
99 | if ~test2D %desable object creation and vector editing if NbDim different from 2 |
---|
100 | test_create=0; |
---|
101 | test_edit_vect=0; |
---|
102 | end |
---|
103 | %delete the current zoom rectangle |
---|
104 | if isfield(AxeData,'CurrentRectZoom') & ishandle(AxeData.CurrentRectZoom) |
---|
105 | delete(AxeData.CurrentRectZoom) |
---|
106 | AxeData.CurrentRectZoom=[]; |
---|
107 | end |
---|
108 | |
---|
109 | if testzoom %&& ~test_create && ~test_edit && ~test_edit_vect && exist('xy','var') |
---|
110 | AxeData.Drawing='zoom'; %initiate drawing mode |
---|
111 | AxeData.CurrentObject=[];%unselect objects |
---|
112 | elseif ~isempty(huvmat) |
---|
113 | %selection of an existing projection object |
---|
114 | if test_edit && (isequal(tag_obj,'proj_object')||isequal(tag_obj,'DeformPoint')) |
---|
115 | if ~(isfield(AxeData,'Drawing') && isequal(AxeData.Drawing,'create')) |
---|
116 | userdata=get(hcurrentobject,'UserData'); |
---|
117 | if ishandle(userdata)%the selected line depends on a parent line |
---|
118 | AxeData.CurrentObject=userdata;% the parent object becomes the current one |
---|
119 | else |
---|
120 | AxeData.CurrentObject=hcurrentobject;% the selected object becomes the current one |
---|
121 | end |
---|
122 | ObjectData=get(AxeData.CurrentObject,'UserData'); |
---|
123 | if test_edit & isfield(ObjectData,'IndexObj') |
---|
124 | hother=findobj('Tag','proj_object','Type','line');%find all the proj objects |
---|
125 | set(hother,'Color','b');%reset all the proj objects in 'blue' by default |
---|
126 | set(hother,'Selected','off') |
---|
127 | hother=findobj('Tag','proj_object','Type','rectangle'); |
---|
128 | set(hother,'EdgeColor','b'); |
---|
129 | set(hother,'Selected','off'); |
---|
130 | hother=findobj('Tag','proj_object','Type','image'); |
---|
131 | for iobj=1:length(hother) |
---|
132 | Acolor=get(hother(iobj),'CData'); |
---|
133 | Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2)); |
---|
134 | set(hother(iobj),'CData',Acolor); |
---|
135 | end |
---|
136 | hother=findobj('Tag','DeformPoint'); |
---|
137 | set(hother,'Color','b'); |
---|
138 | set(hother,'Selected','off') |
---|
139 | if isequal(get(AxeData.CurrentObject,'Type'),'line') |
---|
140 | set(AxeData.CurrentObject,'Color','m'); %set the selected object to magenta color |
---|
141 | elseif isequal(get(AxeData.CurrentObject,'Type'),'rectangle') |
---|
142 | set(AxeData.CurrentObject,'EdgeColor','m'); %set the selected object to magenta color |
---|
143 | end |
---|
144 | if isfield(ObjectData,'SubObject')& ishandle(ObjectData.SubObject) |
---|
145 | for iobj=1:length(ObjectData.SubObject) |
---|
146 | hsub=ObjectData.SubObject(iobj); |
---|
147 | if isequal(get(hsub,'Type'),'rectangle') |
---|
148 | set(hsub,'EdgeColor','m'); %set the selected object to magenta color |
---|
149 | elseif isequal(get(hsub,'Type'),'image') |
---|
150 | Acolor=get(hsub,'CData'); |
---|
151 | Acolor(:,:,1)=Acolor(:,:,3); |
---|
152 | set(hsub,'CData',Acolor); |
---|
153 | else |
---|
154 | set(hsub,'Color','m') |
---|
155 | end |
---|
156 | end |
---|
157 | end |
---|
158 | if isequal(tag_obj,'DeformPoint') |
---|
159 | set(hcurrentobject,'Color','m'); %set the selected DeformPoint to magenta color |
---|
160 | end |
---|
161 | IndexObj=ObjectData.IndexObj; |
---|
162 | hlist_object=findobj(huvmat,'Tag','list_object'); |
---|
163 | set(hlist_object,'Value',IndexObj); |
---|
164 | testdeform=0; |
---|
165 | set(gcbo,'Pointer','circle'); |
---|
166 | AxeData.Drawing='deform'; |
---|
167 | if isequal(tag_obj,'DeformPoint') |
---|
168 | if isfield(ObjectData,'DeformPoint') |
---|
169 | set(hcurrentobject,'Selected','on') |
---|
170 | for ipt=1:length(ObjectData.DeformPoint) |
---|
171 | if isequal(ObjectData.DeformPoint(ipt),hcurrentobject) |
---|
172 | AxeData.CurrentIndex=ipt; |
---|
173 | testdeform=1; |
---|
174 | end |
---|
175 | end |
---|
176 | end |
---|
177 | end |
---|
178 | if testdeform==0 |
---|
179 | AxeData.Drawing='translate'; |
---|
180 | set(AxeData.CurrentObject,'Selected','on') |
---|
181 | set(gcbo,'Pointer','fleur'); |
---|
182 | end |
---|
183 | end |
---|
184 | end |
---|
185 | end |
---|
186 | % create new projection object |
---|
187 | if test_create && ~isempty(xy) && ~(isfield(AxeData,'Drawing')&& isequal(AxeData.Drawing,'create')) |
---|
188 | ObjectData=read_set_object(UvData.sethandles); |
---|
189 | ObjectData.Coord=[]; %reset previous object coordinates |
---|
190 | ObjectData.Coord(1,1)=xy(1,1); |
---|
191 | ObjectData.Coord(1,2)=xy(1,2); |
---|
192 | ObjectData.Coord(1,3)=0; |
---|
193 | if isfield(AxeData,'ObjectCoord') & size(AxeData.ObjectCoord,2)==3 |
---|
194 | ObjectData.Coord(1,3)=AxeData.ObjectCoord(1,3); %generaliser au cas avec angle |
---|
195 | end |
---|
196 | AxeData.CurrentObject=plot_object(ObjectData,[],haxes,'m');%draw the object and its handle becomes AxeData.CurrentObject |
---|
197 | if isfield(UvData,'Object') |
---|
198 | IndexObj=length(UvData.Object)+1;% add the object as index IndexObj on the list of the interface |
---|
199 | else |
---|
200 | IndexObj=2; |
---|
201 | end |
---|
202 | UvData.Object{IndexObj}=ObjectData; |
---|
203 | UvData.Object{IndexObj}.HandlesDisplay(1)=AxeData.CurrentObject; |
---|
204 | set(huvmat,'UserData',UvData) |
---|
205 | list_str=get(hhuvmat.list_object,'String'); |
---|
206 | list_str{IndexObj}=[num2str(IndexObj) '-' set_title(ObjectData.Style,ObjectData.ProjMode)]; |
---|
207 | if ~isequal(list_str{end},'...') |
---|
208 | list_str{end+1}='...'; |
---|
209 | end |
---|
210 | set(hhuvmat.list_object,'String',list_str) |
---|
211 | set(hhuvmat.list_object,'Value',IndexObj) |
---|
212 | PlotData=get(AxeData.CurrentObject,'UserData'); |
---|
213 | PlotData.IndexObj=IndexObj; |
---|
214 | set(AxeData.CurrentObject,'UserData',PlotData); %record the object index in the graph |
---|
215 | AxeData.Drawing='create'; |
---|
216 | end |
---|
217 | |
---|
218 | % create calibration points if the GUI geometry_calib is opened |
---|
219 | if test_cal & ~isempty(xy) |
---|
220 | h_geometry_calib=findobj(allchild(0),'Name','geometry_calib'); %find the geomterty_calib GUI |
---|
221 | hh_geometry_calib=guidata(h_geometry_calib); |
---|
222 | h_ListCoord=hh_geometry_calib.ListCoord; %findobj(h_geometry_calib,'Tag','ListCoord'); |
---|
223 | h_edit_append=hh_geometry_calib.edit_append;%findobj(h_geometry_calib,'Tag','edit_append'); |
---|
224 | if isequal(get(h_edit_append,'Value'),1) |
---|
225 | if ~isequal(coord_type,'') |
---|
226 | set(handles_coord,'Value',1) |
---|
227 | coord_type=''; |
---|
228 | set(hhuvmat.FixedLimits,'Value',0)% put FixedLimits option to 'off' |
---|
229 | set(hhuvmat.FixedLimits,'BackgroundColor',[0.7 0.7 0.7]) |
---|
230 | uvmat('run0_Callback',hObject,eventdata,hhuvmat); %file input with xml reading in uvmat |
---|
231 | end |
---|
232 | % if isequal(coord_type,'px')|isequal(coord_type,'');%px cordinates |
---|
233 | strline=[ ' | ' ' | ' ' | ' num2str(xy(1,1),4) ' | ' num2str(xy(1,2),4)]; |
---|
234 | % else %phys cordinates |
---|
235 | % strline=[ num2str(xy(1,1),4) ' | ' num2str(xy(1,2),4) ' | 0 | ' ' | ' ]; |
---|
236 | % end |
---|
237 | Coord=get(h_ListCoord,'String'); |
---|
238 | val=get(h_ListCoord,'Value'); |
---|
239 | if isequal(Coord,{''}) |
---|
240 | val=0; |
---|
241 | end |
---|
242 | if length(Coord)>val |
---|
243 | Coord(val+2:length(Coord)+1)=Coord(val+1:length(Coord));% push the list forward beyond the current point |
---|
244 | end |
---|
245 | Coord{val+1}=strline; |
---|
246 | set(h_ListCoord,'String',Coord) |
---|
247 | set(h_ListCoord,'Value',val+1) |
---|
248 | geometry_calib('ListCoord_Callback',hObject,eventdata,hh_geometry_calib) |
---|
249 | data=read_geometry_calib(Coord); |
---|
250 | if isequal(coord_type,'px')|isequal(coord_type,'');%px cordinates |
---|
251 | XCoord=data.Coord(:,4); |
---|
252 | YCoord=data.Coord(:,5); |
---|
253 | else %phys cordinates |
---|
254 | XCoord=data.Coord(:,1); |
---|
255 | YCoord=data.Coord(:,2); |
---|
256 | end |
---|
257 | hh=findobj('Tag','calib_points') |
---|
258 | if isempty(hh) |
---|
259 | line(XCoord,YCoord,'Color','m','Tag','calib_points','LineStyle','.','Marker','+'); |
---|
260 | else |
---|
261 | set(hh,'XData',XCoord) |
---|
262 | set(hh,'YData',YCoord) |
---|
263 | end |
---|
264 | hhh=findobj('Tag','calib_marker'); |
---|
265 | if ~isempty(hhh) |
---|
266 | set(hhh,'XData',xy(1,1)) |
---|
267 | set(hhh,'YData',xy(1,2)) |
---|
268 | else |
---|
269 | line(xy(1,1),xy(1,2),'Color','m','Tag','calib_marker','LineStyle','.','Marker','o','MarkerSize',20); |
---|
270 | end |
---|
271 | %uistack(h_geometry_calib,'top') |
---|
272 | end |
---|
273 | end |
---|
274 | |
---|
275 | % edit vectors |
---|
276 | if test_edit_vect & ~isempty(ivec) |
---|
277 | % FF_100=FF-100*double(uint(abs(FF)/100); %value of FF without units and dizaines |
---|
278 | if ~(isfield(AxeData,'FF')&& ~isempty(AxeData.FF)) |
---|
279 | AxeData.FF=zeros(size(AxeData.X)); |
---|
280 | end |
---|
281 | if isequal(AxeData.FF(ivec),0) |
---|
282 | AxeData.FF(ivec)=100; %mark vector #ivec as false |
---|
283 | else |
---|
284 | AxeData.FF(ivec)=0; |
---|
285 | end |
---|
286 | PlotParam=read_plot_param(hhuvmat); |
---|
287 | [PlotType,ScalOut]= plot_field(AxeData,haxes,PlotParam,1); |
---|
288 | end |
---|
289 | end |
---|
290 | set(haxes,'UserData',AxeData); |
---|
291 | |
---|
292 | %------------------------------------------------------ |
---|
293 | function update_plot(AxeData,haxes) |
---|
294 | %-------------------------------------------- |
---|
295 | |
---|
296 | |
---|
297 | % %determine the axes of action of the set_edit interface |
---|
298 | % % haxes= findobj(huvmat,'Tag','axes3'); %main plotting axes as default |
---|
299 | % % AxeData=get(haxes,'UserData') |
---|
300 | % %For vector field representation |
---|
301 | % PlotHandles.auto_xy=findobj(huvmat,'Tag','auto_xy'); |
---|
302 | % PlotHandles.VecScale=findobj(huvmat,'Tag','VecScale'); |
---|
303 | % PlotHandles.AutoVec=findobj(huvmat,'Tag','AutoVec'); |
---|
304 | % PlotHandles.checkyellow=findobj(huvmat,'Tag','checkyellow'); |
---|
305 | % PlotHandles.checkblack=findobj(huvmat,'Tag','checkblack'); |
---|
306 | % PlotHandles.col_vec=findobj(huvmat,'Tag','col_vec'); |
---|
307 | % PlotHandles.colcode1=findobj(huvmat,'Tag','colcode1'); |
---|
308 | % PlotHandles.colcode2=findobj(huvmat,'Tag','colcode2'); |
---|
309 | % PlotHandles.vec_col_bar=findobj(huvmat,'Tag','vec_col_bar'); |
---|
310 | % PlotHandles.slider1=findobj(huvmat,'Tag','slider1'); |
---|
311 | % PlotHandles.slider2=findobj(huvmat,'Tag','slider2'); |
---|
312 | % PlotHandles.max_vec=findobj(huvmat,'Tag','max_vec'); |
---|
313 | % PlotHandles.min_vec=findobj(huvmat,'Tag','min_vec'); |
---|
314 | % PlotHandles.AutoVecColor=findobj(huvmat,'Tag','AutoVecColor'); |
---|
315 | % PlotHandles.decimate4=findobj(huvmat,'Tag','decimate4'); |
---|
316 | % |
---|
317 | % %vectors |
---|
318 | % Vectors.VecScale=str2num(get(PlotHandles.VecScale,'String')); |
---|
319 | % Vectors.AutoVec=get(PlotHandles.AutoVec,'Value');%automatic vector length |
---|
320 | % Vectors.checkyellow=get(PlotHandles.checkyellow,'Value'); |
---|
321 | % Vectors.checkblack=get(PlotHandles.checkblack,'Value'); |
---|
322 | % Vectors.decimate4=get(PlotHandles.decimate4,'Value');% =1; for reducing the nbre of vectors |
---|
323 | % menu_col=get(PlotHandles.col_vec,'String'); |
---|
324 | % menu_val=get(PlotHandles.col_vec,'Value'); |
---|
325 | % Vectors.CName=menu_col{menu_val}; %'ima_cor','black','white',... |
---|
326 | % Vectors.colcode1=str2num(get(PlotHandles.colcode1,'String'));% first threshold for rgb, first value for'continuous' |
---|
327 | % Vectors.colcode2=str2num(get(PlotHandles.colcode2,'String'));% second threshold for rgb, last value (saturation) for 'continuous' |
---|
328 | % Vectors.option=get(PlotHandles.vec_col_bar,'Value'); % =1 (64 colors), =0 (3 colors) |
---|
329 | % Vectors.min=get(PlotHandles.slider1,'Min'); |
---|
330 | % Vectors.max=get(PlotHandles.slider1,'Max'); |
---|
331 | % Vectors.auto=get(PlotHandles.AutoVecColor,'Value');% =1; thresholds scaling relative to min and max, =0 fixed thresholds |
---|
332 | % PlotParam.Vectors=Vectors; |
---|
333 | |
---|