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