function qfilt2ui(hFig,Hq)
%QFILT2UI  Convert QFILT object to UICONTROL.
%   QFILT2UI(HFIG,HQ) converts the qfilt object HQ to uicontrol settings and
%   sets all the uicontrols on the quantized page on figire HFIG.

%   Thomas A. Bryan
%   Copyright 1988-2000 The MathWorks, Inc.
%   $Revision: 1.4 $  $Date: 2000/06/15 20:04:53 $ 
ud = get(hFig,'userdata');
% Set the scale values
set(ud.h.quantize_params.qfiltobjs.scalevalues,...
    'string',mat2str(scalevalues(Hq)))
% Set the quantizer uicontrols
quantizers = {'coefficient','input','output','multiplicand','product','sum'};
for k=1:length(quantizers)
  q = quantizer(Hq,quantizers{k});
  quantizer2ui(q,ud.h.quantize_params.quantizerprops,k);
end

% Store the enable states in a cell array
ud.specs.quantize.enablestates = get(ud.h.quantize_params.enablehandles,'enable');
% Store the user data
set(hFig,'Userdata',ud);

%----------------------------------------------------------------------
function quantizer2ui(q,quantizerprops,n)
%QUANTIZER2UI Convert QUANTIZER object to UICONTROL.
%   QUANTIZER2UI(Q,QUANTIZERPROPS,N) converts QUANTIZER Q to the Nth quantizer
%   on the uicontrol.  QUANTIZERPROPS is the handle to the quantizer properties.
%   The quantizers are displayed on the gui by lines (k).  They are: 
%     ------------------------------------------------------------
%     (k) Data path    Quantizer  Mode Roundmode Overflowmode Format
%     ------------------------------------------------------------
%     (1) Coefficient
%     (2) Input
%     (3) Output
%     (4) Multiplicand
%     (5) Product
%     (6) Sum
%     ------------------------------------------------------------
%   All of the properties of a quantizer are stored in the user data of its
%   mode property.
%   When the mode is 'fixed' or 'float', then we need to store the values
%   that the user sets.  When the modes are 'double' or 'single', we don't
%   have to store their values because double and single have pre-set values.
%   When toggling back from single or double to fixed or float, the
%   user-input values are remembered and restored.
set(quantizerprops.quantizers(n),'value',...
    find(strcmpi(class(q),{'quantizer','unitquantizer'})));

set(quantizerprops.modes(n),'value',...
    find(strcmpi(mode(q),{'fixed','float','double','single'})));

set(quantizerprops.roundmodes(n),'value',...
    find(strcmpi(roundmode(q),{'ceil','convergent','fix','floor','round'})));

set(quantizerprops.overflowmodes(n),'value',...
    find(strcmpi(overflowmode(q),{'saturate','wrap'})));

set(quantizerprops.formats(n),'string',mat2str(format(q)))

v = [quantizerprops.roundmodes(n),quantizerprops.overflowmodes(n),...
      quantizerprops.formats(n)];
switch mode(q)
  case {'fixed','float'}
    set(v,'enable','on')
  otherwise
    set(v,'enable','off')
end


