Changeset 192 for trunk/src/mouse_up.m


Ignore:
Timestamp:
Feb 14, 2011, 7:03:10 PM (13 years ago)
Author:
sommeria
Message:

civ: version working for all systems: windows, linux, mac
plots: introduction of axes limits , bug repairs (still further work needed)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/mouse_up.m

    r183 r192  
    2828currentfig=hObject;
    2929tagfig=get(currentfig,'tag');
    30 hhcurrentfig=guidata(currentfig);
     30currentaxes=gca; %store the current axes handle
     31AxeData=get(currentaxes,'UserData');
     32if isfield(AxeData,'CurrentOrigin')
     33    CurrentOrigin=AxeData.CurrentOrigin;
     34end
     35if isfield(AxeData,'ParentRect')% case of a zoom plot as current axis
     36    parentaxes=get(AxeData.ParentRect,'parent');
     37    AxeData=get(parentaxes,'UserData');
     38    controlGUI=get(parentaxes,'parent');%handles of the GUI parent of the zoom plot
     39    hhcurrentfig=guidata(controlGUI);
     40    testsubplot=1;
     41else
     42    hhcurrentfig=guidata(currentfig);%the current figure is a GUI (uvmat or view_field)
     43    testsubplot=0;
     44end
    3145test_zoom=get(hhcurrentfig.zoom,'Value');
    3246
    33 % if ~exist('handles','var')
    34 %    handles=get(gcbo,'UserData');
    35 % end
    3647huvmat=findobj(allchild(0),'tag','uvmat');%find the uvmat interface handle
    3748if ~isempty(huvmat)
    3849    hhuvmat=guidata(huvmat);
    3950    UvData=get(huvmat,'UserData');
    40 %     if isfield(UvData,'MouseAction')
    41 %         MouseAction=UvData.MouseAction;% set the mouse action (edit, create objects...)
    42 %     end
    4351   test_ruler=~test_zoom && isequal(get(hhuvmat.MenuRuler,'checked'),'on');%test for ruler  action, second priority
    4452end
    45 currentfig=hObject;
    46 currentaxes=gca; %store the current axes handle
    47 AxeData=get(currentaxes,'UserData');
    48 
    4953test_drawing=0;%default
    5054
     
    161165                    ViewFieldData.axes3=ProjData;
    162166                    set(hview_field,'UserData',ViewFieldData)
    163                     PlotHandles=guidata(hview_field);
     167%                     PlotHandles=guidata(hview_field);
    164168                else
    165169                    UvData.axes3=ProjData;
    166                     PlotHandles=hhuvmat;
     170%                     PlotHandles=hhuvmat;
    167171                end
    168                 [PlotType,PlotParam]=plot_field(ProjData,PlotHandles.axes3,PlotHandles);%update an existing field plot
    169                 write_plot_param(PlotHandles,PlotParam); %update the display of plotting parameters for the current object
     172                [PlotType,PlotParam]=plot_field(ProjData,hhcurrentfig.axes3,hhcurrentfig);%update an existing field plot
     173                write_plot_param(hhcurrentfig,PlotParam); %update the display of plotting parameters for the current object
    170174            end
    171175            %             if  isfield(UvData.Object{IndexObj},'PlotParam')
     
    190194
    191195%% creation of a new zoom plot
    192 test_replot=0;
    193196if isequal(get(currentfig,'SelectionType'),'normal');%if left button has been pressed
    194 %         FigData=get(currentfig,'UserData');
    195         hparentfig=currentfig;
    196         %open or update a new zoom figure if a rectangle has been drawn
    197         if ishandle(currentaxes);
    198             if isfield(AxeData,'CurrentRectZoom') && ~isempty(AxeData.CurrentRectZoom) && ishandle(AxeData.CurrentRectZoom)
    199                 PosRect=get(AxeData.CurrentRectZoom,'Position');
    200                 if isfield(AxeData,'CurrentVec') && ~isempty(AxeData.CurrentVec) && ishandle(AxeData.CurrentVec)
    201                     delete(AxeData.CurrentVec)
    202                 end
     197    hparentfig=currentfig;
     198    %open or update a new zoom figure if a rectangle has been drawn
     199    if ishandle(currentaxes);
     200        if isfield(AxeData,'CurrentRectZoom') && ~isempty(AxeData.CurrentRectZoom) && ishandle(AxeData.CurrentRectZoom)
     201            PosRect=get(AxeData.CurrentRectZoom,'Position');
     202            if isfield(AxeData,'CurrentVec') && ~isempty(AxeData.CurrentVec) && ishandle(AxeData.CurrentVec)
     203                delete(AxeData.CurrentVec)
     204            end
     205            if ~testsubplot
    203206                hfig2=figure;%create new figure
    204207                set(hfig2,'name','zoom')
     
    207210                map=colormap(currentaxes);
    208211                colormap(map);%transmit the current colormap to the zoom fig
    209                 set(hfig2,'Position',[0.2 0.33 0.6 0.6]);
    210                 if test_replot==0
    211                     set(hfig2,'Unit','normalized')
    212                     set(hfig2,'KeyPressFcn',{@keyboard_callback,handles})%set keyboard action function
    213                     set(hfig2,'WindowButtonMotionFcn',{@mouse_motion,handles})%set mouse action function
    214                     set(hfig2,'WindowButtonDownFcn',{@mouse_down})%set mouse click action function
    215                     set(hfig2,'WindowButtonUpFcn',{@mouse_up,handles}) 
    216                     set(hfig2,'DeleteFcn',{@close_fig,AxeData.CurrentRectZoom,'zoom'})
    217                     set(hfig2,'UserData',AxeData.CurrentRectZoom)% record the parent object (zoom rectangle) in the new fig
    218                     AxeData.ZoomAxes=copyobj(currentaxes,hfig2); %copy the current graph axes to the zoom figure
    219                     figure(hfig2)
    220                     set(AxeData.ZoomAxes,'Position',[0.1300    0.1100    0.7750    0.8150])% standard axes position on a figure
    221                     hcol=findobj(hparentfig,'Tag','Colorbar'); %look for colorbar axes
    222                     if ~isempty(hcol)             
    223                         hcol_new=colorbar;
    224                         YTick=get(hcol,'YTick');
    225                         YTicklabel=get(hcol,'Yticklabel'); 
    226                         colbarlim=get(hcol,'YLim');
    227                         newcolbarlim=get(hcol_new,'YLim');
    228                         scale_bar=(newcolbarlim(2)-newcolbarlim(1))/(colbarlim(2)-colbarlim(1));               
    229                         YTick_rescaled=newcolbarlim(1)+scale_bar*(YTick-colbarlim(1));
    230                         set(hcol_new,'YTick',YTick_rescaled);
    231                         set(hcol_new,'Yticklabel',YTicklabel);
    232                     end
     212                set(hfig2,'Position',[0.2 0.33 0.6 0.6]);         
     213                set(hfig2,'Unit','normalized')
     214                set(hfig2,'KeyPressFcn',{@keyboard_callback,handles})%set keyboard action function
     215                set(hfig2,'WindowButtonMotionFcn',{@mouse_motion,handles})%set mouse action function
     216                set(hfig2,'WindowButtonDownFcn',{@mouse_down})%set mouse click action function
     217                set(hfig2,'WindowButtonUpFcn',{@mouse_up,handles})
     218                set(hfig2,'DeleteFcn',{@close_fig,AxeData.CurrentRectZoom,'zoom'})
     219                set(hfig2,'UserData',AxeData.CurrentRectZoom)% record the parent object (zoom rectangle) in the new fig
     220                AxeData.ZoomAxes=copyobj(currentaxes,hfig2); %copy the current graph axes to the zoom figure
     221                ChildAxeData=get(AxeData.ZoomAxes,'UserData');
     222                if isfield(ChildAxeData,'ParentGUI')
     223                    ChildAxeData=rmfield(ChildAxeData,'ParentGUI');%no parent GUI, e.g. uvmat,  for the new plot
    233224                end
    234                 if ishandle(AxeData.ZoomAxes)
    235                     hnew_rect=findobj(AxeData.ZoomAxes,'Tag','rect_zoom');
    236                     if ~isempty(hnew_rect)
    237                         delete(hnew_rect);
    238                         ChildAxeData=get(AxeData.ZoomAxes,'UserData');
    239                         ChildAxeData.CurrentRectZoom=[]; % no rect zoom in the new window
    240                         ChildAxeData.Drawing='off';
    241                         ChildAxeData.ParentRect=AxeData.CurrentRectZoom;%set the rectangle as a 'parent' associated to the new axes
    242                         set(AxeData.ZoomAxes,'UserData',ChildAxeData);%update the AxeData of the new axes
    243                         set(AxeData.ZoomAxes,'Xlim',[PosRect(1) PosRect(1)+PosRect(3)])
    244                         set(AxeData.ZoomAxes,'Ylim',[PosRect(2) PosRect(2)+PosRect(4)])
    245                     end
     225                %figure(hfig2)
     226                %set(0,'CurrentFigure',hfig2)% the zoom figure becomes the current figure
     227                set(AxeData.ZoomAxes,'Position',[0.1300    0.1100    0.7750    0.8150])% standard axes position on a figure
     228                hcol=findobj(hparentfig,'Tag','Colorbar'); %look for colorbar axes
     229                if ~isempty(hcol)
     230                    hcol_new=colorbar;
     231                    YTick=get(hcol,'YTick');
     232                    YTicklabel=get(hcol,'Yticklabel');
     233                    colbarlim=get(hcol,'YLim');
     234                    newcolbarlim=get(hcol_new,'YLim');
     235                    scale_bar=(newcolbarlim(2)-newcolbarlim(1))/(colbarlim(2)-colbarlim(1));
     236                    YTick_rescaled=newcolbarlim(1)+scale_bar*(YTick-colbarlim(1));
     237                    set(hcol_new,'YTick',YTick_rescaled);
     238                    set(hcol_new,'Yticklabel',YTicklabel);
    246239                end
    247240            end
    248         end
     241    %             if ishandle(AxeData.ZoomAxes)
     242%             hnew_rect=findobj(AxeData.ZoomAxes,'Tag','rect_zoom');
     243%             if ~isempty(hnew_rect)
     244%                 delete(hnew_rect);
     245
     246                ChildAxeData.CurrentRectZoom=[]; % no rect zoom in the new window
     247                ChildAxeData.Drawing='off';
     248                ChildAxeData.ParentRect=AxeData.CurrentRectZoom;%set the rectangle as a 'parent' associated to the new axe
     249                PosRect=CurrentOrigin;
     250                xy=get(currentaxes,'CurrentPoint')%xy(1,1),xy(1,2): current x,y positions in axes coordinates
     251                set(AxeData.ZoomAxes,'Xlim',[PosRect(1) xy(1,1)])
     252                set(AxeData.ZoomAxes,'Ylim',[PosRect(2) xy(1,2)])
     253%             end
     254            set(AxeData.ZoomAxes,'UserData',ChildAxeData);%update the AxeData of the new axes
     255        end
     256    end
    249257end
    250258
     
    252260if test_zoom
    253261    xy=get(currentaxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
    254      if  isequal(get(currentfig,'SelectionType'),'normal');%if left button has been pressed
    255         xlim=get(currentaxes,'XLim');
    256         xlim_new(2)=0.5*xy(1,1)+0.5*xlim(2);
    257         xlim_new(1)=0.5*xy(1,1)+0.5*xlim(1);
    258         set(currentaxes,'XLim',xlim_new)
    259         ylim=get(currentaxes,'YLim');
    260         ylim_new(2)=0.5*xy(1,2)+0.5*ylim(2);
    261         ylim_new(1)=0.5*xy(1,2)+0.5*ylim(1);
    262         set(currentaxes,'YLim',ylim_new)
    263         if isfield(AxeData,'ParentRect')% update the position of the parent rectangle represneting the field
    264             hparentrect=AxeData.ParentRect;
    265             xlim=get(currentaxes,'XLim');
    266             ylim=get(currentaxes,'YLim');
    267             rect([1 2])=[xlim(1) ylim(1)];
    268             rect([3 4])=[xlim(2)-xlim(1) ylim(2)-ylim(1)];
    269             set(hparentrect,'Position',rect)
    270         end
    271      %zoom out by a factor of 2 out when the right mouse button has been used
    272      elseif isequal(get(currentfig,'SelectionType'),'alt'); %if right button has been pressed
    273 %             alpha=2; %zoom factor (zoom out by a factor 2)
    274             xlim=get(currentaxes,'XLim');
    275             xlim_new(1)=2*xlim(1)-xy(1,1);
    276             xlim_new(2)=2*xlim(2)-xy(1,1);
    277 %             xlim_new(1)=(1+alpha)*xlim(1)/2+(1-alpha)*xlim(2)/2;
    278 %             xlim_new(2)=(1-alpha)*xlim(1)/2+(1+alpha)*xlim(2)/2;
    279             ylim=get(currentaxes,'YLim');
    280             ylim_new(1)=2*ylim(1)-xy(1,2);
    281             ylim_new(2)=2*ylim(2)-xy(1,2);
    282 %             ylim_new(1)=(1+alpha)*ylim(1)/2+(1-alpha)*ylim(2)/2;
    283 %             ylim_new(2)=(1-alpha)*ylim(1)/2+(1+alpha)*ylim(2)/2;
    284             if isfield(AxeData,'RangeX') && isfield(AxeData,'RangeY')
    285                 xlim_new(1)=max(AxeData.RangeX(1),xlim_new(1));
    286                 xlim_new(2)=min(AxeData.RangeX(2),xlim_new(2));
    287                 ylim_new(1)=max(AxeData.RangeY(1),ylim_new(1));
    288                 ylim_new(2)=min(AxeData.RangeY(2),ylim_new(2));
    289                 if isequal(xlim_new,AxeData.RangeX) && isequal(ylim_new,AxeData.RangeY)
    290                     set(hhuvmat.zoom,'Value',0)
    291                     set(hhuvmat.zoom,'BackgroundColor',[0.7 0.7 0.7])
    292                     set(hhuvmat.FixedLimits,'Value',0)
    293                     set(hhuvmat.FixedLimits,'BackgroundColor',[0.7 0.7 0.7])
    294                 end
    295             end
    296             set(currentaxes,'XLim',xlim_new)
    297             set(currentaxes,'YLim',ylim_new)
    298             %test whther zoom out is operating (to inactivate AxedAta
    299             if ~isfield(AxeData,'CurrentXLim')|| ~isequal(xlim,AxeData.CurrentXLim)
    300                 AxeData.CurrentXLim=xlim;%
    301             end
    302             if isfield(AxeData,'ParentRect')% update the position of the parent rectangle represneting the field
    303                 hparentrect=AxeData.ParentRect;
    304                 xlim=get(currentaxes,'XLim');
    305                 ylim=get(currentaxes,'YLim');
    306                 rect([1 2])=[xlim(1) ylim(1)];
    307                 rect([3 4])=[xlim(2)-xlim(1) ylim(2)-ylim(1)];
    308                 set(hparentrect,'Position',rect)
    309             end
    310       end
     262    xlim=get(currentaxes,'XLim');
     263    ylim=get(currentaxes,'YLim');
     264    if  isequal(get(currentfig,'SelectionType'),'normal');%if left button has been pressed
     265        xlim(1)=0.5*xy(1,1)+0.5*xlim(1);
     266        xlim(2)=0.5*xy(1,1)+0.5*xlim(2);
     267        set(currentaxes,'XLim',xlim)
     268        ylim(2)=0.5*xy(1,2)+0.5*ylim(2);
     269        ylim(1)=0.5*xy(1,2)+0.5*ylim(1);
     270        set(currentaxes,'YLim',ylim)
     271        %zoom out by a factor of 2 out when the right mouse button has been used
     272    else%if isequal(get(currentfig,'SelectionType'),'alt'); %if right button has been pressed
     273        xlim(1)=2*xlim(1)-xy(1,1);
     274        xlim(2)=2*xlim(2)-xy(1,1);
     275        ylim(1)=2*ylim(1)-xy(1,2);
     276        ylim(2)=2*ylim(2)-xy(1,2);
     277        %             ylim_new(1)=(1+alpha)*ylim(1)/2+(1-alpha)*ylim(2)/2;
     278        %             ylim_new(2)=(1-alpha)*ylim(1)/2+(1+alpha)*ylim(2)/2;
     279        if isfield(AxeData,'RangeX') && isfield(AxeData,'RangeY')
     280            xlim(1)=max(AxeData.RangeX(1),xlim(1));
     281            xlim(2)=min(AxeData.RangeX(2),xlim(2));
     282            ylim(1)=max(AxeData.RangeY(1),ylim(1));
     283            ylim(2)=min(AxeData.RangeY(2),ylim(2));
     284            if isequal(xlim,AxeData.RangeX) && isequal(ylim,AxeData.RangeY)
     285                set(hhuvmat.zoom,'Value',0)
     286                set(hhuvmat.zoom,'BackgroundColor',[0.7 0.7 0.7])
     287                set(hhuvmat.FixedLimits,'Value',0)
     288                set(hhuvmat.FixedLimits,'BackgroundColor',[0.7 0.7 0.7])
     289            end
     290        end
     291        set(currentaxes,'XLim',xlim)
     292        set(currentaxes,'YLim',ylim)
     293        %test whther zoom out is operating (to inactivate AxedAta
     294        if ~isfield(AxeData,'CurrentXLim')|| ~isequal(xlim,AxeData.CurrentXLim)
     295            AxeData.CurrentXLim=xlim;%
     296        end
     297    end
     298%     if isfield(AxeData,'ParentRect')% update the position of the parent rectangle represneting the field
     299%         hparentrect=AxeData.ParentRect;
     300%         xlim=get(currentaxes,'XLim');
     301%         ylim=get(currentaxes,'YLim');
     302%         rect([1 2])=[xlim(1) ylim(1)];
     303%         rect([3 4])=[xlim(2)-xlim(1) ylim(2)-ylim(1)];
     304%         set(hparentrect,'Position',rect)
     305    if isfield(AxeData,'LimEditBox')&& AxeData.LimEditBox% update display of the GUI containing the axis (uvmat or view_field)
     306        set(hhcurrentfig.MinX,'String',num2str(xlim(1)))
     307        set(hhcurrentfig.MaxX,'String',num2str(xlim(2)))
     308        set(hhcurrentfig.MinY,'String',num2str(ylim(1)))
     309        set(hhcurrentfig.MaxY,'String',num2str(ylim(2)))
     310    end
    311311end
    312312
Note: See TracChangeset for help on using the changeset viewer.