function RespObj = axeslims(RespObj)
%AXESLIMS  Sets the axes limits for Initial Condition Response Objects
%
%   RespObj = AXESLIMS(RespObj)

%   Authors: Karen Gondoly, 5-14-98
%   Revised: Adam DiVergilio, 11-99
%   Copyright 1986-2000 The MathWorks, Inc. 
%   $Revision: 1.14 $  $Date: 2000/07/26 21:06:05 $

%---Get key response properties
AllRespProps = get(RespObj,'Undocumented');
DispAx = AllRespProps.PlotAxes;  
Xlims = AllRespProps.Xlim;
Ylims = AllRespProps.Ylim;
AutoX = strcmp(AllRespProps.XlimMode,'auto');
AutoY = strcmp(AllRespProps.YlimMode,'auto');

%---Find visible DC lines and response characteristic lines 
SHH = get(0,'ShowHiddenHandles');
set(0,'ShowHiddenHandles','on');
DCLines = findobj(DispAx,'tag','ExtraTimeLine','Visible','on');
PRLines = findobj(DispAx,'Tag','PeakResponseMarker','Visible','on','Marker','none');
set(0,'ShowHiddenHandles',SHH)

%---Set axis lim mode
if AutoX
   set(DCLines,'Xdata',[0 0])  % Don't hide (show zero DC value on plot)
   set(DispAx(:),'XlimMode','auto')
end
if AutoY
   set(PRLines,'visible','off')
   set(DispAx(:),'YlimMode','auto')
end

%---Adjust X-limits
if AutoX
   %---Enforce uniform X-axis limits across each column
	VisAx = DispAx(strcmp(get(DispAx,'Visible'),'on'),1);
	if isempty(VisAx)
		Xlims{1} = [0 1];
	else
		Xlims{1} = get(VisAx(1),'Xlim');
	end
end

%---Adjust Y-limits
if AutoY
   Ylims = get(DispAx(:,1),{'Ylim'});
end

%---Toggle grid
RespObj = plotgrid(RespObj);

% Update axis limits in RespObj
% RE: Leave XlimMode and YlimMode untouched
RespObj = respfcn('setxylims',RespObj,Xlims,Ylims);

%---Rescale the ExtraTime Lines
if AutoX
   % SET below only valid in auto mode (when all Xlims are equal)
   set(DCLines,'Xdata',Xlims{1})
end

%---Rescale the Peak Response Lines
for ctL=1:length(PRLines)
   X = get(PRLines(ctL),'Xdata');
   Y = get(PRLines(ctL),'Ydata');
   if ~isequal(Y(1),Y(2))
      Ylim = get(get(PRLines(ctL),'Parent'),'Ylim');
      set(PRLines(ctL),'Ydata',[Ylim(1),Y(2)]);
   elseif ~isequal(X(1),X(2))
      Xlim = get(get(PRLines(ctL),'Parent'),'Xlim');
      set(PRLines(ctL),'Xdata',[Xlim(1),X(2)]);
   end
end

set(PRLines,'visible','on')
