function scopingIds = getScopingIds(this, treeId)
% Get the scoping Ids corresponding to a tree ID

% Copyright 2017-2021 The MathWorks, Inc.

% If FPTRoot is selected
if strcmpi(treeId, 'FPTRoot')
    % Get all the scoping ids for each tree id in model hierarchy 
    keys = this.ResultScopingMap.keys;
    % Preallocate cell array
    allScopingIds = cell(numel(keys), 1);
    % For each tree id
    for keyIdx = 1:numel(keys)
        % Get all the unique scoping ids under that tree
        allScopingIds{keyIdx} = unique(this.ResultScopingMap(keys{keyIdx}));
    end
    % Flatten the cell array to get all scoping ids under all the tree ids
    % in the model hierarchy and produce a list of unique scoping ids
    scopingIds = unique([allScopingIds{:}]);
elseif this.ResultScopingMap.isKey(treeId)
    % Grab the scoping ids for the specific tree id specified
    scopingIds = unique(this.ResultScopingMap(treeId));
else
    scopingIds = {};
end
