source: trunk/src/mouse_down.m @ 688

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

mouse action improved for translations, use of magenta color to indicate that REFRESH is needed

File size: 24.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
26%% look for parameters set by the current figure (handle=input parameter hObject)
27AxeData=[];%default data stored on the current axes
28FigData=get(hObject,'UserData'); %default data stored on the current object
29if ishandle(FigData)% case of a zoom plot, the handle of the parent rectangle is stored in UserData, its parent is the plotting axes of the rectangle
30    hCurrentGUI=get(get(FigData,'parent'),'parent');%handle of the current GUI: zoom plot
31else
32    hCurrentGUI=hObject; % handle of the current GUI: usual plot
33end
34hhCurrentGUI=guidata(hCurrentGUI);% tags of the children of the current GUI
35CheckZoom=0;
36if isfield(hhCurrentGUI,'CheckZoom') && get(hhCurrentGUI.CheckZoom,'Value');%test for zoom action, first priority
37    CheckZoom=1;
38end
39test_piv=isfield(FigData,'CivHandle');
40set(hCurrentGUI,'Units','pixels')
41GUI_pos=get(hCurrentGUI,'Position');%position of the GUI series on the screen (in pixels), used to position message boxes
42set(hCurrentGUI,'Units','normalized')% back to current unit for fig position
43
44%% determine the currently selected items
45hcurrentobject=gco;% current object handle (selected by the mouse)
46CurrentGUI_tag=get(hCurrentGUI,'Tag');
47obj_tag=get(gco,'Tag');%tag of the currently selected object
48xy=[];%default
49xy_fig=get(hObject,'CurrentPoint');% current point of the current figure (gcbo)
50haxes=[];
51
52%% look for parameters set by the GUI uvmat
53test_ruler=0;
54test_edit=0;
55test_create=0;
56huvmat=findobj(allchild(0),'tag','uvmat');%find the uvmat interface handle which controls the option of  mouse action
57if ~isempty(huvmat)
58    hhuvmat=guidata(huvmat);%handles of elements in uvmat
59    UvData=get(huvmat,'UserData');
60    test_ruler=isequal(get(hhuvmat.MenuRuler,'checked'),'on');%test for ruler  action, second priority;
61    test_edit=get(hhuvmat.CheckEditObject,'Value');%&& (isequal(obj_tag,'proj_object')||isequal(obj_tag,'DeformPoint'));%test for object editing, third priority
62    hset_object=findobj(allchild(0),'Name','set_object');
63    if ~isempty(hset_object)
64        hPLOT=findobj(hset_object,'tag','REFRESH');
65        test_create=strcmp(get(hPLOT,'enable'),'on') &&~get(hhuvmat.CheckEditObject,'Value');% create new object if set_object is in mode enable and uvmat not in mode 'EditObject'
66    end
67    test_edit_vect=get(hhuvmat.edit_vect,'Value') && ~test_create && ~(isequal(obj_tag,'proj_object')||isequal(obj_tag,'DeformPoint')) ;%test for vector editing,  priority 4
68    test_cal=isequal(get(hhuvmat.MenuCalib,'checked'),'on');% test for calibration
69    if test_cal% test for calibration popints,  priority 6
70        h_calib=findobj(allchild(0),'tag','geometry_calib');
71        if isempty(h_calib)
72            test_cal=0;
73            set(hhuvmat.MenuCalib,'checked','off');% test for calibration off
74        else
75            hh_calib=guidata(h_calib);
76            test_cal=get(hh_calib.CheckEnableMouse,'Value');
77        end
78    end
79end
80
81%% loop on all the objects in the current figure (selected by the last mouse click)
82hchildren=get(hObject,'Children');%handles of all objects in the current figure
83check_visible=strcmp(get(hchildren,'Visible'),'on')& ~strcmp(get(hchildren,'Type'),'uimenu');% if visible='on', =0 otherwise
84hchildren=hchildren(check_visible); %keep only the visible children
85set(hchildren,'Units','normalized');
86PosChildren=get(hchildren,'Position');% set of object positions
87if iscell(PosChildren)% only one child
88    PosLength=cellfun('length',PosChildren);% set of vector lengths for object positions
89    hchildren=hchildren(PosLength==4);% keep only objects with position defined by a 4 element vector
90    PosChildren=cell2mat(PosChildren(PosLength==4));% convert cells to matrix of positions
91end
92if size(PosChildren,2)~=4
93    return
94end
95xy_fig_mat=ones(size(PosChildren,1),1)*xy_fig;% mouse position set to a matrix
96check_pos=xy_fig_mat >= PosChildren(:,1:2) & xy_fig_mat <= PosChildren(:,1:2)+PosChildren(:,3:4);% compare object to mouse position
97ind_object=find(check_pos(:,1) & check_pos(:,2),1);% select the index of the (first) object under the mouse
98hchild=hchildren(ind_object);% corresponding object handle
99htype='';
100if ~isempty(hchild)
101    htype=get(hchild,'Type');%type of object child of the current figure
102    switch htype
103        %if the mouse is over an axis, look at the data
104        case 'axes'
105            haxes=hchild;
106            xy=get(hchild,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
107            AxeData=get(hchild,'UserData');% data attached to the axis
108            AxeData.Enable='on';% unable current axes for mouse up action
109            AxeData.CurrentOrigin=xy(1,1:2);% The current point set by the mouse becomes the current origin
110           
111            if test_edit_vect
112                ivec=[];
113                FigData=get(hCurrentGUI,'UserData');
114                tagaxes=get(hchild,'tag');
115                if isfield(FigData,tagaxes)
116                    Field=FigData.(tagaxes);
117                    [CellInfo,NbDim,errormsg]=find_field_cells(Field);%analyse the physical fields contained in Field
118                    if isempty(errormsg)
119                    for icell=1:numel(CellInfo)%look for all physical fields
120                        if NbDim(icell)==2 % select 2D field
121                            if  isfield(Field,'CoordMesh') && ~isempty(Field.CoordMesh)&&...
122                                    ~isempty(CellInfo{icell}.VarIndex_coord_x) && ~isempty(CellInfo{icell}.VarIndex_coord_y)%case of unstructured data
123                                X=Field.(Field.ListVarName{CellInfo{icell}.VarIndex_coord_x});
124                                Y=Field.(Field.ListVarName{CellInfo{icell}.VarIndex_coord_y});
125                                flag_vec=(X<(xy(1,1)+Field.CoordMesh/4) & X>(xy(1,1)-Field.CoordMesh/4)) & ...%flagx=1 for the vectors with x position selected by the mouse
126                                    (Y<(xy(1,2)+Field.CoordMesh/4) & Y>(xy(1,2)-Field.CoordMesh/4));%f
127                                ivec=find(flag_vec,1);% search the (first) selected vector index ivec
128                            end
129                        end
130                    end
131                    end
132                end
133            end
134            set(hchild,'UserData',AxeData)
135            %if the mouse is over a uicontrol, with right mouse button activated, duplicate the display in an editable  zoom window
136        case 'uicontrol'
137            if isequal(get(hObject,'SelectionType'),'alt') %% && ~isequal(get(hchild,'tag'),'frame_object')
138                obj_pos=PosChildren(ind_object,:);
139                msg_pos(1:2)=GUI_pos(1:2)+obj_pos(1:2).*GUI_pos(3:4);
140                display_str=get(hchild,'TooltipString');
141                msgbox_uvmat(['uicontrol: ' get(hchild,'Tag')],display_str,get(hchild,'String'),msg_pos);
142                return %leave the function once a uicontrol has been selected
143            end
144           
145            %if the mouse is over a uipanel, look at the children of the uipanel
146        case 'uipanel'
147            if isequal(get(hObject,'SelectionType'),'alt')
148                panel_pos=PosChildren(ind_object,:);%position of the panel
149                hhchildren=get(hchild,'Children');%handles of all objects in the selected panel
150                check_visible=strcmp(get(hhchildren,'Visible'),'on');%=1 if visible='on', =0 otherwise
151                hhchildren=hhchildren(check_visible); %keep only the visible children               
152                PosChildren=get(hhchildren,'Position');
153                PosLength=cellfun('length',PosChildren);
154                hhchildren=hhchildren(PosLength==4);% keep only object with position defined by a 4 element vector
155                PosChildren=cell2mat(PosChildren(PosLength==4));% transform cell array to a matrix of positions
156                xy_panel=(xy_fig-panel_pos(1:2))./panel_pos(3:4);% mouse position relative to the panel
157                xy_panel_mat=ones(size(PosChildren,1),1)*xy_panel;% mouse position on the figure transformed to a matrix
158                check_pos=xy_panel_mat >= PosChildren(:,1:2) & xy_panel_mat <= PosChildren(:,1:2)+PosChildren(:,3:4);% compare object to mouse position
159                ind_object=find(check_pos(:,1) & check_pos(:,2),1);% select the index of the (first) object under the mouse
160                if ~isempty(ind_object)
161                    hhchild=hhchildren(ind_object);% corresponding object handle
162                    if strcmp(get(hhchild,'Type'),'uicontrol')
163                        msg_pos=GUI_pos(1:2)+panel_pos(1:2).*GUI_pos(3:4)+PosChildren(ind_object,1:2).*panel_pos(3:4).*GUI_pos(3:4);
164                        display_str=get(hhchild,'TooltipString');
165                        msgbox_uvmat(['uicontrol: ' get(hhchild,'Tag')],display_str,get(hhchild,'String'),msg_pos);
166                    end
167                end
168            end           
169    end
170end
171    if ~strcmp(htype,'axes')
172        currentaxes=get(hObject,'CurrentAxes');
173        if ~isempty(currentaxes)
174        AxeData=get(currentaxes,'UserData');% data attached to the axis
175        AxeData.Enable='off';% desactivate current axes for mouse up action
176        set(currentaxes,'UserData',AxeData);
177        end
178    end
179   
180%% zoom has first priority, stop here
181if CheckZoom
182    return
183end
184
185%% Creation of a display window zoom of text_display
186if strcmp(get(hObject,'SelectionType'),'alt') && strcmp(htype,'axes') && ~test_edit && ~test_create
187    set(0,'Unit','pixels')
188    GUISize=get(0,'ScreenSize');% get the size of the screen, to put the fig on the upper right   
189    Width=300;% fig width in points (1/72 inch)
190    Height=200;
191    Left=GUI_pos(1)+GUI_pos(3)-Width; %right edge close to the right, with margin=40
192    Bottom=GUI_pos(2)+GUI_pos(4)-Height; %put fig at top right
193    hfig_text=figure('Name','text_display','MenuBar','none','NumberTitle','off','Position',[Left,Bottom,Width,Height]);
194    AxeData.htext_display=uicontrol('Style','edit','Units','normalized', 'Position', [0.05 0.05 0.9 0.9],'Max',2,'BackgroundColor',[1 1 1],...
195        'FontUnits','points','FontSize',14);
196    set(hchild,'UserData',AxeData);
197    return %leave the function once a uicontrol has been selected
198end
199
200%% creation of a zoom subfig
201if isfield(hhCurrentGUI,'CheckZoomFig') && get(hhCurrentGUI.CheckZoomFig,'Value')
202    AxeData.Drawing='zoom'; %initiate drawing mode
203    AxeData.CurrentObject=[];%unselect objects
204    set(hchild,'UserData',AxeData);
205    return
206end
207
208if isempty(huvmat)%further options require the uvmat GUI
209    return
210end
211
212%% ruler has second priority
213if test_ruler && ~isempty(xy)
214    AxeData.RulerCoord(1,1:2)=xy(1,1:2);
215    AxeData.RulerHandle=line([xy(1,1) xy(1,1)],[xy(1,2) xy(1,2)],'Color','m','Tag','ruler');
216    AxeData.Drawing='ruler';
217    set(hchild,'UserData',AxeData);
218    return
219end
220
221%% PIV test
222if test_piv
223    figure
224    newaxes=axes;
225    copyobj(AxeData.CurrentCorrImage,newaxes);
226    set(newaxes,'CLim',[0 1])
227    copyobj(AxeData.CurrentVector,newaxes)
228    copyobj(AxeData.TitleHandle,newaxes)
229    colorbar
230end
231
232%% desable  object creation and vector editing if NbDim different from 2
233if ~(isfield(AxeData,'NbDim') && isequal(AxeData.NbDim,2))
234    test_create=0;
235    test_edit_vect=0;
236end
237
238%% selection of an existing projection object (third priority)
239if  test_edit
240    testdeform=0;
241    if ~(isfield(AxeData,'Drawing') && isequal(AxeData.Drawing,'create'))
242        userdata=get(hcurrentobject,'UserData');
243        if ishandle(userdata)%the selected line depends on a parent line
244            AxeData.CurrentObject=userdata;% the parent object becomes the current one
245        else
246            AxeData.CurrentObject=hcurrentobject;% the selected object becomes the current one
247        end
248        ObjectData=get(AxeData.CurrentObject,'UserData');
249        if isfield(ObjectData,'IndexObj')
250            hother=findobj('Tag','proj_object','Type','line');%find all the proj objects
251            set(hother,'Color','b');%reset all the proj objects in 'blue' by default
252            set(hother,'Selected','off')
253            hother=findobj('Tag','proj_object','Type','rectangle');
254            set(hother,'EdgeColor','b');
255            set(hother,'Selected','off');
256            hother=findobj('Tag','proj_object','Type','image');
257            for iobj=1:length(hother)
258                   Acolor=get(hother(iobj),'CData');
259                   Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2));
260                   set(hother(iobj),'CData',Acolor);
261            end
262            hother=findobj('Tag','DeformPoint');
263            set(hother,'Color','b');
264            set(hother,'Selected','off')   
265            if isequal(get(AxeData.CurrentObject,'Type'),'line')
266                set(AxeData.CurrentObject,'Color','m'); %set the selected object to magenta color
267            elseif isequal(get(AxeData.CurrentObject,'Type'),'rectangle')
268                 set(AxeData.CurrentObject,'EdgeColor','m'); %set the selected object to magenta color
269            end
270            if isfield(ObjectData,'SubObject')& ishandle(ObjectData.SubObject)
271                for iobj=1:length(ObjectData.SubObject)
272                    hsub=ObjectData.SubObject(iobj);
273                    if isequal(get(hsub,'Type'),'rectangle')
274                        set(hsub,'EdgeColor','m'); %set the selected object to magenta color
275                    elseif isequal(get(hsub,'Type'),'image')
276                       Acolor=get(hsub,'CData');
277                       Acolor(:,:,1)=Acolor(:,:,3);
278                       set(hsub,'CData',Acolor);
279                    else
280                        set(hsub,'Color','m')
281                    end
282                end
283            end
284            if isequal(obj_tag,'DeformPoint')
285                 set(hcurrentobject,'Color','m'); %set the selected DeformPoint to magenta color
286            end
287            IndexObj=ObjectData.IndexObj;
288                    %indicate on the list of the GUI uvmat which object has been selected
289            if strcmp(get(hCurrentGUI,'tag'),'uvmat') %if the uvmat graph has been selected, object projection is on the other frame view_field
290                set(hhuvmat.ListObject,'Value',IndexObj);
291            else
292                set(hhuvmat.ListObject_1,'Value',IndexObj);
293                list_str=get(hhuvmat.ListObject_1,'String');
294                UvData.ProjObject{IndexObj}.Name=list_str{IndexObj};
295            end
296            set_object(UvData.ProjObject{IndexObj})
297            axes(hchild);%set back the current axes haxes
298            set(gcbo,'Pointer','circle');
299            AxeData.Drawing='deform';
300            if isequal(obj_tag,'DeformPoint')       
301               if isfield(ObjectData,'DeformPoint')
302                   set(hcurrentobject,'Selected','on')
303                   for ipt=1:length(ObjectData.DeformPoint)
304                       if isequal(ObjectData.DeformPoint(ipt),hcurrentobject)
305                            AxeData.CurrentIndex=ipt;
306                            testdeform=1;
307                       end
308                   end
309               end
310            end
311%             if testdeform==0
312%                 AxeData.Drawing='translate';
313%                 set(AxeData.CurrentObject,'Selected','on')
314%                 set(gcbo,'Pointer','fleur');
315%             end
316        else
317            if strcmp(get(hCurrentGUI,'tag'),'uvmat') %if the uvmat graph has been selected, object projection is on the other frame view_field
318               IndexObj=get(hhuvmat.ListObject,'Value');
319               AxeData.CurrentObject=UvData.ProjObject{IndexObj}.DisplayHandle.uvmat;
320            else
321                IndexObj=get(hhuvmat.ListObject_1,'Value');
322                AxeData.CurrentObject=UvData.ProjObject{IndexObj}.DisplayHandle.view_field;
323            end   
324            ObjectData=get(AxeData.CurrentObject,'UserData');
325            ObjectData.IndexObj=IndexObj;
326            set(AxeData.CurrentObject,'UserData',ObjectData)
327        end
328        if testdeform==0
329                AxeData.Drawing='translate';
330                set(AxeData.CurrentObject,'Selected','on')
331                set(gcbo,'Pointer','fleur');
332        end
333    end
334end
335
336%%  create  projection  object
337if  test_create && ~isempty(xy) && ~strcmp(get(hCurrentGUI,'SelectionType'),'alt')
338    % activate this option if the GUI set_object is opened
339    sethandles=guidata(hset_object);% handles of the elements in the GUI set_object
340    ObjectData=read_GUI(hset_object); %read object parameters in the GUI set_object
341    IndexObj=length(UvData.ProjObject);
342    % if the currently selected object is already finished, a new object is initiated
343    if ~isfield(UvData.ProjObject{IndexObj},'CreateMode')
344        IndexObj=IndexObj+1;%start new object
345        ObjectData.Coord=[];
346        ObjectNameNew=ObjectData.Name;
347        if isempty(ObjectNameNew)
348            ObjectNameNew=ObjectData.Type;
349        end
350        % add an index to the object name if the proposed name already exists
351        vers=0;% index of the name
352        ListObject=get(hhuvmat.ListObject,'String');
353        detectname=1;
354        while ~isempty(detectname)
355            detectname=find(strcmp(ObjectNameNew,ListObject),1);%test the existence of the proposed name in the list
356            if detectname% if the object name already exists
357                indstr=regexp(ObjectNameNew,'\D');
358                if indstr(end)<length(ObjectNameNew) %object name ends by a number
359                    vers=str2double(ObjectNameNew(indstr(end)+1:end))+1;
360                    ObjectNameNew=[ObjectNameNew(1:indstr(end)) num2str(vers)];
361                else
362                    vers=vers+1;
363                    ObjectNameNew=[ObjectNameNew(1:indstr(end)) '_' num2str(vers)];
364                end
365            end
366        end
367        ObjectName=ObjectNameNew;
368        set(sethandles.Name,'String',ObjectName)% display the default name in set_object
369        ListObject=[ListObject;{ObjectName}];
370        set(hhuvmat.ListObject,'String',ListObject);%complement the object list
371        set(hhuvmat.ListObject_1,'String',ListObject);%complement the object list
372        if strcmp(CurrentGUI_tag,'uvmat')
373            set(hhuvmat.ListObject,'Value',IndexObj)
374        else
375            set(hhuvmat.ListObject_1,'Value',IndexObj)
376        end
377        UvData.ProjObject{IndexObj}.DisplayHandle.uvmat=hhuvmat.PlotAxes; % axes for plot_object
378        UvData.ProjObject{IndexObj}.DisplayHandle.view_field=[]; %no plot handle before plot_field operation
379        set(hhuvmat.CheckViewObject,'Value',1)
380    end
381    ObjectData.Coord=[ObjectData.Coord ;xy(1,1:2)];% append the coordinates marked by the mouse to the object
382    %TODO replace 0 by z coord for 3D
383    hobject=UvData.ProjObject{IndexObj}.DisplayHandle.(CurrentGUI_tag);
384    if isempty(hobject)
385        hobject=haxes;
386    end
387    if strcmp(CurrentGUI_tag,'uvmat')
388        ProjObject=UvData.ProjObject{get(hhuvmat.ListObject_1,'Value')};
389    else
390        ProjObject=UvData.ProjObject{get(hhuvmat.ListObject,'Value')};
391    end
392    AxeData.CurrentObject=plot_object(ObjectData,ProjObject,hobject,'m');%draw the object and its handle becomes AxeData.CurrentObject
393    UvData.ProjObject{IndexObj}=ObjectData;
394    UvData.ProjObject{IndexObj}.DisplayHandle.(CurrentGUI_tag)=AxeData.CurrentObject;% attribute the current plot object handle to the Object
395    UvData.ProjObject{IndexObj}.CreateMode='on';% mark the object as in the course of creation
396    set(huvmat,'UserData',UvData)
397    PlotData=get(AxeData.CurrentObject,'UserData');
398    PlotData.IndexObj=IndexObj;
399    set(AxeData.CurrentObject,'UserData',PlotData); %record the object index in the graph (memory used for mouse motion)
400    AxeData.Drawing='create';% flag for mouse motion
401
402    %show object coordinates in the GUI set_object
403    h_set_object=findobj(allchild(0),'Tag','set_object');
404    hh_set_object=guidata(h_set_object);
405    set(hh_set_object.Coord,'Data',ObjectData.Coord);
406end
407
408%% create calibration points if the GUI geometry_calib is opened, if the main axes PlotAxes of uvmat has ben selected
409if  test_cal && ~isempty(haxes) && strcmp(get(haxes,'tag'),'PlotAxes')
410    h_geometry_calib=findobj(allchild(0),'Name','geometry_calib'); %find the geomterty_calib GUI
411    hh_geometry_calib=guidata(h_geometry_calib);
412    h_CheckEnableMouse=hh_geometry_calib.CheckEnableMouse;
413    if isequal(get(h_CheckEnableMouse,'Value'),1) && ~isempty(haxes)
414        if ~isequal(get(hhuvmat.TransformName,'Value'),1); %active only with no transform (px coordinates)
415            set(hhuvmat.TransformName,'Value',1)
416            uvmat('TransformName_Callback',hObject,eventdata,hhuvmat); %file input with xml reading  in uvmat
417            set(hhuvmat.CheckFixLimits,'Value',0)% put FixedLimits option to 'off' (to sse the whole field)
418            return
419        end
420        h_ListCoord=hh_geometry_calib.ListCoord; %findobj(h_geometry_calib,'Tag','ListCoord');
421        Coord=get(h_ListCoord,'Data');
422        %data=read_geometry_calib(Coord);%transform char cell to numbers
423        xlim=get(haxes,'XLim');
424        ind_range_x=abs((xlim(2)-xlim(1))/50);
425        ylim=get(haxes,'YLim');
426        ind_range_y=abs((ylim(2)-ylim(1))/50);
427        ind_range=sqrt(ind_range_x*ind_range_y);
428        test_newpoint=1;
429        %if size(data.Coord,2)>=5 %if calibration points already exist
430        if ~isempty(Coord)
431        XCoord=(Coord(:,4));
432        YCoord=(Coord(:,5));
433        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
434            (YCoord<xy(1,2)+ind_range) & (YCoord>xy(1,2)-ind_range),1);%find the first calibration point in the neighborhood of the mouse
435        test_newpoint=isempty(index_point);%test for no existing calibration point near the mouse position
436        end
437        %end
438        %val=find(Data.Coord(:,6));
439       
440        %create a new calib point if we are not close to an existing one
441        hh=findobj('Tag','calib_points');%look for handle of calibration points
442        if test_newpoint
443            Coord=[Coord;[0 0 0 xy(1,1) xy(1,2) 0]];
444            set(h_ListCoord,'Data',Coord)
445        end
446        if isempty(hh)
447            hh=line(Coord(:,4),Coord(:,5),'Color','m','Tag','calib_points','LineStyle','.','Marker','+');
448        else
449            set(hh,'XData',Coord(:,4))
450            set(hh,'YData',Coord(:,5))
451        end
452         if test_newpoint
453             set(hh,'UserData',size(Coord,1))% flag the points to edit mode
454         else
455             set(hh,'UserData',index_point)% mark the selected point index for future mouse motion
456         end
457        hhh=findobj('Tag','calib_marker');%look for handle of point marker (circle)
458        if ~isempty(hhh)
459            set(hhh,'Position',[xy(1,1)-ind_range/2 xy(1,2)-ind_range/2 ind_range ind_range])
460        else
461            rectangle('Curvature',[1 1],...
462                'Position',[xy(1,1)-ind_range/2 xy(1,2)-ind_range/2 ind_range ind_range],'EdgeColor','m',...
463                'LineStyle','-','Tag','calib_marker');
464        end
465        AxeData.Drawing='calibration';
466    end
467end
468
469%% edit vectors
470if test_edit_vect && ~isempty(ivec)
471    %create the error flag FF if it does not exist
472    if ~isfield(Field,'FF')
473        Field.ListVarName=[Field.ListVarName 'FF'];
474        Field.VarDimName=[Field.VarDimName Field.VarDimName{CellInfo{icell}.VarIndex_coord_x}];
475        nbvar=length(Field.ListVarName);
476        Field.VarAttribute{nbvar}.Role='errorflag';
477        Field.FF=zeros(size(Field.X));
478    end
479    if isequal(Field.FF(ivec),0)
480        Field.FF(ivec)=100; %mark vector #ivec as false
481    else
482        Field.FF(ivec)=0;
483    end
484    PlotParam=read_GUI(hCurrentGUI);
485    plot_field(Field,haxes,PlotParam);
486    eval(['FigData.' tagaxes '=Field;'])%record the modified field in FigData
487    set(hCurrentGUI,'UserData',FigData);
488end 
489set(haxes,'UserData',AxeData);
490
Note: See TracBrowser for help on using the repository browser.