function update_importparams(fcn,hFig)
% UPDATE_IMPORTPARAMS Updates all the frames that contain the uicontrols
%                     to import filters (Import mode).
% Inputs:
%   fcn   - Update function.
%   hFig  - Handle to the Filter Design GUI figure.

%   Author(s): P. Pacheco, P. Costa, R. Losada
%   Copyright 1988-2000 The MathWorks, Inc.
%   $Revision: 1.8 $  $Date: 2000/06/13 21:23:49 $ 

feval(fcn,hFig);

%-------------------------------------------------------------------------
function update_all(hFig)
% UPDATE_ALL Calls all the update functions to update the Specify 
%            Coefficients frame (tab).

update_coffsframe(hFig);      % Update the Specify Cofficients frame.
update_impfiltstruct(hFig);   % Update Filter Structure popupmenu.
update_importFsTitle(hFig);   % Update the Sampling Frequency title.
update_importFsPopup(hFig);   % Update the Sampling Frequency units popupmenu.
update_importFsEditBox(hFig); % Update the Specified Sampling Frequency.
 

%-------------------------------------------------------------------------
function update_coffsframe(hFig)
% UPDATE_COFFSFRAME Update the Specify Cofficients frame.

% Update the "Specify Filter Coefficients" frame (tab) including
% the filter coefficient edit boxes, labels and Clear push buttons.
%
% Input:
%    hFig    - Handle to the Filter Design GUI figure.

% Get the user data stored in the figure
ud = get(hFig,'Userdata');

% Turn on the visiblity of the "Specify Filter Coefficients" frame
h_specifyCoeffs = ud.h.import_params.importFilter.frame;
set(h_specifyCoeffs,'Visible','On');

% Handles to both the coefficient edit boxes and clear push buttons
h_ebtoTurnOn   = ud.h.import_params.importFilter.coeffebs;
h_pbtnToTurnOn = ud.h.import_params.importFilter.clrpbs;

% Get a shorten version of the strings used in the filter structure popupmenu. 
filtstructStr = importstructurestr(ud, ud.specs.import.impfiltstruct.struct);

% Determine how many uicontrols to display.
switch  filtstructStr,
case {'df1','df2','df1t','df2t','sos','lattaps','lattarma'},  
    indx = [1:2];
case 'ss',                               
    indx = [1:4];
case {'lattmamin','lattmamax','qfilt'},  
    indx = [1];
end

% Index into array of handles for the Edit boxes and push buttons.
h_ebtoTurnOn = h_ebtoTurnOn(indx);
h_pbtnToTurnOn = h_pbtnToTurnOn(indx);

% Turn on the filter structure specific labels and edit boxes.
setScUisVis(ud,filtstructStr,h_ebtoTurnOn,h_pbtnToTurnOn); 
setScUiStrs(ud,filtstructStr); 

% Update the "Apply" button.
update_actionbtn('update_enablestate',hFig);


%-------------------------------------------------------------------------
function update_impfiltstruct(hFig)
%UPDATE_IMPFILTESTRUCT Update Filter Structure popupmenu (Import or Specify mode).
%
% Input:
%    hFig    - Handle to the Filter Design GUI figure.

ud = get(hFig,'Userdata');

% Turn on the visiblity of the popup and label.
h_filterstructUis = [ud.h.import_params.importFilter.pop, ...
        ud.h.import_params.importFilter.popLbl];
set(h_filterstructUis,'Visible','On');

% Cache handle to the filter structure popup
h_pop = ud.h.import_params.importFilter.pop;
filtStructStrs = get(h_pop,'String');

currentFiltStruct = ud.specs.import.impfiltstruct.struct;

% Setting the filter structure popup 'String' (based on 
% the ud structure)
indx = find(strcmpi(currentFiltStruct,filtStructStrs));
set(h_pop,'Value',indx);


%-------------------------------------------------------------------------
function update_importFsTitle(hFig)
%UPDATE_IMPORTFSTITLE  Update the Sampling Frequency title
%
% Input:
%    hFig    - Handle to the Filter Design GUI figure.

ud = get(hFig,'Userdata');

% Turn on the visiblity of the Sampling Frequency title
h_FsUis = ud.h.import_params.importFs.fstitle;
set(h_FsUis,'Visible','On');


%-------------------------------------------------------------------------
function update_importFsPopup(hFig)
%UPDATE_IMPORTFSPOPUP  Update the Specified Sampling Frequency Units popupmenu.
%
% Input:
%    hFig    - Handle to the Filter Design GUI figure.

ud = get(hFig,'Userdata');

% Turn on the visiblity of the popup and label.
h_FsPopupUis = [ud.h.import_params.importFs.fspop, ...
        ud.h.import_params.importFs.fslbl];
set(h_FsPopupUis,'Visible','On');

% Cache handle to the Sampling Frequency units Popupmenu.
h_pop = ud.h.import_params.importFs.fspop;
fsUnitStrs = get(h_pop,'String');

currentFsUnits = ud.specs.import.fs.freqUnits;

% Setting the sampling frequency units popup 'String' (based on 
% the ud structure)
indx = find(strcmpi(currentFsUnits,fsUnitStrs));
set(h_pop,'Value',indx);

% The "Fs" edit box is not enabled for Normalized units.
if strcmpi(currentFsUnits,'Normalized (0 to 1)'),
    enableState = 'Off';
    bgc = [.8 .8 .8];
