function dummy = deletepz(Editor)
%DELETEPZ  Deletes pole or zero graphically.

%   Author(s): P. Gahinet
%   Copyright 1986-2000 The MathWorks, Inc. 
%   $Revision: 1.8 $  $Date: 2000/08/22 14:58:41 $

% REVISIT
dummy = [];

% Pointers
HG = Editor.HG;
CompData = Editor.LoopData.Compensator;
if isempty(CompData.PZGroup)  
    % Nothing to delete
    return
end

% Acquire pole/zero position 
CP = get(HG.PlotAxes,'CurrentPoint');
if CP{1}(1,3)==1,
   % Delete pole in mag axes
   CP = CP{1};
   Axes = HG.PlotAxes(1);
   PZViews = HG.Compensator.Magnitude;
   Yscale = Editor.MagnitudeScale;
elseif CP{2}(1,3)==1,
   % Delete pole in phase axes
   CP = CP{2};
   Axes = HG.PlotAxes(2);
   PZViews = HG.Compensator.Phase;
   Yscale = 'linear';
end
Xm = CP(1,1);  Ym = CP(1,2);  % pointer location

% Get positions of compensator poles and zeros
hPZ = [get(PZViews,{'Zero'}) ; get(PZViews,{'Pole'})];
hPZ = cat(1,hPZ{:});
X = get(hPZ,{'Xdata'});  X = cat(1,X{:});
Y = get(hPZ,{'Ydata'});  Y = cat(1,Y{:});

% Adjust for X and Y scales (distance measured in pixels, not data units)
Lims = get(Axes,{'Xlim','Ylim'});
if strncmp(Editor.FrequencyScale,'log',3)
    Lims{1} = log2(Lims{1});   Xm = log2(Xm);
    ispos = (X>0);
    X(ispos,:) = log2(X(ispos,:));   
    X(~ispos,:) = -Inf;   
end
if strncmp(Yscale,'log',3)
    Lims{2} = log2(Lims{2});   Ym = log2(Ym);
    ispos = (Y>0);
    Y(ispos,:) = log2(Y(ispos,:));   
    Y(~ispos,:) = -Inf;   
end

% Determine nearest match
[distmin,imin] = ...
    min(abs(((Xm-X)/diff(Lims{1})).^2 + ((Ym-Y)/diff(Lims{2})).^2));

if distmin < 0.03^2,
    % Identify selected group and get its description
    SelectedGroup = get(get(hPZ(imin),'UserData'),'GroupData');
    isel = find(CompData.PZGroup==SelectedGroup);
    Description = describe(CompData.PZGroup(isel),CompData.Ts);
    
    % Start transaction
    T = handle.transaction(get(findpackage('sisodata'),'DefaultDatabase'));
    set(T,'Name',sprintf('Delete %s',Description{1}),...
        'OperationStore','on','InverseOperationStore','on');
    
    % Delete selected group from list of compensator PZ groups
    delete(CompData.PZGroup(isel));
    CompData.PZGroup = CompData.PZGroup([1:isel-1,isel+1:end],:);
    
    % Register transaction
    register(Editor.LoopData,T);
    
    % Notify peers of deletion
    dataevent(Editor.LoopData,'all');
    
    % Notify status and history listeners
    Status = sprintf('Deleted %s',Description{2});
    Editor.up.send('StatusChanged',...
        sisodata.dataevent(Editor.up,'StatusChanged',{Status,Status}));
end
