function dummy = plotconstr(Editor,Ts)
%PLOTCONSTR  Renders design constraints.

%   Author(s): K. Gondoly and P. Gahinet
%   Copyright 1986-2000 The MathWorks, Inc. 
%   $Revision: 1.9 $  $Date: 2000/08/15 20:06:06 $

% REVISIT
dummy = [];

Constraints = Editor.Constraints;
HG = Editor.HG;
PlotAxes = HG.PlotAxes;

% Delete existing constraint lines
delete(HG.ConstraintLines(ishandle(HG.ConstraintLines)))
HG.ConstraintLines = zeros(0,1);

% Plot settling time constraint
if Constraints.SettlingTime.On
   % Constraint exp(Re(p)*st)<0.02
   TbxPrefs = cstprefs.tbxprefs;
   alpha = log(TbxPrefs.SettlingTimeThreshold)/Constraints.SettlingTime.Value;  % Re(p)<alpha
   if Ts,
      % Discrete time: for z=rho*exp(i*theta), Re(p)=log(rho)/Ts<alpha -> rho_crit = exp(Ts*alpha)
      rho = exp(alpha*Ts);
      theta = -pi:pi/40:pi;
      HG.ConstraintLines(end+1,:) = ...
         line(rho*cos(theta),rho*sin(theta),...
         'Color',[.5 .5 .5],'LineStyle','-','Parent',PlotAxes,...
         'HelpTopicKey','settlingtimeconstraint');
   else
      % Continuous time: vertical line x = alpha
      HG.ConstraintLines(end+1,:) = ...
         line([alpha alpha],get(PlotAxes,'Ylim'),...
         'Color',[.5 .5 .5],'LineStyle','-','Parent',PlotAxes,...
         'HelpTopicKey','settlingtimeconstraint');
   end
end


% Plot damping and peak overshoot constraints
Zeta = [];
if Constraints.Damping.On
   Zeta = [Zeta , Constraints.Damping.Value];
end
if Constraints.Overshoot.On
   t = (log(Constraints.Overshoot.Value/100)/pi)^2;
   Zeta = [Zeta , sqrt(t/(1+t))];
end

if ~isempty(Zeta)
   if Ts,
      % Discrete time: isodamping lines are 
      %      rho   = exp(-Zeta*t)
      %      theta = +/-sqrt(1-Zeta^2)*t
      % with t = 0:0.1:pi
      for k=1:length(Zeta)
         tmax = pi/sqrt(1-min(.99,Zeta(k))^2);
         t = -tmax:tmax/50:tmax;
         rho = exp(-Zeta(k)*abs(t));
         theta = sqrt(1-Zeta(k)^2)*t;
         HG.ConstraintLines(end+1,:) = ...
            line(rho.*cos(theta),rho.*sin(theta),...
            'Color',[.5 .5 .5],'LineStyle','-','Parent',PlotAxes,...
            'HelpTopicKey','dampingratioconstraint');
    end
   else
      % Continuous time: ray  x = -Zeta*t, y = sqrt(1-Zeta^2)*t
      Xlim = get(PlotAxes,'Xlim');
      Ylim = get(PlotAxes,'Ylim');
      rho = sqrt(max(1,Xlim(1)^2)+max(1,Ylim(1)^2));
      for k=1:length(Zeta)
         c = -Zeta(k);
         s = sqrt(1-Zeta(k)^2);
         HG.ConstraintLines(end+1,:) = ...
            line([c*rho 0 c*rho],[s*rho 0 -s*rho],...
            'Color',[.5 .5 .5],'LineStyle','-','Parent',PlotAxes,...
            'HelpTopicKey','dampingratioconstraint');
      end
   end
end


% Plot natural frequency constraint
if Constraints.NaturalFrequency.On
    w0 = unitconv(Constraints.NaturalFrequency.Value,...
        Editor.FrequencyUnits,'rad/sec');
    if Ts
        % Discrete time: parametrized as
        %    rho = exp(Ts*w0*cos(t))
        %    theta = Ts*w0*sin(t)
        % for t in [-pi,pi]
        t = -pi:pi/100:pi;
        w0 = Ts * w0;
        % Restrict w0*Ts to [-pi,pi]
        w0 = mod(w0,2*pi);
        w0 = w0 - 2*pi*(w0>pi);
        % Parameterize plot
        rho = exp(w0 * cos(t));
        theta = w0 * sin(t);
        HG.ConstraintLines(end+1,:) = ...
            line(rho.*cos(theta),rho.*sin(theta),...
            'Color',[.5 .5 .5],'LineStyle','-','Parent',PlotAxes,...
            'HelpTopicKey','naturalfrequencyconstraint');
    else
        % Continuous time: circle with radius w0
        t = -pi:pi/50:pi;
        HG.ConstraintLines(end+1,:) = ...
            line(w0*cos(t),w0*sin(t),...
            'Color',[.5 .5 .5],'LineStyle','-','Parent',PlotAxes,...
            'HelpTopicKey','naturalfrequencyconstraint');
    end
end

% Save lines
Editor.HG = HG;



