Changeset 156 for trunk/src/mouse_down.m
- Timestamp:
- Dec 19, 2010, 10:11:04 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/mouse_down.m
r150 r156 24 24 function xy=mouse_down(hObject,eventdata) 25 25 26 MouseAction='none'; %default26 %MouseAction='none'; %default 27 27 huvmat=findobj(allchild(0),'tag','uvmat');%find the uvmat interface handle which controls theoption of mouse action 28 28 if isempty(huvmat) … … 30 30 end 31 31 hhuvmat=guidata(huvmat);%handles of elements in uvmat 32 guihandles=guidata(hObject);33 32 UvData=get(huvmat,'UserData'); 34 MouseAction='none'; %default33 %MouseAction='none'; %default 35 34 currentfig=hObject; 36 35 hhcurrentfig=guidata(currentfig); 37 test_zoom=get(hhcurrentfig.zoom,'Value') 38 %test_zoom=get(guihandles.zoom,'Value');% get the mouse action from the uvmat GUI: options: 39 if isfield(UvData,'MouseAction') 40 MouseAction=UvData.MouseAction;% get the mouse action from the uvmat GUI: options: 41 end 42 43 test_create=~test_zoom && (isequal(MouseAction,'create_object') || isequal(MouseAction,'create_mask')); 36 test_zoom=get(hhcurrentfig.zoom,'Value');%test for zoom action, first priority 37 % if isfield(UvData,'MouseAction') 38 % MouseAction=UvData.MouseAction;% get the mouse action from the uvmat GUI: options: 39 % end 40 44 41 %test_cal=get(handles.cal,'Value'); 45 test_cal=strcmp(MouseAction,'calib'); 46 test_ruler=strcmp(MouseAction,'ruler'); 47 test_edit=strcmp(MouseAction,'edit_object'); 48 test_edit_vect=strcmp(MouseAction,'edit_vect'); 42 % test_cal=strcmp(MouseAction,'calib'); 43 test_ruler=isequal(get(hhuvmat.MenuRuler,'checked'),'on');%test for ruler action, second priority 44 %test_ruler=strcmp(MouseAction,'ruler'); 45 %test_edit=strcmp(MouseAction,'edit_object'); 46 test_edit=get(hhuvmat.edit_object,'Value');%test for object editing, third priority 47 %test_edit_vect=strcmp(MouseAction,'edit_vect');%test for vector editing, priority 4 48 test_edit_vect=get(hhuvmat.edit_vect,'Value');%test for vector editing, priority 4 49 test_create=isequal(get(hhuvmat.MenuObject,'checked'),'on');% test for object creation, priority 5 50 if test_create 51 hset_object=findobj(allchild(0),'tag','set_object'); 52 test_create=~isempty(hset_object)&&~test_edit; 53 end 54 test_cal=isequal(get(hhuvmat.MenuCalib,'checked'),'on');% test for calibration 55 if test_cal% test for calibration popints, priority 6 56 h_calib=findobj(allchild(0),'tag','geometry_calib'); 57 if isempty(h_calib) 58 test_cal=0; 59 set(hhuvmat.MenuCalib,'checked','off');% test for calibration off 60 else 61 hh_calib=guidata(h_calib); 62 test_cal=get(hh_calib.edit_append,'Value'); 63 end 64 end 65 %test_create=~test_zoom && strcmp(MouseAction,'create_object')&&~test_edit && ~test_edit_vect ;% || isequal(MouseAction,'create_mask')); 49 66 xdisplay=[];%default 50 67 ydisplay=[];%default 51 68 AxeData=[];%default 52 69 53 % edit an existing point or line if found70 %% edit an existing point or line if found 54 71 hcurrentobject=gco;% current object handle (selected by the mouse) 55 72 hcurrentfig=hObject;% current figure handle … … 60 77 hchild=get(hcurrentfig,'Children');%handles of all objects in the current figure 61 78 haxes=[]; 62 % loop on all the objects in the current figure (selected by the last mouse click) 79 80 %% loop on all the objects in the current figure (selected by the last mouse click) 63 81 for ichild=1:length(hchild) 64 82 obj_pos=get(hchild(ichild),'Position');%position of the object … … 74 92 AxeData=get(haxes,'UserData');% data attached to the axis 75 93 AxeData.CurrentOrigin=[xy(1,1) xy(1,2)];% The current point set by the mouse becomes the current origin 76 if ~isequal(tag_obj,'proj_object') & ~test_create 77 x_mouse=xy(1,1);%default 78 y_mouse=xy(1,2);%default 79 u_mouse=[]; 80 v_mouse=[]; 81 w_mouse=[]; 82 A_mouse=[]; 83 c_text=[]; 84 f_text=[]; 85 ff_text=[]; 86 ivec=[]; 87 if isfield(AxeData,'X') & isfield(AxeData,'Y') & isfield(AxeData,'Mesh')% test on the existence of a vector field in the current axis 88 flag_vec=(AxeData.X<(xy(1,1)+AxeData.Mesh/4) & AxeData.X>(xy(1,1)-AxeData.Mesh/4)) & ...%flagx=1 for the vectors with x position selected by the mouse 89 (AxeData.Y<(xy(1,2)+AxeData.Mesh/4) & AxeData.Y>(xy(1,2)-AxeData.Mesh/4));%f 90 ivec=find(flag_vec,1);% search the (first) selected vector index ivec 94 if test_edit_vect && ~isequal(tag_obj,'proj_object') & ~test_create 95 ivec=[]; 96 FigData=get(hcurrentfig,'UserData'); 97 tagaxes=get(haxes,'tag'); 98 if isfield(FigData,tagaxes) 99 eval(['Field=FigData.' tagaxes ';']) 100 [CellVarIndex,NbDim,VarType]=find_field_indices(Field);%analyse the physical fields contained in Field 101 for icell=1:numel(CellVarIndex)%look for all physical fields 102 if NbDim(icell)==2 % select 2D field 103 if isfield(Field,'Mesh') && ~isempty(Field.Mesh)&& ~isempty(VarType{icell}.coord_x) && ~isempty(VarType{icell}.coord_y)%case of unstructured data 104 eval(['X=Field.' Field.ListVarName{VarType{icell}.coord_x} ';']) 105 eval(['Y=Field.' Field.ListVarName{VarType{icell}.coord_y} ';']) 106 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 107 (Y<(xy(1,2)+Field.Mesh/4) & Y>(xy(1,2)-Field.Mesh/4));%f 108 ivec=find(flag_vec,1);% search the (first) selected vector index ivec 109 end 110 end 111 end 91 112 end 92 113 end … … 113 134 end 114 135 115 % zoom has first priority136 %% zoom has first priority 116 137 if test_zoom %&& ~test_create && ~test_edit && ~test_edit_vect && exist('xy','var') 117 138 AxeData.Drawing='zoom'; %initiate drawing mode … … 120 141 return 121 142 end 122 if isempty(huvmat) 123 return 124 end 125 126 % ruler has second priority143 if isempty(huvmat)%further options require the uvmat GUI 144 return 145 end 146 147 %% ruler has second priority 127 148 if test_ruler 128 UvData.RulerCoord(1,1)=xy(1,1); 129 UvData.RulerCoord(1,2)=xy(1,2); 130 UvData.RulerHandle=line([xy(1,1) xy(1,1)],[xy(1,2) xy(1,2)],'Color','m','Tag','ruler'); 131 set(huvmat,'UserData',UvData) 149 AxeData.RulerCoord(1,1)=xy(1,1); 150 AxeData.RulerCoord(1,2)=xy(1,2); 151 AxeData.RulerHandle=line([xy(1,1) xy(1,1)],[xy(1,2) xy(1,2)],'Color','m','Tag','ruler'); 132 152 AxeData.Drawing='ruler'; 133 153 set(haxes,'UserData',AxeData); … … 135 155 end 136 156 137 % selection of an existing projection object157 %% selection of an existing projection object (third priority) 138 158 if test_edit && (isequal(tag_obj,'proj_object')||isequal(tag_obj,'DeformPoint')) 139 159 if ~(isfield(AxeData,'Drawing') && isequal(AxeData.Drawing,'create')) … … 222 242 end 223 243 end 224 % create new projection object 244 245 %% create new projection object 225 246 if test_create && ~isempty(xy) && ~(isfield(AxeData,'Drawing')&& isequal(AxeData.Drawing,'create')) 226 ObjectData=read_set_object(UvData.sethandles); 227 ObjectData.Coord=[]; %reset previous object coordinates 228 ObjectData.Coord(1,1)=xy(1,1); 229 ObjectData.Coord(1,2)=xy(1,2); 230 ObjectData.Coord(1,3)=0; 231 if isfield(AxeData,'ObjectCoord') & size(AxeData.ObjectCoord,2)==3 232 ObjectData.Coord(1,3)=AxeData.ObjectCoord(1,3); %generaliser au cas avec angle 233 end 234 AxeData.CurrentObject=plot_object(ObjectData,[],haxes,'m');%draw the object and its handle becomes AxeData.CurrentObject 235 if isfield(UvData,'Object') 236 IndexObj=length(UvData.Object)+1;% add the object as index IndexObj on the list of the interface 237 else 238 IndexObj=2; 239 end 240 UvData.Object{IndexObj}=ObjectData; 241 UvData.Object{IndexObj}.HandlesDisplay(1)=AxeData.CurrentObject; 242 set(huvmat,'UserData',UvData) 243 list_str=get(hhuvmat.list_object_1,'String'); 244 object_name=get(UvData.sethandles.TITLE,'String') 245 if isempty(object_name)|| strcmp(object_name,'') 246 list_str{IndexObj}=[num2str(IndexObj) '-' ObjectData.Style]; 247 set(UvData.sethandles.TITLE,'String',list_str{IndexObj}) 248 else 249 list_str{IndexObj}=object_name; 250 end 251 set(hhuvmat.list_object_1,'String',list_str) 252 list_str{end+1}='...'; 253 set(hhuvmat.list_object_2,'String',list_str) 254 if strcmp(fig_tag,'view_field')%we are in view_field plot 255 set(hhuvmat.list_object_1,'Value',IndexObj)% the projection field will be plotted in uvmat frame 256 else%we are in uvmat plot 257 set(hhuvmat.list_object_2,'Value',IndexObj) 258 end 259 PlotData=get(AxeData.CurrentObject,'UserData'); 260 PlotData.IndexObj=IndexObj; 261 set(AxeData.CurrentObject,'UserData',PlotData); %record the object index in the graph 262 AxeData.Drawing='create'; 247 hset_object=findobj(allchild(0),'tag','set_object'); 248 if ~isempty(hset_object) 249 sethandles=guidata(hset_object); 250 ObjectData=read_set_object(sethandles); 251 ObjectData.Coord=[]; %reset previous object coordinates 252 ObjectData.Coord(1,1)=xy(1,1); 253 ObjectData.Coord(1,2)=xy(1,2); 254 ObjectData.Coord(1,3)=0; 255 if isfield(AxeData,'ObjectCoord') & size(AxeData.ObjectCoord,2)==3 256 ObjectData.Coord(1,3)=AxeData.ObjectCoord(1,3); %generaliser au cas avec angle 257 end 258 AxeData.CurrentObject=plot_object(ObjectData,[],haxes,'m');%draw the object and its handle becomes AxeData.CurrentObject 259 if isfield(UvData,'Object') 260 IndexObj=length(UvData.Object)+1;% add the object as index IndexObj on the list of the interface 261 else 262 IndexObj=2; 263 end 264 UvData.Object{IndexObj}=ObjectData; 265 list_str=get(hhuvmat.list_object_1,'String'); 266 object_name=get(sethandles.TITLE,'String'); 267 if isempty(object_name)|| strcmp(object_name,'') 268 list_str{IndexObj}=[num2str(IndexObj) '-' ObjectData.Style]; 269 set(sethandles.TITLE,'String',list_str{IndexObj}) 270 else 271 list_str{IndexObj}=object_name; 272 end 273 set(hhuvmat.list_object_1,'String',list_str) 274 list_str{end+1}='...'; 275 set(hhuvmat.list_object_2,'String',list_str) 276 if strcmp(fig_tag,'view_field')%we are in view_field plot 277 set(hhuvmat.list_object_1,'Value',IndexObj)% the projection field will be plotted in uvmat frame 278 UvData.Object{IndexObj}.DisplayHandle_uvmat=[]; 279 UvData.Object{IndexObj}.DisplayHandle_view_field=AxeData.CurrentObject; 280 else%we are in uvmat plot 281 set(hhuvmat.list_object_2,'Value',IndexObj) 282 UvData.Object{IndexObj}.DisplayHandle_uvmat=AxeData.CurrentObject; 283 UvData.Object{IndexObj}.DisplayHandle_view_field=[]; 284 end 285 set(huvmat,'UserData',UvData) 286 PlotData=get(AxeData.CurrentObject,'UserData'); 287 PlotData.IndexObj=IndexObj; 288 set(AxeData.CurrentObject,'UserData',PlotData); %record the object index in the graph 289 AxeData.Drawing='create'; 290 end 263 291 end 264 292 … … 267 295 h_geometry_calib=findobj(allchild(0),'Name','geometry_calib'); %find the geomterty_calib GUI 268 296 hh_geometry_calib=guidata(h_geometry_calib); 269 h_ListCoord=hh_geometry_calib.ListCoord; %findobj(h_geometry_calib,'Tag','ListCoord');270 297 h_edit_append=hh_geometry_calib.edit_append;%findobj(h_geometry_calib,'Tag','edit_append'); 271 298 if isequal(get(h_edit_append,'Value'),1) && ~isempty(haxes) 299 h_ListCoord=hh_geometry_calib.ListCoord; %findobj(h_geometry_calib,'Tag','ListCoord'); 272 300 coord_value=get(hhuvmat.transform_fct,'Value');% set uvmat to pixel coordinates, run it again if not 273 301 if ~(isequal(coord_value,1)||isequal(coord_value,3)); %active only with no transform or px (no phys) … … 303 331 Coord{val}=strline; 304 332 set(h_ListCoord,'String',Coord) 305 % set(h_ListCoord,'Value',val+1)306 333 data=read_geometry_calib(Coord);%transform char cell to numbers 307 334 XCoord=data.Coord(:,4); … … 330 357 331 358 % edit vectors 332 if test_edit_vect & ~isempty(ivec) 333 if ~(isfield(AxeData,'FF')&& ~isempty(AxeData.FF)) 334 AxeData.FF=zeros(size(AxeData.X)); 335 end 336 if isequal(AxeData.FF(ivec),0) 337 AxeData.FF(ivec)=100; %mark vector #ivec as false 359 if test_edit_vect && ~isempty(ivec) 360 %create the error flag FF if it does not exist 361 if ~isfield(Field,'FF') 362 Field.ListVarName=[Field.ListVarName 'FF']; 363 Field.VarDimName=[Field.VarDimName Field.VarDimName{VarType{icell}.coord_x}]; 364 nbvar=length(Field.ListVarName); 365 Field.VarAttribute{nbvar}.Role='errorflag'; 366 Field.FF=zeros(size(Field.X)); 367 end 368 if isequal(Field.FF(ivec),0) 369 Field.FF(ivec)=100 %mark vector #ivec as false 338 370 else 339 AxeData.FF(ivec)=0; 340 end 341 PlotParam=read_plot_param(hhuvmat); 342 [PlotType,ScalOut]= plot_field(AxeData,haxes,PlotParam,1); 371 Field.FF(ivec)=0; 372 end 373 PlotParam=read_plot_param(hhcurrentfig); 374 plot_field(Field,haxes,PlotParam); 375 eval(['FigData.' tagaxes '=Field;'])%record the modified field in FigData 376 set(hcurrentfig,'UserData',FigData); 343 377 end 344 378 set(haxes,'UserData',AxeData);
Note: See TracChangeset
for help on using the changeset viewer.