Contents

Define Custom Checks

About Custom Checks

You can create a custom check to use in the Model Advisor. Creating custom checks provides you with the ability to specify which conditions and configuration settings the Model Advisor reviews.

You define custom checks in one or more functions that specify the properties of each instance of the ModelAdvisor.Check class. Define one instance of this class for each custom check that you want to add to the Model Advisor, and register the custom check as described in Register Checks and Process Callbacks.

The following sections describe how to define custom checks.

Contents of Check Definitions

When you define a Model Advisor check, it contains the information listed in the following table.

ContentsDescription
Check ID (required)Uniquely identifies the check. The Model Advisor uses this id to access the check.
Handle to check callback function (required)Function that specifies the contents of a check.
Check name (recommended)Creates a name for the check that the Model Advisor displays.
Check properties (optional)Creates a user interface with the check. When adding checks as tasks, the Model Advisor uses the task properties instead of the check properties, except for Visible and LicenseName. For more information, see ModelAdvisor.Check and ModelAdvisor.Task.

    Tip   When you add checks to the Model Advisor as tasks, specify only the required properties of a check, because the task definition includes the additional properties. For example, you define the description of the check in the task definition using the ModelAdvisor.Task.Description property instead of the ModelAdvisor.Check.TitleTips property.

Input Parameters (optional)Adds input parameters that request input from the user. The Model Advisor uses the input to perform the check.
Action (optional)Adds automatic fixing action.
Explore Result button (optional)Adds the Explore Result button that the user clicks to open the Model Advisor Result Explorer.

Display and Enable Checks

You can create a check and specify how it appears in the Model Advisor. You can define when to display a check, or whether a user can select or clear a check using the Visible, Enable, and Value properties of the ModelAdvisor.Check class.

    Note:   When adding checks to the Model Advisor as tasks, specify these properties in the ModelAdvisor.Task class. If you specify the properties in both ModelAdvisor.Check and ModelAdvisor.Task, the ModelAdvisor.Task properties take precedence, except for the Visible and LicenseName properties. For more information, see ModelAdvisor.Task.

Modify the behavior of the Visible, Enable, and Value properties in a process callback function (see Define Startup and Post-Execution Actions Using Process Callback Functions). The following chart illustrates how these properties interact.

Define Where Custom Checks Appear

Specify where the Model Advisor places custom checks using the following guidelines:

Check Definition Function

The following is an example of a function that defines the custom checks associated with the callback functions described in Create Callback Functions and Results. The check definition function returns a cell array of custom checks to be added to the Model Advisor.

The check definitions in the example use the tasks described in Define Custom Tasks.

% Defines custom Model Advisor checks
function defineModelAdvisorChecks

% Sample check 1: Informational check
rec = ModelAdvisor.Check('mathworks.example.configManagement');
rec.Title = 'Informational check for model configuration management';
setCallbackFcn(rec, @modelVersionChecksumCallbackUsingFT,'None','StyleOne');
rec.CallbackContext = 'PostCompile';
mdladvRoot = ModelAdvisor.Root;
mdladvRoot.register(rec);

% Sample check 2: Basic Check with Pass/Fail Status
rec = ModelAdvisor.Check('mathworks.example.unconnectedObjects');
rec.Title = 'Check for unconnected objects';
setCallbackFcn(rec, @unconnectedObjectsCallbackUsingFT,'None','StyleOne');
mdladvRoot = ModelAdvisor.Root;
mdladvRoot.register(rec);

% Sample Check 3: Check with Subchecks and Actions
rec = ModelAdvisor.Check('mathworks.example.optimizationSettings');
rec.Title = 'Check safety-related optimization settings';
setCallbackFcn(rec, @OptmizationSettingCallback,'None','StyleOne');
% Define an automatic fix action for this check
modifyAction = ModelAdvisor.Action;
setCallbackFcn(modifyAction, @modifyOptmizationSetting);
modifyAction.Name = 'Modify Settings';
modifyAction.Description = ['Modify model configuration optimization' ...
                            ' settings that can impact safety.'];
modifyAction.Enable = true;
setAction(rec, modifyAction);
mdladvRoot = ModelAdvisor.Root;
mdladvRoot.register(rec);

Define Check Input Parameters

With input parameters, the check author can request input from the user for a Model Advisor check. Define input parameters using the ModelAdvisor.InputParameter class inside a custom check function (see Define Custom Checks). You must define one instance of this class for each input parameter that you want to add to a Model Advisor check.

    Note:   You do not have to create input parameters for every custom check.

Specify Input Parameter Layout

Specify the layout of input parameters in an input parameter definition. To place input parameters, use the following methods.

MethodDescription

ModelAdvisor.Check setInputParametersLayoutGrid

