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