function dummy = refreshgain(Editor,action)
%REFRESHGAIN  Refreshes plot during dynamic gain update.

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

% REVISIT
dummy = [];

persistent GainListener

switch action
case 'init'
   % Initialization for dynamic gain update (drag).
   % Switch editor's RefreshMode to quick
   Editor.RefreshMode = 'quick';
   
   % Install listener on gain data
   CompData = Editor.LoopData.Compensator;
   GainListener = handle.listener(CompData,findprop(CompData,'Gain'),...
       'PropertyPostSet',{@LocalUpdatePlot Editor});
   
case 'finish'
   % Return editor's RefreshMode to normal
   Editor.RefreshMode = 'normal';
   
   % Delete listener
   delete(GainListener);
   GainListener = [];
   
end


%-------------------------Local Functions-------------------------

%%%%%%%%%%%%%%%%%%%%%%%
%%% LocalUpdatePlot %%%
%%%%%%%%%%%%%%%%%%%%%%%
function LocalUpdatePlot(hSrcProp,event,Editor)
% Update position of closed-loop poles (magenta squares)

% REVISIT: merge next three
GainData = event.AffectedObject.Gain;
NewGainMag = GainData.Magnitude;

% Compute closed-loop poles 
Editor.ClosedPoles = fastrloc(Editor.LoopData.OpenLoop,NewGainMag);
% matchlsq(Editor.ClosedPoles,fastrloc(NormOpenLoop,NewGainMag));

% Update red square locations
% REVISIT: merge
HG = Editor.HG;
set(HG.ClosedLoop,...
    {'Xdata'},num2cell(real(Editor.ClosedPoles)),...
    {'Ydata'},num2cell(imag(Editor.ClosedPoles)))









