function dummy = plotcomp(Editor)
%PLOTCOMP  Renders compensator poles and zeros.

%   Author(s): P. Gahinet
%   Copyright 1986-2000 The MathWorks, Inc. 
%   $Revision: 1.8 $ $Date: 2000/08/02 16:06:32 $

% REVISIT
dummy = [];

% Get pole/zero group information
PZGroups = Editor.LoopData.Compensator.PZGroup;
Nf = length(PZGroups);  % number of groups after update

% Initialize list of PZ group renderers (@PZVIEW objects)
HG = Editor.HG;  
Nc = length(HG.Compensator);  % current number of PZVIEW objects
% Delete extra groups
if Nc>Nf,
    delete(HG.Compensator(Nf+1:Nc));
    HG.Compensator = HG.Compensator(1:Nf,:);
end
% Add new groups
for ct=1:Nf-Nc,
    HG.Compensator = [HG.Compensator ; sisogui.pzview];
end

% Render each pole/zero group
for ct=1:Nf
    h = HG.Compensator(ct);  % group renderer object
    h.GroupData = PZGroups(ct);
    LocalRender(h,HG.PlotAxes,Editor);
end

Editor.HG = HG;


%----------------- Local functions -----------------

%%%%%%%%%%%%%%%
% LocalRender %
%%%%%%%%%%%%%%%
function LocalRender(hView,PlotAxes,Editor)
% Renders pole/zero group
% HVIEW = @PZVIEW object rendering a given pole/zero group

Style = Editor.LineStyle;

% Render zeros
Zeros = hView.GroupData.Zero;   % zero values
hZeros = zeros(size(Zeros));
for ct=1:length(hZeros)
    hZeros(ct) = line(real(Zeros(ct)),imag(Zeros(ct)),...
        'LineStyle','none',...
        'Color',Style.Color.Compensator,...
        'Marker','o','MarkerSize',6,...
        'Parent',PlotAxes,...
        'UserData',hView,...
        'HelpTopicKey','sisocompensatorpolezero',...
        'ButtonDownFcn',{@LocalMovePZ Editor}); 
end
hView.Zero = hZeros;

% Render poles
Poles = hView.GroupData.Pole;   % pole values
hPoles = zeros(size(Poles));
for ct=1:length(hPoles)
    hPoles(ct) = line(real(Poles(ct)),imag(Poles(ct)),...
        'LineStyle','none',...
        'Color',Style.Color.Compensator,...
        'Marker','x','MarkerSize',8,...
        'Parent',PlotAxes,...
        'UserData',hView,...
        'HelpTopicKey','sisocompensatorpolezero',...
        'ButtonDownFcn',{@LocalMovePZ Editor});  
end
hView.Pole = hPoles;


%%%%%%%%%%%%%%%%%%%
%%% LocalMovePZ %%%
%%%%%%%%%%%%%%%%%%%
function LocalMovePZ(hSrc,event,Editor)
% Callback for button down on closed-loop poles

SISOfig = gcbf;
if strcmp(Editor.EditMode,'idle')  
    switch get(SISOfig,'SelectionType')
    case 'open'
        % Double click: edit pole/zero location
        % REVISIT: do it??
    case 'normal'
        % Left click: initialize dragging of closed-loop pole
        % Switch edit mode to drag
        Editor.ModeData = 'pz';
        Editor.EditMode = 'drag';
        % Change pointer
        setptr(SISOfig,'closedhand')
        % Initialize tracking algorithm and notify peers
        Status = trackpz(Editor,'init');
		hgset_status(Editor,Status);
    end
end

