source: trunk/src/mouse_down.m @ 975

Last change on this file since 975 was 967, checked in by sommeria, 8 years ago

3D cuts improved

File size: 28.0 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-2016, LEGI UMR 5519 / CNRS UGA 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        %get handles of the GUI set_object
433    h_set_object=findobj(allchild(0),'Tag','set_object');
434    hh_set_object=guidata(h_set_object);
435    if strcmp(ObjectData.Type,'plane_z')&& ~isempty(ObjectData.Coord)
436        Delta_x=(xy(1,1)-ObjectData.Coord(1,1));%displacement along x
437        Delta_y=(xy(1,2)-ObjectData.Coord(1,2));%displacement along y
438        ObjectData.Angle(1)=(180/pi)*angle(Delta_x+i*Delta_y);
439        ObjectData.Angle(2)=90;       
440        set(hh_set_object.num_Angle_1,'String',num2str(ObjectData.Angle(1)))
441        set(hh_set_object.num_Angle_2,'String',num2str(ObjectData.Angle(2)))
442         drawing_status='off';
443    else
444        ObjectData.Coord=[ObjectData.Coord ;xy(1,1:2)];% append the coordinates marked by the mouse to the object
445        set(hh_set_object.Coord,'Data',ObjectData.Coord);%append the current mouse cordinates in the GUI set_object
446        drawing_status='create';
447    end
448    drawing_status='create';
449    %TODO replace 0 by z coord for 3D
450    hobject=UvData.ProjObject{IndexObj}.DisplayHandle.(CurrentGUI_tag);
451    if isempty(hobject)
452        hobject=haxes;
453    end
454    if strcmp(CurrentGUI_tag,'uvmat')
455        ProjObject=UvData.ProjObject{get(hhuvmat.ListObject_1,'Value')};
456    else
457        ProjObject=UvData.ProjObject{get(hhuvmat.ListObject,'Value')};
458    end
459    AxeData.CurrentObject=plot_object(ObjectData,ProjObject,hobject,'m');%draw the object and its handle becomes AxeData.CurrentObject
460    UvData.ProjObject{IndexObj}=ObjectData;
461    UvData.ProjObject{IndexObj}.DisplayHandle.(CurrentGUI_tag)=AxeData.CurrentObject;% attribute the current plot object handle to the Object
462    UvData.ProjObject{IndexObj}.CreateMode='on';% mark the object as in the course of creation
463    set(huvmat,'UserData',UvData)
464    PlotData=get(AxeData.CurrentObject,'UserData');
465    PlotData.IndexObj=IndexObj;
466    set(AxeData.CurrentObject,'UserData',PlotData); %record the object index in the graph (memory used for mouse motion)
467    AxeData.Drawing=drawing_status;% flag for mouse motion
468end
469
470%% create calibration points if the GUI geometry_calib is opened, if the main axes PlotAxes of uvmat has ben selected
471if  test_cal && ~isempty(haxes) && strcmp(get(haxes,'tag'),'PlotAxes')
472    h_geometry_calib=findobj(allchild(0),'Name','geometry_calib'); %find the geomterty_calib GUI
473    hh_geometry_calib=guidata(h_geometry_calib);
474    h_CheckEnableMouse=hh_geometry_calib.CheckEnableMouse;
475    if isequal(get(h_CheckEnableMouse,'Value'),1) && ~isempty(haxes)
476        if ~isequal(get(hhuvmat.TransformName,'Value'),1); %active only with no transform (px coordinates)
477            set(hhuvmat.TransformName,'Value',1)
478            uvmat('TransformName_Callback',hObject,eventdata,hhuvmat); %file input with xml reading  in uvmat
479            set(hhuvmat.CheckFixLimits,'Value',0)% put FixedLimits option to 'off' (to sse the whole field)
480            return
481        end
482        h_ListCoord=hh_geometry_calib.ListCoord; %findobj(h_geometry_calib,'Tag','ListCoord');
483        Coord=get(h_ListCoord,'Data');
484        %data=read_geometry_calib(Coord);%transform char cell to numbers
485        xlim=get(haxes,'XLim');
486        ind_range_x=abs((xlim(2)-xlim(1))/50);
487        ylim=get(haxes,'YLim');
488        ind_range_y=abs((ylim(2)-ylim(1))/50);
489        ind_range=sqrt(ind_range_x*ind_range_y);
490        test_newpoint=1;
491        %if size(data.Coord,2)>=5 %if calibration points already exist
492        if ~isempty(Coord)
493        XCoord=(Coord(:,4));
494        YCoord=(Coord(:,5));
495        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
496            (YCoord<xy(1,2)+ind_range) & (YCoord>xy(1,2)-ind_range),1);%find the first calibration point in the neighborhood of the mouse
497        test_newpoint=isempty(index_point);%test for no existing calibration point near the mouse position
498        end
499        %end
500        %val=find(Data.Coord(:,6));
501       
502        %create a new calib point if we are not close to an existing one
503        hh=findobj('Tag','calib_points');%look for handle of calibration points
504        if test_newpoint
505            Coord=[Coord;[0 0 0 xy(1,1) xy(1,2) 0]];
506            set(h_ListCoord,'Data',Coord)
507        end
508        if isempty(hh)
509            hh=line(Coord(:,4),Coord(:,5),'Color','m','Tag','calib_points','LineStyle','none','Marker','+');
510        else
511            set(hh,'XData',Coord(:,4))
512            set(hh,'YData',Coord(:,5))
513        end
514         if test_newpoint
515             set(hh,'UserData',size(Coord,1))% flag the points to edit mode
516         else
517             set(hh,'UserData',index_point)% mark the selected point index for future mouse motion
518         end
519        hhh=findobj('Tag','calib_marker');%look for handle of point marker (circle)
520        if ~isempty(hhh)
521            set(hhh,'Position',[xy(1,1)-ind_range/2 xy(1,2)-ind_range/2 ind_range ind_range])
522        else
523            rectangle('Curvature',[1 1],...
524                'Position',[xy(1,1)-ind_range/2 xy(1,2)-ind_range/2 ind_range ind_range],'EdgeColor','m',...
525                'LineStyle','-','Tag','calib_marker');
526        end
527        AxeData.Drawing='calibration';
528    end
529end
530
531%% edit vectors
532if test_edit_vect && ~isempty(ivec)
533    %create the error flag FF if it does not exist
534    if ~isfield(Field,'FF')
535        Field.ListVarName=[Field.ListVarName 'FF'];
536        Field.VarDimName=[Field.VarDimName Field.VarDimName{CellInfo{icell}.VarIndex_coord_x}];
537        nbvar=length(Field.ListVarName);
538        Field.VarAttribute{nbvar}.Role='errorflag';
539        Field.FF=zeros(size(Field.X));
540    end
541    if isequal(Field.FF(ivec),0)
542        Field.FF(ivec)=100; %mark vector #ivec as false
543    else
544        Field.FF(ivec)=0;
545    end
546    PlotParam=read_GUI(hCurrentGUI);
547    plot_field(Field,haxes,PlotParam);
548    eval(['FigData.' tagaxes '=Field;'])%record the modified field in FigData
549    set(hCurrentGUI,'UserData',FigData);
550end 
551set(haxes,'UserData',AxeData);
552
Note: See TracBrowser for help on using the repository browser.