% SLCOVERAGE.METRICSELECTOR Coverage filter metric selector class
% Selects metric outcomes of a block for filtering.
%   so = slcoverage.MetricSelector(type, blockH, idx, outcomeIdx) - creates a selector object
%       type       - slcoverage.MetricSelectorType
%       blockH     - block handle or Simulink ID
%       idx        - coverage objective index
%       outcomeIdx - objective outcome index
%
% SLCOVERAGE.METRICSELECTOR methods:
%   slcoverage.MetricSelector.allSelectors(blockH) - all MetricSelectors
%                                                    for a block
% See also: SLCOVERAGE.METRICSELECTORTYPE, SLCOVERAGE.FILTERRULE,
%           SLCOVERAGE.FILTER

% Copyright 2017 The MathWorks, Inc.

classdef MetricSelector < slcoverage.Selector & matlab.mixin.CustomDisplay
properties (SetAccess = private)
    ObjectiveIndex = 0
    OutcomeIndex = 0; 
end
methods
   function  this = MetricSelector(type, name, idx, outcomeIdx)
        [status, msgId] = SlCov.CoverageAPI.checkCvLicense;
        if status == 0
            error(message(msgId));
        end
        
        try 
            name = Simulink.ID.getSID(name);
        catch
        end
      
        typeValidationFcn = @(x)validateattributes(x, {'slcoverage.MetricSelectorType'}, {'scalar'}, 'MetricSelector', 'type', 1);
        sidValidationFcn = @(x)validateattributes(x, {'char'}, {'vector'}, 'MetricSelector', 'name', 2);
        idxValidationFcn = @(x)validateattributes(x, {'numeric'}, {'positive', 'integer', 'scalar'}, 'MetricSelector', 'idx', 3);
        outcomeIdxValidationFcn = @(x)validateattributes(x, {'numeric'}, {'positive', 'integer', 'scalar'}, 'MetricSelector', 'outcomeIdx', 4);
        p = inputParser;
        p.addRequired('type', typeValidationFcn);
        p.addRequired('name', sidValidationFcn);
        p.addRequired('idx', idxValidationFcn);
        p.addRequired('outcomeIdx', outcomeIdxValidationFcn);
        parse(p, type, name, idx, outcomeIdx);

        this@slcoverage.Selector(name, type, name);       
        this.ObjectiveIndex = idx;
        this.OutcomeIndex = outcomeIdx; 
        this.setConstructorCode(sprintf('slcoverage.MetricSelector(%s, ''%s'', %d, %d)', ... 
                        mat2str(this.Type), this.SId,  this.ObjectiveIndex , this.OutcomeIndex));

   end
end
%===================
methods  (Static = true)    
    function s = allSelectors(blockH)
        s = slcoverage.Selector.allSelectors(blockH, 'Type', 'slcoverage.MetricSelectorType');
    end
end

end