Specifies the size of the input parameter grid.

ModelAdvisor.InputParameter setRowSpan

Specifies the number of rows the parameter occupies in the Input Parameter layout grid.

ModelAdvisor.InputParameter setColSpan

Specifies the number of columns the parameter occupies in the Input Parameter layout grid.

For information on using these methods, see the ModelAdvisor.Check and ModelAdvisor.InputParameter class documentation.

Input Parameter Definition

The following is an example of defining input parameters that you add to a custom check. You must include input parameter definitions inside a custom check definition (see Check Definition Function). The following code, when included in a custom check definition, creates three input parameters.

rec = ModelAdvisor.Check('com.mathworks.sample.Check1');
rec.setInputParametersLayoutGrid([3 2]);
% define input parameters
inputParam1 = ModelAdvisor.InputParameter;
inputParam1.Name = 'Skip font checks.';
inputParam1.Type = 'Bool';
inputParam1.Value = false;
inputParam1.Description = 'sample tooltip';
inputParam1.setRowSpan([1 1]);
inputParam1.setColSpan([1 1]);
inputParam2 = ModelAdvisor.InputParameter;
inputParam2.Name = 'Standard font size';
inputParam2.Value='12';
inputParam2.Type='String';
inputParam2.Description='sample tooltip';
inputParam2.setRowSpan([2 2]);
inputParam2.setColSpan([1 1]);
inputParam3 = ModelAdvisor.InputParameter;
inputParam3.Name='Valid font';
inputParam3.Type='Combobox';
inputParam3.Description='sample tooltip';
inputParam3.Entries={'Arial', 'Arial Black'};
inputParam3.setRowSpan([2 2]);
inputParam3.setColSpan([2 2]);
rec.setInputParameters({inputParam1,inputParam2,inputParam3});

The Model Advisor displays these input parameters in the right pane, in an Input Parameters box.

Define Model Advisor Result Explorer Views

A list view provides a way for users to fix check warnings and failures using the Model Advisor Result Explorer. Creating a list view allows you to :

  • Add the Explore Result button to the custom check in the Model Advisor window.

  • Provide the information to populate the Model Advisor Result Explorer.

For information on using the Model Advisor Results Explorer, see Batch-Fix Warnings or Failures.

Define list views using the ModelAdvisor.ListViewParameter class inside a custom check function (see Define Custom Checks). You must define one instance of this class for each list view that you want to add to a Model Advisor Result Explorer window.

    Note:   You do not have to create list views for every custom check.

List View Definition

The following is an example of defining list views. You must make the Explore Result button visible using the ModelAdvisor.Check.ListViewVisible property inside a custom check function, and include list view definitions inside a check callback function (see Detailed Check Callback Function).

The following code, when included in a check definition function, adds the Explore Result button to the check in the Model Advisor.

rec = ModelAdvisor.Check('com.mathworks.sample.Check1');
% add 'Explore Result' button
rec.ListViewVisible = true;

The following code, when included in a check callback function, provides the information to populate the Model Advisor Result Explorer.

mdladvObj = Simulink.ModelAdvisor.getModelAdvisor(system);
mdladvObj.setCheckResultStatus(true);

% define list view parameters
myLVParam = ModelAdvisor.ListViewParameter;
myLVParam.Name = 'Invalid font blocks'; % the name appeared at pull down filter
myLVParam.Data = get_param(searchResult,'object')';
myLVParam.Attributes = {'FontName'}; % name is default property
mdladvObj.setListViewParameters({myLVParam});

Define Check Actions

An action provides a way for you to specify an action that the Model Advisor performs to fix a Model Advisor check. When you define an action, the Model Advisor window includes an Action box below the Analysis box.

You define actions using the ModelAdvisor.Action class inside a custom check function (see Define Custom Checks). You must define:

  • One instance of this class for each action that you want to take.

  • One action callback function for each action (see Action Callback Function).

    Note:  

    • Each check can contain only one action.

    • You do not have to create actions for every custom check.

Action Definition

The following is an example of defining actions within a custom check. You must include action definitions inside a check definition function (see Check Definition Function).

The following code, when included in a check definition function, provides the information to populate the Action box in the Model Advisor.

rec = ModelAdvisor.Check('mathworks.example.optimizationSettings');
% Define an automatic fix action for this check
modifyAction = ModelAdvisor.Action;
modifyAction.setCallbackFcn(@modifyOptmizationSetting);
modifyAction.Name = 'Modify Settings';
modifyAction.Description = ['Modify model configuration optimization' ...
                            ' settings that can impact safety'];
modifyAction.Enable = true;
rec.setAction(modifyAction);

The Model Advisor, in the right pane, displays an Action box.

Was this topic helpful?