Index: trunk/src/mouse_up.m
===================================================================
--- trunk/src/mouse_up.m	(revision 623)
+++ trunk/src/mouse_up.m	(revision 625)
@@ -25,40 +25,46 @@
 
 test_ruler=0;%default
-hcurrentfig=hObject;
-fig_tag=get(hcurrentfig,'tag');
-currentaxes=gca; %store the current axes handle
-AxeData=get(currentaxes,'UserData');
+AxeData=get(gca,'UserData');
+if isfield(AxeData,'ParentAxes')% case of a zoom plot as current axis
+    hcurrentaxes=AxeData.ParentAxes;
+    AxeData=get(hcurrentaxes,'UserData');
+    hcurrentfig=get(hcurrentaxes,'parent');%handles of the GUI parent of the zoom plot
+    testsubplot=1;% mouse selection is on a zoom subplot
+else
+    hcurrentfig=hObject;
+    hcurrentaxes=gca; %store the current axes handle
+    testsubplot=0;
+end
 CurrentOrigin=[];
 if isfield(AxeData,'CurrentOrigin')
     CurrentOrigin=AxeData.CurrentOrigin;
 end
-if isfield(AxeData,'ParentRect')% case of a zoom plot as current axis
-    parentaxes=get(AxeData.ParentRect,'parent');
-    AxeData=get(parentaxes,'UserData');
-    controlGUI=get(parentaxes,'parent');%handles of the GUI parent of the zoom plot
-    hhcurrentfig=guidata(controlGUI);
-    testsubplot=1;
-else
-    hhcurrentfig=guidata(hcurrentfig);%the current figure is a GUI (uvmat or view_field)
-    testsubplot=0;
-end
-test_zoom=get(hhcurrentfig.CheckZoom,'Value');
-
+FigTag=get(hcurrentfig,'tag');
+hhcurrentfig=guidata(hcurrentfig);%the current figure is a GUI (uvmat or view_field)
+CheckZoom=get(hhcurrentfig.CheckZoom,'Value');
+CheckZoomFig=get(hhcurrentfig.CheckZoomFig,'Value');%exclusive to CheckZoom
 huvmat=findobj(allchild(0),'tag','uvmat');%find the uvmat interface handle
 if ~isempty(huvmat)
     hhuvmat=guidata(huvmat);
     UvData=get(huvmat,'UserData');
