Defining Custom Checks

About Custom Checks

Custom checks allow you to create a new check to use in the Model Advisor. You define custom checks in one or more functions that specify the properties of each instance of the ModelAdvisor.Check class. You must 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 Registering Custom Checks, Tasks, and Groups. The sections that follow describe how to define custom checks.

Properties of Custom Checks

The following table describes the properties of the ModelAdvisor.Check class:

PropertyData TypeDefault ValueDescription
TitleString'' (null string)Name of the check as it should appear in the Model Advisor.
IDString'' (null string)Permanent, unique identifier for the check that you must specify.

    Caution  

    • The value of ID must remain constant.

    • The Model Advisor generates an error if ID is not unique.

    • Tasks and factory groups should refer to checks by ID.

TitleTipsString'' (null string)Description of the check, which the Model Advisor displays in its right pane when you view details about the check.
CallbackHandleFunction handle[] (empty handle)Handle to the callback function for the check.
CallbackContextEnumeration'None'Context for checking the model or subsystem:
  • None = No special requirements

  • PostCompile = Model must be compiled

CallbackStyleEnumeration'StyleOne'Type of callback function:
  • StyleOne = Simple check callback function

  • StyleTwo = Detailed check callback function

  • StyleThree = Check callback function with hyperlinked results

VisibleBooleantrueShow or hide check?
  • true = Display check in the Model Advisor

  • false = Hide check

EnableBooleantrueCan user enable and disable check?
  • true = Display check box control

  • false = Check box control is unavailable

ValueBooleantrueInitial status:
  • true = Check is enabled

  • false = Check is disabled

LicenseNameCell array{ } (empty cell array)Cell array of names of product licenses required to enable the check. The Model Advisor does not display the check if license requirements are not met.

    Tip   To find the correct text for license strings, type help license at the MATLAB command line.

ResultCell array{ } (empty cell array)Cell array used for storing the results returned by the callback function referenced by CallbackHandle.

ListViewVisibleBooleanfalse

A boolean value that sets the status of the Explore Result button.

  • true = Display the Explore Result button.

  • false = Hides the Explore Result button.

How Visible, Enable, and Value Properties Interact

Typically, you modify the behavior of the Visible, Enable, and Value properties in a process callback function (see Defining a Process Callback Function). The following chart illustrates how these properties interact:

Defining Where Custom Checks Appear

You can specify where the Model Advisor places custom checks within the Model Advisor tree using the following guidelines.

Code Example: Check Definition Function

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

function defineModelAdvisorChecks
mdladvRoot = ModelAdvisor.Root;

% --- sample check 1
rec = ModelAdvisor.Check('com.mathworks.sample.Check1');
rec.Title = 'Check Simulink block font';
rec.TitleTips = 'Example style three callback';
rec.setCallbackFcn(@SampleStyleThreeCallback,'None','StyleThree');
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});
% define action (fix) operation
myAction = ModelAdvisor.Action;
myAction.setCallbackFcn(@sampleActionCB);
myAction.Name='Fix block fonts';
myAction.Description=...
    'Click the button to update all blocks with specified font';
rec.setAction(myAction);
% add 'Explore Result' button
rec.ListViewVisible = true;
% publish check into By Product > Demo group.
mdladvRoot.publish(rec, 'Demo');

% --- sample check 2
rec = ModelAdvisor.Check('com.mathworks.sample.Check2');
rec.Title = 'Check Simulink window screen color';
rec.TitleTips = 'Example style one callback';
rec.setCallbackFcn(@SampleStyleOneCallback,'None','StyleOne');
% define action (fix) operation
myAction2 = ModelAdvisor.Action;
myAction2.setCallbackFcn(@sampleActionCB2);
myAction2.Name='Fix window screen color';
myAction2.Description=...
    'Click the button to change Simulink window screen color to white';
rec.setAction(myAction2);
% publish check into By Product > Demo group.
mdladvRoot.publish(rec, 'Demo');

% --- sample check 3
rec = ModelAdvisor.Check('com.mathworks.sample.Check3');
rec.Title = 'Check model optimization settings';
rec.TitleTips = 'Example style two callback';
rec.setCallbackFcn(@SampleStyleTwoCallback,'None','StyleTwo');
% define action (fix) operation
myAction3 = ModelAdvisor.Action;
myAction3.setCallbackFcn(@sampleActionCB3);
myAction3.Name='Fix model optimization settings';
myAction3.Description='Click the button to turn on model optimization settings';
rec.setAction(myAction3);
% publish check into By Product > Demo group.
mdladvRoot.publish(rec, 'Demo');
  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS