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 | AxeData=[];%default |
---|
26 | FigData=get(hObject,'UserData'); |
---|
27 | 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 |
---|
28 | hcurrentfig=get(get(FigData,'parent'),'parent'); |
---|
29 | else |
---|
30 | hcurrentfig=hObject;%usual plot |
---|
31 | end |
---|
32 | set(hcurrentfig,'Units','pixels') |
---|
33 | GUI_pos=get(hcurrentfig,'Position');%position of the GUI series (in pixels) |
---|
34 | set(hcurrentfig,'Units','normalized') |
---|
35 | hhcurrentfig=guidata(hcurrentfig); |
---|
36 | if isfield(hhcurrentfig,'CheckZoom') |
---|
37 | test_zoom=get(hhcurrentfig.CheckZoom,'Value');%test for zoom action, first priority |
---|
38 | else |
---|
39 | test_zoom=0; |
---|
40 | end |
---|
41 | test_piv=isfield(FigData,'CivHandle'); |
---|
42 | |
---|
43 | %% look for parameters set by the GUI uvmat |
---|
44 | test_ruler=0; |
---|
45 | test_edit=0; |
---|
46 | test_create=0; |
---|
47 | huvmat=findobj(allchild(0),'tag','uvmat');%find the uvmat interface handle which controls theoption of mouse action |
---|
48 | if ~isempty(huvmat) |
---|
49 | hhuvmat=guidata(huvmat);%handles of elements in uvmat |
---|
50 | UvData=get(huvmat,'UserData'); |
---|
51 | test_ruler=isequal(get(hhuvmat.MenuRuler,'checked'),'on');%test for ruler action, second priority; |
---|
52 | test_edit=get(hhuvmat.edit_object,'Value');%test for object editing, third priority |
---|
53 | test_edit_vect=get(hhuvmat.edit_vect,'Value');%test for vector editing, priority 4 |
---|
54 | % test_create=isequal(get(hhuvmat.MenuObject,'checked'),'on');% test for object creation, priority 5 |
---|
55 | % if test_create |
---|
56 | test_create=0; |
---|
57 | hset_object=findobj(allchild(0),'tag','set_object'); |
---|
58 | |
---|
59 | if ~isempty(hset_object) |
---|
60 | hPLOT=findobj(hset_object,'tag','PLOT'); |
---|
61 | test_create=strcmp(get(hPLOT,'enable'),'on') &&~test_edit;% create new object if set_object is in mode enable and uvmat not in mode 'edit_object' |
---|
62 | end |
---|
63 | |
---|
64 | test_cal=isequal(get(hhuvmat.MenuCalib,'checked'),'on');% test for calibration |
---|
65 | if test_cal% test for calibration popints, priority 6 |
---|
66 | h_calib=findobj(allchild(0),'tag','geometry_calib'); |
---|
67 | if isempty(h_calib) |
---|
68 | test_cal=0; |
---|
69 | set(hhuvmat.MenuCalib,'checked','off');% test for calibration off |
---|
70 | else |
---|
71 | hh_calib=guidata(h_calib); |
---|
72 | test_cal=get(hh_calib.edit_append,'Value'); |
---|
73 | end |
---|
74 | end |
---|
75 | end |
---|
76 | |
---|
77 | %% determine the currently selected items |
---|
78 | hcurrentobject=gco;% current object handle (selected by the mouse) |
---|
79 | %hcurrentfig=hObject;% current figure handle |
---|
80 | fig_tag=get(hcurrentfig,'Tag'); |
---|
81 | tag_obj=get(gco,'Tag');%tag of the currently selected object |
---|
82 | xy=[];%default |
---|
83 | xy_fig=get(hObject,'CurrentPoint');% current point of the current figure (gcbo) |
---|
84 | hchildren=get(hObject,'Children');%handles of all objects in the current figure |
---|
85 | haxes=[]; |
---|
86 | |
---|
87 | %% loop on all the objects in the current figure (selected by the last mouse click) |
---|
88 | output_str=''; |
---|
89 | state_visible=get(hchildren,'Visible'); |
---|
90 | check_visible=strcmp('on',state_visible);%=1 if visible='on', =0 otherwise |
---|
91 | hchildren=hchildren(find(check_visible)); %kkep only the visible children |
---|
92 | for ichild=1:length(hchildren) |
---|
93 | hchild=hchildren(ichild); %handle of the current obj |
---|
94 | obj_pos=get(hchild,'Position');%position of the object |
---|
95 | 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); |
---|
96 | htype=get(hchild,'Type');%type of object child of the current figure |
---|
97 | switch htype |
---|
98 | %if the mouse is over an axis, look at the data |
---|
99 | case 'axes' |
---|
100 | y_lim=get(hchild,'YLim'); |
---|
101 | x_lim=get(hchild,'XLim'); |
---|
102 | haxes=hchild; |
---|
103 | xy=get(hchild,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates |
---|
104 | 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) |
---|
105 | AxeData=get(hchild,'UserData');% data attached to the axis |
---|
106 | AxeData.CurrentOrigin=[xy(1,1) xy(1,2)];% The current point set by the mouse becomes the current origin |
---|
107 | if test_edit_vect && ~isequal(tag_obj,'proj_object') & ~test_create |
---|
108 | ivec=[]; |
---|
109 | FigData=get(hcurrentfig,'UserData'); |
---|
110 | tagaxes=get(hchild,'tag'); |
---|
111 | if isfield(FigData,tagaxes) |
---|
112 | Field=FigData.(tagaxes); |
---|
113 | [CellVarIndex,NbDim,VarType]=find_field_cells(Field);%analyse the physical fields contained in Field |
---|
114 | for icell=1:numel(CellVarIndex)%look for all physical fields |
---|
115 | if NbDim(icell)==2 % select 2D field |
---|
116 | if isfield(Field,'Mesh') && ~isempty(Field.Mesh)&& ~isempty(VarType{icell}.coord_x) && ~isempty(VarType{icell}.coord_y)%case of unstructured data |
---|
117 | eval(['X=Field.' Field.ListVarName{VarType{icell}.coord_x} ';']) |
---|
118 | eval(['Y=Field.' Field.ListVarName{VarType{icell}.coord_y} ';']) |
---|
119 | 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 |
---|
120 | (Y<(xy(1,2)+Field.Mesh/4) & Y>(xy(1,2)-Field.Mesh/4));%f |
---|
121 | ivec=find(flag_vec,1);% search the (first) selected vector index ivec |
---|
122 | end |
---|
123 | end |
---|
124 | end |
---|
125 | end |
---|
126 | end |
---|
127 | else |
---|
128 | hchild=[];%mouse out of axes |
---|
129 | end |
---|
130 | break |
---|
131 | |
---|
132 | %if the mouse is over a uicontrol, duplicate the display in an editable zoom window |
---|
133 | case 'uicontrol' |
---|
134 | if isequal(get(hObject,'SelectionType'),'alt') && isequal(get(hchild,'Visible'),'on') && ~isequal(get(hchild,'tag'),'frame_object')&&... |
---|
135 | ~isequal(get(hchild,'tag'),'ListObject') |
---|
136 | if ~strcmp(get(hchild,'Style'),'frame')%do not visualisaze frames |
---|
137 | msg_pos(1:2)=GUI_pos(1:2)+obj_pos(1:2).*GUI_pos(3:4); |
---|
138 | display_str=get(hchild,'TooltipString'); |
---|
139 | output_str=msgbox_uvmat(['uicontrol: ' get(hchild,'Tag')],display_str,get(hchild,'String'),msg_pos); |
---|
140 | break |
---|
141 | end |
---|
142 | end |
---|
143 | case 'uipanel' |
---|
144 | panel_pos=obj_pos;%position of the panel |
---|
145 | hhchildren=get(hchild,'Children');%handles of all objects in the current GUI |
---|
146 | %% loop on all the objects in the current figure (selected by the last mouse click) |
---|
147 | for iichild=1:length(hhchildren) |
---|
148 | hchild=hhchildren(iichild); |
---|
149 | rel_pos=get(hchild,'Position');%position of the object relative to the uipanel |
---|
150 | obj_pos(1:2)=panel_pos(1:2)+rel_pos(1:2).*panel_pos(3:4); |
---|
151 | obj_pos(3:4)=panel_pos(3:4).*rel_pos(3:4); |
---|
152 | if numel(obj_pos)>=4 && 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); |
---|
153 | htype=get(hchild,'Type');%type of object child of the current figure |
---|
154 | %if the mouse is over a uicontrol, look at the data |
---|
155 | if strcmp(htype,'uicontrol') && strcmp(get(hchild,'Visible'),'on') |
---|
156 | msg_pos(1:2)=GUI_pos(1:2)+obj_pos(1:2).*GUI_pos(3:4); |
---|
157 | display_str=get(hchild,'TooltipString'); |
---|
158 | output_str=msgbox_uvmat(['uicontrol: ' get(hchild,'Tag')],display_str,get(hchild,'String'),msg_pos); |
---|
159 | break |
---|
160 | end |
---|
161 | end |
---|
162 | end |
---|
163 | end |
---|
164 | if ~isempty(output_str) |
---|
165 | break %leave the current loop if a uicontrol has been selected |
---|
166 | end |
---|
167 | end |
---|
168 | end |
---|
169 | if ~isempty(output_str) |
---|
170 | set(hObject,'Units','pixels') |
---|
171 | if strcmp(get(hchild,'enable'),'on') |
---|
172 | set(hchild,'String',output_str)% fill the parent uicontrol with the sttring edited in the msgbox |
---|
173 | end |
---|
174 | end |
---|
175 | |
---|
176 | %% desable object creation and vector editing if NbDim different from 2 |
---|
177 | if ~(isfield(AxeData,'NbDim') && isequal(AxeData.NbDim,2)) |
---|
178 | test_create=0; |
---|
179 | test_edit_vect=0; |
---|
180 | end |
---|
181 | |
---|
182 | %% delete the current zoom rectangle |
---|
183 | if isfield(AxeData,'CurrentRectZoom') && ~isempty(AxeData.CurrentRectZoom) && ishandle(AxeData.CurrentRectZoom) |
---|
184 | delete(AxeData.CurrentRectZoom) |
---|
185 | AxeData.CurrentRectZoom=[]; |
---|
186 | end |
---|
187 | |
---|
188 | %% zoom has first priority |
---|
189 | if test_zoom %&& ~test_create && ~test_edit && ~test_edit_vect && exist('xy','var') |
---|
190 | AxeData.Drawing='zoom'; %initiate drawing mode |
---|
191 | AxeData.CurrentObject=[];%unselect objects |
---|
192 | set(hchild,'UserData',AxeData); |
---|
193 | return |
---|
194 | end |
---|
195 | if isempty(huvmat)%further options require the uvmat GUI |
---|
196 | return |
---|
197 | end |
---|
198 | |
---|
199 | %% ruler has second priority |
---|
200 | if test_ruler |
---|
201 | AxeData.RulerCoord(1,1)=xy(1,1); |
---|
202 | AxeData.RulerCoord(1,2)=xy(1,2); |
---|
203 | AxeData.RulerHandle=line([xy(1,1) xy(1,1)],[xy(1,2) xy(1,2)],'Color','m','Tag','ruler'); |
---|
204 | AxeData.Drawing='ruler'; |
---|
205 | set(hchild,'UserData',AxeData); |
---|
206 | return |
---|
207 | end |
---|
208 | |
---|
209 | %% PIV test |
---|
210 | if test_piv |
---|
211 | figure |
---|
212 | newaxes=axes; |
---|
213 | copyobj(AxeData.CurrentCorrImage,newaxes); |
---|
214 | set(newaxes,'CLim',[0 1]) |
---|
215 | copyobj(AxeData.CurrentVector,newaxes) |
---|
216 | copyobj(AxeData.TitleHandle,newaxes) |
---|
217 | colorbar |
---|
218 | end |
---|
219 | |
---|
220 | %% selection of an existing projection object (third priority) |
---|
221 | if test_edit && (isequal(tag_obj,'proj_object')||isequal(tag_obj,'DeformPoint')) |
---|
222 | if ~(isfield(AxeData,'Drawing') && isequal(AxeData.Drawing,'create')) |
---|
223 | userdata=get(hcurrentobject,'UserData'); |
---|
224 | if ishandle(userdata)%the selected line depends on a parent line |
---|
225 | AxeData.CurrentObject=userdata;% the parent object becomes the current one |
---|
226 | else |
---|
227 | AxeData.CurrentObject=hcurrentobject;% the selected object becomes the current one |
---|
228 | end |
---|
229 | ObjectData=get(AxeData.CurrentObject,'UserData'); |
---|
230 | if test_edit && isfield(ObjectData,'IndexObj') |
---|
231 | hother=findobj('Tag','proj_object','Type','line');%find all the proj objects |
---|
232 | set(hother,'Color','b');%reset all the proj objects in 'blue' by default |
---|
233 | set(hother,'Selected','off') |
---|
234 | hother=findobj('Tag','proj_object','Type','rectangle'); |
---|
235 | set(hother,'EdgeColor','b'); |
---|
236 | set(hother,'Selected','off'); |
---|
237 | hother=findobj('Tag','proj_object','Type','image'); |
---|
238 | for iobj=1:length(hother) |
---|
239 | Acolor=get(hother(iobj),'CData'); |
---|
240 | Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2)); |
---|
241 | set(hother(iobj),'CData',Acolor); |
---|
242 | end |
---|
243 | hother=findobj('Tag','DeformPoint'); |
---|
244 | set(hother,'Color','b'); |
---|
245 | set(hother,'Selected','off') |
---|
246 | if isequal(get(AxeData.CurrentObject,'Type'),'line') |
---|
247 | set(AxeData.CurrentObject,'Color','m'); %set the selected object to magenta color |
---|
248 | elseif isequal(get(AxeData.CurrentObject,'Type'),'rectangle') |
---|
249 | set(AxeData.CurrentObject,'EdgeColor','m'); %set the selected object to magenta color |
---|
250 | end |
---|
251 | if isfield(ObjectData,'SubObject')& ishandle(ObjectData.SubObject) |
---|
252 | for iobj=1:length(ObjectData.SubObject) |
---|
253 | hsub=ObjectData.SubObject(iobj); |
---|
254 | if isequal(get(hsub,'Type'),'rectangle') |
---|
255 | set(hsub,'EdgeColor','m'); %set the selected object to magenta color |
---|
256 | elseif isequal(get(hsub,'Type'),'image') |
---|
257 | Acolor=get(hsub,'CData'); |
---|
258 | Acolor(:,:,1)=Acolor(:,:,3); |
---|
259 | set(hsub,'CData',Acolor); |
---|
260 | else |
---|
261 | set(hsub,'Color','m') |
---|
262 | end |
---|
263 | end |
---|
264 | end |
---|
265 | if isequal(tag_obj,'DeformPoint') |
---|
266 | set(hcurrentobject,'Color','m'); %set the selected DeformPoint to magenta color |
---|
267 | end |
---|
268 | IndexObj=ObjectData.IndexObj; |
---|
269 | %indicate on the list of the GUI uvmat which object has been selected |
---|
270 | if strcmp(get(hcurrentfig,'tag'),'uvmat') %if the uvmat graph has been selected, object projection is on the other frame view_field |
---|
271 | % IndexObj=get(hhuvmat.ListObject,'Value'); |
---|
272 | % if IndexObj>IndexObj_old(1) |
---|
273 | % IndexObj=[IndexObj_old(1) IndexObj]; |
---|
274 | % else |
---|
275 | % IndexObj=[1 IndexObj]; |
---|
276 | % end |
---|
277 | set(hhuvmat.ListObject,'Value',IndexObj); |
---|
278 | % set(hhuvmat.ListObject,'UserData',IndexObj); |
---|
279 | else |
---|
280 | set(hhuvmat.ListObject_1,'Value',IndexObj); |
---|
281 | list_str=get(hhuvmat.ListObject_1,'String'); |
---|
282 | UvData.Object{IndexObj}.Name=list_str{IndexObj}; |
---|
283 | end |
---|
284 | % h_set_object=findobj(allchild(0),'Tag','set_object'); |
---|
285 | % if ~isempty(h_set_object) |
---|
286 | % delete(h_set_object) |
---|
287 | % end |
---|
288 | set_object(UvData.Object{IndexObj}) |
---|
289 | axes(hchild);%set back the current axes haxes |
---|
290 | testdeform=0; |
---|
291 | set(gcbo,'Pointer','circle'); |
---|
292 | AxeData.Drawing='deform'; |
---|
293 | if isequal(tag_obj,'DeformPoint') |
---|
294 | if isfield(ObjectData,'DeformPoint') |
---|
295 | set(hcurrentobject,'Selected','on') |
---|
296 | for ipt=1:length(ObjectData.DeformPoint) |
---|
297 | if isequal(ObjectData.DeformPoint(ipt),hcurrentobject) |
---|
298 | AxeData.CurrentIndex=ipt; |
---|
299 | testdeform=1; |
---|
300 | end |
---|
301 | end |
---|
302 | end |
---|
303 | end |
---|
304 | if testdeform==0 |
---|
305 | AxeData.Drawing='translate'; |
---|
306 | set(AxeData.CurrentObject,'Selected','on') |
---|
307 | set(gcbo,'Pointer','fleur'); |
---|
308 | end |
---|
309 | end |
---|
310 | end |
---|
311 | end |
---|
312 | |
---|
313 | %% create projection object |
---|
314 | if test_create && ~isempty(xy) %&& ~(isfield(AxeData,'Drawing')&& isequal(AxeData.Drawing,'create')) |
---|
315 | hset_object=findobj(allchild(0),'tag','set_object'); |
---|
316 | % activate this option if the GUI set_object is opened |
---|
317 | if ~isempty(hset_object) |
---|
318 | sethandles=guidata(hset_object);% handles of the elements in the GUI set_object |
---|
319 | ObjectData=read_GUI(hset_object); %read object parameters in the GUI set_object |
---|
320 | IndexObj=length(UvData.Object); |
---|
321 | %initiate a new object (no data .Coord yet recorded) |
---|
322 | if ~isfield(UvData.Object{IndexObj},'Coord'); |
---|
323 | ObjectData.Coord=[]; |
---|
324 | ObjectNameNew=ObjectData.Name; |
---|
325 | if isempty(ObjectNameNew) |
---|
326 | ObjectNameNew=ObjectData.Type; |
---|
327 | end |
---|
328 | % add an index to the object name if the proposed name already exists |
---|
329 | vers=0;% index of the name |
---|
330 | ListObject=get(hhuvmat.ListObject,'String'); |
---|
331 | detectname=1; |
---|
332 | while ~isempty(detectname) |
---|
333 | detectname=find(strcmp(ObjectNameNew,ListObject),1);%test the existence of the proposed name in the list |
---|
334 | if detectname% if the object name already exists |
---|
335 | indstr=regexp(ObjectNameNew,'\D'); |
---|
336 | if indstr(end)<length(ObjectNameNew) %object name ends by a number |
---|
337 | vers=str2double(ObjectNameNew(indstr(end)+1:end))+1; |
---|
338 | ObjectNameNew=[ObjectNameNew(1:indstr(end)) num2str(vers)]; |
---|
339 | else |
---|
340 | vers=vers+1; |
---|
341 | ObjectNameNew=[ObjectNameNew(1:indstr(end)) '_' num2str(vers)]; |
---|
342 | end |
---|
343 | end |
---|
344 | end |
---|
345 | ObjectName=ObjectNameNew; |
---|
346 | set(sethandles.Name,'String',ObjectName)% display the default name in set_object |
---|
347 | if isempty(ListObject) |
---|
348 | ListObject={ObjectName}; |
---|
349 | else |
---|
350 | ListObject{end}=ObjectName; |
---|
351 | end |
---|
352 | set(hhuvmat.ListObject,'String',ListObject);%complement the object list |
---|
353 | set(hhuvmat.ListObject_1,'String',ListObject);%complement the object list |
---|
354 | set(hhuvmat.ListObject,'Value',IndexObj) |
---|
355 | set(hhuvmat.ViewObject,'Value',1) |
---|
356 | end |
---|
357 | ObjectData.Coord=[ObjectData.Coord ;xy(1,1:2)];% append the coordinates marked by the mouse to the object |
---|
358 | hobject=UvData.Object{IndexObj}.DisplayHandle.(fig_tag); |
---|
359 | if isempty(hobject) |
---|
360 | hobject=haxes; |
---|
361 | end |
---|
362 | ProjObject=UvData.Object{get(hhuvmat.ListObject_1,'Value')}; |
---|
363 | AxeData.CurrentObject=plot_object(ObjectData,ProjObject,hobject,'m');%draw the object and its handle becomes AxeData.CurrentObject |
---|
364 | UvData.Object{IndexObj}=ObjectData; |
---|
365 | UvData.Object{IndexObj}.DisplayHandle.(fig_tag)=AxeData.CurrentObject;% attribute the current plot object handle to the Object |
---|
366 | %UvData.Object{IndexObj}.DisplayHandle_view_field=AxeData.CurrentObject; |
---|
367 | set(huvmat,'UserData',UvData) |
---|
368 | PlotData=get(AxeData.CurrentObject,'UserData'); |
---|
369 | PlotData.IndexObj=IndexObj; |
---|
370 | set(AxeData.CurrentObject,'UserData',PlotData); %record the object index in the graph (memory used for mouse motion) |
---|
371 | AxeData.Drawing='create';% flag for mouse motion |
---|
372 | %show object coordinates in the GUI set_object |
---|
373 | h_set_object=findobj(allchild(0),'Tag','set_object'); |
---|
374 | hh_set_object=guidata(h_set_object); |
---|
375 | set(hh_set_object.Coord,'Data',ObjectData.Coord); |
---|
376 | end |
---|
377 | end |
---|
378 | |
---|
379 | %% create calibration points if the GUI geometry_calib is opened, if the main axes axes3 of uvmat has ben selected |
---|
380 | if ~test_zoom && test_cal && ~isempty(haxes) && strcmp(get(haxes,'tag'),'axes3') |
---|
381 | h_geometry_calib=findobj(allchild(0),'Name','geometry_calib'); %find the geomterty_calib GUI |
---|
382 | hh_geometry_calib=guidata(h_geometry_calib); |
---|
383 | h_edit_append=hh_geometry_calib.edit_append;%findobj(h_geometry_calib,'Tag','edit_append'); |
---|
384 | if isequal(get(h_edit_append,'Value'),1) && ~isempty(haxes) |
---|
385 | h_ListCoord=hh_geometry_calib.ListCoord; %findobj(h_geometry_calib,'Tag','ListCoord'); |
---|
386 | coord_value=get(hhuvmat.transform_fct,'Value');% set uvmat to pixel coordinates, run it again if not |
---|
387 | if ~(isequal(coord_value,1)||isequal(coord_value,3)); %active only with no transform or px (no phys) |
---|
388 | set(hhuvmat.transform_fct,'Value',1) |
---|
389 | uvmat('transform_fct_Callback',hObject,eventdata,hhuvmat); %file input with xml reading in uvmat |
---|
390 | set(hhuvmat.CheckFixedLimits,'Value',0)% put FixedLimits option to 'off' |
---|
391 | set(hhuvmat.CheckFixedLimits,'BackgroundColor',[0.7 0.7 0.7]) |
---|
392 | return |
---|
393 | end |
---|
394 | Coord=get(h_ListCoord,'String'); |
---|
395 | data=read_geometry_calib(Coord);%transform char cell to numbers |
---|
396 | xlim=get(haxes,'XLim'); |
---|
397 | ind_range_x=abs((xlim(2)-xlim(1))/50); |
---|
398 | ylim=get(haxes,'YLim'); |
---|
399 | ind_range_y=abs((ylim(2)-ylim(1))/50); |
---|
400 | ind_range=sqrt(ind_range_x*ind_range_y); |
---|
401 | test_newpoint=1; |
---|
402 | if size(data.Coord,2)>=5 %if calibration points already exist |
---|
403 | XCoord=(data.Coord(:,4)); |
---|
404 | YCoord=(data.Coord(:,5)); |
---|
405 | 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 |
---|
406 | (YCoord<xy(1,2)+ind_range) & (YCoord>xy(1,2)-ind_range),1);%find the first calibration point in the neighborhood of the mouse |
---|
407 | test_newpoint=isempty(index_point);%test for no existing calibration point near the mouse position |
---|
408 | end |
---|
409 | val=get(h_ListCoord,'Value'); |
---|
410 | %create a new calib point if we are not close to an existing one |
---|
411 | if test_newpoint |
---|
412 | strline=[ ' | ' ' | ' ' | ' num2str(xy(1,1),4) ' | ' num2str(xy(1,2),4)]; |
---|
413 | |
---|
414 | if length(Coord)>=val |
---|
415 | Coord(val+1:length(Coord)+1)=Coord(val:length(Coord));% push the list forward beyond the current point |
---|
416 | end |
---|
417 | Coord{val}=strline; |
---|
418 | set(h_ListCoord,'String',Coord) |
---|
419 | data=read_geometry_calib(Coord);%transform char cell to numbers |
---|
420 | XCoord=data.Coord(:,4); |
---|
421 | YCoord=data.Coord(:,5); |
---|
422 | end |
---|
423 | hh=findobj('Tag','calib_points');%look for handle of calibration points |
---|
424 | if isempty(hh) |
---|
425 | hh=line(XCoord,YCoord,'Color','m','Tag','calib_points','LineStyle','.','Marker','+'); |
---|
426 | else |
---|
427 | set(hh,'XData',XCoord) |
---|
428 | set(hh,'YData',YCoord) |
---|
429 | end |
---|
430 | set(hh,'UserData',val)% flag the points to edit mode |
---|
431 | hhh=findobj('Tag','calib_marker');%look for handle of point marker (circle) |
---|
432 | if ~isempty(hhh) |
---|
433 | set(hhh,'Position',[xy(1,1)-ind_range/2 xy(1,2)-ind_range/2 ind_range ind_range]) |
---|
434 | else |
---|
435 | rectangle('Curvature',[1 1],... |
---|
436 | 'Position',[xy(1,1)-ind_range/2 xy(1,2)-ind_range/2 ind_range ind_range],'EdgeColor','m',... |
---|
437 | 'LineStyle','-','Tag','calib_marker'); |
---|
438 | % line([xy(1,1) xy(1,1)],[xy(1,2) xy(1,2)],'Color','m','Tag','calib_marker','LineStyle','.','Marker','o','MarkerSize',ind_range); |
---|
439 | end |
---|
440 | AxeData.Drawing='calibration'; |
---|
441 | end |
---|
442 | end |
---|
443 | |
---|
444 | %% edit vectors |
---|
445 | if test_edit_vect && ~isempty(ivec) |
---|
446 | %create the error flag FF if it does not exist |
---|
447 | if ~isfield(Field,'FF') |
---|
448 | Field.ListVarName=[Field.ListVarName 'FF']; |
---|
449 | Field.VarDimName=[Field.VarDimName Field.VarDimName{VarType{icell}.coord_x}]; |
---|
450 | nbvar=length(Field.ListVarName); |
---|
451 | Field.VarAttribute{nbvar}.Role='errorflag'; |
---|
452 | Field.FF=zeros(size(Field.X)); |
---|
453 | end |
---|
454 | if isequal(Field.FF(ivec),0) |
---|
455 | Field.FF(ivec)=100; %mark vector #ivec as false |
---|
456 | else |
---|
457 | Field.FF(ivec)=0; |
---|
458 | end |
---|
459 | PlotParam=read_GUI(hcurrentfig); |
---|
460 | plot_field(Field,haxes,PlotParam); |
---|
461 | eval(['FigData.' tagaxes '=Field;'])%record the modified field in FigData |
---|
462 | set(hcurrentfig,'UserData',FigData); |
---|
463 | end |
---|
464 | set(haxes,'UserData',AxeData); |
---|
465 | |
---|