-   test_ruler=~test_zoom && isequal(get(hhuvmat.MenuRuler,'checked'),'on');%test for ruler  action, second priority
-end
-test_drawing=0;%default
-
-%% finalize the fabrication or the translation/deformation of an object and plot the corresponding projected field
+   test_ruler=~CheckZoom && isequal(get(hhuvmat.MenuRuler,'checked'),'on');%test for ruler  action, second priority
+end
+test_drawing=0;%default, =1 to allow drawing by further mouse action
+xy=get(gca,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
+
+
+%% proceed with the creation or editing (translation/deformation) of an object
 if ~isempty(huvmat) && isfield(AxeData,'Drawing') && ~isequal(AxeData.Drawing,'off') && isfield(AxeData,'CurrentObject')...
         && ~isempty(AxeData.CurrentObject) && ishandle(AxeData.CurrentObject)
-    xy=get(currentaxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
+    %     xy=get(currentaxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
     PlotData=get(AxeData.CurrentObject,'UserData');%get data attached to the current projection object
     IndexObj=PlotData.IndexObj;
     ObjectData=UvData.ProjObject{IndexObj};
     check_multiple=0;
+    
+    h_set_object=findobj(allchild(0),'Tag','set_object');
+    hh_set_object=guidata(h_set_object);
+    ObjectData.Coord=get(hh_set_object.Coord,'Data');
+    
     % ending translation
     if isequal(AxeData.Drawing,'translate')
@@ -69,5 +75,5 @@
         ObjectData.Coord(:,2)=ObjectData.Coord(:,2)+DY;
         
-    %ending object deformation
+        %ending object deformation
     elseif isequal(AxeData.Drawing,'deform')
         ind_move=AxeData.CurrentIndex;
@@ -75,5 +81,5 @@
         ObjectData.Coord(ind_move,2)=xy(1,2);
         
-    %creating object
+        %creating object
     else
         switch ObjectData.Type
@@ -85,18 +91,18 @@
                 end
             case {'rectangle','ellipse','volume'}
-%                  if size(ObjectData.Coord,1)==1 % this is the mouse up for the first point, continue until next click
-%                     check_multiple=1;
-%                  else
-                ObjectData.Coord=(CurrentOrigin+xy(1,1:2))/2;% keep only the first point coordinate     
+                %                  if size(ObjectData.Coord,1)==1 % this is the mouse up for the first point, continue until next click
+                %                     check_multiple=1;
+                %                  else
+                ObjectData.Coord=(CurrentOrigin+xy(1,1:2))/2;% keep only the first point coordinate
                 ObjectData.RangeX=abs(ObjectData.Coord(1,1)-xy(1,1));%rectangle width
-                ObjectData.RangeY=abs(ObjectData.Coord(1,2)-xy(1,2));%rectangle height    
+                ObjectData.RangeY=abs(ObjectData.Coord(1,2)-xy(1,2));%rectangle height
                 if isequal(ObjectData.RangeX,0)||isequal(ObjectData.RangeY,0)
                     check_multiple=1;% pass to next mous up if width of height=0
                 end
-%                 ObjectData.Coord(1,1)=(xy(1,1)+XYData(1))/2;%origin rectangle, x coordinate
-%                 ObjectData.Coord(1,2)=(xy(1,2)+XYData(2))/2;
-%                 ObjectData.RangeX=abs(xy(1,1)-XYData(1))/2;%rectangle width
-%                 ObjectData.RangeY=abs(xy(1,2)-XYData(2))/2;%rectangle height
-%                  end
+                %                 ObjectData.Coord(1,1)=(xy(1,1)+XYData(1))/2;%origin rectangle, x coordinate
+                %                 ObjectData.Coord(1,2)=(xy(1,2)+XYData(2))/2;
+                %                 ObjectData.RangeX=abs(xy(1,1)-XYData(1))/2;%rectangle width
+                %                 ObjectData.RangeY=abs(xy(1,2)-XYData(2))/2;%rectangle height
+                %                  end
             case 'plane' %case of 'plane'
                 DX=(xy(1,1)-ObjectData.Coord(1,1));
@@ -110,24 +116,24 @@
                 end
             otherwise
-                check_multiple=1; 
+                check_multiple=1;
         end
     end
     
     %show object coordinates in the GUI set_object
-    h_set_object=findobj(allchild(0),'Tag','set_object');
-    hh_set_object=guidata(h_set_object);
-    set(hh_set_object.Coord,'Data',ObjectData.Coord);
+    %     h_set_object=findobj(allchild(0),'Tag','set_object');
+    %     hh_set_object=guidata(h_set_object);
+    %     set(hh_set_object.Coord,'Data',ObjectData.Coord);
     if strcmp(ObjectData.Type,'rectangle')||strcmp(ObjectData.Type,'ellipse')
         set(hh_set_object.num_RangeX_2,'String',num2str(ObjectData.RangeX,4));
         set(hh_set_object.num_RangeY_2,'String',num2str(ObjectData.RangeY,4));
     end
-
-    %stop drawing and plot projected field if the object manipulation is finished
+    
+    %% stop drawing and plot the projected field if the object manipulation is finished
     if check_multiple==0  || isequal(get(hcurrentfig,'SelectionType'),'alt')
         AxeData.CurrentOrigin=[]; %suppress the current origin
-        hobject=UvData.ProjObject{IndexObj}.DisplayHandle.(fig_tag);
+        hobject=UvData.ProjObject{IndexObj}.DisplayHandle.(FigTag);
         if ~isempty(hObject)
-         ProjObject=UvData.ProjObject{get(hhuvmat.ListObject_1,'Value')};
-        AxeData.CurrentObject=plot_object(ObjectData,ProjObject,hobject,'m');%draw the object and its handle becomes AxeData.CurrentObject
+            ProjObject=UvData.ProjObject{get(hhuvmat.ListObject_1,'Value')};
+            AxeData.CurrentObject=plot_object(ObjectData,ProjObject,hobject,'m');%draw the object and its handle becomes AxeData.CurrentObject
         end
         %%
@@ -136,5 +142,5 @@
             ProjData= proj_field(UvData.Field,ObjectData);%project the current interface field on ObjectData
             if ~isempty(ProjData)
-                if strcmp(fig_tag,'uvmat')% uvmat plot selected, projection plot seen in view_field
+                if strcmp(FigTag,'uvmat')% uvmat plot selected, projection plot seen in view_field
                     hview_field=findobj(allchild(0),'tag','view_field');
                     if isempty(hview_field)
@@ -159,61 +165,66 @@
                 else
                     UvData.PlotAxes=ProjData;
-                    [PlotType,PlotParam]=plot_field(ProjData,hhuvmat.PlotAxes,read_GUI(hhuvmat));%update an existing field plot
+                    [PlotType,PlotParam]=plot_field(ProjData,hhuvmat.PlotAxes,read_GUI(huvmat));%update an existing field plot
                     errormsg=fill_GUI(PlotParam,huvmat);
                 end
             end
             set(hhuvmat.ViewField,'Value',1);%
-            set(hhuvmat.edit_object,'BackgroundColor',[1 1 0]);% paint the edit text in yellow
-            set(hhuvmat.edit_object,'Value',1);%
+            set(hhuvmat.edit_object,'Value',1);%           
             set(hhuvmat.edit_object,'Enable','on');%
             set(hhuvmat.MenuEditObject,'Enable','on');%
             set(hhuvmat.MenuEdit,'Enable','on');%
+            set(get(h_set_object,'children'),'Enable','on')
+        end
+        UvData.ProjObject{IndexObj}=ObjectData;
+        if isfield(UvData.ProjObject{IndexObj},'CreateMode')
+            UvData.ProjObject{IndexObj}=rmfield(UvData.ProjObject{IndexObj},'CreateMode');%remove createMode to mark the object as finished
         end
     else
-%         test_drawing=1;%allow continuation of drawing object
-%          AxeData.CurrentOrigin=[xy(1,1) xy(1,2)]; %the current point becomes the next current origin
-    end
-    UvData.ProjObject{IndexObj}=ObjectData;
+        test_drawing=1;%allow continuation of drawing object
+        AxeData.CurrentOrigin=[xy(1,1) xy(1,2)]; %the current point becomes the next current origin
+    end
+    %     UvData.ProjObject{IndexObj}=ObjectData;
     hother=findobj('Tag','deformpoint');%find all the deformpoints
     set(hother,'Color','b');%reset all the deformpoints in 'blue'
 end
 
-%% creation of a new zoom plot
-if isequal(get(hcurrentfig,'SelectionType'),'normal');%if left button has been pressed
+%% creation or update of a  zoom sub-plot
+if CheckZoomFig && isequal(get(hcurrentfig,'SelectionType'),'normal')&&...%if left button has been pressed
+     ~isempty(CurrentOrigin) && ~isequal(CurrentOrigin(1),xy(1,1)) && ~isequal(CurrentOrigin(2),xy(1,2))%if mouse moved in x and y since presed down
     hparentfig=hcurrentfig;
     %open or update a new zoom figure if a rectangle has been drawn
-    if ishandle(currentaxes);
+    if ishandle(hcurrentaxes);
         if isfield(AxeData,'CurrentRectZoom') && ~isempty(AxeData.CurrentRectZoom) && ishandle(AxeData.CurrentRectZoom)
-            PosRect=get(AxeData.CurrentRectZoom,'Position');
+            %PosRect=get(AxeData.CurrentRectZoom,'Position');
             if isfield(AxeData,'CurrentVec') && ~isempty(AxeData.CurrentVec) && ishandle(AxeData.CurrentVec)
                 delete(AxeData.CurrentVec)
             end
-            if ~testsubplot
-                hfig2=figure;%create new figure
-                set(hfig2,'name','zoom')
-                set(0,'Unit','pixels')
-                set(hfig2,'Unit','pixels')
-                FigPos=get(hfig2,'Position');
-                ScreenSize=get(0,'ScreenSize');% get the size of the screen, to put the fig on the upper right
-                Left=ScreenSize(3)- FigPos(3)-40; %right edge close to the right, with margin=40 
-                Bottom=ScreenSize(4)-FigPos(4)-40; %put fig at top right
-                FigPos(1:2)=[Left Bottom];
-                set(hfig2,'Position',FigPos);
-                map=colormap(currentaxes);
-                colormap(map);%transmit the current colormap to the zoom fig
-                set(hfig2,'KeyPressFcn',{@keyboard_callback,handles})%set keyboard action function
-                set(hfig2,'WindowButtonMotionFcn',{@mouse_motion,handles})%set mouse action function
-                set(hfig2,'WindowButtonDownFcn',{@mouse_down})%set mouse click action function
-                set(hfig2,'WindowButtonUpFcn',{@mouse_up,handles})
-                set(hfig2,'DeleteFcn',{@close_fig,AxeData.CurrentRectZoom,'zoom'})
-                set(hfig2,'UserData',AxeData.CurrentRectZoom)% record the parent object (zoom rectangle) in the new fig
-                AxeData.ZoomAxes=copyobj(currentaxes,hfig2); %copy the current graph axes to the zoom figure
+            if ~testsubplot% if we are not already on a zoom plot
+                hfig2=findobj(allchild(0),'Tag','zoom_fig');
+                if isempty(hfig2)% create zoom sub plot if absent
+                    hfig2=figure('name',['zoom_' FigTag],'tag','zoom_fig');%create new figure (unit='pixels' by default)
+                    set(0,'Unit','pixels')
+                    FigPos=get(hfig2,'Position');%get the standard width and height of the fig
+                    ScreenSize=get(0,'ScreenSize');% get the size of the screen, to put the fig on the upper right
+                    Left=ScreenSize(3)- FigPos(3)-40; %right edge close to the right, with margin=40
+                    Bottom=ScreenSize(4)-FigPos(4)-40; %put fig at top right
+                    FigPos(1:2)=[Left Bottom];
+                    set(hfig2,'Position',FigPos);% put the zoom fig close to the upper right of the screen
+                    map=colormap(hcurrentaxes);
+                    colormap(map);%transmit the current colormap to the zoom fig
+                    set(hfig2,'KeyPressFcn',{@keyboard_callback,handles})%set keyboard action function
+                    set(hfig2,'WindowButtonMotionFcn',{@mouse_motion,handles})%set mouse action function
+                    set(hfig2,'WindowButtonDownFcn',{@mouse_down})%set mouse click action function
+                    set(hfig2,'WindowButtonUpFcn',{@mouse_up,handles})
+                else
+                    zoom_axes=findobj(hfig2,'Type','axes');%delete existing axes
+                    axes(zoom_axes);%make the zoom axes apparent
+                    delete(zoom_axes)
+                end
+                set(hfig2,'DeleteFcn',{@close_fig,AxeData.CurrentRectZoom})
+                set(hfig2,'UserData',AxeData.CurrentRectZoom)% record the parent object (zoom rectangle) in the new fig   
+                AxeData.ZoomAxes=copyobj(hcurrentaxes,hfig2); %copy the current graph axes to the zoom figure
                 hrect_zoom=findobj(AxeData.ZoomAxes,'Tag','rect_zoom');%find and delete the copy of the rect_zoom rectangle
                 delete(hrect_zoom)
-                ChildAxeData=get(AxeData.ZoomAxes,'UserData');
-                if isfield(ChildAxeData,'ParentGUI')
-                    ChildAxeData=rmfield(ChildAxeData,'ParentGUI');%no parent GUI, e.g. uvmat,  for the new plot
-                end
-                set(AxeData.ZoomAxes,'Position',[0.1300    0.1100    0.7750    0.8150])% standard axes position on a figure
                 hcol=findobj(hparentfig,'Tag','Colorbar'); %look for colorbar axes
                 if ~isempty(hcol)
@@ -228,12 +239,23 @@
                     set(hcol_new,'Yticklabel',YTicklabel);
                 end
-            end          
+                ChildAxeData=get(AxeData.ZoomAxes,'UserData');
+            end  
+            ChildAxeData.CurrentOrigin=[];% forget the current origin
             ChildAxeData.CurrentRectZoom=[]; % no rect zoom in the new window
             ChildAxeData.Drawing='off';
-            ChildAxeData.ParentRect=AxeData.CurrentRectZoom;%set the rectangle as a 'parent' associated to the new axe
-            PosRect=CurrentOrigin;
-            xy=get(currentaxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
-            set(AxeData.ZoomAxes,'Xlim',[PosRect(1) xy(1,1)])
-            set(AxeData.ZoomAxes,'Ylim',[PosRect(2) xy(1,2)])
+            ChildAxeData.ParentAxes=hcurrentaxes;
+            ChildAxeData.ParentRect=AxeData.CurrentRectZoom;%set the rectangle drawing as a 'parent' associated to the new axe
+            %PosRect=CurrentOrigin;
+           % xy=get(hcurrentaxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
+            if xy(1,1)>CurrentOrigin(1)
+            set(AxeData.ZoomAxes,'Xlim',[CurrentOrigin(1) xy(1,1)])
+            else
+                set(AxeData.ZoomAxes,'Xlim',[xy(1,1) CurrentOrigin(1)])
+            end
+            if xy(1,2)>CurrentOrigin(2)
+            set(AxeData.ZoomAxes,'Ylim',[CurrentOrigin(2) xy(1,2)])
+            else
+                set(AxeData.ZoomAxes,'Ylim',[xy(1,2) CurrentOrigin(2)])
+            end
             set(AxeData.ZoomAxes,'UserData',ChildAxeData);%update the AxeData of the new axes
         end
@@ -242,21 +264,26 @@
 
 %% zoom in or out by a factor 2 if no new figure is created
-if test_zoom
-    xy=get(currentaxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
-    xlim=get(currentaxes,'XLim');
-    ylim=get(currentaxes,'YLim');
+if CheckZoom
+    if testsubplot
+        haxes=gca;% zoom on a zoom sub-plot
+    else
+        haxes=hcurrentaxes;% zoom on the main plot
+    end
+   % xy=get(haxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
+    xlim=get(haxes,'XLim');
+    ylim=get(haxes,'YLim');
     % if left mouse button has been pressed, zoom in by a factor of 2
-    if  isequal(get(hcurrentfig,'SelectionType'),'normal');%if left button has been pressed, zoom in by a factor of 2
-        PlotBoxAspectRatio=get(currentaxes,'PlotBoxAspectRatio');
+    if  isequal(get(gcf,'SelectionType'),'normal');%if left button has been pressed, zoom in by a factor of 2
+        PlotBoxAspectRatio=get(haxes,'PlotBoxAspectRatio');
         yoverx=PlotBoxAspectRatio(2)/PlotBoxAspectRatio(1);
         if yoverx <2
             xlim(1)=0.5*xy(1,1)+0.5*xlim(1);
             xlim(2)=0.5*xy(1,1)+0.5*xlim(2);%double the field whith the middle at the selected points
-            set(currentaxes,'XLim',xlim)
+            set(haxes,'XLim',xlim)
         end
         if yoverx >0.5
             ylim(2)=0.5*xy(1,2)+0.5*ylim(2);
             ylim(1)=0.5*xy(1,2)+0.5*ylim(1);
-            set(currentaxes,'YLim',ylim)
+            set(haxes,'YLim',ylim)
         end
         
@@ -267,5 +294,6 @@
         ylim(1)=2*ylim(1)-xy(1,2);
         ylim(2)=2*ylim(2)-xy(1,2);
-        if isfield(AxeData,'RangeX')&& isfield(AxeData,'RangeY')
+        % adjust the zoom out to the available field
+        if ~testsubplot && isfield(AxeData,'RangeX')&& isfield(AxeData,'RangeY')
             xlim(1)=max(AxeData.RangeX(1),xlim(1));
             xlim(2)=min(AxeData.RangeX(2),xlim(2));
@@ -279,11 +307,11 @@
             if isequal(xlim,AxeData.RangeX) && isequal(ylim,AxeData.RangeY)
                 set(hhuvmat.CheckZoom,'Value',0)
-                set(hhuvmat.CheckZoom,'BackgroundColor',[0.7 0.7 0.7])
+               % set(hhuvmat.CheckZoom,'BackgroundColor',[0.7 0.7 0.7])
                 set(hhuvmat.CheckFixLimits,'Value',0)
-                set(hhuvmat.CheckFixLimits,'BackgroundColor',[0.7 0.7 0.7])
-            end
-        end
-        set(currentaxes,'XLim',xlim)
-        set(currentaxes,'YLim',ylim)
+              %  set(hhuvmat.CheckFixLimits,'BackgroundColor',[0.7 0.7 0.7])
+            end
+        end
+        set(haxes,'XLim',xlim)
+        set(haxes,'YLim',ylim)
         %test whther zoom out is operating (to inactivate AxedAta
         if ~isfield(AxeData,'CurrentXLim')|| ~isequal(xlim,AxeData.CurrentXLim)
@@ -291,5 +319,8 @@
         end
     end
-    if isfield(AxeData,'LimEditBox')&& AxeData.LimEditBox% update display of the GUI containing the axis (uvmat or view_field)
+    %if isfield(AxeData,'LimEditBox')&& AxeData.LimEditBox% update display of the GUI containing the axis (uvmat or view_field)
+    if testsubplot
+        set(AxeData.CurrentRectZoom,'Position',[xlim(1) ylim(1) xlim(2)-xlim(1) ylim(2)-ylim(1)])
+    else
         set(hhcurrentfig.num_MinX,'String',num2str(xlim(1)))
         set(hhcurrentfig.num_MaxX,'String',num2str(xlim(2)))
@@ -300,10 +331,10 @@
 
 %% editing calibration point
-if ~test_zoom && isfield(AxeData,'Drawing') && isequal(AxeData.Drawing,'calibration')
+if ~CheckZoom && isfield(AxeData,'Drawing') && isequal(AxeData.Drawing,'calibration')
     h_geometry_calib=findobj(allchild(0),'tag','geometry_calib'); %find the geomterty_calib GUI
     if ~isempty(h_geometry_calib)
         hh_geometry_calib=guidata(h_geometry_calib);
         edit_test=get(hh_geometry_calib.edit_append,'Value');
-        hh=findobj(currentaxes,'tag','calib_points');%look for handle of calibration points
+        hh=findobj(hcurrentaxes,'tag','calib_points');%look for handle of calibration points
         if ~isempty(hh) && edit_test
             index_point=get(hh,'UserData');
@@ -313,5 +344,5 @@
             data=read_geometry_calib(Coord);
             %         val=get(h_ListCoord,'Value');
-            xy=get(currentaxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
+          %  xy=get(hcurrentaxes,'CurrentPoint');%xy(1,1),xy(1,2): current x,y positions in axes coordinates
             data.Coord(index_point,4)=xy(1,1);
             data.Coord(index_point,5)=xy(1,2);
@@ -331,7 +362,7 @@
 
 %% finalising ruler
-if test_ruler
+if test_ruler && ~isempty(xy)
     set(hhuvmat.MenuRuler,'checked','off')%desable the ruler option in uvmat
-    xy=get(currentaxes,'CurrentPoint');% get the current mouse coordinates
+    xy=get(hcurrentaxes,'CurrentPoint');% get the current mouse coordinates
     RulerCoord=[AxeData.RulerCoord ;xy(1,1:2)];% append the recorded ruler origin to the current mouse coordinates
     RulerCoord=diff(RulerCoord,1);% coordiante difference between segment end and beginning
@@ -346,5 +377,5 @@
 
 %% display the data of the current object selected with the mouse right click
-if isequal(get(hcurrentfig,'SelectionType'),'alt') && ~test_zoom && (~isfield(AxeData,'Drawing')||~isequal(AxeData.Drawing,'create'))
+if isequal(get(hcurrentfig,'SelectionType'),'alt') && ~CheckZoom && (~isfield(AxeData,'Drawing')||~isequal(AxeData.Drawing,'create'))
     hother=findobj('Tag','proj_object');%find all the proj objects
     nbselect=0;
@@ -384,9 +415,19 @@
         AxeData.Drawing='off';%stop current drawing action
 end
-set(currentaxes,'UserData',AxeData);
+set(hcurrentaxes,'UserData',AxeData);
 if ~isempty(huvmat)
     set(huvmat,'UserData',UvData);
 end
 
-    
-
+%------------------------------------------------------------------------    
+% --- 'close_fig': function  activated when a zoom figure is closed
+%------------------------------------------------------------------------
+function close_fig(ggg,eventdata,hparent)
+
+hfig=get(get(hparent,'parent'),'parent');
+hbutton=findobj(hfig,'Tag','CheckZoomFig');
+if ~isempty(hbutton)
+    set(hbutton,'Value',0)% desactivate the zoom fig option
+end
+delete(hparent)  % delete the rectangle showing the zoom graph in the parent fig
+
