source: trunk/src/mouse_motion.m @ 1172

Last change on this file since 1172 was 1169, checked in by sommeria, 3 months ago

civ3 introduced

File size: 26.9 KB
RevLine 
[11]1%'mouse_motion': permanently called by mouse motion over a figure (Callback for 'WindowButtonMotionFcn' of the figure)
2%-----------------------------------------------------------------------
3%
4% function mouse_motion(hObject,eventdata,handles)
5% activated by the command:
6% set(hObject,'WindowButtonMotionFcn',{'mouse_motion',handles})
7% where hObject is the handle of the figure
[809]8
9%=======================================================================
[1126]10% Copyright 2008-2024, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
[809]11%   http://www.legi.grenoble-inp.fr
[1127]12%   Joel.Sommeria - Joel.Sommeria (A) univ-grenoble-alpes.fr
[11]13%
14%     This file is part of the toolbox UVMAT.
[809]15%
[11]16%     UVMAT is free software; you can redistribute it and/or modify
[809]17%     it under the terms of the GNU General Public License as published
18%     by the Free Software Foundation; either version 2 of the license,
19%     or (at your option) any later version.
20%
[11]21%     UVMAT is distributed in the hope that it will be useful,
22%     but WITHOUT ANY WARRANTY; without even the implied warranty of
23%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
[809]24%     GNU General Public License (see LICENSE.txt) for more details.
25%=======================================================================
[11]26
27function mouse_motion(hObject,eventdata,handles)
[78]28
[187]29FigData=get(hObject,'UserData');
30if 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
[625]31    hCurrentFig=get(get(FigData,'parent'),'parent');
[187]32else
[625]33    hCurrentFig=hObject;%usual plot
[187]34end
[714]35if strcmp(get(hCurrentFig,'Pointer'),'watch')
36    return % no action if a calculation is running
37end
[625]38hhCurrentFig=guidata(hCurrentFig);%handles of the elements in the GUI containing the current figure (uvmat or view_field)
[622]39CheckZoom=get(hhCurrentFig.CheckZoom,'Value');% check for zoom on mode
40CheckZoomFig=get(hhCurrentFig.CheckZoomFig,'Value');% check for zoom sub fig creation mode
[625]41hPlotAxes=hhCurrentFig.PlotAxes';% handles of the main plot axes
42AxeData=get(hPlotAxes,'UserData');% data attached to the axis
[627]43htext_display(1)=handles.text_display;
44if isfield(AxeData,'htext_display')&&ishandle(AxeData.htext_display)
45    htext_display(2)=AxeData.htext_display;
46end
[625]47test_draw=0;%test for mouse drawing of object, =0 by default
48if isfield(AxeData,'Drawing')&& ~isempty(AxeData.Drawing)
49    test_draw=~isequal(AxeData.Drawing,'off');%=1 if mouse drawing of object is active
50end
[622]51test_zoom_draw=0;
[150]52test_object=0; %test for object editing or creation
[701]53test_create_object=0;
[681]54test_edit_object=0;% edit test for mouse shape: an arrow
[150]55test_ruler=0;%test for active ruler
[663]56test_transform=0;
[150]57huvmat=findobj(allchild(0),'tag','uvmat');%find the uvmat interface handle
[71]58if ~isempty(huvmat)
[432]59    hhuvmat=guidata(huvmat);%handles of the elements in uvma
[701]60    test_create_object=strcmp(get(hhuvmat.MenuObject,'checked'),'on');
[650]61    test_edit_object=get(hhuvmat.CheckEditObject,'Value');
[156]62    test_ruler=isequal(get(hhuvmat.MenuRuler,'checked'),'on');
[664]63    test_transform=~isequal(get(hhuvmat.TransformName,'Value'),1);
[150]64end
[231]65test_piv=0;
[856]66if isfield(FigData,'CivHandle')% look for handle of the civ_input GUI
[231]67    if ~ishandle(FigData.CivHandle)
68        delete(hObject)
[682]69        set(hCurrentFig,'Pointer','arrow');
[231]70        return
71    end
[856]72    hhciv=guidata(FigData.CivHandle);% list of handles in the GUI civ_input
[231]73    test_piv=1;
[150]74end
[432]75%find the current axe 'CurrentAxes' and display the current mouse position or uicontrol tag
[11]76text_displ_1='';
77text_displ_2='';
78text_displ_3='';
79text_displ_4='';
80
[625]81% AxeData=[];%default
[67]82xy=[];%default
[741]83set(hCurrentFig,'Units','normalized')
[622]84xy_fig=get(hObject,'CurrentPoint');% current point of the current figure (gcbo)
[11]85pointershape='arrow';% default pointer is an arrow
[150]86
[432]87%% loop on all the objects in the current figure, detect whether the mouse is over a plot  axes
[622]88hchildren=get(hObject,'Children');%handles of all objects in the current figure
89check_visible=strcmp(get(hchildren,'Visible'),'on');% if visible='on', =0 otherwise
90hchildren=hchildren(check_visible); %kkep only the visible children
91PosChildren=get(hchildren,'Position');% set of object positions
92if iscell(PosChildren)% only one child
93    PosLength=cellfun('length',PosChildren);% set of vector lengths for object positions
94    hchildren=hchildren(PosLength==4);% keep only objects with position defined by a 4 element vector
95    PosChildren=cell2mat(PosChildren(PosLength==4));% convert cells to matrix of positions
96end
97if size(PosChildren,2)~=4
[682]98    set(hCurrentFig,'Pointer','arrow');
[622]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
[432]105CurrentAxes=[];
[622]106
107%if the mouse is over an axis, look at the data
[682]108htype=get(hchild,'Type');
109if strcmp(htype,'axes')
[622]110    CurrentAxes=hchild;
111    xy=get(CurrentAxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
112    test_zoom_draw=test_draw && isequal(AxeData.Drawing,'zoom')&& isfield(AxeData,'CurrentOrigin') && isequal(get(gcf,'SelectionType'),'normal');
113    test_object=test_draw && isfield(AxeData,'CurrentObject') && ~isempty(AxeData.CurrentObject) && ishandle(AxeData.CurrentObject);
[701]114    if CheckZoom
115           pointershape='zoom';
116    elseif CheckZoomFig
117            pointershape='zoomfig';
118    elseif ~test_edit_object  && ~test_ruler
[699]119        if CheckZoom
120           pointershape='zoom';
[701]121        elseif test_draw|| test_create_object
122            pointershape='crosshair';%set pointer with cross shape
[699]123        else
[886]124        pointershape='crosshair';%set pointer with large cross (default when mouse is over an axis)
[699]125        end
[622]126    end
[859]127    FigData=get(hCurrentFig,'UserData'); % user data of the current figure
128    tagaxes=get(CurrentAxes,'tag'); % tag name of the current axes, for instance PlotAxes
[622]129    if isfield(FigData,tagaxes)
[859]130        Field=FigData.(tagaxes); % the current field is sought as substructure of FigData with key tagaxes
[1009]131
[622]132        if isfield(Field,'ListVarName')
133            [CellInfo,NbDimArray]=find_field_cells(Field);%analyse the physical fields contained in Field
134            text_displ_1='';
135            text_displ_2='';
136            text_displ_3='';
137            text_displ_4='';
138            text_displ_5='';
139            ivec=[];
140            xName='';
141            z=[];
142            for icell=1:numel(CellInfo)%look for all physical fields
143                if NbDimArray(icell)>=2 % select 2D field
144                    if  isfield(Field,'CoordMesh') && ~isempty(Field.CoordMesh)&& strcmp(CellInfo{icell}.CoordType,'scattered')%case of unstructured data
145                        X=Field.(Field.ListVarName{CellInfo{icell}.CoordIndex(end)});
146                        Y=Field.(Field.ListVarName{CellInfo{icell}.CoordIndex(end-1)});
147                        flag_vec=(X<(xy(1,1)+Field.CoordMesh/3) & X>(xy(1,1)-Field.CoordMesh/3)) & ...%flagx=1 for the vectors with x position selected by the mouse
148                            (Y<(xy(1,2)+Field.CoordMesh/3) & Y>(xy(1,2)-Field.CoordMesh/3));%f
149                        ivec=find(flag_vec,1);% search the (first) selected vector index ivec
150                        hhh=findobj(CurrentAxes,'Tag','vector_marker');
151                        if ~isempty(ivec)
152                            % mark the vectors with a circle in the absence of other operations
153                            if ~test_object && ~test_edit_object && ~test_ruler && ~CheckZoomFig
154                                pointershape='arrow'; %mouse indicates  the detection of a vector
155                                if isempty(hhh)
[625]156                                    set(0,'CurrentFigure',hCurrentFig)
157                                    set(hCurrentFig,'CurrentAxes',CurrentAxes)
[622]158                                    rectangle('Curvature',[1 1],...
159                                        'Position',[X(ivec)-Field.CoordMesh/2 Y(ivec)-Field.CoordMesh/2 Field.CoordMesh Field.CoordMesh],'EdgeColor','m',...
160                                        'LineStyle','-','Tag','vector_marker');
[251]161                                else
[622]162                                    set(hhh,'Visible','on')
163                                    set(hhh,'Position',[X(ivec)-Field.CoordMesh/2 Y(ivec)-Field.CoordMesh/2 Field.CoordMesh Field.CoordMesh])
[251]164                                end
[622]165                            end
166                            %display the field values
[1158]167                                if isfield (CellInfo{icell},'XName')
168                                    XName=CellInfo{icell}.XName;
169                                    text_displ_2=[XName '=' num2str(Field.(XName)(ivec),4)];
170                                end
171                                if isfield (CellInfo{icell},'YName')
172                                    YName=CellInfo{icell}.YName;
173                                    text_displ_2=[text_displ_2 ',' YName '=' num2str(Field.(YName)(ivec),4)];
174                                end
[622]175                            for ivar=1:numel(CellInfo{icell}.VarIndex)
176                                VarName=Field.ListVarName{CellInfo{icell}.VarIndex(ivar)};
177                                VarVal=Field.(VarName)(ivec);
178                                var_text=[VarName '=' num2str(VarVal,4) ','];
[1158]179 
[622]180                                if isequal(ivar,CellInfo{icell}.CoordIndex(end))||isequal(ivar,CellInfo{icell}.CoordIndex(end-1))||isequal(ivar,CellInfo{icell}.CoordIndex(1))
181                                    text_displ_1=[text_displ_1 var_text];
182                                elseif (isfield(CellInfo{icell},'VarIndex_vector_x') && isequal(ivar,CellInfo{icell}.VarIndex_vector_x))||isequal(ivar,CellInfo{icell}.VarIndex_vector_y)||...
183                                        (isfield(CellInfo{icell},'VarIndex_vector_z') && isequal(ivar,CellInfo{icell}.VarIndex_vector_z))
184                                    text_displ_4=[text_displ_4 var_text];
185                                else
186                                    text_displ_5=[text_displ_5 var_text];
[105]187                                end
[61]188                            end
[622]189                        else
190                            if ~isempty(hhh)
191                                set(hhh,'Visible','off')
192                            end
[71]193                        end
[622]194                    elseif strcmp(CellInfo{icell}.CoordType,'grid') %structured coordinates
195                        yName=Field.ListVarName{CellInfo{icell}.CoordIndex(1)};
196                        xName=Field.ListVarName{CellInfo{icell}.CoordIndex(2)};
197                        y=Field.(yName);
198                        x=Field.(xName);
199                        VarName=Field.ListVarName{CellInfo{icell}.VarIndex(1)};
200                        nxy=size(Field.(VarName));
201                        MaxAY=max(y(1),y(end));
202                        MinAY=min(y(1),y(end));
203                        if (xy(1,1)>x(1))&(xy(1,1)<x(end))&(xy(1,2)<MaxAY)&(xy(1,2)>MinAY)
204                            indx0=1+round((nxy(2)-1)*(xy(1,1)-x(1))/(x(end)-x(1))); % index x of pixel
205                            indy0=1+round((nxy(1)-1)*(xy(1,2)-y(1))/(y(end)-y(1))); % index y of pixel
206                            if indx0>=1 & indx0<=nxy(2) & indy0>=1 & indy0<=nxy(1)
207                                text_displ_2=['i='  num2str(indx0) ',j=' num2str(indy0) ','];
208                                for ivar=1:numel(CellInfo{icell}.VarIndex)
209                                    VarName=Field.ListVarName{CellInfo{icell}.VarIndex(ivar)};
210                                    VarVal=Field.(VarName)(indy0,indx0,:);
211                                    var_text=[VarName '=' num2str(VarVal) ','];
212                                    text_displ_4=[text_displ_4 var_text];
213                                end
214                            end
[251]215                        end
216                    end
[622]217                end
218            end
219            % display the current x,y plot coordinates in the absence of detected vector
220            if isempty(ivec)
221                if isempty(xName)
222                    xName='x';
223                    yName='y';
224                end
225                text_displ_1=[xName '=' num2str(xy(1,1),4) ', ' yName '=' num2str(xy(1,2),4) ','];
226            end
[970]227            %display the original phys x,y,z coordinates if defined by the projection plane
[741]228            if isfield(Field,'ProjObjectType') && strcmp(Field.ProjObjectType,'plane') && isfield(Field,'ProjObjectCoord') && length(Field.ProjObjectCoord)>=3
[970]229                pos=[xy(1,1) xy(1,2) 0];%coordinates on the graph
[741]230                if isfield(Field,'ProjObjectAngle')&&~isequal(Field.ProjObjectAngle,[0 0 0])
[1087]231                    [norm_plane(1) norm_plane(2) norm_plane(3)] =rotate_vector(Field.ProjObjectAngle*pi/180,0,0,1);%angle2normal(Field.ProjObjectAngle);
[1078]232                    pos(3)=-(norm_plane(1)*(pos(1)-Field.ProjObjectCoord(1))+norm_plane(2)*(pos(2)-Field.ProjObjectCoord(2)))/norm_plane(3);                               
[622]233                end
[1078]234                pos(3)=pos(3)+Field.ProjObjectCoord(3);
[622]235                text_displ_3=[text_displ_3 'x,y,z=' num2str(pos,4)];
236            end
237            % case of PIV correlation display
238            if test_piv
[856]239               [dd,ind_pt]=min(abs(Field.X-xy(1,1))+abs(Field.Y-xy(1,2)));
240                   Param.CheckCiv2=0;
241                   par_civ=read_GUI(hhciv.Civ1);%read the Civ1 panel in civ_input
242                   shiftx=par_civ.SearchBoxShift(1);
243                   shifty=par_civ.SearchBoxShift(2);
[622]244                xround=Field.X(ind_pt);
245                yround=Field.Y(ind_pt);
[856]246               
[859]247                % mark the correlation box with a rectangle in view_field
[856]248                ibx2=floor((par_civ.CorrBoxSize(1)-1)/2);
249                iby2=floor((par_civ.CorrBoxSize(2)-1)/2);
[1163]250                isx2=par_civ.SearchRange(1);
251                isy2=par_civ.SearchRange(2);
[622]252                hhh=findobj(CurrentAxes,'Tag','PIV_box_marker');
253                hhhh=findobj(CurrentAxes,'Tag','PIV_search_marker');
254                if isempty(hhh)
[625]255                    set(0,'CurrentFigure',hCurrentFig)
256                    set(hCurrentFig,'CurrentAxes',CurrentAxes)
[622]257                    rectangle('Curvature',[0 0],...
258                        'Position',[xround-ibx2 yround-iby2 2*ibx2 2*iby2],'EdgeColor','m',...
259                        'LineStyle','-','Tag','PIV_box_marker');
260                    rectangle('Curvature',[0 0],...
[1168]261                        'Position',[xround-isx2-ibx2+shiftx yround-isy2-iby2+shifty 2*isx2+2*ibx2 2*isy2+2*iby2],'EdgeColor','m',...
[622]262                        'LineStyle','- -','Tag','PIV_search_marker');
263                else
264                    set(hhh,'Position',[xround-ibx2 yround-iby2 2*ibx2 2*iby2])
[1168]265                    set(hhhh,'Position',[xround-isx2-ibx2+shiftx yround-isy2-iby2+shifty 2*isx2+2*ibx2 2*isy2+2*iby2])
[622]266                end
[856]267               
268                % perform the PIV calculation as the single point xround yround
269                par_civ.ImageA=Field.A;
270                par_civ.ImageB=Field.B;
271                par_civ.ImageHeight=size(par_civ.ImageA,1);
272                par_civ.ImageWidth=size(par_civ.ImageA,2);
273                par_civ.Grid=[xround yround];% PIV calculation with a single point
[1169]274                [~,~,utable,vtable,~,~,result_conv,errormsg]= civ(par_civ);
[622]275                if ~isempty(errormsg)
276                    text_displ_5=errormsg;
277                else
[1168]278                    rangx(1)=-isx2+shiftx;
279                    rangx(2)=isx2+shiftx;
280                    rangy(1)=-isy2-shifty;
281                    rangy(2)=isy2-shifty;
[622]282                    hcorr=[];
283                    if isfield(AxeData,'CurrentCorrImage')
284                        hcorr=AxeData.CurrentCorrImage;
285                        if ~ishandle(hcorr)
286                            hcorr=[];
[207]287                        end
[11]288                    end
[622]289                    if isempty(hcorr)
290                        corrfig=findobj(allchild(0),'tag','corrfig');
291                        if ~isempty(corrfig)
292                            set(0,'CurrentFigure',corrfig(1))
[862]293                            AxeData.CurrentCorrImage=imagesc(rangx,-rangy,result_conv,[0 1]);% plot the correlation map, with full colormap from 0 to 1
[1169]294                            AxeData.CurrentVector=line([0 utable],[0 vtable],'Tag','vector');
[862]295                            AxeData.TitleHandle=title(['[x,y]= ' num2str(par_civ.Grid) ' px']);
[622]296                            colorbar
297                            set(CurrentAxes,'UserData',AxeData)
[862]298                            ParentAxe=get(AxeData.CurrentCorrImage,'parent');
299                            set(ParentAxe,'YDir','normal')
300                             set(ParentAxe,'DataAspectRatio',[1 1 1]); %equal axis scale
[150]301                        end
[622]302                    else
303                        set(AxeData.CurrentCorrImage,'CData',result_conv)
304                        set(AxeData.CurrentCorrImage,'XData',rangx)
305                        set(AxeData.CurrentCorrImage,'YData',-rangy)
[862]306                        ParentAxe=get(AxeData.CurrentCorrImage,'parent');
307                        rangx(1)=min(rangx(1),0);
308                        rangx(2)=max(rangx(2),0);
309                        rangy(2)=max(rangy(2),0);
310                        rangy(1)=min(rangy(1),0);
311                         set(ParentAxe,'XLim',rangx)
312                         set(ParentAxe,'YLim',[-rangy(2) -rangy(1)])
[1169]313                        set(AxeData.CurrentVector,'XData',[0 utable],'YData',[0 vtable]);
[862]314                        set(AxeData.TitleHandle,'String',['[x,y]= ' num2str(par_civ.Grid) ' px'])
[11]315                    end
316                end
[251]317            end
[11]318        end
319    end
320end
[292]321if ~isempty(text_displ_1)
[542]322    text_displ=[{text_displ_1};{text_displ_2};{text_displ_3};{text_displ_4};{text_displ_5}];
323    ind_blank=find(strcmp('',text_displ));
324    if ~isempty(ind_blank)
325        text_displ(ind_blank)=[];
326    end
[627]327    set(htext_display,'String',text_displ)
[292]328else
[627]329   set(htext_display,'String',get(handles.text_display,'UserData'))
[292]330end
[11]331
[71]332%%%%%%%%%%%%%
[622]333%% draw a zoom rectangle if checkZoomFig has been selected
[71]334if test_zoom_draw
[622]335   xy_rect=AxeData.CurrentOrigin;% mark the previous position from mouse down
[71]336   if ~isempty(xy_rect)
337        rect(1)=min(xy(1,1),xy_rect(1));%origin rectangle, x coordinate
338        rect(2)=min(xy(1,2),xy_rect(2));%origin rectangle, y coordinate
339        rect(3)=abs(xy(1,1)-xy_rect(1));%rectangle width
340        rect(4)=abs(xy(1,2)-xy_rect(2));%rectangle height
[622]341        if rect(3)>0 && rect(4)>0
342            if isfield(AxeData,'CurrentRectZoom')&& ~isempty(AxeData.CurrentRectZoom) && ishandle(AxeData.CurrentRectZoom)
[71]343                set(AxeData.CurrentRectZoom,'Position',rect);%update the rectangle position
344            else
[622]345                AxeData.CurrentRectZoom=rectangle('Position',rect,'Tag','rect_zoom','EdgeColor','b');
[432]346                set(CurrentAxes,'UserData',AxeData)
[71]347            end
348        end
349   end
350end
351
[11]352%%%%%%%%%%%%%%%%%
[150]353%% create or modify an object
[682]354if strcmp(htype,'axes') && ~isempty(huvmat) && test_object
[432]355    UvData=get(huvmat,'UserData');
[11]356    PlotData=get(AxeData.CurrentObject,'UserData');
[432]357    if ~isfield(PlotData,'IndexObj')
[682]358        set(hCurrentFig,'Pointer','arrow');
[432]359        return
360    end
[966]361    if numel(UvData.ProjObject)<PlotData.IndexObj
362        return
363    end
[622]364    ObjectData=UvData.ProjObject{PlotData.IndexObj};
[432]365    if isequal(hObject,huvmat)% if the mouse ifs over the GUI uvmat
[966]366        if numel(UvData.ProjObject)<get(hhuvmat.ListObject_1,'Value')
367            return
368        end
[622]369        ProjObject=UvData.ProjObject{get(hhuvmat.ListObject_1,'Value')};
[432]370    else
[966]371        if numel(UvData.ProjObject)<get(hhuvmat.ListObject,'Value')
372            return
373        end
[622]374        ProjObject=UvData.ProjObject{get(hhuvmat.ListObject,'Value')};
[432]375    end
376    XYData=AxeData.CurrentOrigin;
[1080]377 
[432]378    if isequal(AxeData.Drawing,'create') && isfield(AxeData,'CurrentOrigin') && ~isempty(AxeData.CurrentOrigin)
[954]379        switch ObjectData.Type
[1072]380            case {'line','polyline','polygon','points'}
[954]381                ObjectData.Coord=[ObjectData.Coord ;xy(1,1:2)];
[1080]382                plot_object(ObjectData,ProjObject,AxeData.CurrentObject,'m');
[954]383            case {'rectangle','ellipse','volume'}
384                ObjectData.Coord=(AxeData.CurrentOrigin+xy(1,1:2))/2;% keep only the first point coordinate
[622]385                ObjectData.RangeX=abs(ObjectData.Coord(1,1)-xy(1,1));%rectangle width
[954]386                ObjectData.RangeY=abs(ObjectData.Coord(1,2)-xy(1,2));%rectangle height
[1080]387                plot_object(ObjectData,ProjObject,AxeData.CurrentObject,'m');
[954]388            case 'plane' %case of 'plane'
389                DX=(xy(1,1)-ObjectData.Coord(1,1));
390                DY=(xy(1,2)-ObjectData.Coord(1,2));
391                ObjectData.Phi=(angle(DX+i*DY))*180/pi;%rectangle widt
392                if isfield(ObjectData,'RangeX')
393                    XMax=sqrt(DX*DX+DY*DY);
394                    if XMax>max(ObjectData.RangeX)
395                        ObjectData.RangeX=[min(ObjectData.RangeX) XMax];
396                    end
[11]397                end
[1080]398                hline=findobj(hPlotAxes,'Tag','mouse_line');
399                if isempty(hline)
400                    hline=line([AxeData.CurrentOrigin(1) xy(1,1)],[AxeData.CurrentOrigin(2) xy(1,2)],'Tag','mouse_line');
401                else
402                    set(hline,'XData',[AxeData.CurrentOrigin(1) xy(1,1)])
403                    set(hline,'YData',[AxeData.CurrentOrigin(2) xy(1,2)])
404                end
[11]405        end
[1080]406
[432]407        pointershape='crosshair';
[681]408    elseif test_edit_object && isequal(AxeData.Drawing,'translate')
[432]409        DX=xy(1,1)-XYData(1);%translation from initial position
410        DY=xy(1,2)-XYData(2);
411        ObjectData.Coord(:,1)=ObjectData.Coord(:,1)+DX;
412        ObjectData.Coord(:,2)=ObjectData.Coord(:,2)+DY;
413        plot_object(ObjectData,ProjObject,AxeData.CurrentObject,'m');
414        pointershape='fleur';
[681]415    elseif test_edit_object && isequal(AxeData.Drawing,'deform')
[432]416        ind_move=AxeData.CurrentIndex;
417        ObjectData.Coord(ind_move,1)=xy(1,1);
418        ObjectData.Coord(ind_move,2)=xy(1,2);
419        plot_object(ObjectData,ProjObject,AxeData.CurrentObject,'m');
420        pointershape='circle';
[11]421    end
[432]422end
[67]423
[150]424%% detect calibration points if the GUI geometry_calib is opened
[67]425h_geometry_calib=findobj(allchild(0),'Name','geometry_calib'); %find the geomterty_calib GUI
[682]426if strcmp(htype,'axes') && ~CheckZoom && ~isempty(h_geometry_calib)
[67]427    pointershape='crosshair';%default for geometry_calib: ready to create new points
428    hh_geometry_calib=guidata(h_geometry_calib);
[156]429    if  ~isempty(xy) && isfield(hh_geometry_calib,'ListCoord')
[67]430        h_ListCoord=hh_geometry_calib.ListCoord; %findobj(h_geometry_calib,'Tag','ListCoord');
[657]431        data.Coord=get(h_ListCoord,'Data');
432        if isnumeric(data.Coord)&&~isempty(data.Coord)
[663]433            if test_transform
[738]434                XCoord=(data.Coord(:,1));
435                YCoord=(data.Coord(:,2));
[663]436            else
[738]437                XCoord=(data.Coord(:,4));
438                YCoord=(data.Coord(:,5));
[663]439            end
[432]440            xy=get(CurrentAxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
[67]441            if ~isempty(xy)
[432]442                xlim=get(CurrentAxes,'XLim');
[738]443%                 ind_range_x=abs((xlim(2)-xlim(1))/50);
[432]444                ylim=get(CurrentAxes,'YLim');
[738]445                ind_range=max(abs(xlim(2)-xlim(1)),abs(ylim(end)-ylim(1)))/25;%defines the size of the circle marker
446%                 ind_range_y=abs((ylim(2)-ylim(1))/50);
447%                 ind_range=sqrt(ind_range_x*ind_range_y);
448                index_point=find((XCoord<xy(1,1)+ind_range/2) & (XCoord>xy(1,1)-ind_range/2) & ...%flagx=1 for the vectors with x position selected by the mouse
449                    (YCoord<xy(1,2)+ind_range/2) & (YCoord>xy(1,2)-ind_range/2),1);%find the first calibration point in the neighborhood of the mouse
[67]450                if ~isempty(index_point)
[738]451                    pointershape='arrow';% default pointer is an arrow
[78]452                end
453                hh=findobj('Tag','calib_points');%look for handle of calibration points
[738]454                if ~isempty(hh) && ~isempty(get(hh,'UserData')) %&& get(hh_geometry_calib.CheckEnableMouse,'Value')
455                    %set(hh,'UserData',index_point)
[173]456                    index_point=get(hh,'UserData');
[1143]457                    if isnumeric(index_point)
[78]458                    XCoord(index_point)=xy(1,1);
459                    YCoord(index_point)=xy(1,2);
460                    set(hh,'XData',XCoord)
461                    set(hh,'YData',YCoord)
[1143]462                    end
[738]463                end
[1143]464                if ~isempty(index_point)&& isnumeric(index_point)
[738]465                    set(hh_geometry_calib.CoordLine,'String',num2str(index_point))
466                   % Data=get(h_ListCoord,'Data');
467%                     Data(:,6)=zeros(size(Data,1),1);
468%                     Data(index_point,6)=-1;%mrk the point on the GUI geometry_calib
469%                     set(h_ListCoord,'Data',Data);
[67]470                    hhh=findobj('Tag','calib_marker');%look for handle of point marker (circle)
471                    if ~isempty(hhh)
[71]472                        set(hhh,'Position',[XCoord(index_point)-ind_range/2 YCoord(index_point)-ind_range/2 ind_range ind_range])
[657]473                    else
[837]474                        axes(hchild)
[738]475                        rectangle('Curvature',[1 1],...
476                            'Position',[XCoord(index_point)-ind_range/2 YCoord(index_point)-ind_range/2 ind_range ind_range],'EdgeColor','m',...
477                            'LineStyle','-','Tag','calib_marker');
[67]478                    end
[78]479                end
[67]480            end
481        end
482    end
483end
484
[150]485%% draw ruler
[156]486if test_ruler && isfield(AxeData,'Drawing') && isequal(AxeData.Drawing,'ruler')
[1112]487    if isfield(AxeData,'RulerHandle') && ~isempty(findobj(AxeData.RulerHandle)) && size(xy,2)>=2
[156]488        pointershape='crosshair'; %give  the mouse pointer a cross shape
489        RulerCoord=[AxeData.RulerCoord ;xy(1,1:2)]; %coordinates defining the ruler segment
490        set(AxeData.RulerHandle,'XData',RulerCoord(:,1));% updtate the x coordinates for the ruler graphic object
491        set(AxeData.RulerHandle,'YData',RulerCoord(:,2));% updtate the y coordinates for the ruler graphic object
492    end
[60]493end
[150]494
495%% update the mouse pointer
[699]496if strcmp(pointershape,'zoom')||strcmp(pointershape,'zoomfig')
497    CData=set_pointershape(pointershape);
498    set(hCurrentFig,'Pointer','custom','PointerShapeCData',CData,'PointerShapeHotSpot',[9 9])
499else
[625]500set(hCurrentFig,'Pointer',pointershape);
[699]501end
502
503function CData=set_pointershape(pointershape)
504        CData=ones(16,16);
505        [ind_x,ind_y]=meshgrid([1:16],[1:16]);
506        if strcmp(pointershape,'zoom')
507        radius=(ind_x-9).*(ind_x-9)+(ind_y-8.5).*(ind_y-9);
508        CData(radius<25 & radius>16)=2; %make white circle
509        CData(radius<16 | radius>40)=NaN; %make the centre transparent
510        CData(16,16)=1; CData(15,16)=2;
511        CData(15,15)=1; CData(14,15)=2;
512        CData(14,14)=1; CData(13,14)=2;
513        CData(13,13)=1; CData(12,13)=2;
514        elseif strcmp(pointershape,'zoomfig')
515            CData(:,1:3)=2;
516            CData(:,14:16)=2;
517                        CData(1:3,:)=2;
518            CData(14:16,:)=2;
519            CData(CData==1)=NaN;
520        end
Note: See TracBrowser for help on using the repository browser.