else
    enableState = 'On';
    bgc = 'White';
end
set(ud.h.import_params.importFs.fseb,'Enable',enableState,...
    'BackgroundColor',bgc);


%-------------------------------------------------------------------------
function update_importFsEditBox(hFig)
%UPDATE_IMPORTFSEDITBOX Update the Specified Sampling Frequency edit box.
%
% Input:
%    hFig    - Handle to the Filter Design GUI figure.

ud = get(hFig,'Userdata');

% Turn on the visiblity of the Sampling Frequency edit box
% and Edit box label.
h_FsUis = [ud.h.import_params.importFs.fseb,...
        ud.h.import_params.importFs.fseblbl];
set(h_FsUis,'Visible','On');

% Cache handle to the sampling frequency edit box.
h_fsEb = ud.h.import_params.importFs.fseb;
fsString = get(h_fsEb,'String');

currentFsString = ud.specs.import.fs.Fs;

% Setting the sampling frequency edit box
if ~strcmp(fsString, currentFsString),
    % Save current sampling frequency to ud
    ud.specs.import.fs.Fs = currentFsString;
    set(h_fsEb,'String',currentFsString);
end


%-------------------------------------------------------------------
%                       Utility Functions
%-------------------------------------------------------------------
function setScUisVis(ud,filtStructStr, h_ebtoTurnOn, h_pbToTurnOn)
%SETICUISVIS Set the Specify Filter Coefficients uicontrols (edit boxes 
%            and labels) Visibilities.
%
% Input:
%    ud             - FDATool UserData structure.
%    filtStructStr  - String used to distinguish the filter structure.
%    h_ebtoTurnOn   - Handles to the correct coefficient edit boxes to 
%                     turn on.
%    h_bpToTurnOn   - Handles to the correct Clear push buttons to 
%                     turn on.

% Structure of handles to the uicontrols in the Specify Coefficients frame.
importCoeff = ud.h.import_params.importFilter;

% Handles to all filter structure uicontrols in the frame
if ud.flags.fdqexists,
    h_uis = [importCoeff.coeffebs,...
            importCoeff.tflbls,...
            importCoeff.soslbls,...
            importCoeff.sslbls,...
            importCoeff.lattarmalbls,...
            importCoeff.lattapslbls,...    
            importCoeff.lattmaminlbls,...
            importCoeff.lattmamaxlbls,...
            importCoeff.qfiltlbls,...
            importCoeff.clrpbs];
else
    h_uis = [importCoeff.coeffebs,...
            importCoeff.tflbls,...
            importCoeff.soslbls,...
            importCoeff.sslbls,...
            importCoeff.lattarmalbls,...
            importCoeff.lattapslbls,...    
            importCoeff.lattmaminlbls,...
            importCoeff.lattmamaxlbls,...
            importCoeff.clrpbs];
end
set(h_uis,'Visible','Off');

% The labels for the df1, df2, df1t, and df2t structures are stored
% in tflbls leg of the importCoeff structure.
if any(strcmpi(filtStructStr,{'df1','df2','df2t','df1t'})),
    filtStructStr = 'tf';
end

% Turn on the 'filtStructStr' specific labels. 
ebLblStr = ['importCoeff.' filtStructStr 'lbls'];
set((eval(ebLblStr)),'Visible','On');

% Turn on the correct number of coefficient edit boxes.
set(h_ebtoTurnOn,'Visible','On',...
    'Enable','On',...
    'BackgroundColor','White');

% Turn on the correct number of "Clear" Push buttons.
set(h_pbToTurnOn,'Visible','On',...
    'Enable','On');


% The "Ladder coeff" parameter is not valid for "Lattice MA (min. phase)"
% and "Lattice MA (max. phase)" so we don't show it.
if strcmp(filtStructStr,'lattmamin') | strcmp(filtStructStr,'lattmamax')
    set(importCoeff.lattmaminlbls(end),'Visible','Off');
    set(importCoeff.lattmamaxlbls(end),'Visible','Off');
end

% The "Ladder coeff" parameter is not valid for "Lattice allpass",
% however it exists within the structure, so we disable both uicontrols.
if strcmp(filtStructStr,'lattaps') 
    set(h_ebtoTurnOn(2),'Enable','Off',...
        'BackgroundColor',[.8 .8 .8]);
    set(h_pbToTurnOn(2),'Enable','Off');
end


%-------------------------------------------------------------------------
function setScUiStrs(ud,filtStructStr)
%SETSCUISTRS Set the Specify Filter Coefficients edit box strings from ud.
%
% Input:
%    ud              - UserData from FDATOOL.
%    filtStructStr   - String used to distinguish the filter structure.

% The uicontrols for the df1, df2, df1t, and df2t structures are stored
% in tflbls leg of the importCoeff structure.
if any(strcmpi(filtStructStr,{'df1','df2','df2t','df1t'})),
    filtStructStr = 'tf';
end

% Get the filter structure variables (strings) from the UserData
filtVarStr = ['ud.specs.import.impfiltstruct.' filtStructStr 'VarStrs'];
strs = eval(filtVarStr);

% Get handles to the Edit Boxes in the Specify Filter Coefficients frame.
h_ebs = ud.h.import_params.importFilter.coeffebs;

for n = 1:length(strs),
    set(h_ebs(n),'String',strs{n});
end

% [EOF] update_importparams.m
