function dummy = setgain(LoopData,NewValue)
%SETGAIN  Sets the loop gain value.

%   Author(s): P. Gahinet
%   Copyright 1986-2000 The MathWorks, Inc. 
%   $Revision: 1.4 $ $Date: 2000/06/14 20:18:29 $

% REVISIT
dummy = [];

CompData = LoopData.Compensator;

% Start transaction
T = handle.transaction(get(findpackage('sisodata'),'DefaultDatabase'));
set(T,'Name','Edit Gain','OperationStore','on','InverseOperationStore','on');

% REVISIT: merge + simplify
OldSign = CompData.Gain.Sign;
NewSign = sign(NewValue) + (~NewValue);
CompData.Gain = struct('Sign',NewSign,'Magnitude',abs(NewValue));

% Commit and stack transaction
register(LoopData,T);

% Trigger update
if OldSign*NewSign<0,
    % Change of feedback sign: update all plot data
    dataevent(LoopData,'all');
else
    % Lightweight update
    dataevent(LoopData,'gain');
end


