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 | eval(['Field=FigData.' tagaxes ';']) |
---|
113 | [CellVarIndex,NbDim,VarType]=find_field_indices(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 | case 'uicontrol' %if the mouse is over a uicontrol, duplicate the display in an editable zoom window |
---|
132 | if isequal(get(hObject,'SelectionType'),'alt') && isequal(get(hchild,'Visible'),'on') && ~isequal(get(hchild,'tag'),'frame_object')&&... |
---|
133 | ~isequal(get(hchild,'tag'),'ListObject') |
---|
134 | if ~strcmp(get(hchild,'Style'),'frame')%do not visualisaze frames |
---|
135 | msg_pos(1:2)=GUI_pos(1:2)+obj_pos(1:2).*GUI_pos(3:4); |
---|
136 | output_str=msgbox_uvmat(['uicontrol: ' get(hchild,'Tag')],'',get(hchild,'String'),msg_pos); |
---|
137 | break |
---|
138 | end |
---|
139 | end |
---|
140 | case 'uipanel' |
---|
141 | panel_pos=obj_pos;%position of the panel |
---|
142 | hhchildren=get(hchild,'Children');%handles of all objects in the current GUI |
---|
143 | %% loop on all the objects in the current figure (selected by the last mouse click) |
---|
144 | for iichild=1:length(hhchildren) |
---|
145 | hchild=hhchildren(iichild); |
---|
146 | rel_pos=get(hchild,'Position');%position of the object relative to the uipanel |
---|
147 | obj_pos(1:2)=panel_pos(1:2)+rel_pos(1:2).*panel_pos(3:4); |
---|
148 | obj_pos(3:4)=panel_pos(3:4).*rel_pos(3:4); |
---|
149 | 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); |
---|
150 | htype=get(hchild,'Type');%type of object child of the current figure |
---|
151 | %if the mouse is over a uicontrol, look at the data |
---|
152 | if strcmp(htype,'uicontrol') && strcmp(get(hchild,'Visible'),'on') |
---|
153 | msg_pos(1:2)=GUI_pos(1:2)+obj_pos(1:2).*GUI_pos(3:4); |
---|
154 | output_str=msgbox_uvmat(['uicontrol: ' get(hchild,'Tag')],'',get(hchild,'String'),msg_pos); |
---|
155 | break |
---|
156 | end |
---|
157 | end |
---|
158 | end |
---|
159 | end |
---|
160 | if ~isempty(output_str) |
---|
161 | break %leave the current loop if a uicontrol has been selected |
---|
162 | end |
---|
163 | end |
---|
164 | end |
---|
165 | if ~isempty(output_str) |
---|
166 | set(hObject,'Units','pixels') |
---|
167 | set(hchild,'String',output_str) |
---|
168 | end |
---|
169 | |
---|
170 | %% desable object creation and vector editing if NbDim different from 2 |
---|
171 | if ~(isfield(AxeData,'NbDim') && isequal(AxeData.NbDim,2)) |
---|
172 | test_create=0; |
---|
173 | test_edit_vect=0; |
---|
174 | end |
---|
175 | |
---|
176 | %% delete the current zoom rectangle |
---|
177 | if isfield(AxeData,'CurrentRectZoom') && ishandle(AxeData.CurrentRectZoom) |
---|
178 | delete(AxeData.CurrentRectZoom) |
---|
179 | AxeData.CurrentRectZoom=[]; |
---|
180 | end |
---|
181 | |
---|
182 | %% zoom has first priority |
---|
183 | if test_zoom %&& ~test_create && ~test_edit && ~test_edit_vect && exist('xy','var') |
---|
184 | AxeData.Drawing='zoom'; %initiate drawing mode |
---|
185 | AxeData.CurrentObject=[];%unselect objects |
---|
186 | set(hchild,'UserData',AxeData); |
---|
187 | return |
---|
188 | end |
---|
189 | if isempty(huvmat)%further options require the uvmat GUI |
---|
190 | return |
---|
191 | end |
---|
192 | |
---|
193 | %% ruler has second priority |
---|
194 | if test_ruler |
---|
195 | AxeData.RulerCoord(1,1)=xy(1,1); |
---|
196 | AxeData.RulerCoord(1,2)=xy(1,2); |
---|
197 | AxeData.RulerHandle=line([xy(1,1) xy(1,1)],[xy(1,2) xy(1,2)],'Color','m','Tag','ruler'); |
---|
198 | AxeData.Drawing='ruler'; |
---|
199 | set(hchild,'UserData',AxeData); |
---|
200 | return |
---|
201 | end |
---|
202 | |
---|
203 | %% PIV test |
---|
204 | if test_piv |
---|
205 | figure |
---|
206 | newaxes=axes; |
---|
207 | copyobj(AxeData.CurrentCorrImage,newaxes); |
---|
208 | set(newaxes,'CLim',[0 1]) |
---|
209 | copyobj(AxeData.CurrentVector,newaxes) |
---|
210 | copyobj(AxeData.TitleHandle,newaxes) |
---|
211 | colorbar |
---|
212 | end |
---|
213 | |
---|
214 | %% selection of an existing projection object (third priority) |
---|
215 | if test_edit && (isequal(tag_obj,'proj_object')||isequal(tag_obj,'DeformPoint')) |
---|
216 | if ~(isfield(AxeData,'Drawing') && isequal(AxeData.Drawing,'create')) |
---|
217 | userdata=get(hcurrentobject,'UserData'); |
---|
218 | if ishandle(userdata)%the selected line depends on a parent line |
---|
219 | AxeData.CurrentObject=userdata;% the parent object becomes the current one |
---|
220 | else |
---|
221 | AxeData.CurrentObject=hcurrentobject;% the selected object becomes the current one |
---|
222 | end |
---|
223 | ObjectData=get(AxeData.CurrentObject,'UserData'); |
---|
224 | if test_edit && isfield(ObjectData,'IndexObj') |
---|
225 | hother=findobj('Tag','proj_object','Type','line');%find all the proj objects |
---|
226 | set(hother,'Color','b');%reset all the proj objects in 'blue' by default |
---|
227 | set(hother,'Selected','off') |
---|
228 | hother=findobj('Tag','proj_object','Type','rectangle'); |
---|
229 | set(hother,'EdgeColor','b'); |
---|
230 | set(hother,'Selected','off'); |
---|
231 | hother=findobj('Tag','proj_object','Type','image'); |
---|
232 | for iobj=1:length(hother) |
---|
233 | Acolor=get(hother(iobj),'CData'); |
---|
234 | Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2)); |
---|
235 | set(hother(iobj),'CData',Acolor); |
---|
236 | end |
---|
237 | hother=findobj('Tag','DeformPoint'); |
---|
238 | set(hother,'Color','b'); |
---|
239 | set(hother,'Selected','off') |
---|
240 | if isequal(get(AxeData.CurrentObject,'Type'),'line') |
---|
241 | set(AxeData.CurrentObject,'Color','m'); %set the selected object to magenta color |
---|
242 | elseif isequal(get(AxeData.CurrentObject,'Type'),'rectangle') |
---|
243 | set(AxeData.CurrentObject,'EdgeColor','m'); %set the selected object to magenta color |
---|
244 | end |
---|
245 | if isfield(ObjectData,'SubObject')& ishandle(ObjectData.SubObject) |
---|
246 | for iobj=1:length(ObjectData.SubObject) |
---|
247 | hsub=ObjectData.SubObject(iobj); |
---|
248 | if isequal(get(hsub,'Type'),'rectangle') |
---|
249 | set(hsub,'EdgeColor','m'); %set the selected object to magenta color |
---|
250 | elseif isequal(get(hsub,'Type'),'image') |
---|
251 | Acolor=get(hsub,'CData'); |
---|
252 | Acolor(:,:,1)=Acolor(:,:,3); |
---|
253 | set(hsub,'CData',Acolor); |
---|
254 | else |
---|
255 | set(hsub,'Color','m') |
---|
256 | end |
---|
257 | end |
---|
258 | end |
---|
259 | if isequal(tag_obj,'DeformPoint') |
---|
260 | set(hcurrentobject,'Color','m'); %set the selected DeformPoint to magenta color |
---|
261 | end |
---|
262 | IndexObj=ObjectData.IndexObj; |
---|
263 | %indicate on the list of the GUI uvmat which object has been selected |
---|
264 | if strcmp(get(hcurrentfig,'tag'),'uvmat') %if the uvmat graph has been selected, object projection is on the other frame view_field |
---|
265 | % IndexObj=get(hhuvmat.ListObject,'Value'); |
---|
266 | % if IndexObj>IndexObj_old(1) |
---|
267 | % IndexObj=[IndexObj_old(1) IndexObj]; |
---|
268 | % else |
---|
269 | % IndexObj=[1 IndexObj]; |
---|
270 | % end |
---|
271 | set(hhuvmat.ListObject,'Value',IndexObj); |
---|
272 | % set(hhuvmat.ListObject,'UserData',IndexObj); |
---|
273 | else |
---|
274 | set(hhuvmat.ListObject_1,'Value',IndexObj); |
---|
275 | list_str=get(hhuvmat.ListObject_1,'String'); |
---|
276 | UvData.Object{IndexObj}.Name=list_str{IndexObj}; |
---|
277 | end |
---|
278 | % h_set_object=findobj(allchild(0),'Tag','set_object'); |
---|
279 | % if ~isempty(h_set_object) |
---|
280 | % delete(h_set_object) |
---|
281 | % end |
---|
282 | set_object(UvData.Object{IndexObj}) |
---|
283 | axes(hchild);%set back the current axes haxes |
---|
284 | testdeform=0; |
---|
285 | set(gcbo,'Pointer','circle'); |
---|
286 | AxeData.Drawing='deform'; |
---|
287 | if isequal(tag_obj,'DeformPoint') |
---|
288 | if isfield(ObjectData,'DeformPoint') |
---|
289 | set(hcurrentobject,'Selected','on') |
---|
290 | for ipt=1:length(ObjectData.DeformPoint) |
---|
291 | if isequal(ObjectData.DeformPoint(ipt),hcurrentobject) |
---|
292 | AxeData.CurrentIndex=ipt; |
---|
293 | testdeform=1; |
---|
294 | end |
---|
295 | end |
---|
296 | end |
---|
297 | end |
---|
298 | if testdeform==0 |
---|
299 | AxeData.Drawing='translate'; |
---|
300 | set(AxeData.CurrentObject,'Selected','on') |
---|
301 | set(gcbo,'Pointer','fleur'); |
---|
302 | end |
---|
303 | end |
---|
304 | end |
---|
305 | end |
---|
306 | |
---|
307 | %% create projection object |
---|
308 | if test_create && ~isempty(xy) %&& ~(isfield(AxeData,'Drawing')&& isequal(AxeData.Drawing,'create')) |
---|
309 | hset_object=findobj(allchild(0),'tag','set_object'); |
---|
310 | % activate this option if the GUI set_object is opened |
---|
311 | if ~isempty(hset_object) |
---|
312 | sethandles=guidata(hset_object);% handles of the elements in the GUI set_object |
---|
313 | ObjectData=read_GUI(hset_object); %read object parameters in the GUI set_object |
---|
314 | IndexObj=length(UvData.Object); |
---|
315 | %initiate a new object (no data .Coord yet recorded) |
---|
316 | if ~isfield(UvData.Object{IndexObj},'Coord'); |
---|
317 | ObjectData.Coord=[]; |
---|
318 | ObjectNameNew=ObjectData.Name; |
---|
319 | if isempty(ObjectNameNew) |
---|
320 | ObjectNameNew=ObjectData.Type; |
---|
321 | end |
---|
322 | % add an index to the object name if the proposed name already exists |
---|
323 | vers=0;% index of the name |
---|
324 | ListObject=get(hhuvmat.ListObject,'String'); |
---|
325 | detectname=1; |
---|
326 | while ~isempty(detectname) |
---|
327 | detectname=find(strcmp(ObjectNameNew,ListObject),1);%test the existence of the proposed name in the list |
---|
328 | if detectname% if the object name already exists |
---|
329 | indstr=regexp(ObjectNameNew,'\D'); |
---|
330 | if indstr(end)<length(ObjectNameNew) %object name ends by a number |
---|
331 | vers=str2double(ObjectNameNew(indstr(end)+1:end))+1; |
---|
332 | ObjectNameNew=[ObjectNameNew(1:indstr(end)) num2str(vers)]; |
---|
333 | else |
---|
334 | vers=vers+1; |
---|
335 | ObjectNameNew=[ObjectNameNew(1:indstr(end)) '_' num2str(vers)]; |
---|
336 | end |
---|
337 | end |
---|
338 | end |
---|
339 | ObjectName=ObjectNameNew; |
---|
340 | set(sethandles.Name,'String',ObjectName)% display the default name in set_object |
---|
341 | ListObject{end}=ObjectName; |
---|
342 | set(hhuvmat.ListObject,'String',ListObject);%complement the object list |
---|
343 | set(hhuvmat.ListObject_1,'String',ListObject);%complement the object list |
---|
344 | set(hhuvmat.ListObject,'Value',IndexObj) |
---|
345 | set(hhuvmat.ViewObject,'Value',1) |
---|
346 | end |
---|
347 | ObjectData.Coord=[ObjectData.Coord ;xy(1,1:2)];% append the coordinates marked by the mouse to the object |
---|
348 | hobject=UvData.Object{IndexObj}.DisplayHandle.(fig_tag); |
---|
349 | if isempty(hobject) |
---|
350 | hobject=haxes; |
---|
351 | end |
---|
352 | ProjObject=UvData.Object{get(hhuvmat.ListObject_1,'Value')}; |
---|
353 | AxeData.CurrentObject=plot_object(ObjectData,ProjObject,hobject,'m');%draw the object and its handle becomes AxeData.CurrentObject |
---|
354 | UvData.Object{IndexObj}=ObjectData; |
---|
355 | UvData.Object{IndexObj}.DisplayHandle.(fig_tag)=AxeData.CurrentObject;% attribute the current plot object handle to the Object |
---|
356 | %UvData.Object{IndexObj}.DisplayHandle_view_field=AxeData.CurrentObject; |
---|
357 | set(huvmat,'UserData',UvData) |
---|
358 | PlotData=get(AxeData.CurrentObject,'UserData'); |
---|
359 | PlotData.IndexObj=IndexObj; |
---|
360 | set(AxeData.CurrentObject,'UserData',PlotData); %record the object index in the graph (memory used for mouse motion) |
---|
361 | AxeData.Drawing='create';% flag for mouse motion |
---|
362 | %show object coordinates in the GUI set_object |
---|
363 | h_set_object=findobj(allchild(0),'Tag','set_object'); |
---|
364 | hh_set_object=guidata(h_set_object); |
---|
365 | set(hh_set_object.Coord,'Data',ObjectData.Coord); |
---|
366 | end |
---|
367 | end |
---|
368 | |
---|
369 | %% create calibration points if the GUI geometry_calib is opened, if the main axes axes3 of uvmat has ben selected |
---|
370 | if ~test_zoom && test_cal && ~isempty(haxes) && strcmp(get(haxes,'tag'),'axes3') |
---|
371 | h_geometry_calib=findobj(allchild(0),'Name','geometry_calib'); %find the geomterty_calib GUI |
---|
372 | hh_geometry_calib=guidata(h_geometry_calib); |
---|
373 | h_edit_append=hh_geometry_calib.edit_append;%findobj(h_geometry_calib,'Tag','edit_append'); |
---|
374 | if isequal(get(h_edit_append,'Value'),1) && ~isempty(haxes) |
---|
375 | h_ListCoord=hh_geometry_calib.ListCoord; %findobj(h_geometry_calib,'Tag','ListCoord'); |
---|
376 | coord_value=get(hhuvmat.transform_fct,'Value');% set uvmat to pixel coordinates, run it again if not |
---|
377 | if ~(isequal(coord_value,1)||isequal(coord_value,3)); %active only with no transform or px (no phys) |
---|
378 | set(hhuvmat.transform_fct,'Value',1) |
---|
379 | uvmat('transform_fct_Callback',hObject,eventdata,hhuvmat); %file input with xml reading in uvmat |
---|
380 | set(hhuvmat.CheckFixedLimits,'Value',0)% put FixedLimits option to 'off' |
---|
381 | set(hhuvmat.CheckFixedLimits,'BackgroundColor',[0.7 0.7 0.7]) |
---|
382 | return |
---|
383 | end |
---|
384 | Coord=get(h_ListCoord,'String'); |
---|
385 | data=read_geometry_calib(Coord);%transform char cell to numbers |
---|
386 | xlim=get(haxes,'XLim'); |
---|
387 | ind_range_x=abs((xlim(2)-xlim(1))/50); |
---|
388 | ylim=get(haxes,'YLim'); |
---|
389 | ind_range_y=abs((ylim(2)-ylim(1))/50); |
---|
390 | ind_range=sqrt(ind_range_x*ind_range_y); |
---|
391 | test_newpoint=1; |
---|
392 | if size(data.Coord,2)>=5 %if calibration points already exist |
---|
393 | XCoord=(data.Coord(:,4)); |
---|
394 | YCoord=(data.Coord(:,5)); |
---|
395 | 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 |
---|
396 | (YCoord<xy(1,2)+ind_range) & (YCoord>xy(1,2)-ind_range),1);%find the first calibration point in the neighborhood of the mouse |
---|
397 | test_newpoint=isempty(index_point);%test for no existing calibration point near the mouse position |
---|
398 | end |
---|
399 | val=get(h_ListCoord,'Value'); |
---|
400 | %create a new calib point if we are not close to an existing one |
---|
401 | if test_newpoint |
---|
402 | strline=[ ' | ' ' | ' ' | ' num2str(xy(1,1),4) ' | ' num2str(xy(1,2),4)]; |
---|
403 | |
---|
404 | if length(Coord)>=val |
---|
405 | Coord(val+1:length(Coord)+1)=Coord(val:length(Coord));% push the list forward beyond the current point |
---|
406 | end |
---|
407 | Coord{val}=strline; |
---|
408 | set(h_ListCoord,'String',Coord) |
---|
409 | data=read_geometry_calib(Coord);%transform char cell to numbers |
---|
410 | XCoord=data.Coord(:,4); |
---|
411 | YCoord=data.Coord(:,5); |
---|
412 | end |
---|
413 | hh=findobj('Tag','calib_points');%look for handle of calibration points |
---|
414 | if isempty(hh) |
---|
415 | hh=line(XCoord,YCoord,'Color','m','Tag','calib_points','LineStyle','.','Marker','+'); |
---|
416 | else |
---|
417 | set(hh,'XData',XCoord) |
---|
418 | set(hh,'YData',YCoord) |
---|
419 | end |
---|
420 | set(hh,'UserData',val)% flag the points to edit mode |
---|
421 | hhh=findobj('Tag','calib_marker');%look for handle of point marker (circle) |
---|
422 | if ~isempty(hhh) |
---|
423 | set(hhh,'Position',[xy(1,1)-ind_range/2 xy(1,2)-ind_range/2 ind_range ind_range]) |
---|
424 | else |
---|
425 | rectangle('Curvature',[1 1],... |
---|
426 | 'Position',[xy(1,1)-ind_range/2 xy(1,2)-ind_range/2 ind_range ind_range],'EdgeColor','m',... |
---|
427 | 'LineStyle','-','Tag','calib_marker'); |
---|
428 | % line([xy(1,1) xy(1,1)],[xy(1,2) xy(1,2)],'Color','m','Tag','calib_marker','LineStyle','.','Marker','o','MarkerSize',ind_range); |
---|
429 | end |
---|
430 | AxeData.Drawing='calibration'; |
---|
431 | end |
---|
432 | end |
---|
433 | |
---|
434 | %% edit vectors |
---|
435 | if test_edit_vect && ~isempty(ivec) |
---|
436 | %create the error flag FF if it does not exist |
---|
437 | if ~isfield(Field,'FF') |
---|
438 | Field.ListVarName=[Field.ListVarName 'FF']; |
---|
439 | Field.VarDimName=[Field.VarDimName Field.VarDimName{VarType{icell}.coord_x}]; |
---|
440 | nbvar=length(Field.ListVarName); |
---|
441 | Field.VarAttribute{nbvar}.Role='errorflag'; |
---|
442 | Field.FF=zeros(size(Field.X)); |
---|
443 | end |
---|
444 | if isequal(Field.FF(ivec),0) |
---|
445 | Field.FF(ivec)=100; %mark vector #ivec as false |
---|
446 | else |
---|
447 | Field.FF(ivec)=0; |
---|
448 | end |
---|
449 | PlotParam=read_GUI(hcurrentfig); |
---|
450 | plot_field(Field,haxes,PlotParam); |
---|
451 | eval(['FigData.' tagaxes '=Field;'])%record the modified field in FigData |
---|
452 | set(hcurrentfig,'UserData',FigData); |
---|
453 | end |
---|
454 | set(haxes,'UserData',AxeData); |
---|
455 | |
---|