source: trunk/src/mouse_down.m @ 46

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

various bug fixes

File size: 16.2 KB
Line 
1%'mouse_down': function activated when the mouse button is pressed on a figure (callback for 'WindowButtonDownFcn'
2%--------------------------------------------------------------
3% xy=mouse_down(hObject,eventdata)
4% activated by the command:
5% set(hObject,'WindowButtonDownFcn',{'mouse_down'}),
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 xy=mouse_down(hObject,eventdata)
25testzoom=0;%default
26MouseAction='none'; %default
27huvmat=findobj(allchild(0),'Name','uvmat');%find the uvmat interface handle which controls theoption of  mouse action
28if ~isempty(huvmat)
29    hhuvmat=guidata(huvmat);%handles of elements in uvmat
30    UvData=get(huvmat,'UserData');
31    testzoom=get(hhuvmat.zoom,'Value');% get the mouse action from the uvmat GUI: options:
32    if isfield(UvData,'MouseAction')
33        MouseAction=UvData.MouseAction;% get the mouse action from the uvmat GUI: options:
34    end
35end
36test_create=~testzoom && (isequal(MouseAction,'create_object') || isequal(MouseAction,'create_mask'));
37%test_cal=get(handles.cal,'Value');
38test_cal=isequal(MouseAction,'calib');
39menu_coord=get(hhuvmat.transform_fct,'String');
40coord_choice=get(hhuvmat.transform_fct,'Value');
41coord_type=menu_coord{coord_choice};
42test_edit=isequal(MouseAction,'edit_object');
43test_edit_vect=isequal(MouseAction,'edit_vect');
44xdisplay=[];%default
45ydisplay=[];%default
46haxes=[];
47AxeData=[];%default
48
49%edit an existing point or line if found
50hcurrentobject=gco;% current object handle (selected by the mouse)
51hcurrentfig=gcbo;% current figure handle
52tag_obj=get(gco,'Tag');
53xy=[];%default
54xy_fig=get(hcurrentfig,'CurrentPoint');% current point of the current figure (gcbo)
55hchild=get(hcurrentfig,'Children');%handles of all objects in the current figure
56% loop on all the objects in the current figure (selected by the last mouse click)
57for ichild=1:length(hchild)
58    obj_pos=get(hchild(ichild),'Position');%position of the object
59    if xy_fig(1) >=obj_pos(1) & xy_fig(2) >= obj_pos(2)& xy_fig(1) <=obj_pos(1)+obj_pos(3) & xy_fig(2) <= obj_pos(2)+obj_pos(4);
60        htype=get(hchild(ichild),'Type');%type of object child of the current figure
61        %if the mouse is over an axis, look at the data
62        if isequal(htype,'axes')
63            haxes=hchild(ichild);
64            xy=get(haxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
65            AxeData=get(haxes,'UserData');% data attached to the axis
66            AxeData.CurrentOrigin=[xy(1,1) xy(1,2)];% The current point set by the mouse becomes the current origin
67            if ~isequal(tag_obj,'proj_object') & ~test_create
68                x_mouse=xy(1,1);%default
69                y_mouse=xy(1,2);%default
70                u_mouse=[];
71                v_mouse=[];
72                w_mouse=[];
73                A_mouse=[];
74                c_text=[];
75                f_text=[];
76                ff_text=[];     
77                ivec=[];   
78                if isfield(AxeData,'X') & isfield(AxeData,'Y') & isfield(AxeData,'Mesh')% test on the existence of a vector field in the current axis
79                    flag_vec=(AxeData.X<(xy(1,1)+AxeData.Mesh/4) & AxeData.X>(xy(1,1)-AxeData.Mesh/4)) & ...%flagx=1 for the vectors with x position selected by the mouse
80                      (AxeData.Y<(xy(1,2)+AxeData.Mesh/4) & AxeData.Y>(xy(1,2)-AxeData.Mesh/4));%f
81                    ivec=find(flag_vec);% search the selected vector index ivec
82                    if length(ivec)>0
83                        ivec=ivec(1);%choice the first selected vector if several are selected                       
84                    end
85                end
86            end
87        elseif isequal(get(hchild(ichild),'Visible'),'on')& ~isequal(get(hchild(ichild),'Style'),'frame')
88           %FAIRE UNE OPTION D'AIDE AVEC BOUTON SOURIS DROIT (ALT)??
89        end
90    end
91end
92test2D=0;
93if isfield(AxeData,'NbDim')
94    if isequal(AxeData.NbDim,2)
95        test2D=1;
96    end
97end
98if ~test2D     %desable  object creation and vector editing if NbDim different from 2
99    test_create=0;
100    test_edit_vect=0;
101end
102%delete the current zoom rectangle
103if isfield(AxeData,'CurrentRectZoom') & ishandle(AxeData.CurrentRectZoom)
104    delete(AxeData.CurrentRectZoom)
105    AxeData.CurrentRectZoom=[];
106end   
107
108if testzoom %&& ~test_create && ~test_edit && ~test_edit_vect && exist('xy','var')
109     AxeData.Drawing='zoom'; %initiate drawing mode
110     AxeData.CurrentObject=[];%unselect objects
111elseif ~isempty(huvmat)
112    %selection of an existing projection object
113    if  test_edit && (isequal(tag_obj,'proj_object')||isequal(tag_obj,'DeformPoint'))
114        if ~(isfield(AxeData,'Drawing') && isequal(AxeData.Drawing,'create'))
115            userdata=get(hcurrentobject,'UserData');
116            if ishandle(userdata)%the selected line depends on a parent line
117                AxeData.CurrentObject=userdata;% the parent object becomes the current one
118            else
119                AxeData.CurrentObject=hcurrentobject;% the selected object becomes the current one
120            end
121            ObjectData=get(AxeData.CurrentObject,'UserData');
122            if test_edit & isfield(ObjectData,'IndexObj')
123                hother=findobj('Tag','proj_object','Type','line');%find all the proj objects
124                set(hother,'Color','b');%reset all the proj objects in 'blue' by default
125                set(hother,'Selected','off')
126                hother=findobj('Tag','proj_object','Type','rectangle');
127                set(hother,'EdgeColor','b');
128                set(hother,'Selected','off');
129                hother=findobj('Tag','proj_object','Type','image');
130                for iobj=1:length(hother)
131                       Acolor=get(hother(iobj),'CData');
132                       Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2));
133                       set(hother(iobj),'CData',Acolor);
134                end
135                hother=findobj('Tag','DeformPoint');
136                set(hother,'Color','b');
137                set(hother,'Selected','off')   
138                if isequal(get(AxeData.CurrentObject,'Type'),'line')
139                    set(AxeData.CurrentObject,'Color','m'); %set the selected object to magenta color
140                elseif isequal(get(AxeData.CurrentObject,'Type'),'rectangle')
141                     set(AxeData.CurrentObject,'EdgeColor','m'); %set the selected object to magenta color
142                end
143                if isfield(ObjectData,'SubObject')& ishandle(ObjectData.SubObject)
144                    for iobj=1:length(ObjectData.SubObject)
145                        hsub=ObjectData.SubObject(iobj);
146                        if isequal(get(hsub,'Type'),'rectangle')
147                            set(hsub,'EdgeColor','m'); %set the selected object to magenta color
148                        elseif isequal(get(hsub,'Type'),'image')
149                           Acolor=get(hsub,'CData');
150                           Acolor(:,:,1)=Acolor(:,:,3);
151                           set(hsub,'CData',Acolor);
152                        else
153                            set(hsub,'Color','m')
154                        end
155                    end
156                end
157                if isequal(tag_obj,'DeformPoint')
158                     set(hcurrentobject,'Color','m'); %set the selected DeformPoint to magenta color
159                end
160                IndexObj=ObjectData.IndexObj;
161                hlist_object=findobj(huvmat,'Tag','list_object');
162                set(hlist_object,'Value',IndexObj);
163                testdeform=0;
164                set(gcbo,'Pointer','circle');
165                AxeData.Drawing='deform';
166                if isequal(tag_obj,'DeformPoint')       
167                   if isfield(ObjectData,'DeformPoint')
168                       set(hcurrentobject,'Selected','on')
169                       for ipt=1:length(ObjectData.DeformPoint)
170                           if isequal(ObjectData.DeformPoint(ipt),hcurrentobject)
171                                AxeData.CurrentIndex=ipt;
172                                testdeform=1;
173                           end
174                       end
175                   end
176                end
177                if testdeform==0
178                    AxeData.Drawing='translate';
179                    set(AxeData.CurrentObject,'Selected','on')
180                    set(gcbo,'Pointer','fleur');
181                end
182            end
183        end
184    end
185    %  create new projection  object
186    if  test_create && ~isempty(xy) && ~(isfield(AxeData,'Drawing')&& isequal(AxeData.Drawing,'create'))
187            ObjectData=read_set_object(UvData.sethandles);
188            ObjectData.Coord=[]; %reset previous object coordinates
189            ObjectData.Coord(1,1)=xy(1,1);
190            ObjectData.Coord(1,2)=xy(1,2);
191            ObjectData.Coord(1,3)=0;
192            if isfield(AxeData,'ObjectCoord') & size(AxeData.ObjectCoord,2)==3
193                 ObjectData.Coord(1,3)=AxeData.ObjectCoord(1,3); %generaliser au cas avec angle
194            end
195            AxeData.CurrentObject=plot_object(ObjectData,[],haxes,'m');%draw the object and its handle becomes AxeData.CurrentObject
196            if isfield(UvData,'Object')
197                IndexObj=length(UvData.Object)+1;% add the object as index IndexObj on the list of the interface
198            else
199                IndexObj=2;
200            end 
201            UvData.Object{IndexObj}=ObjectData;
202            UvData.Object{IndexObj}.HandlesDisplay(1)=AxeData.CurrentObject;
203            set(huvmat,'UserData',UvData)
204            list_str=get(hhuvmat.list_object,'String');
205            list_str{IndexObj}=[num2str(IndexObj) '-' ObjectData.Style];
206            if ~isequal(list_str{end},'...')
207                 list_str{end+1}='...';
208            end
209            set(hhuvmat.list_object,'String',list_str)
210            set(hhuvmat.list_object,'Value',IndexObj)
211            PlotData=get(AxeData.CurrentObject,'UserData');
212            PlotData.IndexObj=IndexObj;
213            set(AxeData.CurrentObject,'UserData',PlotData); %record the object index in the graph
214            AxeData.Drawing='create';
215    end
216
217    % create calibration points if the GUI geometry_calib is opened
218    if test_cal & ~isempty(xy)
219        h_geometry_calib=findobj(allchild(0),'Name','geometry_calib'); %find the geomterty_calib GUI
220        hh_geometry_calib=guidata(h_geometry_calib);
221        h_ListCoord=hh_geometry_calib.ListCoord; %findobj(h_geometry_calib,'Tag','ListCoord');
222        h_edit_append=hh_geometry_calib.edit_append;%findobj(h_geometry_calib,'Tag','edit_append');
223        if isequal(get(h_edit_append,'Value'),1)
224            if ~isequal(coord_type,'')
225                set(handles_coord,'Value',1)
226                coord_type='';
227                set(hhuvmat.FixedLimits,'Value',0)% put FixedLimits option to 'off'
228                set(hhuvmat.FixedLimits,'BackgroundColor',[0.7 0.7 0.7])
229                uvmat('run0_Callback',hObject,eventdata,hhuvmat); %file input with xml reading  in uvmat
230            end
231%             if isequal(coord_type,'px')|isequal(coord_type,'');%px cordinates
232                strline=[ '    |    '  '    |    '  '    |    ' num2str(xy(1,1),4) '    |    ' num2str(xy(1,2),4)];
233%             else %phys cordinates
234%                 strline=[ num2str(xy(1,1),4) '    |    '  num2str(xy(1,2),4) '    |    0      |    '  '    |    ' ];
235%             end
236            Coord=get(h_ListCoord,'String');
237            val=get(h_ListCoord,'Value');
238            if isequal(Coord,{''})
239                val=0;
240            end
241            if length(Coord)>val
242                Coord(val+2:length(Coord)+1)=Coord(val+1:length(Coord));% push the list forward beyond the current point
243            end
244            Coord{val+1}=strline;
245            set(h_ListCoord,'String',Coord)
246            set(h_ListCoord,'Value',val+1)
247            geometry_calib('ListCoord_Callback',hObject,eventdata,hh_geometry_calib)
248            data=read_geometry_calib(Coord);
249            if isequal(coord_type,'px')|isequal(coord_type,'');%px cordinates
250                XCoord=data.Coord(:,4);
251                YCoord=data.Coord(:,5);
252            else %phys cordinates
253                XCoord=data.Coord(:,1);
254                YCoord=data.Coord(:,2);
255            end
256            hh=findobj('Tag','calib_points');           
257            if isempty(hh)
258                line(XCoord,YCoord,'Color','m','Tag','calib_points','LineStyle','.','Marker','+');
259            else
260                set(hh,'XData',XCoord)
261                set(hh,'YData',YCoord)
262            end
263            hhh=findobj('Tag','calib_marker');
264            if ~isempty(hhh)
265                set(hhh,'XData',xy(1,1))
266                set(hhh,'YData',xy(1,2))
267            else
268                line(xy(1,1),xy(1,2),'Color','m','Tag','calib_marker','LineStyle','.','Marker','o','MarkerSize',20);
269            end
270            %uistack(h_geometry_calib,'top')
271        end
272    end
273
274    % edit vectors
275    if test_edit_vect & ~isempty(ivec)
276    %     FF_100=FF-100*double(uint(abs(FF)/100); %value of FF without units and dizaines
277        if ~(isfield(AxeData,'FF')&& ~isempty(AxeData.FF))
278            AxeData.FF=zeros(size(AxeData.X));
279        end
280        if isequal(AxeData.FF(ivec),0)
281            AxeData.FF(ivec)=100; %mark vector #ivec as false
282        else
283            AxeData.FF(ivec)=0;
284        end
285        PlotParam=read_plot_param(hhuvmat);
286        [PlotType,ScalOut]= plot_field(AxeData,haxes,PlotParam,1);
287    end   
288end
289set(haxes,'UserData',AxeData);
290
291%------------------------------------------------------
292function update_plot(AxeData,haxes)
293%--------------------------------------------
294
295
296% %determine the axes of action of the set_edit interface
297% % haxes= findobj(huvmat,'Tag','axes3'); %main plotting axes as default
298% % AxeData=get(haxes,'UserData')
299% %For vector field representation
300% PlotHandles.auto_xy=findobj(huvmat,'Tag','auto_xy');
301% PlotHandles.VecScale=findobj(huvmat,'Tag','VecScale');
302% PlotHandles.AutoVec=findobj(huvmat,'Tag','AutoVec');
303% PlotHandles.checkyellow=findobj(huvmat,'Tag','checkyellow');
304% PlotHandles.checkblack=findobj(huvmat,'Tag','checkblack');
305% PlotHandles.col_vec=findobj(huvmat,'Tag','col_vec');
306% PlotHandles.colcode1=findobj(huvmat,'Tag','colcode1');
307% PlotHandles.colcode2=findobj(huvmat,'Tag','colcode2');
308% PlotHandles.vec_col_bar=findobj(huvmat,'Tag','vec_col_bar');
309% PlotHandles.slider1=findobj(huvmat,'Tag','slider1');
310% PlotHandles.slider2=findobj(huvmat,'Tag','slider2');
311% PlotHandles.max_vec=findobj(huvmat,'Tag','max_vec');
312% PlotHandles.min_vec=findobj(huvmat,'Tag','min_vec');
313% PlotHandles.AutoVecColor=findobj(huvmat,'Tag','AutoVecColor');
314% PlotHandles.decimate4=findobj(huvmat,'Tag','decimate4');
315%
316% %vectors
317% Vectors.VecScale=str2num(get(PlotHandles.VecScale,'String'));
318% Vectors.AutoVec=get(PlotHandles.AutoVec,'Value');%automatic vector length
319% Vectors.checkyellow=get(PlotHandles.checkyellow,'Value');
320% Vectors.checkblack=get(PlotHandles.checkblack,'Value');
321% Vectors.decimate4=get(PlotHandles.decimate4,'Value');% =1; for reducing the nbre of vectors
322% menu_col=get(PlotHandles.col_vec,'String');
323% menu_val=get(PlotHandles.col_vec,'Value');
324% Vectors.CName=menu_col{menu_val}; %'ima_cor','black','white',...
325% Vectors.colcode1=str2num(get(PlotHandles.colcode1,'String'));% first threshold for rgb, first value for'continuous'
326% Vectors.colcode2=str2num(get(PlotHandles.colcode2,'String'));% second threshold for rgb, last value (saturation) for 'continuous'
327% Vectors.option=get(PlotHandles.vec_col_bar,'Value'); % =1 (64 colors), =0 (3 colors)
328% Vectors.min=get(PlotHandles.slider1,'Min');
329% Vectors.max=get(PlotHandles.slider1,'Max');
330% Vectors.auto=get(PlotHandles.AutoVecColor,'Value');% =1; thresholds scaling relative to min and max, =0 fixed thresholds
331% PlotParam.Vectors=Vectors;
332
Note: See TracBrowser for help on using the repository browser.