Changeset 622 for trunk/src/mouse_up.m


Ignore:
Timestamp:
Apr 29, 2013, 11:35:27 AM (11 years ago)
Author:
sommeria
Message:

mouse system for uvmat imrpoved

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/mouse_up.m

    r608 r622  
    2323
    2424function mouse_up(hObject,eventdata,handles)
    25 %MouseAction='none'; %default
    26 test_zoom=0;%default
     25
    2726test_ruler=0;%default
    28 currentfig=hObject;
    29 tagfig=get(currentfig,'tag');
     27hcurrentfig=hObject;
     28fig_tag=get(hcurrentfig,'tag');
    3029currentaxes=gca; %store the current axes handle
    3130AxeData=get(currentaxes,'UserData');
     31CurrentOrigin=[];
    3232if isfield(AxeData,'CurrentOrigin')
    3333    CurrentOrigin=AxeData.CurrentOrigin;
     
    4040    testsubplot=1;
    4141else
    42     hhcurrentfig=guidata(currentfig);%the current figure is a GUI (uvmat or view_field)
     42    hhcurrentfig=guidata(hcurrentfig);%the current figure is a GUI (uvmat or view_field)
    4343    testsubplot=0;
    4444end
     
    5959    PlotData=get(AxeData.CurrentObject,'UserData');%get data attached to the current projection object
    6060    IndexObj=PlotData.IndexObj;
    61     ObjectData=UvData.Object{IndexObj};
     61    ObjectData=UvData.ProjObject{IndexObj};
    6262    check_multiple=0;
    6363    % ending translation
     
    7979        switch ObjectData.Type
    8080            case {'line'}
    81                 if isfield(AxeData,'ObjectCoord') && size(AxeData.ObjectCoord,2)==3
    82                     xy(1,3)=AxeData.ObjectCoord(1,3); % z coordinate of the mouse: to generalise ...
     81                if size(ObjectData.Coord,1)==1 % this is the mouse up for the first point, continue until next click
     82                    check_multiple=1;
    8383                else
    84                     xy(1,3)=0; % z coordinate set to 0 by default
    85                 end
    86                 %                 if ~isequal(ObjectData.Coord,xy(1,:))
    87                 if ~isequal(ObjectData.Coord(end,1:2),xy(1,1:2))
    88                     ObjectData.Coord=[ObjectData.Coord ;xy(1,1:2)];% append the second point of the line if different from the first one
    89                 end
    90                 %                 end
     84                    %ObjectData.Coord=[ObjectData.Coord ;CurrentOrigin];% append the second point of the line (the last pointed position during mouse down)
     85                end
    9186            case {'rectangle','ellipse','volume'}
    92                 XYData=AxeData.CurrentOrigin;
    93                 ObjectData.Coord(1,1)=(xy(1,1)+XYData(1))/2;%origin rectangle, x coordinate
    94                 ObjectData.Coord(1,2)=(xy(1,2)+XYData(2))/2;
    95                 ObjectData.RangeX=abs(xy(1,1)-XYData(1))/2;%rectangle width
    96                 ObjectData.RangeY=abs(xy(1,2)-XYData(2))/2;%rectangle height
     87%                  if size(ObjectData.Coord,1)==1 % this is the mouse up for the first point, continue until next click
     88%                     check_multiple=1;
     89%                  else
     90                ObjectData.Coord=(CurrentOrigin+xy(1,1:2))/2;% keep only the first point coordinate     
     91                ObjectData.RangeX=abs(ObjectData.Coord(1,1)-xy(1,1));%rectangle width
     92                ObjectData.RangeY=abs(ObjectData.Coord(1,2)-xy(1,2));%rectangle height   
     93                if isequal(ObjectData.RangeX,0)||isequal(ObjectData.RangeY,0)
     94                    check_multiple=1;% pass to next mous up if width of height=0
     95                end
     96%                 ObjectData.Coord(1,1)=(xy(1,1)+XYData(1))/2;%origin rectangle, x coordinate
     97%                 ObjectData.Coord(1,2)=(xy(1,2)+XYData(2))/2;
     98%                 ObjectData.RangeX=abs(xy(1,1)-XYData(1))/2;%rectangle width
     99%                 ObjectData.RangeY=abs(xy(1,2)-XYData(2))/2;%rectangle height
     100%                  end
    97101            case 'plane' %case of 'plane'
    98102                DX=(xy(1,1)-ObjectData.Coord(1,1));
     
    106110                end
    107111            otherwise
    108                 check_multiple=1;
     112                check_multiple=1; 
    109113        end
    110114    end
     
    120124
    121125    %stop drawing and plot projected field if the object manipulation is finished
    122     if check_multiple==0  || isequal(get(currentfig,'SelectionType'),'alt')
     126    if check_multiple==0  || isequal(get(hcurrentfig,'SelectionType'),'alt')
    123127        AxeData.CurrentOrigin=[]; %suppress the current origin
    124 %         if isequal(ObjectData.Type,'line') && size(ObjectData.Coord,1)>=2
    125 % %             AxeData.Drawing='off';
    126 % %             set(currentaxes,'UserData',AxeData);
    127 %             
    128 %         end
     128        hobject=UvData.ProjObject{IndexObj}.DisplayHandle.(fig_tag);
     129        if ~isempty(hObject)
     130         ProjObject=UvData.ProjObject{get(hhuvmat.ListObject_1,'Value')};
     131        AxeData.CurrentObject=plot_object(ObjectData,ProjObject,hobject,'m');%draw the object and its handle becomes AxeData.CurrentObject
     132        end
     133        %%
    129134        if  ~isempty(ObjectData)
    130             %              testmask=0;
    131             %              hmask=findobj(huvmat,'Tag','makemask');
    132             %              if ~isempty(hmask)
    133             %                 testmask=get(hmask,'Value');
    134             %              end
    135            
    136135            % plot the field projected on the object
    137136            ProjData= proj_field(UvData.Field,ObjectData);%project the current interface field on ObjectData
    138137            if ~isempty(ProjData)
    139                 if strcmp(tagfig,'uvmat')% uvmat plot selected, projection plot seen in view_field
     138                if strcmp(fig_tag,'uvmat')% uvmat plot selected, projection plot seen in view_field
    140139                    hview_field=findobj(allchild(0),'tag','view_field');
    141140                    if isempty(hview_field)
     
    144143                        hhview_field=guidata(hview_field);
    145144                        [PlotType,PlotParam]=plot_field(ProjData,hhview_field.PlotAxes,read_GUI(hview_field));%update an existing  plot in view_field
    146                         %write_plot_param(hhview_field,PlotParam); %update the display of plotting parameters for the current object
    147145                        errormsg=fill_GUI(PlotParam,hview_field);
    148146                    end
    149147                    ViewFieldData=get(hview_field,'UserData');
    150                     %                     ViewFieldData.PlotAxes=ProjData;
    151148                    haxes=findobj(hview_field,'tag','axes3');
    152149                    if strcmp(get(haxes,'Visible'),'off')%sempty(PlotParam.Coordinates)% case of no plot display (pure text table)
     
    164161                    [PlotType,PlotParam]=plot_field(ProjData,hhuvmat.PlotAxes,read_GUI(hhuvmat));%update an existing field plot
    165162                    errormsg=fill_GUI(PlotParam,huvmat);
    166                    % write_plot_param(hhuvmat,PlotParam); %update the display of plotting parameters for the current object
    167163                end
    168164            end
     
    176172    else
    177173        test_drawing=1;%allow continuation of drawing object
    178         AxeData.CurrentOrigin=[xy(1,1) xy(1,2)]; %the current point becomes the next current origin
    179     end
    180     UvData.Object{IndexObj}=ObjectData;
     174         AxeData.CurrentOrigin=[xy(1,1) xy(1,2)]; %the current point becomes the next current origin
     175    end
     176    UvData.ProjObject{IndexObj}=ObjectData;
    181177    hother=findobj('Tag','deformpoint');%find all the deformpoints
    182178    set(hother,'Color','b');%reset all the deformpoints in 'blue'
     
    184180
    185181%% creation of a new zoom plot
    186 if isequal(get(currentfig,'SelectionType'),'normal');%if left button has been pressed
    187     hparentfig=currentfig;
     182if isequal(get(hcurrentfig,'SelectionType'),'normal');%if left button has been pressed
     183    hparentfig=hcurrentfig;
    188184    %open or update a new zoom figure if a rectangle has been drawn
    189185    if ishandle(currentaxes);
     
    196192                hfig2=figure;%create new figure
    197193                set(hfig2,'name','zoom')
    198                 set(hfig2,'Units','normalized')
    199                 set(hfig2,'Position',[0.2 0.33 0.6 0.6]);
     194                set(0,'Unit','pixels')
     195                set(hfig2,'Unit','pixels')
     196                FigPos=get(hfig2,'Position');
     197                ScreenSize=get(0,'ScreenSize');% get the size of the screen, to put the fig on the upper right
     198                Left=ScreenSize(3)- FigPos(3)-40; %right edge close to the right, with margin=40
     199                Bottom=ScreenSize(4)-FigPos(4)-40; %put fig at top right
     200                FigPos(1:2)=[Left Bottom];
     201                set(hfig2,'Position',FigPos);
    200202                map=colormap(currentaxes);
    201203                colormap(map);%transmit the current colormap to the zoom fig
    202                 set(hfig2,'Position',[0.2 0.33 0.6 0.6]);
    203                 set(hfig2,'Unit','normalized')
    204204                set(hfig2,'KeyPressFcn',{@keyboard_callback,handles})%set keyboard action function
    205205                set(hfig2,'WindowButtonMotionFcn',{@mouse_motion,handles})%set mouse action function
     
    209209                set(hfig2,'UserData',AxeData.CurrentRectZoom)% record the parent object (zoom rectangle) in the new fig
    210210                AxeData.ZoomAxes=copyobj(currentaxes,hfig2); %copy the current graph axes to the zoom figure
     211                hrect_zoom=findobj(AxeData.ZoomAxes,'Tag','rect_zoom');%find and delete the copy of the rect_zoom rectangle
     212                delete(hrect_zoom)
    211213                ChildAxeData=get(AxeData.ZoomAxes,'UserData');
    212214                if isfield(ChildAxeData,'ParentGUI')
    213215                    ChildAxeData=rmfield(ChildAxeData,'ParentGUI');%no parent GUI, e.g. uvmat,  for the new plot
    214216                end
    215                 %figure(hfig2)
    216                 %set(0,'CurrentFigure',hfig2)% the zoom figure becomes the current figure
    217217                set(AxeData.ZoomAxes,'Position',[0.1300    0.1100    0.7750    0.8150])% standard axes position on a figure
    218218                hcol=findobj(hparentfig,'Tag','Colorbar'); %look for colorbar axes
     
    247247    ylim=get(currentaxes,'YLim');
    248248    % if left mouse button has been pressed, zoom in by a factor of 2
    249     if  isequal(get(currentfig,'SelectionType'),'normal');%if left button has been pressed, zoom in by a factor of 2
     249    if  isequal(get(hcurrentfig,'SelectionType'),'normal');%if left button has been pressed, zoom in by a factor of 2
    250250        PlotBoxAspectRatio=get(currentaxes,'PlotBoxAspectRatio');
    251251        yoverx=PlotBoxAspectRatio(2)/PlotBoxAspectRatio(1);
     
    346346
    347347%% display the data of the current object selected with the mouse right click
    348 if isequal(get(currentfig,'SelectionType'),'alt') && ~test_zoom && (~isfield(AxeData,'Drawing')||~isequal(AxeData.Drawing,'create'))
     348if isequal(get(hcurrentfig,'SelectionType'),'alt') && ~test_zoom && (~isfield(AxeData,'Drawing')||~isequal(AxeData.Drawing,'create'))
    349349    hother=findobj('Tag','proj_object');%find all the proj objects
    350350    nbselect=0;
     
    368368    end
    369369%     if ((nbselect==0) && isequal(get(currentobj,'Type'),'axes')) || isequal(currentobj,huvmat)
    370 %         currentfig=get(currentobj,'parent');
    371 %         figname=get(currentfig,'name');
     370%         hcurrentfig=get(currentobj,'parent');
     371%         figname=get(hcurrentfig,'name');
    372372%         eval(['global Data_' figname])
    373373%         eval(['Data_' figname '=get(currentobj,''UserData'')']);
Note: See TracChangeset for help on using the changeset viewer.