Main Content

ModelAdvisor.FormatTemplate

Template for formatting Model Advisor analysis results

Description

Use the ModelAdvisor.FormatTemplate class to format the result of a check in the analysis result pane of the Model Advisor for a uniform look and feel among the checks you create. You can format the analysis results as a table or a list.

Creation

Description

obj = ModelAdvisor.FormatTemplate(type) creates an object of the ModelAdvisor.FormatTemplate class. type is a character vector identifying the format type of the template, either list or table.

You must return the result object to the Model Advisor to display the formatted result in the analysis result pane.

Note

Use the ModelAdvisor.FormatTemplate class in check callbacks.

Input Arguments

expand all

Type of ModelAdvisor.FormatTemplate.

Object Functions

addRowAdd row to table
setCheckTextAdd description of check to result
setColTitlesAdd column titles to table
setInformationAdd description of subcheck to result
setListObjAdd list of hyperlinks to model objects
setRecActionAdd Recommended Action section and text
setRefLinkAdd See Also section and links
setSubBarAdd line between subcheck results
setSubResultStatusAdd status to the check or subcheck result
setSubResultStatusTextAdd text below status in result
setSubTitleAdd title for subcheck in result
setTableInfoAdd data to table
setTableTitleAdd title to table

Examples

Format Model Advisor Results

The following code creates two template objects, ft1 and ft2, and uses them to format the result of running the check in a table and a list. The result identifies the blocks in the model. The graphics following the code display the output as it appears in the Model Advisor when the check passes and fails.

function sl_customization(cm)

% register custom checks
cm.addModelAdvisorCheckFcn(@defineModelAdvisorChecks);

% register custom factory group 
cm.addModelAdvisorTaskFcn(@defineModelAdvisorTasks);


% -----------------------------
% defines Model Advisor Checks
% -----------------------------
function defineModelAdvisorChecks

% Define and register a sample check 
rec = ModelAdvisor.Check('mathworks.example.SampleStyleOne');
rec.Title = 'Sample check for Model Advisor using the ModelAdvisor.FormatTemplate';
setCallbackFcn(rec, @SampleStyleOneCallback,'None','StyleOne');

mdladvRoot = ModelAdvisor.Root;
mdladvRoot.register(rec);


% -----------------------------
% defines Model Advisor Tasks
% -----------------------------
function defineModelAdvisorTasks
mdladvRoot = ModelAdvisor.Root;
 
% --- sample factory group
rec = ModelAdvisor.FactoryGroup('com.mathworks.sample.factorygroup');
rec.DisplayName='My Group 1';
rec.Description='Demo Factory Group';
rec.addCheck('mathworks.example.SampleStyleOne');
mdladvRoot.publish(rec); % publish inside By Group list

% -----------------------------
% Sample Check With Subchecks Callback Function
% -----------------------------
function ResultDescription = SampleStyleOneCallback(system)
mdladvObj = Simulink.ModelAdvisor.getModelAdvisor(system); % get object

% Initialize variables
ResultDescription={};
ResultStatus = false; % Default check status is 'Warning'
mdladvObj.setCheckResultStatus(ResultStatus);

% Create FormatTemplate object for first subcheck, specify table format
ft1 = ModelAdvisor.FormatTemplate('TableTemplate');

% Add information describing the overall check
setCheckText(ft1, ['Find and report all blocks in the model. '...
    '(setCheckText method - Description of what the check reviews)']);

% Add information describing the subcheck
setSubTitle(ft1, 'Table of Blocks (setSubTitle method - Title of the subcheck)');
setInformation(ft1, ['Find and report all blocks in a table. '...
    '(setInformation method - Description of what the subcheck reviews)']);

% Add See Also section for references to standards
setRefLink(ft1, {{'Standard 1 reference (setRefLink method)'},
    {'Standard 2 reference (setRefLink method)'}});

% Add information to the table
setTableTitle(ft1, {'Blocks in the Model (setTableTitle method)'});
setColTitles(ft1, {'Index (setColTitles method)',
    'Block Name (setColTitles method)'});

% Perform the check actions
allBlocks = find_system(system);
if length(find_system(system)) == 1
    % Add status for subcheck
    setSubResultStatus(ft1, 'Warn');
    setSubResultStatusText(ft1, ['The model does not contain blocks. '...
        '(setSubResultStatusText method - Description of result status)']);
    setRecAction(ft1, {'Add blocks to the model. '...
        '(setRecAction method - Description of how to fix the problem)'});
    ResultStatus = false;
else
    % Add status for subcheck
    setSubResultStatus(ft1, 'Pass');
    setSubResultStatusText(ft1, ['The model contains blocks. '...
        '(setSubResultStatusText method - Description of result status)']);
    for inx = 2 : length(allBlocks)
        % Add information to the table
        addRow(ft1, {inx-1,allBlocks(inx)});
    end
    ResultStatus = true;
end

% Pass table template object for subcheck to Model Advisor
ResultDescription{end+1} = ft1;

% Create FormatTemplate object for second subcheck, specify list format
ft2 = ModelAdvisor.FormatTemplate('ListTemplate');

% Add information describing the subcheck
setSubTitle(ft2, 'List of Blocks (setSubTitle method - Title of the subcheck)');
setInformation(ft2, ['Find and report all blocks in a list. '...
    '(setInformation method - Description of what the subcheck reviews)']);

% Add See Also section for references to standards
setRefLink(ft2, {{'Standard 1 reference (setRefLink method)'},
    {'Standard 2 reference (setRefLink method)'}});

% Last subcheck, suppress line
setSubBar(ft2, false);

% Perform the subcheck actions
if length(find_system(system)) == 1
    % Add status for subcheck
    setSubResultStatus(ft2, 'Warn');
    setSubResultStatusText(ft2, ['The model does not contain blocks. '...
        '(setSubResultStatusText method - Description of result status)']);
    setRecAction(ft2, {'Add blocks to the model. '...
        '(setRecAction method - Description of how to fix the problem)'});
    ResultStatus = false;
else
    % Add status for subcheck
    setSubResultStatus(ft2, 'Pass');
    setSubResultStatusText(ft2, ['The model contains blocks. '...
        '(setSubResultStatusText method - Description of result status)']);
    % Add information to the list
    setListObj(ft2, allBlocks);
end

% Pass list template object for the subcheck to Model Advisor
ResultDescription{end+1} = ft2;
% Set overall check status
mdladvObj.setCheckResultStatus(ResultStatus);

The following graphic displays the output as it appears in the Model Advisor when the check passes.

The following graphic displays the output as it appears in the Model Advisor when the check fails.

Alternatives

When you define a ModelAdvisor.Check object, for the CallbackStyle property, if you specify DetailStyle, you do not have to use the ModelAdvisor.FormatTemplate API or the other formatting APIs to the format results that appear in the Model Advisor report. DetailStyle also allows you to view results by block, subsystem, or recommended action.

If the default formatting does not meet your needs, use one of the other callback function styles and use the ModelAdvisor.FormatTemplate API or the other formatting APIs. The ModelAdvisor.FormatTemplate class provides a uniform look and feel among the checks you create.

Introduced in R2009a