source: trunk/src/mouse_down.m @ 1155

Last change on this file since 1155 was 1127, checked in by g7moreau, 11 months ago

Update Joel email

File size: 30.5 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-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
10%   http://www.legi.grenoble-inp.fr
11%   Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.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 (uvmat or view_field)
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: it can be a drawn object, a plot axis, ..;)
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');% contains the input field as UvData.Field
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
211if ~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
218end
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 && ~strcmp(get(hcurrentobject,'Type'),'figure')
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        else
363            if strcmp(get(hCurrentGUI,'tag'),'uvmat') %if the uvmat graph has been selected, object projection is on the other frame view_field
364               IndexObj=get(hhuvmat.ListObject,'Value');
365               AxeData.CurrentObject=UvData.ProjObject{IndexObj}.DisplayHandle.uvmat;
366            else
367                IndexObj=get(hhuvmat.ListObject_1,'Value');
368                AxeData.CurrentObject=UvData.ProjObject{IndexObj}.DisplayHandle.view_field;
369            end   
370            ObjectData=get(AxeData.CurrentObject,'UserData');
371            ObjectData.IndexObj=IndexObj;
372            set(AxeData.CurrentObject,'UserData',ObjectData)
373        end
374        if testdeform==0
375                AxeData.Drawing='translate';
376                set(AxeData.CurrentObject,'Selected','on')
377                set(gcbo,'Pointer','fleur');
378        end
379    end
380end
381
382%%  create  projection  object within the GUI uvmat
383if  test_create && ~isempty(xy) && ~strcmp(get(hCurrentGUI,'SelectionType'),'alt')
384    % activate this option if the GUI set_object is opened
385    sethandles=guidata(hset_object);% handles of the elements in the GUI set_object
386    ObjectData=read_GUI(hset_object); %read object parameters in the GUI set_object
387    IndexObj=length(UvData.ProjObject);
388    % if the currently selected object is already finished, a new object is initiated
389    if ~isfield(UvData.ProjObject{IndexObj},'CreateMode')
390        IndexObj=IndexObj+1;%start new object
391        ObjectData.Coord=[];
392        ObjectName=ObjectData.Name;
393        if isempty(ObjectName)
394            ObjectName=ObjectData.Type;
395        end
396        % add an index to the object name if the proposed name already exists
397        %vers=0;% index of the name
398        ListObject=get(hhuvmat.ListObject,'String');
399        ObjectName=rename_indexing(ObjectName,ListObject);% add an index or upgrade it if the object naem already exists
400        set(sethandles.Name,'String',ObjectName)% display the default name in set_object
401        ListObject=[ListObject;{ObjectName}];
402        set(hhuvmat.ListObject,'String',ListObject);%complement the object list
403        set(hhuvmat.ListObject_1,'String',ListObject);%complement the object list
404        if strcmp(CurrentGUI_tag,'uvmat')
405            set(hhuvmat.ListObject,'Value',IndexObj)
406        else
407            set(hhuvmat.ListObject_1,'Value',IndexObj)
408        end
409        UvData.ProjObject{IndexObj}.DisplayHandle.uvmat=hhuvmat.PlotAxes; % axes for plot_object
410        UvData.ProjObject{IndexObj}.DisplayHandle.view_field=[]; %no plot handle before plot_field operation
411        set(hhuvmat.CheckViewObject,'Value',1)
412    end
413        %get handles of the GUI set_object
414    h_set_object=findobj(allchild(0),'Tag','set_object');
415    hh_set_object=guidata(h_set_object);
416    if strcmp(ObjectData.Type,'plane')
417        if isempty(ObjectData.Coord)||(isfield(ObjectData,'RangeX') && size(ObjectData.RangeX,2)==2)% draw a new plane
418            ObjectData.Coord=xy(1,1:2);% record the coordinates marked by the mouse as origin of the new plane
419           
420            if isfield(FigData,'PlotAxes')
421                Field=FigData.PlotAxes;% field represented on the plot (already projected)
422                if isfield(Field,'ProjObjectType') && strcmp(Field.ProjObjectType,'plane') && isfield(Field,'ProjObjectCoord') && length(Field.ProjObjectCoord)>=3
423                    zpos=Field.ProjObjectCoord(1,3);
424                    if isfield(Field,'ProjObjectAngle')&&~isequal(Field.ProjObjectAngle,[0 0 0])
425                        norm_plane=rotate_vector(Field.ProjObjectAngle,0,0,1);%angle2normal(Field.ProjObjectAngle);
426                        zpos=zpos-(norm_plane(1)*(xy(1,1)-Field.ProjObjectCoord(1))+norm_plane(2)*(xy(1,2)-Field.ProjObjectCoord(2)))/norm_plane(3);
427                    end
428                    ObjectData.Coord(3)=zpos;
429                end
430            end
431           
432            set(hh_set_object.Coord,'Data',ObjectData.Coord);%append the current mouse cordinates in the GUI set_object
433            set(hh_set_object.num_RangeX_2,'String','')
434            set(hh_set_object.num_Angle_1,'String','0')
435            drawing_status='create';
436        else
437
438            Delta_x=(xy(1,1)-ObjectData.Coord(1,1));%displacement along x
439            Delta_y=(xy(1,2)-ObjectData.Coord(1,2));%displacement along y
440            theta=angle(Delta_x+1i*Delta_y);
441            M2=[cos(theta) -sin(theta) 0;sin(theta) cos(theta) 0;0 0 1];% rotation matrix around the vertical axis with angle theta
442            M1=[1 0 0;0 0 -1; 0 1 0]; % rotation matrix around the x axis with angle pi/2
443            Angle=rodrigues(M2*M1);
444              [RangeX,RangeY]=set_plane_bounds(theta,ObjectData.Coord(1,:),UvData.Field);
445            set(hh_set_object.num_Angle_1,'String',num2str(Angle(1)))
446            set(hh_set_object.num_Angle_2,'String',num2str(Angle(2)))
447             set(hh_set_object.num_Angle_3,'String',num2str(Angle(3)))
448            set(hh_set_object.num_RangeX_1,'String',num2str(RangeX(1)))
449            set(hh_set_object.num_RangeX_2,'String',num2str(RangeX(2)))
450            set(hh_set_object.num_RangeY_1,'String',num2str(RangeY(1)))
451            set(hh_set_object.num_RangeY_2,'String',num2str(RangeY(2)))
452            drawing_status='off';
453        end
454    else
455        ObjectData.Coord=[ObjectData.Coord ;xy(1,1:2)];% append the coordinates marked by the mouse to the object
456        set(hh_set_object.Coord,'Data',ObjectData.Coord);%append the current mouse cordinates in the GUI set_object
457        drawing_status='create';
458    end
459    %drawing_status='create';
460    %TODO replace 0 by z coord for 3D
461    hobject=UvData.ProjObject{IndexObj}.DisplayHandle.(CurrentGUI_tag);
462    if isempty(hobject)
463        hobject=haxes;
464    end
465    if strcmp(CurrentGUI_tag,'uvmat')
466        ProjObject=UvData.ProjObject{get(hhuvmat.ListObject_1,'Value')};
467    else
468        ProjObject=UvData.ProjObject{get(hhuvmat.ListObject,'Value')};
469    end
470    AxeData.CurrentObject=plot_object(ObjectData,ProjObject,hobject,'m');%draw the object and its handle becomes AxeData.CurrentObject
471    UvData.ProjObject{IndexObj}=ObjectData;
472    UvData.ProjObject{IndexObj}.DisplayHandle.(CurrentGUI_tag)=AxeData.CurrentObject;% attribute the current plot object handle to the Object
473    UvData.ProjObject{IndexObj}.CreateMode='on';% mark the object as in the course of creation
474    set(huvmat,'UserData',UvData)
475    PlotData=get(AxeData.CurrentObject,'UserData');
476    PlotData.IndexObj=IndexObj;
477    set(AxeData.CurrentObject,'UserData',PlotData); %record the object index in the graph (memory used for mouse motion)
478    AxeData.Drawing=drawing_status;% flag for mouse motion
479end
480
481%% create calibration points if the GUI geometry_calib is opened, if the main axes PlotAxes of uvmat has ben selected
482if  test_cal && ~isempty(haxes) && strcmp(get(haxes,'tag'),'PlotAxes')
483    h_geometry_calib=findobj(allchild(0),'Name','geometry_calib'); %find the geomterty_calib GUI
484    hh_geometry_calib=guidata(h_geometry_calib);
485    h_CheckEnableMouse=hh_geometry_calib.CheckEnableMouse;
486    if isequal(get(h_CheckEnableMouse,'Value'),1) && ~isempty(haxes)
487        if ~isequal(get(hhuvmat.TransformName,'Value'),1); %active only with no transform (px coordinates)
488            set(hhuvmat.TransformName,'Value',1)
489            uvmat('TransformName_Callback',hObject,eventdata,hhuvmat); %file input with xml reading  in uvmat
490            set(hhuvmat.CheckFixLimits,'Value',0)% put FixedLimits option to 'off' (to sse the whole field)
491            return
492        end
493        h_ListCoord=hh_geometry_calib.ListCoord; %findobj(h_geometry_calib,'Tag','ListCoord');
494        Coord=get(h_ListCoord,'Data');
495        %data=read_geometry_calib(Coord);%transform char cell to numbers
496        xlim=get(haxes,'XLim');
497        ind_range_x=abs((xlim(2)-xlim(1))/50);
498        ylim=get(haxes,'YLim');
499        ind_range_y=abs((ylim(2)-ylim(1))/50);
500        ind_range=sqrt(ind_range_x*ind_range_y);
501        test_newpoint=1;
502        %if size(data.Coord,2)>=5 %if calibration points already exist
503        if ~isempty(Coord)
504        XCoord=(Coord(:,4));
505        YCoord=(Coord(:,5));
506        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
507            (YCoord<xy(1,2)+ind_range) & (YCoord>xy(1,2)-ind_range),1);%find the first calibration point in the neighborhood of the mouse
508        test_newpoint=isempty(index_point);%test for no existing calibration point near the mouse position
509        end
510        %end
511        %val=find(Data.Coord(:,6));
512       
513        %create a new calib point if we are not close to an existing one
514        hh=findobj('Tag','calib_points');%look for handle of calibration points
515        if test_newpoint
516            Coord=[Coord;[0 0 0 xy(1,1) xy(1,2) 0]];
517            set(h_ListCoord,'Data',Coord)
518        end
519        if isempty(hh)
520            hh=line(Coord(:,4),Coord(:,5),'Color','m','Tag','calib_points','LineStyle','none','Marker','+');
521        else
522            set(hh,'XData',Coord(:,4))
523            set(hh,'YData',Coord(:,5))
524        end
525         if test_newpoint
526             set(hh,'UserData',size(Coord,1))% flag the points to edit mode
527         else
528             set(hh,'UserData',index_point)% mark the selected point index for future mouse motion
529         end
530        hhh=findobj('Tag','calib_marker');%look for handle of point marker (circle)
531        if ~isempty(hhh)
532            set(hhh,'Position',[xy(1,1)-ind_range/2 xy(1,2)-ind_range/2 ind_range ind_range])
533        else
534            rectangle('Curvature',[1 1],...
535                'Position',[xy(1,1)-ind_range/2 xy(1,2)-ind_range/2 ind_range ind_range],'EdgeColor','m',...
536                'LineStyle','-','Tag','calib_marker');
537        end
538        AxeData.Drawing='calibration';
539    end
540end
541
542%% edit vectors
543if test_edit_vect && ~isempty(ivec)
544    %create the error flag FF if it does not exist
545    if ~isfield(Field,'FF')
546        Field.ListVarName=[Field.ListVarName 'FF'];
547        Field.VarDimName=[Field.VarDimName Field.VarDimName{CellInfo{icell}.VarIndex_coord_x}];
548        nbvar=length(Field.ListVarName);
549        Field.VarAttribute{nbvar}.Role='errorflag';
550        Field.FF=zeros(size(Field.X));
551    end
552    if isequal(Field.FF(ivec),0)
553        Field.FF(ivec)=100; %mark vector #ivec as false
554    else
555        Field.FF(ivec)=0;
556    end
557    PlotParam=read_GUI(hCurrentGUI);
558    plot_field(Field,haxes,PlotParam);
559    eval(['FigData.' tagaxes '=Field;'])%record the modified field in FigData
560    set(hCurrentGUI,'UserData',FigData);
561end 
562set(haxes,'UserData',AxeData);
563
564function [RangeX,RangeY]=set_plane_bounds(theta,OriginCoord,Field)   
565
566iX=[1;0;0];
567iY=[0;1;0];
568iZ=[0;0;1];
569% [iX_proj,iY_proj]=rotate_vector(-PlaneAngle,iX,iY,iZ);%initial coordinates of the new base vector along X and Y
570maxnX=[];
571minnX=[];
572Max_vec=[Field.XMax Field.YMax Field.ZMax];
573Min_vec=[Field.XMin Field.YMin Field.ZMin];
574RangeY=[Field.ZMin Field.ZMax]-OriginCoord(3);% bound on Z become bound on the new z axis at 90 ?
575iX_proj(1)=cos(theta);%cosine of the angle of the new axis with x
576iX_proj(2)=sin(theta);
577OriginCoord(3)=[];% work of the bounds in x, y
578%bounds from the input field acting on the new X axis
579ind_bound=find(iX_proj~=0);% dimensions for which the bound acts
580Max_vec_X=(Max_vec(ind_bound)-OriginCoord(ind_bound))./iX_proj(ind_bound);%Abscissa of upper edge in the new coordinates
581Min_vec_X=(Min_vec(ind_bound)-OriginCoord(ind_bound))./iX_proj(ind_bound);%Abscissa of lower edge in the new coordinates
582%lower bound of X
583RangeX(1)=max(min(Max_vec_X,Min_vec_X));
584%upper bound of X
585RangeX(2)=min(max(Max_vec_X,Min_vec_X));%must be with the field range along each coordinate x,y,z
586
587
588
589
590
Note: See TracBrowser for help on using the repository browser.