Changeset 625 for trunk/src/mouse_down.m
- Timestamp:
- May 2, 2013, 7:51:42 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/mouse_down.m
r623 r625 28 28 FigData=get(hObject,'UserData'); %default data stored on the current object 29 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 30 h currentfig=get(get(FigData,'parent'),'parent');%handle of the current GUI: zoom plot30 hCurrentGUI=get(get(FigData,'parent'),'parent');%handle of the current GUI: zoom plot 31 31 else 32 h currentfig=hObject; % handle of the current GUI: usual plot33 end 34 hh currentfig=guidata(hcurrentfig);% tags of the children of the current GUI32 hCurrentGUI=hObject; % handle of the current GUI: usual plot 33 end 34 hhCurrentGUI=guidata(hCurrentGUI);% tags of the children of the current GUI 35 35 CheckZoom=0; 36 if isfield(hh currentfig,'CheckZoom') && get(hhcurrentfig.CheckZoom,'Value');%test for zoom action, first priority36 if isfield(hhCurrentGUI,'CheckZoom') && get(hhCurrentGUI.CheckZoom,'Value');%test for zoom action, first priority 37 37 CheckZoom=1; 38 38 end 39 39 test_piv=isfield(FigData,'CivHandle'); 40 set(h currentfig,'Units','pixels')41 GUI_pos=get(h currentfig,'Position');%position of the GUI series on the screen (in pixels), used to position message boxes42 set(h currentfig,'Units','normalized')% back to current unit for fig position40 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 43 43 44 44 %% determine the currently selected items 45 45 hcurrentobject=gco;% current object handle (selected by the mouse) 46 fig_tag=get(hcurrentfig,'Tag');46 CurrentGUI_tag=get(hCurrentGUI,'Tag'); 47 47 obj_tag=get(gco,'Tag');%tag of the currently selected object 48 48 xy=[];%default … … 63 63 if ~isempty(hset_object) 64 64 hPLOT=findobj(hset_object,'tag','PLOT'); 65 test_create=strcmp(get(hPLOT,'enable'),'on') &&~ test_edit;% create new object if set_object is in mode enable and uvmat not in mode 'edit_object'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' 66 66 end 67 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 … … 81 81 %% loop on all the objects in the current figure (selected by the last mouse click) 82 82 hchildren=get(hObject,'Children');%handles of all objects in the current figure 83 check_visible=strcmp(get(hchildren,'Visible'),'on');% if visible='on', =0 otherwise 84 hchildren=hchildren(check_visible); %kkep only the visible children 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'); 85 86 PosChildren=get(hchildren,'Position');% set of object positions 86 87 if iscell(PosChildren)% only one child … … 96 97 ind_object=find(check_pos(:,1) & check_pos(:,2),1);% select the index of the (first) object under the mouse 97 98 hchild=hchildren(ind_object);% corresponding object handle 98 if isempty(hchild) 99 % if test_edit||test_create 100 % hPlotAxes=findobj(hcurrentfig,'Tag','PlotAxes'); 101 % if ~isempty( hPlotAxes) 102 % PosPlotAxes=get(hPlotAxes,'Position'); 103 % PosDiff(1)=xy_fig(1)-PosPlotAxes(1)-PosPlotAxes(3);% distance to the right axes edge 104 % PosDiff(2)=PosPlotAxes(1)-xy_fig(1);% distance to the left axes edge 105 % PosDiff(3)=xy_fig(2)-PosPlotAxes(1)-PosPlotAxes(3);% distance to the top axes edge 106 % PosDiff(4)=PosPlotAxes(2)-xy_fig(2);% distance to the low axes edge 107 % [tild,ind_sel]=max(PosDiff); 108 % list_arrow=[29 28 30 31]; 109 % arrow_option=list_arrow(ind_sel); 110 % keyboard_callback(hcurrentfig,arrow_option) 111 % return 112 % end 113 % end 114 else 99 if ~isempty(hchild) 115 100 htype=get(hchild,'Type');%type of object child of the current figure 116 101 switch htype … … 129 114 if test_edit_vect 130 115 ivec=[]; 131 FigData=get(h currentfig,'UserData');116 FigData=get(hCurrentGUI,'UserData'); 132 117 tagaxes=get(hchild,'tag'); 133 118 if isfield(FigData,tagaxes) … … 200 185 201 186 %% creation of a zoom subfig 202 if isfield(hh currentfig,'CheckZoomFig') && get(hhcurrentfig.CheckZoomFig,'Value')187 if isfield(hhCurrentGUI,'CheckZoomFig') && get(hhCurrentGUI.CheckZoomFig,'Value') 203 188 AxeData.Drawing='zoom'; %initiate drawing mode 204 189 AxeData.CurrentObject=[];%unselect objects … … 212 197 213 198 %% ruler has second priority 214 if test_ruler 199 if test_ruler && ~isempty(xy) 215 200 AxeData.RulerCoord(1,1:2)=xy(1,1:2); 216 201 AxeData.RulerHandle=line([xy(1,1) xy(1,1)],[xy(1,2) xy(1,2)],'Color','m','Tag','ruler'); … … 287 272 IndexObj=ObjectData.IndexObj; 288 273 %indicate on the list of the GUI uvmat which object has been selected 289 if strcmp(get(h currentfig,'tag'),'uvmat') %if the uvmat graph has been selected, object projection is on the other frame view_field274 if strcmp(get(hCurrentGUI,'tag'),'uvmat') %if the uvmat graph has been selected, object projection is on the other frame view_field 290 275 % IndexObj=get(hhuvmat.ListObject,'Value'); 291 276 % if IndexObj>IndexObj_old(1) … … 331 316 332 317 %% create projection object 333 if test_create && ~isempty(xy) 318 if test_create && ~isempty(xy) && ~strcmp(get(hCurrentGUI,'SelectionType'),'alt') 334 319 % activate this option if the GUI set_object is opened 335 if ~isempty(hset_object) && ~strcmp(get(hcurrentfig,'SelectionType'),'alt') 336 sethandles=guidata(hset_object);% handles of the elements in the GUI set_object 337 ObjectData=read_GUI(hset_object); %read object parameters in the GUI set_object 338 IndexObj=length(UvData.ProjObject); 339 %initiate a new object (no data .Coord yet recorded) 340 if ~isfield(UvData.ProjObject{IndexObj},'Coord'); 341 ObjectData.Coord=[]; 342 ObjectNameNew=ObjectData.Name; 343 if isempty(ObjectNameNew) 344 ObjectNameNew=ObjectData.Type; 345 end 346 % add an index to the object name if the proposed name already exists 347 vers=0;% index of the name 348 ListObject=get(hhuvmat.ListObject,'String'); 349 detectname=1; 350 while ~isempty(detectname) 351 detectname=find(strcmp(ObjectNameNew,ListObject),1);%test the existence of the proposed name in the list 352 if detectname% if the object name already exists 353 indstr=regexp(ObjectNameNew,'\D'); 354 if indstr(end)<length(ObjectNameNew) %object name ends by a number 355 vers=str2double(ObjectNameNew(indstr(end)+1:end))+1; 356 ObjectNameNew=[ObjectNameNew(1:indstr(end)) num2str(vers)]; 357 else 358 vers=vers+1; 359 ObjectNameNew=[ObjectNameNew(1:indstr(end)) '_' num2str(vers)]; 360 end 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)]; 361 345 end 362 346 end 363 ObjectName=ObjectNameNew; 364 set(sethandles.Name,'String',ObjectName)% display the default name in set_object 365 if isempty(ListObject) 366 ListObject={ObjectName}; 367 else 368 ListObject{end}=ObjectName; 369 end 370 set(hhuvmat.ListObject,'String',ListObject);%complement the object list 371 set(hhuvmat.ListObject_1,'String',ListObject);%complement the object list 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') 372 354 set(hhuvmat.ListObject,'Value',IndexObj) 373 set(hhuvmat.ViewObject,'Value',1) 374 end 375 ObjectData.Coord=[ObjectData.Coord ;xy(1,1:2)];% append the coordinates marked by the mouse to the object 376 %TODO replace 0 by z coord for 3D 377 hobject=UvData.ProjObject{IndexObj}.DisplayHandle.(fig_tag); 378 if isempty(hobject) 379 hobject=haxes; 380 end 355 else 356 set(hhuvmat.ListObject_1,'Value',IndexObj) 357 end 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') 381 369 ProjObject=UvData.ProjObject{get(hhuvmat.ListObject_1,'Value')}; 382 AxeData.CurrentObject=plot_object(ObjectData,ProjObject,hobject,'m');%draw the object and its handle becomes AxeData.CurrentObject 383 UvData.ProjObject{IndexObj}=ObjectData; 384 UvData.ProjObject{IndexObj}.DisplayHandle.(fig_tag)=AxeData.CurrentObject;% attribute the current plot object handle to the Object 385 set(huvmat,'UserData',UvData) 386 PlotData=get(AxeData.CurrentObject,'UserData'); 387 PlotData.IndexObj=IndexObj; 388 set(AxeData.CurrentObject,'UserData',PlotData); %record the object index in the graph (memory used for mouse motion) 389 AxeData.Drawing='create';% flag for mouse motion 390 %show object coordinates in the GUI set_object 391 h_set_object=findobj(allchild(0),'Tag','set_object'); 392 hh_set_object=guidata(h_set_object); 393 set(hh_set_object.Coord,'Data',ObjectData.Coord); 394 end 370 else 371 ProjObject=UvData.ProjObject{get(hhuvmat.ListObject,'Value')}; 372 end 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); 395 405 end 396 406 … … 475 485 Field.FF(ivec)=0; 476 486 end 477 PlotParam=read_GUI(h currentfig);487 PlotParam=read_GUI(hCurrentGUI); 478 488 plot_field(Field,haxes,PlotParam); 479 489 eval(['FigData.' tagaxes '=Field;'])%record the modified field in FigData 480 set(h currentfig,'UserData',FigData);490 set(hCurrentGUI,'UserData',FigData); 481 491 end 482 492 set(haxes,'UserData',AxeData);
Note: See TracChangeset
for help on using the changeset viewer.