function revertDownstreamIntegrationDriver(this)
% If changes in the configset were canceled, we need to revert any changes
% that were made to the DownstreamIntegrationDriver. We do this by loading
% the original settings from the model back onto the
% DownstreamIntegrationDriver.

% Copyright 2023 The MathWorks, Inc.

% Get local downstream integration driver
hDI = this.getDownstreamIntegrationDriver;
if isempty(hDI)
    return;
end

if ~hDI.HasOpenTransaction
    % No need to revert settings if none of the related settings are being
    % changed
    return;
end

if hdlwa.isWorkflowAdvisorOpenForModel(this.getModelName)
    % Do not load top-level settings again when HDLWA is already open.
    %
    % Ideally, we should not get to this point because we disable the
    % top-level settings in the configset while the HDLWA is open
    %
    % HDLWA expects that the top-level settings in the downstream
    % integration driver (e.g. board, tool, ref design, etc.) are only
    % changed from within the HDLWA. With the in-canvas workflow, the
    % configset can also be used to change the downstream integration
    % driver settings. So when the HDLWA is open, we disable the top-level
    % settings from being edited in the configset. We also prevent
    % reloading existing top-level settings into the downstream integration
    % driver.
    % 
    % For example, calling "loadTopLevelSettings" will refresh the
    % reference design, which can affect the interface table. In
    % particular:
    % (1) Default register addresses (e.g. timestamp) allocated
    % during "validateInterfaceTable" can get erased.
    % (2) The default bus interface can get cleared, even though it was
    % already assigned. This will cause is to get resolved again later, but
    % to the first available address-based interface. This can cause an
    % issue if the previously assigned default bus interface (e.g. AXI4)
    % is not the first one in the list.
    return;
end

try
    hDI.loadTopLevelSettings;
    hDI.updateInterfaceTable;
catch
    % Swallow any errors
end

end