source: trunk/src/mouse_down.m @ 67

Last change on this file since 67 was 67, checked in by sommeria, 11 years ago

civ: RUN civ lounched out of the Matlab work space. RUN and BATCH now runned by a unique sub-function lounch.m.
FiLE PARAM.xml modified to provide different paths for Batch and Run !!!!!
RUN_FIX: minor error message modif
geometry_calib: calib point editing by the mouse
improvement of the interactions between the different GUIs. Close function...

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