function setModel(this, modelName)
% SETMODEL Connects the FPT instance with a model.

% Copyright 2015-2018 The MathWorks, Inc.

    this.Model = modelName;
    this.ModelObject = get_param(modelName,'Object');
    bdObj = get_param(modelName, 'Object');
    delete(this.CloseModelListener);
    this.CloseModelListener = Simulink.listener(bdObj, 'CloseEvent', @(s,e)onModelClose(this));
    delete(this.SimStartListener);
    this.SimStartListener = Simulink.listener(bdObj, 'EngineSimulationBegin',  @(s,e)recordSignals(this));
    delete(this.SimFailedListener);
    this.SimFailedListener = Simulink.listener(bdObj, 'EngineCompFailed',  @(s,e)handleCompFailure(this));
    % g1783351 - the dependency on the 'EngineSimulationEnd' event is
    % eliminated to resolve the premature spinner close issue.
    if ~isempty(this.TreeController)
        this.TreeController.setModel(modelName);
        this.DataController.setModel(modelName);
        this.StartupController.setModel(modelName);
        this.WorkflowController.setModel(modelName);
    end
end
