source: trunk/src/mouse_up.m @ 12

Last change on this file since 12 was 12, checked in by gostiaux, 14 years ago

The files from uvmat.2.2.beta that differed from the current version have been updated.
Now the /raid/soft/UVMAT/src should be operational

File size: 16.0 KB
RevLine 
[11]1%'mouse_up': function  activated when the mouse button is released
2%----------------------------------------------------------------
3% function mouse_up(ggg,eventdata,handles)
4% activated by the command:
5% set(hObject,'WindowButtonUpFcn',{'mouse_up'}),
6% where hObject is the handle of the figure
7%
8%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
9%  Copyright Joel Sommeria, 2008, LEGI / CNRS-UJF-INPG, sommeria@coriolis-legi.org.
10%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
11%     This file is part of the toolbox UVMAT.
12%
13%     UVMAT is free software; you can redistribute it and/or modify
14%     it under the terms of the GNU General Public License as published by
15%     the Free Software Foundation; either version 2 of the License, or
16%     (at your option) any later version.
17%
18%     UVMAT is distributed in the hope that it will be useful,
19%     but WITHOUT ANY WARRANTY; without even the implied warranty of
20%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21%     GNU General Public License (file UVMAT/COPYING.txt) for more details.
22%AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
23
24function mouse_up(ggg,eventdata,handles)
25MouseAction='none'; %default
26zoomstate=0;%default
27if ~exist('handles','var')
28   handles=get(gcbo,'UserData');
29end
30huvmat=findobj(allchild(0),'Name','uvmat');%find the uvmat interface handle
31if ~isempty(huvmat)
32    hhuvmat=guidata(huvmat);
33    UvData=get(huvmat,'UserData');
34    if isfield(UvData,'MouseAction')
35        MouseAction=UvData.MouseAction;% set the mouse action (edit, create objects...)
36    end
37    zoomstate=get(hhuvmat.zoom,'Value');
38end
39if isequal(MouseAction,'calib') && ~zoomstate
40    return
41end
42currentfig=gcbo;
43AxeData=get(gca,'UserData');
44currentaxes=gca; %store the current axes handle
45test_drawing=0;%default
46
47%finalize the fabrication or the translation/deformation of an object and plot the corresponding projected field
48if ~isempty(huvmat) & isfield(AxeData,'Drawing') & ~isequal(AxeData.Drawing,'off') & isfield(AxeData,'CurrentObject')...
49           & ishandle(AxeData.CurrentObject)
50    xy=get(currentaxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
51    PlotData=get(AxeData.CurrentObject,'UserData');%get data attached to the current projection object 
52    IndexObj=PlotData.IndexObj;
53    ObjectData=UvData.Object{IndexObj};   
54    if isequal(AxeData.Drawing,'translate')
55        XYData=AxeData.CurrentOrigin;
56        DX=xy(1,1)-XYData(1);%translation from initial position
57        DY=xy(1,2)-XYData(2);
58        ObjectData.Coord(:,1)=ObjectData.Coord(:,1)+DX;
59        ObjectData.Coord(:,2)=ObjectData.Coord(:,2)+DY;
60    elseif isequal(AxeData.Drawing,'deform')
61        ind_move=AxeData.CurrentIndex;
62        ObjectData.Coord(ind_move,1)=xy(1,1);
63        ObjectData.Coord(ind_move,2)=xy(1,2);
64    else   %creating object
65        if isequal(ObjectData.Style,'line')||isequal(ObjectData.Style,'polyline')||...
66                isequal(ObjectData.Style,'polygon')||isequal(ObjectData.Style,'points')
67            if isfield(AxeData,'ObjectCoord') && size(AxeData.ObjectCoord,2)==3
68              xy(1,3)=AxeData.ObjectCoord(1,3); % z coordinate of the mouse: to generalise ...
69            else
70                 xy(1,3)=0; % z coordinate set to 0 by default
71            end
72            if ~isequal(ObjectData.Coord,xy(1,:))
73                ObjectData.Coord=[ObjectData.Coord ;xy(1,:)];% append the coordiantes marked by the mouse to the eobject
74            end
75        elseif isequal(ObjectData.Style,'rectangle')||isequal(ObjectData.Style,'ellipse')||isequal(ObjectData.Style,'volume')
76            XYData=AxeData.CurrentOrigin;
77            ObjectData.Coord(1,1)=(xy(1,1)+XYData(1))/2;%origin rectangle, x coordinate
78            ObjectData.Coord(1,2)=(xy(1,2)+XYData(2))/2;
79            ObjectData.RangeX=abs(xy(1,1)-XYData(1))/2;%rectangle width
80            ObjectData.RangeY=abs(xy(1,2)-XYData(2))/2;%rectangle height
81        elseif isequal(ObjectData.Style,'plane') %case of 'plane'
82            DX=(xy(1,1)-ObjectData.Coord(1,1));
83            DY=(xy(1,2)-ObjectData.Coord(1,2));
84            ObjectData.Phi=(angle(DX+i*DY))*180/pi;%rectangle widt
85            if isfield(ObjectData,'RangeX')
86                XMax=sqrt(DX*DX+DY*DY);
87                if XMax>max(ObjectData.RangeX)
88                    ObjectData.RangeX=[min(ObjectData.RangeX) XMax];
89                end
90            end
91        end
92    end
93    %set(AxeData.CurrentObject,'UserData',ObjectData); %update the object properties
94    if isequal(ObjectData.Style,'rectangle')||isequal(ObjectData.Style,'ellipse')
95        NbDefPoint=1; 
96    elseif isequal(ObjectData.Style,'line')|| isequal(ObjectData.Style,'plane');
97        NbDefPoint=2;
98    else
99         NbDefPoint=3;
100    end
101   
102    %show object coordinates in the GUI set_object
103    h_set_object=findobj(allchild(0),'Name','set_object');
104    h_XObject=findobj(h_set_object,'Tag','XObject');
105    h_YObject=findobj(h_set_object,'Tag','YObject');
106    h_ZObject=findobj(h_set_object,'Tag','ZObject');
107    set(h_XObject,'String',num2str(ObjectData.Coord(:,1),4));
108    set(h_YObject,'String',num2str(ObjectData.Coord(:,2),4));
109    set(h_ZObject,'String',num2str(ObjectData.Coord(:,3),4));
110    if NbDefPoint<=2 || isequal(get(currentfig,'SelectionType'),'alt') ||...
111              isequal(AxeData.Drawing,'translate') || isequal(AxeData.Drawing,'deform');%stop drawing
112        AxeData.CurrentOrigin=[]; %suppress the current origin
113       if isequal(ObjectData.Style,'line') && size(ObjectData.Coord,1)<=1
114           AxeData.Drawing='off';
115           set(currentaxes,'UserData',AxeData);
116            return % line needs at leqst two points
117       end
118       if  ~isempty(ObjectData)
119             testmask=0;
120             hmask=findobj(huvmat,'Tag','makemask');
121             if ~isempty(hmask)
122                testmask=get(hmask,'Value');
123             end
124             if testmask
125                 PlotHandles=[];%do not project data on the object during mask creation
126             else
127                 PlotHandles=get_plot_handles(handles);%get the handles of the graphic objects setting the plotting parameters
128             end
129            AxeData.hset_object=set_object(ObjectData,PlotHandles);% call the set_object interface ,*
130            UvData.Object{IndexObj}=update_obj(UvData,IndexObj,ObjectData,PlotHandles);
131            %ObjectData=update_obj(UvData,IndexObj,ObjectData,PlotHandles);
132            if  isfield(UvData.Object{IndexObj},'PlotParam')
133                write_plot_param(PlotHandles,UvData.Object{IndexObj}.PlotParam); %update the display of plotting parameters for the current object
134            end             
135            set(hhuvmat.create,'Value',0);% set to 'off' the button for object creation
136            set(hhuvmat.create,'BackgroundColor',[0 1 0]);% paint the creation button in green
137            set(hhuvmat.edit,'BackgroundColor',[1 1 0]);% paint the edit text in yellow
138            set(hhuvmat.edit,'Value',1);%
139            set(hhuvmat.edit,'Enable','on');%
140            set(hhuvmat.MenuEdit,'Enable','on');%
141            set(hhuvmat.MenuEdit,'Enable','on');%
142            set(hhuvmat.MenuObject,'Enable','on');%
143            UvData.MouseAction='edit_object'; % set the edit button to 'on'
144        end
145    else
146       AxeData.CurrentOrigin=[xy(1,1) xy(1,2)]; %the current point becomes the new current origin
147       test_drawing=1;%allow continuation of drawing object
148       UvData.Object{IndexObj}=ObjectData;
149    end
150    hother=findobj('Tag','deformpoint');%find all the deformpoints
151    set(hother,'Color','b');%reset all the deformpoints in 'blue'
152else
153    test_drawing=0;
154end
155
156%creation of a new zoom plot
157test_replot=0;
158if isequal(get(currentfig,'SelectionType'),'normal');%if left button has been pressed
159%         FigData=get(currentfig,'UserData');
160        hparentfig=currentfig;
161        %open or update a new zoom figure if a rectangle has been drawn
162        if ishandle(currentaxes);
163            if isfield(AxeData,'CurrentRectZoom') & ishandle(AxeData.CurrentRectZoom)
164                PosRect=get(AxeData.CurrentRectZoom,'Position');
165                if isfield(AxeData,'CurrentVec') & ishandle(AxeData.CurrentVec)
166                    delete(AxeData.CurrentVec)
167                end
168                %update the axes UvData.Plane2 if it exists, else create it
169%                 if isfield (UvData,'Plane2') & ishandle(UvData.Plane2.Fig)%if the second plan plotting axis already exists
170%                     hfig2=UvData.Plane2.Fig;
171%                     if isequal(gcf,hfig2)%if we are already on the secondary figure
172%                         test_replot=1;
173%                     else
174%                         figure(hfig2)%set hfig2 as the current figure
175%                         clf; %erase axes
176%                     end
177%                 else
178                    hfig2=figure;%create new figure
179                    set(hfig2,'name','zoom')
180                    set(hfig2,'Units','normalized')
181                    set(hfig2,'Position',[0.2 0.33 0.6 0.6]);
182%                     UvData.Plane2.Fig=hfig2;
183                    map=colormap(currentaxes);
184                    colormap(map);%transmit the current colormap to the zoom fig
185                    get(handles.RootFile,'String')
186%                 end
187                set(hfig2,'Position',[0.2 0.33 0.6 0.6]);
188                if test_replot==0
189                    set(hfig2,'Unit','normalized')
190                    set(hfig2,'KeyPressFcn',{@keyboard_callback,handles})%set keyboard action function
191                    set(hfig2,'WindowButtonMotionFcn',{@mouse_motion,handles})%set mouse action function
192                    set(hfig2,'WindowButtonDownFcn',{@mouse_down})%set mouse click action function
193                    set(hfig2,'WindowButtonUpFcn',{@mouse_up,handles}) 
194                    set(hfig2,'DeleteFcn',{@close_fig,AxeData.CurrentRectZoom,'zoom'})
195                    set(hfig2,'UserData',AxeData.CurrentRectZoom)% record the parent object (zoom rectangle) in the new fig
[12]196                    %UvData.Plane2.Axes=copyobj(currentaxes,hfig2); %copy the current graph axes to the zoom figure 
[11]197                    AxeData.ZoomAxes=copyobj(currentaxes,hfig2); %copy the current graph axes to the zoom figure
198                    figure(hfig2)
199                    set(AxeData.ZoomAxes,'Position',[0.1300    0.1100    0.7750    0.8150])% standard axes position on a figure
200                    hcol=findobj(hparentfig,'Tag','Colorbar'); %look for colorbar axes
201                    if ~isempty(hcol)             
202                        hcol_new=colorbar;
203                        YTick=get(hcol,'YTick');
204                        YTicklabel=get(hcol,'Yticklabel'); 
205                        colbarlim=get(hcol,'YLim');
206                        newcolbarlim=get(hcol_new,'YLim');
207                        scale_bar=(newcolbarlim(2)-newcolbarlim(1))/(colbarlim(2)-colbarlim(1));               
208                        YTick_rescaled=newcolbarlim(1)+scale_bar*(YTick-colbarlim(1));
209                        set(hcol_new,'YTick',YTick_rescaled);
210                        set(hcol_new,'Yticklabel',YTicklabel);
211                    end
212                end
213                if ishandle(AxeData.ZoomAxes)
214                    hnew_rect=findobj(AxeData.ZoomAxes,'Tag','rect_zoom');
215                    if ~isempty(hnew_rect)
216                        delete(hnew_rect);
217                        ChildAxeData=get(AxeData.ZoomAxes,'UserData');
218                        ChildAxeData.CurrentRectZoom=[]; % no rect zoom in the new window
219                        ChildAxeData.Drawing='off';
220                        ChildAxeData.ParentRect=AxeData.CurrentRectZoom;%set the rectangle as a 'parent' associated to the new axes
221                        set(AxeData.ZoomAxes,'UserData',ChildAxeData);%update the AxeData of the new axes
222                       % UvData.TopFig=hfig2;%put the new fig to the top of the stack for uvmat
223        %                 set(huvmat,'UserData',UvData)
224                        set(AxeData.ZoomAxes,'Xlim',[PosRect(1) PosRect(1)+PosRect(3)])
225                        set(AxeData.ZoomAxes,'Ylim',[PosRect(2) PosRect(2)+PosRect(4)])
226                    end
227                end
228            end
229        end
230end
231%zoom in if no new figure is created
232if zoomstate
233     if  isequal(get(currentfig,'SelectionType'),'normal');%if left button has been pressed
234        %zoom(2)% zoom in by a factor of 2
235        alpha=0.5; %zoom factor (zoom in by a factor 2)
236        xlim=get(currentaxes,'XLim');
237        xlim_new(1)=(1+alpha)*xlim(1)/2+(1-alpha)*xlim(2)/2;
238        xlim_new(2)=(1-alpha)*xlim(1)/2+(1+alpha)*xlim(2)/2;
239        set(currentaxes,'XLim',xlim_new)
240        ylim=get(currentaxes,'YLim');
241        ylim_new(1)=(1+alpha)*ylim(1)/2+(1-alpha)*ylim(2)/2;
242        ylim_new(2)=(1-alpha)*ylim(1)/2+(1+alpha)*ylim(2)/2;
243        set(currentaxes,'YLim',ylim_new)
244        if isfield(AxeData,'ParentRect')% update the position of the parent rectangle represneting the field
245            hparentrect=AxeData.ParentRect;
246            xlim=get(currentaxes,'XLim');
247            ylim=get(currentaxes,'YLim');
248            rect([1 2])=[xlim(1) ylim(1)];
249            rect([3 4])=[xlim(2)-xlim(1) ylim(2)-ylim(1)];
250            set(hparentrect,'Position',rect)
251        end
252
253     elseif isequal(get(currentfig,'SelectionType'),'alt'); %if right button has been pressed
254            %zoom(0.5)% zoom out by a factor of 2
255            alpha=2; %zoom factor (zoom out by a factor 2)
256            xlim=get(currentaxes,'XLim');
257            xlim_new(1)=(1+alpha)*xlim(1)/2+(1-alpha)*xlim(2)/2;
258            xlim_new(2)=(1-alpha)*xlim(1)/2+(1+alpha)*xlim(2)/2;
259            ylim=get(currentaxes,'YLim');
260            ylim_new(1)=(1+alpha)*ylim(1)/2+(1-alpha)*ylim(2)/2;
261            ylim_new(2)=(1-alpha)*ylim(1)/2+(1+alpha)*ylim(2)/2;
262            set(currentaxes,'XLim',xlim_new)
263            set(currentaxes,'YLim',ylim_new)
264            %test whther zoom out is operating (to inactivate AxedAta
265            if ~isfield(AxeData,'CurrentXLim')| ~isequal(xlim,AxeData.CurrentXLim)
266                AxeData.CurrentXLim=xlim;%
267            end
268            if isfield(AxeData,'ParentRect')% update the position of the parent rectangle represneting the field
269                hparentrect=AxeData.ParentRect;
270                xlim=get(currentaxes,'XLim');
271                ylim=get(currentaxes,'YLim');
272                rect([1 2])=[xlim(1) ylim(1)];
273                rect([3 4])=[xlim(2)-xlim(1) ylim(2)-ylim(1)];
274                set(hparentrect,'Position',rect)
275            end
276      end
277end
278
279%display the data of the current object selected with the mouse right click
280if isequal(get(currentfig,'SelectionType'),'alt') && ~zoomstate && (~isfield(AxeData,'Drawing')||~isequal(AxeData.Drawing,'create'))
281    hother=findobj('Tag','proj_object');%find all the proj objects
282    nbselect=0;
283    %test the existence of selected objects:
284    for iproj=1:length(hother);
285        iselect=isequal(get(hother(iproj),'Selected'),'on');%reset all the proj objects in 'blue' by default
286        nbselect=nbselect+iselect;
287    end
288    hother=findobj('Tag','proj_object','Type','line');%find all the proj objects
289    set(hother,'Color','b');%reset all the proj objects in 'blue' by default
290    set(hother,'Selected','off')
291    hother=findobj('Tag','proj_object','Type','rectangle');
292    set(hother,'EdgeColor','b');
293    set(hother,'Selected','off')
294    hother=findobj('Tag','proj_object','Type','patch');
295    set(hother,'FaceColor','b');   
296    if isequal(get(gco,'Type'),'image')
297        currentobj=get(gco,'parent');%parent axes of the image
298    else
299        currentobj=gco;%default
300    end
301    if ((nbselect==0) && isequal(get(currentobj,'Type'),'axes')) || isequal(currentobj,huvmat)
302        global CurData
303        CurData=get(currentobj,'UserData');
304        %plot_text(CurData)
305        %get_field([],CurData);
306        evalin('base','global CurData')%make CurData global in the workspace
307        objtype=get(currentobj,'Type');
308        display(['UserData of ' objtype ':'])
309        evalin('base','CurData') %display CurData in the workspace
310        commandwindow
311    end
312end
313if test_drawing==0
314        AxeData.Drawing='off';%stop current drawing action
315end
316set(currentaxes,'UserData',AxeData);
317if ~isempty(huvmat)
318    set(huvmat,'UserData',UvData);
319end
320
321   
322
Note: See TracBrowser for help on using the repository browser.