function RespObj = zoomsetup(RespObj,NewState)
%ZOOMSETUP - Set up prior to activating the zoom
%
%   RespObj = ZOOMSETUP(RespObj,ZOOMSTATE) performs the necessary 
%   set up associated with the new zoom state ZOOMSTATE.

%   Authors: K. Gondoly
%            P. Gahinet
%            A. DiVergilio
%   Copyright 1986-2000 The MathWorks, Inc. 
%   $Revision: 1.4 $  $Date: 2000/06/14 20:07:32 $

FigHandle = RespObj.Parent;
LTIdisplayAxes = RespObj.PlotAxes;

% Update RespObj zoom state
RespObj.Zoom = NewState;

%---Set figure pointer style and erase ButtonDownFcn
switch NewState,
case {'xon','yon','on'},
   set(FigHandle,'Pointer','crosshair');
   
   % Hides the other axes from the zoom
   Zlabels = get(findobj(FigHandle,'type','axes'),{'Zlabel'});
   set([Zlabels{:}],'UserData',NaN);   
   Zlabels = get(LTIdisplayAxes,{'Zlabel'});
   set([Zlabels{:}],'UserData',[]);
   
   switch NewState
   case 'xon', % xonly
      %---Nyquist and Nichols can zoom only along a column
      if any(strcmp(RespObj.ResponseType,{'nyquist','nichols'})),
         groups={{'GridGroup',LTIdisplayAxes}};
      else
         groups={{'ListGroup',LTIdisplayAxes(:)}};
      end
      zoomfcn='xonly';
      zoomofffcn = 'rguizfcn(''resetxzoom'',gca);';
   case 'yon', % yonly
      groups={{'GridGroup',LTIdisplayAxes}};
      zoomfcn='yonly';
      zoomofffcn = 'rguizfcn(''resetyzoom'',gca);';
   case 'on', % xy
      groups={{'GridGroup',LTIdisplayAxes}};
      zoomfcn='on';
      zoomofffcn = 'rguizfcn(''resetxyzoom'',gca);';
   end % switch ZoomState 
   
   rguizoom(FigHandle,zoomfcn);
   rguizoom(FigHandle,'setgroup',groups);
   rguizoom(RespObj.BackgroundAxes,'zoomofffcn',zoomofffcn);
   
case 'off',
   % Make sure the current axis is a display axis (clean up callback assumes it)
   if ~strcmp(get(gca,'Tag'),'LTIdisplayAxes'),
      set(FigHandle,'CurrentAxes',LTIdisplayAxes(1))
   end
   rguizoom(FigHandle,'off')
   
case 'reset'
   % Set limit mode to auto and set flag for recomputing axis limits
   RespObj.XlimMode = 'auto';
   RespObj.YlimMode = 'auto';
   RespObj.RefreshAxisLimits = 1;
   
   % RESET mode automatically reverts to off
   RespObj.Zoom = 'off';
   
case {'tight','critical'}
   % Switch lim modes to manual and set flag for recomputing axis limits
   RespObj.XlimMode = 'manual';
   RespObj.YlimMode = 'manual';
   RespObj.RefreshAxisLimits = 1;
   
end % switch ZoomState 
