function this = hdlcc(model) 
%HDLCC   Construct a HDLCC (HDL Coder custom configuration component).
%   HDLCC(MODEL) MODEL is optional and defaults to the empty string.

%   Copyright 2005-2023 The MathWorks, Inc.

if nargin < 1
    model=''; 
end

this = hdlcoderui.hdlcc;

% This string should not be localized as it writes into the model file
this.Description = 'HDL Coder custom configuration component';

if ~hdlcoderui.isslhdlcinstalled
    this.hdlinstalled = false;
    % The SLHDLC is not available in the MATLAB session; NOTE: a light-weight
    % hdlcc is still returned from this constructor so that SL can load models
    % containing hdlcoderui.hdlcc objects without warnings.
    return;
end

this.hdlinstalled = true;

% Construct and store a handle to the HDLCoder object (driver).  
% This is the API between the GUI and the HDL infrastructure.
if ~isempty(model) &&  isempty(this.HDLCoder)
    this.createHDLCoder(model);
end
    
% Build an array of objects representing each "plug-in" subcomponent in
% the HDL Coder Configuration Component (e.g., EDA Scripts, Test Bench,
% etc).
hRPT = hdlcoderui.hdlrpt;
hGS = hdlcoderui.hdlglblsettings;
hTS = hdlcoderui.hdltargetsettings;
hTB = hdlcoderui.hdltb;
hEDA = hdlcoderui.hdledas;

comps = [hRPT, hGS, hTS, hTB, hEDA];

set(this,...
    'SubComponents',comps,...
    'ReadOnly', 'On'); 

% Register events for simulink model.
if ~isempty(model)
    this.registerEventsAtPostLoad(model);

    % Fix to g1983102
    % setting the "HDLSubsystem" parameter intially to model name during
    % creation of HDL ConfigSet component. This solves the creation of "dirty"
    % state when user open configuration dialog and just clicks "OK" without
    % any changes.
    mdlProps = get_param(model, 'HDLParams');
    if isempty(mdlProps)
        mdlProps = slprops.hdlmdlprops;
    end
    % grab only parameter names, no values
    currParams = mdlProps.getCurrentMdlPropNames;
    if ~any(strcmp(currParams, 'HDLSubsystem'))
        % set the HDLSubsystem while maintaining other previously existing
        % HDL params
        % the CLI will be updated with these params later after attachment
        set_param(model, 'HDLParams', slprops.hdlmdlprops([{'HDLSubsystem', model}, mdlProps.getCurrentMdlProps]));
    end
end

% Register to data model
this.loadComponentDataModel(fullfile('toolbox','shared','hdlshared', ...
    'hdlshared_gui','configset','derived'));
end
