function setSerialArchSettings(this)
%SETSERIALARCHSETTINGS Set the SerialArchSettings

%   Copyright 2011 The MathWorks, Inc.t


object = this.filterObj;
hdlfilt = this.hdlfilt;
if getEnableState(this, 'Architecture')
    if  fdhdlcoderui.issupportedsos(object)
        [ff,mult] =  hdlfilterserialinfo(object, 'foldingfactor', 1);
        sp = -1;
    else
        [sp, ff, mult] = hdlfilterserialinfo(object, 'coefficientsource', this.CoefficientSource,'serialpart', -1);
    end
    % sets the fully parallel values
    this.FPSerialPartition = hdlfilt.convSerialPart2String(sp);
    this.FPFoldingFactor = num2str(ff);
    this.FPMultipliers = num2str(mult);
    serial = hdlfilt.isSerialSupported;
    if  ~fdhdlcoderui.issupportedsos(object) && ...
            (serial.fullyserial || serial.partlyserial || serial.cascadeserial)
        % sets the serial properties only for supported filters; sos ones don't
        % need this adjustment
        
        % sets the fully serial values
        [sp, ff, mult] =  hdlfilterserialinfo(object, 'coefficientsource', this.CoefficientSource, 'multipliers', 1);
        this.FSSerialPartition = hdlfilt.convSerialPart2String(sp);
        this.FSFoldingFactor = num2str(ff);
        this.FSMultipliers = num2str(mult);
        
        
        % calculate the cascade serial partition value
        % not part of hdlfilterserialinfo so calculate manually here..
        % change when necessary
        fls = hdlfilt.getfilterlengths;
        if strcmpi(this.CoefficientSource, 'processor interface')
            FL = fls.coeff_len;
        else
            FL = fls.czero_len;
        end
        this.CascadeSerialPartition = num2str([ceil(FL/2) floor(FL/2)]);
        
        [splist, fflist, mullist] = getlistforcomboboxs(hdlfilt, this.CoefficientSource);
        this.SerialPartitionEntry = splist';
        this.FoldingFactorEntry = fflist';
        this.MultipliersEntry = mullist';
        
        
        % now when entries have been calculated and set, make sure the selected
        % values fall into the list else make the change.
        
        cFF = this.FoldingFactor;
        cMult = this.Multipliers;
        cSP = this.SerialPartition;
        currentSPinList = isCurrentSPinList(cSP, this.SerialPartitionEntry);
        
        if ~any(strcmpi(cFF, this.FoldingFactorEntry)) ||  ...
                ~any(strcmpi(cMult, this.MultipliersEntry)) || ...
                ~currentSPinList
            % the new lists have some entries that do not match the current entries
            % find the new defaults and set it
            [sp, ff, mul] =  ...
                getSpecificSerialInfo(this.hdlfilt, this.CoefficientSource, 'Multipliers', 2); % multiplier == 2 is the default way
            this.SerialPartition = this.hdlfilt.convSerialPart2String(sp);
            this.FoldingFactor = num2str(ff);
            this.Multipliers = num2str(mul); 
        end
    end
end
%-------------------------------------------------------------
function currentSPinList = isCurrentSPinList(cSP, spentries)

ii = 1;
currentSPinList = false;
endoflist = false;
while ~currentSPinList && ~endoflist    
    currentSPinList = isequal(str2num(cSP),str2num(spentries{ii})); %#ok<ST2NM>
    ii = ii+1;
    endoflist = (ii >= numel(spentries));
end    


%-------------------------------------------------------------
function  [splist, fflist, mullist] = getlistforcomboboxs(hdlfilt,csvalue)

if isa(hdlfilt, 'hdlfilter.df1sos') || isa(hdlfilt, 'hdlfilter.df2sos')
    [fflist, mullist] = getSerialPartition(hdlfilt);
    splist = {};
else
    [splist, fflist, mullist] = getSerialPartition(hdlfilt, 'CoefficientSource', csvalue);
end
%-------------------------------------------------------------
function  [sp, ff, mul] = getSpecificSerialInfo(hdlfilt, csvalue, prop, val)

if isa(hdlfilt, 'hdlfilter.df1sos') || isa(hdlfilt, 'hdlfilter.df2sos')
    [ff, mul] = getSerialPartition(hdlfilt, prop, val);
    sp = 0; % place holder
else
    [sp, ff, mul] = getSerialPartition(hdlfilt, prop, val, 'CoefficientSource', csvalue);
end

% [EOF]
