Home > . > mouse_up.m

mouse_up

PURPOSE ^

'mouse_up': function activated when the mouse button is released

SYNOPSIS ^

function mouse_up(ggg,eventdata,handles)

DESCRIPTION ^

'mouse_up': function  activated when the mouse button is released
----------------------------------------------------------------
 function mouse_up(ggg,eventdata,handles)
 activated by the command:
 set(hObject,'WindowButtonUpFcn',{'mouse_up'}), 
 where hObject is the handle of the figure

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
     This file is part of the toolbox UVMAT.
 
     UVMAT is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
 
     UVMAT is distributed in the hope that it will be useful,
     but WITHOUT ANY WARRANTY; without even the implied warranty of
     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     GNU General Public License (file UVMAT/COPYING.txt) for more details.
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 %'mouse_up': function  activated when the mouse button is released
0002 %----------------------------------------------------------------
0003 % function mouse_up(ggg,eventdata,handles)
0004 % activated by the command:
0005 % set(hObject,'WindowButtonUpFcn',{'mouse_up'}),
0006 % where hObject is the handle of the figure
0007 %
0008 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
0009 %  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
0010 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
0011 %     This file is part of the toolbox UVMAT.
0012 %
0013 %     UVMAT is free software; you can redistribute it and/or modify
0014 %     it under the terms of the GNU General Public License as published by
0015 %     the Free Software Foundation; either version 2 of the License, or
0016 %     (at your option) any later version.
0017 %
0018 %     UVMAT is distributed in the hope that it will be useful,
0019 %     but WITHOUT ANY WARRANTY; without even the implied warranty of
0020 %     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0021 %     GNU General Public License (file UVMAT/COPYING.txt) for more details.
0022 %AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
0023 
0024 function mouse_up(ggg,eventdata,handles)
0025 MouseAction='none'; %default
0026 zoomstate=0;%default
0027 if ~exist('handles','var')
0028    handles=get(gcbo,'UserData');
0029 end
0030 huvmat=findobj(allchild(0),'Name','uvmat');%find the uvmat interface handle
0031 if ~isempty(huvmat)
0032     hhuvmat=guidata(huvmat);
0033     UvData=get(huvmat,'UserData');
0034     if isfield(UvData,'MouseAction')
0035         MouseAction=UvData.MouseAction;% set the mouse action (edit, create objects...)
0036     end
0037     zoomstate=get(hhuvmat.zoom,'Value');
0038 end
0039 if isequal(MouseAction,'calib') && ~zoomstate
0040     return
0041 end
0042 currentfig=gcbo;
0043 AxeData=get(gca,'UserData');
0044 currentaxes=gca; %store the current axes handle
0045 test_drawing=0;%default
0046 
0047 %finalize the fabrication or the translation/deformation of an object and plot the corresponding projected field
0048 if ~isempty(huvmat) & isfield(AxeData,'Drawing') & ~isequal(AxeData.Drawing,'off') & isfield(AxeData,'CurrentObject')...
0049            & ishandle(AxeData.CurrentObject)
0050     xy=get(currentaxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
0051     PlotData=get(AxeData.CurrentObject,'UserData');%get data attached to the current projection object
0052     IndexObj=PlotData.IndexObj;
0053     ObjectData=UvData.Object{IndexObj};    
0054     if isequal(AxeData.Drawing,'translate')
0055         XYData=AxeData.CurrentOrigin;
0056         DX=xy(1,1)-XYData(1);%translation from initial position
0057         DY=xy(1,2)-XYData(2);
0058         ObjectData.Coord(:,1)=ObjectData.Coord(:,1)+DX;
0059         ObjectData.Coord(:,2)=ObjectData.Coord(:,2)+DY;
0060     elseif isequal(AxeData.Drawing,'deform')
0061         ind_move=AxeData.CurrentIndex;
0062         ObjectData.Coord(ind_move,1)=xy(1,1);
0063         ObjectData.Coord(ind_move,2)=xy(1,2);
0064     else   %creating object
0065         if isequal(ObjectData.Style,'line')||isequal(ObjectData.Style,'polyline')||...
0066                 isequal(ObjectData.Style,'polygon')||isequal(ObjectData.Style,'points')
0067             if isfield(AxeData,'ObjectCoord') && size(AxeData.ObjectCoord,2)==3
0068               xy(1,3)=AxeData.ObjectCoord(1,3); % z coordinate of the mouse: to generalise ...
0069             else
0070                  xy(1,3)=0; % z coordinate set to 0 by default
0071             end
0072             if ~isequal(ObjectData.Coord,xy(1,:))
0073                 ObjectData.Coord=[ObjectData.Coord ;xy(1,:)];% append the coordiantes marked by the mouse to the eobject
0074             end
0075         elseif isequal(ObjectData.Style,'rectangle')||isequal(ObjectData.Style,'ellipse')||isequal(ObjectData.Style,'volume')
0076             XYData=AxeData.CurrentOrigin;
0077             ObjectData.Coord(1,1)=(xy(1,1)+XYData(1))/2;%origin rectangle, x coordinate
0078             ObjectData.Coord(1,2)=(xy(1,2)+XYData(2))/2;
0079             ObjectData.RangeX=abs(xy(1,1)-XYData(1))/2;%rectangle width
0080             ObjectData.RangeY=abs(xy(1,2)-XYData(2))/2;%rectangle height
0081         elseif isequal(ObjectData.Style,'plane') %case of 'plane'
0082             DX=(xy(1,1)-ObjectData.Coord(1,1));
0083             DY=(xy(1,2)-ObjectData.Coord(1,2));
0084             ObjectData.Phi=(angle(DX+i*DY))*180/pi;%rectangle widt
0085             if isfield(ObjectData,'RangeX')
0086                 XMax=sqrt(DX*DX+DY*DY);
0087                 if XMax>max(ObjectData.RangeX)
0088                     ObjectData.RangeX=[min(ObjectData.RangeX) XMax];
0089                 end
0090             end
0091         end
0092     end
0093     %set(AxeData.CurrentObject,'UserData',ObjectData); %update the object properties
0094     if isequal(ObjectData.Style,'rectangle')||isequal(ObjectData.Style,'ellipse')
0095         NbDefPoint=1;  
0096     elseif isequal(ObjectData.Style,'line')|| isequal(ObjectData.Style,'plane');
0097         NbDefPoint=2; 
0098     else
0099          NbDefPoint=3;
0100     end
0101     
0102     %show object coordinates in the GUI set_object
0103     h_set_object=findobj(allchild(0),'Name','set_object');
0104     h_XObject=findobj(h_set_object,'Tag','XObject');
0105     h_YObject=findobj(h_set_object,'Tag','YObject');
0106     h_ZObject=findobj(h_set_object,'Tag','ZObject');
0107     set(h_XObject,'String',num2str(ObjectData.Coord(:,1),4)); 
0108     set(h_YObject,'String',num2str(ObjectData.Coord(:,2),4)); 
0109     set(h_ZObject,'String',num2str(ObjectData.Coord(:,3),4));
0110     if NbDefPoint<=2 || isequal(get(currentfig,'SelectionType'),'alt') ||...
0111               isequal(AxeData.Drawing,'translate') || isequal(AxeData.Drawing,'deform');%stop drawing
0112         AxeData.CurrentOrigin=[]; %suppress the current origin
0113        if isequal(ObjectData.Style,'line') && size(ObjectData.Coord,1)<=1
0114            AxeData.Drawing='off';
0115            set(currentaxes,'UserData',AxeData);
0116             return % line needs at leqst two points
0117        end
0118        if  ~isempty(ObjectData)
0119              testmask=0;
0120              hmask=findobj(huvmat,'Tag','makemask');
0121              if ~isempty(hmask)
0122                 testmask=get(hmask,'Value');
0123              end
0124              if testmask
0125                  PlotHandles=[];%do not project data on the object during mask creation
0126              else
0127                  PlotHandles=get_plot_handles(handles);%get the handles of the graphic objects setting the plotting parameters
0128              end
0129             AxeData.hset_object=set_object(ObjectData,PlotHandles);% call the set_object interface ,*
0130             UvData.Object{IndexObj}=update_obj(UvData,IndexObj,ObjectData,PlotHandles); 
0131             %ObjectData=update_obj(UvData,IndexObj,ObjectData,PlotHandles);
0132             if  isfield(UvData.Object{IndexObj},'PlotParam')
0133                 write_plot_param(PlotHandles,UvData.Object{IndexObj}.PlotParam); %update the display of plotting parameters for the current object
0134             end              
0135             set(hhuvmat.create,'Value',0);% set to 'off' the button for object creation
0136             set(hhuvmat.create,'BackgroundColor',[0 1 0]);% paint the creation button in green
0137             set(hhuvmat.edit,'BackgroundColor',[1 1 0]);% paint the edit text in yellow
0138             set(hhuvmat.edit,'Value',1);%
0139             set(hhuvmat.edit,'Enable','on');%
0140             set(hhuvmat.MenuEdit,'Enable','on');%
0141             set(hhuvmat.MenuEdit,'Enable','on');%
0142             set(hhuvmat.MenuObject,'Enable','on');%
0143             UvData.MouseAction='edit_object'; % set the edit button to 'on'
0144         end
0145     else
0146        AxeData.CurrentOrigin=[xy(1,1) xy(1,2)]; %the current point becomes the new current origin
0147        test_drawing=1;%allow continuation of drawing object
0148        UvData.Object{IndexObj}=ObjectData;
0149     end
0150     hother=findobj('Tag','deformpoint');%find all the deformpoints
0151     set(hother,'Color','b');%reset all the deformpoints in 'blue'
0152 else
0153     test_drawing=0;
0154 end
0155 
0156 %creation of a new zoom plot
0157 test_replot=0;
0158 if isequal(get(currentfig,'SelectionType'),'normal');%if left button has been pressed
0159 %         FigData=get(currentfig,'UserData');
0160         hparentfig=currentfig;
0161         %open or update a new zoom figure if a rectangle has been drawn
0162         if ishandle(currentaxes);
0163             if isfield(AxeData,'CurrentRectZoom') & ishandle(AxeData.CurrentRectZoom)
0164                 PosRect=get(AxeData.CurrentRectZoom,'Position');
0165                 if isfield(AxeData,'CurrentVec') & ishandle(AxeData.CurrentVec)
0166                     delete(AxeData.CurrentVec)
0167                 end
0168                 %update the axes UvData.Plane2 if it exists, else create it
0169 %                 if isfield (UvData,'Plane2') & ishandle(UvData.Plane2.Fig)%if the second plan plotting axis already exists
0170 %                     hfig2=UvData.Plane2.Fig;
0171 %                     if isequal(gcf,hfig2)%if we are already on the secondary figure
0172 %                         test_replot=1;
0173 %                     else
0174 %                         figure(hfig2)%set hfig2 as the current figure
0175 %                         clf; %erase axes
0176 %                     end
0177 %                 else
0178                     hfig2=figure;%create new figure
0179                     set(hfig2,'name','zoom')
0180                     set(hfig2,'Units','normalized')
0181                     set(hfig2,'Position',[0.2 0.33 0.6 0.6]);
0182 %                     UvData.Plane2.Fig=hfig2;
0183                     map=colormap(currentaxes);
0184                     colormap(map);%transmit the current colormap to the zoom fig
0185                     get(handles.RootFile,'String')
0186 %                 end
0187                 set(hfig2,'Position',[0.2 0.33 0.6 0.6]);
0188                 if test_replot==0
0189                     set(hfig2,'Unit','normalized')
0190                     set(hfig2,'KeyPressFcn',{@keyboard_callback,handles})%set keyboard action function
0191                     set(hfig2,'WindowButtonMotionFcn',{@mouse_motion,handles})%set mouse action function
0192                     set(hfig2,'WindowButtonDownFcn',{@mouse_down})%set mouse click action function
0193                     set(hfig2,'WindowButtonUpFcn',{@mouse_up,handles})  
0194                     set(hfig2,'DeleteFcn',{@close_fig,AxeData.CurrentRectZoom,'zoom'})
0195                     set(hfig2,'UserData',AxeData.CurrentRectZoom)% record the parent object (zoom rectangle) in the new fig
0196                     %UvData.Plane2.Axes=copyobj(currentaxes,hfig2); %copy the current graph axes to the zoom figure
0197                     AxeData.ZoomAxes=copyobj(currentaxes,hfig2); %copy the current graph axes to the zoom figure
0198                     figure(hfig2)
0199                     set(AxeData.ZoomAxes,'Position',[0.1300    0.1100    0.7750    0.8150])% standard axes position on a figure
0200                     hcol=findobj(hparentfig,'Tag','Colorbar'); %look for colorbar axes
0201                     if ~isempty(hcol)             
0202                         hcol_new=colorbar;
0203                         YTick=get(hcol,'YTick');
0204                         YTicklabel=get(hcol,'Yticklabel');  
0205                         colbarlim=get(hcol,'YLim'); 
0206                         newcolbarlim=get(hcol_new,'YLim');
0207                         scale_bar=(newcolbarlim(2)-newcolbarlim(1))/(colbarlim(2)-colbarlim(1));                
0208                         YTick_rescaled=newcolbarlim(1)+scale_bar*(YTick-colbarlim(1));
0209                         set(hcol_new,'YTick',YTick_rescaled);
0210                         set(hcol_new,'Yticklabel',YTicklabel);
0211                     end
0212                 end
0213                 if ishandle(AxeData.ZoomAxes)
0214                     hnew_rect=findobj(AxeData.ZoomAxes,'Tag','rect_zoom');
0215                     if ~isempty(hnew_rect)
0216                         delete(hnew_rect);
0217                         ChildAxeData=get(AxeData.ZoomAxes,'UserData');
0218                         ChildAxeData.CurrentRectZoom=[]; % no rect zoom in the new window
0219                         ChildAxeData.Drawing='off';
0220                         ChildAxeData.ParentRect=AxeData.CurrentRectZoom;%set the rectangle as a 'parent' associated to the new axes
0221                         set(AxeData.ZoomAxes,'UserData',ChildAxeData);%update the AxeData of the new axes
0222                        % UvData.TopFig=hfig2;%put the new fig to the top of the stack for uvmat
0223         %                 set(huvmat,'UserData',UvData)
0224                         set(AxeData.ZoomAxes,'Xlim',[PosRect(1) PosRect(1)+PosRect(3)])
0225                         set(AxeData.ZoomAxes,'Ylim',[PosRect(2) PosRect(2)+PosRect(4)])
0226                     end
0227                 end
0228             end
0229         end
0230 end
0231 %zoom in if no new figure is created
0232 if zoomstate
0233      if  isequal(get(currentfig,'SelectionType'),'normal');%if left button has been pressed
0234         %zoom(2)% zoom in by a factor of 2
0235         alpha=0.5; %zoom factor (zoom in by a factor 2)
0236         xlim=get(currentaxes,'XLim');
0237         xlim_new(1)=(1+alpha)*xlim(1)/2+(1-alpha)*xlim(2)/2;
0238         xlim_new(2)=(1-alpha)*xlim(1)/2+(1+alpha)*xlim(2)/2;
0239         set(currentaxes,'XLim',xlim_new)
0240         ylim=get(currentaxes,'YLim'); 
0241         ylim_new(1)=(1+alpha)*ylim(1)/2+(1-alpha)*ylim(2)/2;
0242         ylim_new(2)=(1-alpha)*ylim(1)/2+(1+alpha)*ylim(2)/2;
0243         set(currentaxes,'YLim',ylim_new)
0244         if isfield(AxeData,'ParentRect')% update the position of the parent rectangle represneting the field
0245             hparentrect=AxeData.ParentRect;
0246             xlim=get(currentaxes,'XLim');
0247             ylim=get(currentaxes,'YLim');
0248             rect([1 2])=[xlim(1) ylim(1)];
0249             rect([3 4])=[xlim(2)-xlim(1) ylim(2)-ylim(1)];
0250             set(hparentrect,'Position',rect)
0251         end
0252 
0253      elseif isequal(get(currentfig,'SelectionType'),'alt'); %if right button has been pressed
0254             %zoom(0.5)% zoom out by a factor of 2
0255             alpha=2; %zoom factor (zoom out by a factor 2)
0256             xlim=get(currentaxes,'XLim');
0257             xlim_new(1)=(1+alpha)*xlim(1)/2+(1-alpha)*xlim(2)/2;
0258             xlim_new(2)=(1-alpha)*xlim(1)/2+(1+alpha)*xlim(2)/2;
0259             ylim=get(currentaxes,'YLim');
0260             ylim_new(1)=(1+alpha)*ylim(1)/2+(1-alpha)*ylim(2)/2;
0261             ylim_new(2)=(1-alpha)*ylim(1)/2+(1+alpha)*ylim(2)/2;
0262             set(currentaxes,'XLim',xlim_new)
0263             set(currentaxes,'YLim',ylim_new)
0264             %test whther zoom out is operating (to inactivate AxedAta
0265             if ~isfield(AxeData,'CurrentXLim')| ~isequal(xlim,AxeData.CurrentXLim)
0266                 AxeData.CurrentXLim=xlim;%
0267             end
0268             if isfield(AxeData,'ParentRect')% update the position of the parent rectangle represneting the field
0269                 hparentrect=AxeData.ParentRect;
0270                 xlim=get(currentaxes,'XLim');
0271                 ylim=get(currentaxes,'YLim');
0272                 rect([1 2])=[xlim(1) ylim(1)];
0273                 rect([3 4])=[xlim(2)-xlim(1) ylim(2)-ylim(1)];
0274                 set(hparentrect,'Position',rect)
0275             end
0276       end
0277 end
0278 
0279 %display the data of the current object selected with the mouse right click
0280 if isequal(get(currentfig,'SelectionType'),'alt') && ~zoomstate && (~isfield(AxeData,'Drawing')||~isequal(AxeData.Drawing,'create'))
0281     hother=findobj('Tag','proj_object');%find all the proj objects
0282     nbselect=0;
0283     %test the existence of selected objects:
0284     for iproj=1:length(hother);
0285         iselect=isequal(get(hother(iproj),'Selected'),'on');%reset all the proj objects in 'blue' by default
0286         nbselect=nbselect+iselect;
0287     end
0288     hother=findobj('Tag','proj_object','Type','line');%find all the proj objects
0289     set(hother,'Color','b');%reset all the proj objects in 'blue' by default
0290     set(hother,'Selected','off')
0291     hother=findobj('Tag','proj_object','Type','rectangle');
0292     set(hother,'EdgeColor','b');
0293     set(hother,'Selected','off')
0294     hother=findobj('Tag','proj_object','Type','patch');
0295     set(hother,'FaceColor','b');   
0296     if isequal(get(gco,'Type'),'image')
0297         currentobj=get(gco,'parent');%parent axes of the image
0298     else 
0299         currentobj=gco;%default
0300     end
0301     if ((nbselect==0) && isequal(get(currentobj,'Type'),'axes')) || isequal(currentobj,huvmat)
0302         global CurData
0303         CurData=get(currentobj,'UserData');
0304         %plot_text(CurData)
0305         %get_field([],CurData);
0306         evalin('base','global CurData')%make CurData global in the workspace
0307         objtype=get(currentobj,'Type');
0308         display(['UserData of ' objtype ':'])
0309         evalin('base','CurData') %display CurData in the workspace
0310         commandwindow
0311     end
0312 end
0313 if test_drawing==0
0314         AxeData.Drawing='off';%stop current drawing action
0315 end
0316 set(currentaxes,'UserData',AxeData);
0317 if ~isempty(huvmat)
0318     set(huvmat,'UserData',UvData);
0319 end
0320 
0321     
0322

Generated on Fri 13-Nov-2009 11:17:03 by m2html © 2003