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