source: trunk/src/mouse_down.m @ 844

Last change on this file since 844 was 809, checked in by g7moreau, 10 years ago
  • Add license
File size: 26.9 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
248if isempty(huvmat)%further options require the uvmat GUI
249    return
250end
251
252%% ruler has second priority
253if test_ruler && ~isempty(xy)
254    AxeData.RulerCoord(1,1:2)=xy(1,1:2);
255    AxeData.RulerHandle=line([xy(1,1) xy(1,1)],[xy(1,2) xy(1,2)],'Color','m','Tag','ruler');
256    AxeData.Drawing='ruler';
257    set(hchild,'UserData',AxeData);
258    return
259end
260
261%% PIV test
262if test_piv
263    figure
264    newaxes=axes;
265    copyobj(AxeData.CurrentCorrImage,newaxes);
266    set(newaxes,'CLim',[0 1])
267    copyobj(AxeData.CurrentVector,newaxes)
268    copyobj(AxeData.TitleHandle,newaxes)
269    colorbar
270end
271
272%% desable  object creation and vector editing if NbDim different from 2
273if ~(isfield(AxeData,'NbDim') && isequal(AxeData.NbDim,2))
274    test_create=0;
275    test_edit_vect=0;
276end
277
278%% selection of an existing projection object (third priority)
279if  test_edit
280    testdeform=0;
281    if ~(isfield(AxeData,'Drawing') && isequal(AxeData.Drawing,'create'))
282        userdata=get(hcurrentobject,'UserData');
283        if ishandle(userdata)%the selected line depends on a parent line
284            AxeData.CurrentObject=userdata;% the parent object becomes the current one
285        else
286            AxeData.CurrentObject=hcurrentobject;% the selected object becomes the current one
287        end
288        ObjectData=get(AxeData.CurrentObject,'UserData');
289        if isfield(ObjectData,'IndexObj')
290            hother=findobj('Tag','proj_object','Type','line');%find all the proj objects
291            set(hother,'Color','b');%reset all the proj objects in 'blue' by default
292            set(hother,'Selected','off')
293            hother=findobj('Tag','proj_object','Type','rectangle');
294            set(hother,'EdgeColor','b');
295            set(hother,'Selected','off');
296            hother=findobj('Tag','proj_object','Type','image');
297            for iobj=1:length(hother)
298                   Acolor=get(hother(iobj),'CData');
299                   Acolor(:,:,1)=zeros(size(Acolor,1),size(Acolor,2));
300                   set(hother(iobj),'CData',Acolor);
301            end
302            hother=findobj('Tag','DeformPoint');
303            set(hother,'Color','b');
304            set(hother,'Selected','off')   
305            if isequal(get(AxeData.CurrentObject,'Type'),'line')
306                set(AxeData.CurrentObject,'Color','m'); %set the selected object to magenta color
307            elseif isequal(get(AxeData.CurrentObject,'Type'),'rectangle')
308                 set(AxeData.CurrentObject,'EdgeColor','m'); %set the selected object to magenta color
309            end
310            if isfield(ObjectData,'SubObject')& ishandle(ObjectData.SubObject)
311                for iobj=1:length(ObjectData.SubObject)
312                    hsub=ObjectData.SubObject(iobj);
313                    if isequal(get(hsub,'Type'),'rectangle')
314                        set(hsub,'EdgeColor','m'); %set the selected object to magenta color
315                    elseif isequal(get(hsub,'Type'),'image')
316                       Acolor=get(hsub,'CData');
317                       Acolor(:,:,1)=Acolor(:,:,3);
318                       set(hsub,'CData',Acolor);
319                    else
320                        set(hsub,'Color','m')
321                    end
322                end
323            end
324            if isequal(obj_tag,'DeformPoint')
325                 set(hcurrentobject,'Color','m'); %set the selected DeformPoint to magenta color
326            end
327            IndexObj=ObjectData.IndexObj;
328                    %indicate on the list of the GUI uvmat which object has been selected
329            if strcmp(get(hCurrentGUI,'tag'),'uvmat') %if the uvmat graph has been selected, object projection is on the other frame view_field
330                set(hhuvmat.ListObject,'Value',IndexObj);
331            else
332                set(hhuvmat.ListObject_1,'Value',IndexObj);
333                list_str=get(hhuvmat.ListObject_1,'String');
334                UvData.ProjObject{IndexObj}.Name=list_str{IndexObj};
335            end
336            set_object(UvData.ProjObject{IndexObj})
337            axes(hchild);%set back the current axes haxes
338            set(gcbo,'Pointer','circle');
339            AxeData.Drawing='deform';
340            if isequal(obj_tag,'DeformPoint')       
341               if isfield(ObjectData,'DeformPoint')
342                   set(hcurrentobject,'Selected','on')
343                   for ipt=1:length(ObjectData.DeformPoint)
344                       if isequal(ObjectData.DeformPoint(ipt),hcurrentobject)
345                            AxeData.CurrentIndex=ipt;
346                            testdeform=1;
347                       end
348                   end
349               end
350            end
351%             if testdeform==0
352%                 AxeData.Drawing='translate';
353%                 set(AxeData.CurrentObject,'Selected','on')
354%                 set(gcbo,'Pointer','fleur');
355%             end
356        else
357            if strcmp(get(hCurrentGUI,'tag'),'uvmat') %if the uvmat graph has been selected, object projection is on the other frame view_field
358               IndexObj=get(hhuvmat.ListObject,'Value');
359               AxeData.CurrentObject=UvData.ProjObject{IndexObj}.DisplayHandle.uvmat;
360            else
361                IndexObj=get(hhuvmat.ListObject_1,'Value');
362                AxeData.CurrentObject=UvData.ProjObject{IndexObj}.DisplayHandle.view_field;
363            end   
364            ObjectData=get(AxeData.CurrentObject,'UserData');
365            ObjectData.IndexObj=IndexObj;
366            set(AxeData.CurrentObject,'UserData',ObjectData)
367        end
368        if testdeform==0
369                AxeData.Drawing='translate';
370                set(AxeData.CurrentObject,'Selected','on')
371                set(gcbo,'Pointer','fleur');
372        end
373    end
374end
375
376%%  create  projection  object
377if  test_create && ~isempty(xy) && ~strcmp(get(hCurrentGUI,'SelectionType'),'alt')
378    % activate this option if the GUI set_object is opened
379    sethandles=guidata(hset_object);% handles of the elements in the GUI set_object
380    ObjectData=read_GUI(hset_object); %read object parameters in the GUI set_object
381    IndexObj=length(UvData.ProjObject);
382    % if the currently selected object is already finished, a new object is initiated
383    if ~isfield(UvData.ProjObject{IndexObj},'CreateMode')
384        IndexObj=IndexObj+1;%start new object
385        ObjectData.Coord=[];
386        ObjectNameNew=ObjectData.Name;
387        if isempty(ObjectNameNew)
388            ObjectNameNew=ObjectData.Type;
389        end
390        % add an index to the object name if the proposed name already exists
391        vers=0;% index of the name
392        ListObject=get(hhuvmat.ListObject,'String');
393        detectname=1;
394        while ~isempty(detectname)
395            detectname=find(strcmp(ObjectNameNew,ListObject),1);%test the existence of the proposed name in the list
396            if detectname% if the object name already exists
397                indstr=regexp(ObjectNameNew,'\D');
398                if indstr(end)<length(ObjectNameNew) %object name ends by a number
399                    vers=str2double(ObjectNameNew(indstr(end)+1:end))+1;
400                    ObjectNameNew=[ObjectNameNew(1:indstr(end)) num2str(vers)];
401                else
402                    vers=vers+1;
403                    ObjectNameNew=[ObjectNameNew(1:indstr(end)) '_' num2str(vers)];
404                end
405            end
406        end
407        ObjectName=ObjectNameNew;
408        set(sethandles.Name,'String',ObjectName)% display the default name in set_object
409        ListObject=[ListObject;{ObjectName}];
410        set(hhuvmat.ListObject,'String',ListObject);%complement the object list
411        set(hhuvmat.ListObject_1,'String',ListObject);%complement the object list
412        if strcmp(CurrentGUI_tag,'uvmat')
413            set(hhuvmat.ListObject,'Value',IndexObj)
414        else
415            set(hhuvmat.ListObject_1,'Value',IndexObj)
416        end
417        UvData.ProjObject{IndexObj}.DisplayHandle.uvmat=hhuvmat.PlotAxes; % axes for plot_object
418        UvData.ProjObject{IndexObj}.DisplayHandle.view_field=[]; %no plot handle before plot_field operation
419        set(hhuvmat.CheckViewObject,'Value',1)
420    end
421    ObjectData.Coord=[ObjectData.Coord ;xy(1,1:2)];% append the coordinates marked by the mouse to the object
422    %TODO replace 0 by z coord for 3D
423    hobject=UvData.ProjObject{IndexObj}.DisplayHandle.(CurrentGUI_tag);
424    if isempty(hobject)
425        hobject=haxes;
426    end
427    if strcmp(CurrentGUI_tag,'uvmat')
428        ProjObject=UvData.ProjObject{get(hhuvmat.ListObject_1,'Value')};
429    else
430        ProjObject=UvData.ProjObject{get(hhuvmat.ListObject,'Value')};
431    end
432    AxeData.CurrentObject=plot_object(ObjectData,ProjObject,hobject,'m');%draw the object and its handle becomes AxeData.CurrentObject
433    UvData.ProjObject{IndexObj}=ObjectData;
434    UvData.ProjObject{IndexObj}.DisplayHandle.(CurrentGUI_tag)=AxeData.CurrentObject;% attribute the current plot object handle to the Object
435    UvData.ProjObject{IndexObj}.CreateMode='on';% mark the object as in the course of creation
436    set(huvmat,'UserData',UvData)
437    PlotData=get(AxeData.CurrentObject,'UserData');
438    PlotData.IndexObj=IndexObj;
439    set(AxeData.CurrentObject,'UserData',PlotData); %record the object index in the graph (memory used for mouse motion)
440    AxeData.Drawing='create';% flag for mouse motion
441
442    %show object coordinates in the GUI set_object
443    h_set_object=findobj(allchild(0),'Tag','set_object');
444    hh_set_object=guidata(h_set_object);
445    set(hh_set_object.Coord,'Data',ObjectData.Coord);
446end
447
448%% create calibration points if the GUI geometry_calib is opened, if the main axes PlotAxes of uvmat has ben selected
449if  test_cal && ~isempty(haxes) && strcmp(get(haxes,'tag'),'PlotAxes')
450    h_geometry_calib=findobj(allchild(0),'Name','geometry_calib'); %find the geomterty_calib GUI
451    hh_geometry_calib=guidata(h_geometry_calib);
452    h_CheckEnableMouse=hh_geometry_calib.CheckEnableMouse;
453    if isequal(get(h_CheckEnableMouse,'Value'),1) && ~isempty(haxes)
454        if ~isequal(get(hhuvmat.TransformName,'Value'),1); %active only with no transform (px coordinates)
455            set(hhuvmat.TransformName,'Value',1)
456            uvmat('TransformName_Callback',hObject,eventdata,hhuvmat); %file input with xml reading  in uvmat
457            set(hhuvmat.CheckFixLimits,'Value',0)% put FixedLimits option to 'off' (to sse the whole field)
458            return
459        end
460        h_ListCoord=hh_geometry_calib.ListCoord; %findobj(h_geometry_calib,'Tag','ListCoord');
461        Coord=get(h_ListCoord,'Data');
462        %data=read_geometry_calib(Coord);%transform char cell to numbers
463        xlim=get(haxes,'XLim');
464        ind_range_x=abs((xlim(2)-xlim(1))/50);
465        ylim=get(haxes,'YLim');
466        ind_range_y=abs((ylim(2)-ylim(1))/50);
467        ind_range=sqrt(ind_range_x*ind_range_y);
468        test_newpoint=1;
469        %if size(data.Coord,2)>=5 %if calibration points already exist
470        if ~isempty(Coord)
471        XCoord=(Coord(:,4));
472        YCoord=(Coord(:,5));
473        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
474            (YCoord<xy(1,2)+ind_range) & (YCoord>xy(1,2)-ind_range),1);%find the first calibration point in the neighborhood of the mouse
475        test_newpoint=isempty(index_point);%test for no existing calibration point near the mouse position
476        end
477        %end
478        %val=find(Data.Coord(:,6));
479       
480        %create a new calib point if we are not close to an existing one
481        hh=findobj('Tag','calib_points');%look for handle of calibration points
482        if test_newpoint
483            Coord=[Coord;[0 0 0 xy(1,1) xy(1,2) 0]];
484            set(h_ListCoord,'Data',Coord)
485        end
486        if isempty(hh)
487            hh=line(Coord(:,4),Coord(:,5),'Color','m','Tag','calib_points','LineStyle','.','Marker','+');
488        else
489            set(hh,'XData',Coord(:,4))
490            set(hh,'YData',Coord(:,5))
491        end
492         if test_newpoint
493             set(hh,'UserData',size(Coord,1))% flag the points to edit mode
494         else
495             set(hh,'UserData',index_point)% mark the selected point index for future mouse motion
496         end
497        hhh=findobj('Tag','calib_marker');%look for handle of point marker (circle)
498        if ~isempty(hhh)
499            set(hhh,'Position',[xy(1,1)-ind_range/2 xy(1,2)-ind_range/2 ind_range ind_range])
500        else
501            rectangle('Curvature',[1 1],...
502                'Position',[xy(1,1)-ind_range/2 xy(1,2)-ind_range/2 ind_range ind_range],'EdgeColor','m',...
503                'LineStyle','-','Tag','calib_marker');
504        end
505        AxeData.Drawing='calibration';
506    end
507end
508
509%% edit vectors
510if test_edit_vect && ~isempty(ivec)
511    %create the error flag FF if it does not exist
512    if ~isfield(Field,'FF')
513        Field.ListVarName=[Field.ListVarName 'FF'];
514        Field.VarDimName=[Field.VarDimName Field.VarDimName{CellInfo{icell}.VarIndex_coord_x}];
515        nbvar=length(Field.ListVarName);
516        Field.VarAttribute{nbvar}.Role='errorflag';
517        Field.FF=zeros(size(Field.X));
518    end
519    if isequal(Field.FF(ivec),0)
520        Field.FF(ivec)=100; %mark vector #ivec as false
521    else
522        Field.FF(ivec)=0;
523    end
524    PlotParam=read_GUI(hCurrentGUI);
525    plot_field(Field,haxes,PlotParam);
526    eval(['FigData.' tagaxes '=Field;'])%record the modified field in FigData
527    set(hCurrentGUI,'UserData',FigData);
528end 
529set(haxes,'UserData',AxeData);
530
Note: See TracBrowser for help on using the repository browser.