source: trunk/src/mouse_down.m @ 873

Last change on this file since 873 was 855, checked in by sommeria, 10 years ago

testcivadded

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