%% Get All Selectors
% This example shows how to get all the selectors for an And block and
% then add a rule to justify or exclude a selector. Metric selectors can
% only be justified.

% Copyright 2020-2021 The MathWorks, Inc.

%%
% Load the model and set coverage settings

modelName = 'slvnvdemo_covfilt';
load_system(modelName);
set_param(modelName,'CovEnable','on','CovMetricStructuralLevel','MCDC');

%%
% First, get the block handle for the And block.
%

id = getSimulinkBlockHandle([modelName,'/Saturation']);

%%
% Get the selectors using the block handle.
%

sel = slcoverage.Selector.allSelectors(id)

%%
% The block has ten selectors. You can index into each one to see their
% contents. In this example, you want to justify the sixth selector.
%

sel(6)

%%
% Create a justify rule, then create a filter object and add the rule to
% it.
%

rule = slcoverage.FilterRule(sel(6),'Expected result');
filt = slcoverage.Filter;
filt.addRule(rule);

%%
% Save the filter and generate a coverage report.
%

filt.save('metrfilter');
csim = cvsim(modelName);
csim.filter = 'metrfilter';
cvhtml('cov',csim,'-sRT=0');