ModelAdvisor.ResultDetail Class
Namespace: ModelAdvisor
Define check result details
Description
Use objects of the ModelAdvisor.ResultDetail
class in your custom
check-authoring algorithm to provide details about check results. For checks that run only in
the Model Advisor, use the setResultDetails
method to associate these results with the ModelAdvisor.Check
object and
specify 'DetailStyle
' as the callback style in the
ModelAdvisor.Check.setCallbackFcn
function.
Properties
Data
— Block identifier or signal line handle
string
Block identifier or signal line handle for each block or signal that violates your custom check, specified as a string.
Data Types: char
Type
— Data type
SID
(default) | Signal
Data type, specified as:
SID
– Check violation is on a blockSignal
– Check violation is on a signal
Data Types: enum
Description
— Description of check results
string
Description of the check results, specified as a string.
Data Types: char
Title
— Title
string
Title of the check results, specified as a string.
Data Types: char
Information
— Additional information
string
Additional information about the check results, specified as a string.
Data Types: char
Status
— Status message
string
Status message that appears in the Model Advisor, specified as a string.
Data Types: char
RecAction
— Recommended action
string
Recommended action for fixing the check, specified as a string.
Data Types: char
ViolationType
— Severity of check results
"warn"
(default) | "pass"
| "fail"
| "info"
Severity of check results specified as "pass"
,
"fail"
, "info"
, or
"warn"
.
Data Types: char
Methods
Public Methods
ModelAdvisor.ResultDetail.setData | Associate Model Advisor check result with block or signal |
Examples
Define Custom Model Advisor Check for Block Violations
Create a custom Model Advisor check that checks whether block names appear below the blocks.
Open the model.
openExample('AdvisorCustomizationExample')
Save the model to your working folder. Close the model.
To register the edit-time check, create an sl_customization
function. The sl_customization
function accepts one argument, a
customization manager object. To register the custom check, use the
addModelAdvisorCheckFcn
method. The input to this method is a
handle to the check definition function. For this example,
defineDetailStyleCheck
is the check definition function.
Create the sl_customization
function and save it to your working
folder.
function sl_customization(cm)
cm.addModelAdvisorCheckFcn(@defineDetailStyleCheck);
Create the check definition function. For this example, create a function file
named defineDetailStyleCheck.m
. Copy the following code to
defineDetailStyleCheck.m
and save the function to your
working
folder.
function defineDetailStyleCheck % Create a ModelAdvisor.Check object and set the properties. rec = ModelAdvisor.Check('com.mathworks.sample.detailStyle'); rec.Title = 'Check whether block names appear below blocks'; rec.TitleTips = 'Check position of block names'; rec.setCallbackFcn(@DetailStyleCallback,'None','DetailStyle'); % Create a ModelAdvisor.Action object for setting a fix operation. myAction = ModelAdvisor.Action; myAction.setCallbackFcn(@ActionCB); myAction.Name='Make block names appear below blocks'; myAction.Description='Click the button to place block names below blocks'; rec.setAction(myAction); % Publish the check to the Demo group. mdladvRoot = ModelAdvisor.Root; mdladvRoot.publish(rec, 'Demo'); end % ----------------------------- % This callback function uses the DetailStyle CallbackStyle type. % ----------------------------- function DetailStyleCallback(system, CheckObj) % Get the Model Advisor object. mdladvObj = Simulink.ModelAdvisor.getModelAdvisor(system); % Find the blocks whose names do not appear below the block. violationBlks = find_system(system, 'Type','block',... 'NamePlacement','alternate',... 'ShowName', 'on'); if isempty(violationBlks) ElementResults = ModelAdvisor.ResultDetail; ElementResults.ViolationType = 'info'; ElementResults.Description = 'Identify blocks where the name is not displayed below the block.'; ElementResults.Status = 'All blocks have names displayed below the block.'; mdladvObj.setCheckResultStatus(true); else for i=1:numel(violationBlks) ElementResults(1,i) = ModelAdvisor.ResultDetail; end for i=1:numel(ElementResults) ModelAdvisor.ResultDetail.setData(ElementResults(i), 'SID',violationBlks{i}); ElementResults(i).Description = 'Identify blocks where the name is not displayed below the block.'; ElementResults(i).Status = 'The following blocks have names that do not display below the block:'; ElementResults(i).RecAction = 'Change the location such that the block name is below the block.'; end mdladvObj.setCheckResultStatus(false); mdladvObj.setActionEnable(true); end CheckObj.setResultDetails(ElementResults); end % ----------------------------- % This action callback function changes the location of the block names. % ----------------------------- function result = ActionCB(taskObj) mdladvObj = taskObj.MAObj; checkObj = taskObj.Check; resultDetailObjs = checkObj.ResultDetails; for i=1:numel(resultDetailObjs) block=Simulink.ID.getHandle(resultDetailObjs(i).Data); set_param(block,'NamePlacement','normal'); end result = ModelAdvisor.Text('Changed the location such that the block name is below the block.'); mdladvObj.setActionEnable(false); end
The check definition function contains ModelAdvisor.Check
and ModelAdvisor.Action
objects that
define the check actions and a fix. For more details on these aspects of the code,
see Fix a Model to Comply with Conditions that You Specify with the Model Advisor.
The defineDetailStyleCheck
function contains a
DetailStyleCallback
callback function. To return the blocks
whose names do not appear below them, the DetailStyleCallback
function uses the find_system
function.
When violationBlks
is empty, the code creates one
ModelAdvisor.ResultDetail
object,
ElementResults
. ElementResults
specifies
information about the passing check that appears in the Model Advisor.
When the find_system
function returns a list of blocks that
violate the check, ElementResults
is an array of
ModelAdvisor.ResultDetail
objects. The array contains one
object for each block that violates the check. Each object contains information
about the blocks that appears in the Model Advisor.
Refresh the Model Advisor to update the cache with the new check on the path.
Advisor.Manager.refresh_customizations
Open the AdvisorCustomizationExample
model.
In Simulink®, open the Model Advisor by clicking the Modeling tab and selecting Model Advisor.
In the left pane, select By Product > Demo > Check whether block names appear below blocks and click Run Checks.
To address the warning, click Fix.
Define Custom Edit-Time Check for Signal Violations
Create a custom edit-time check that checks whether signals that connect to Outport blocks have labels.
Open the model.
openExample('AdvisorCustomizationExample')
Save the model to your working folder. Close the model.
To register the custom edit-time check, create an
sl_customization
function and save it to your working
folder.
function sl_customization(cm)
cm.addModelAdvisorCheckFcn(@defineCheck);
Create the check definition function. Inside the function, create a ModelAdvisor.Check
object and specify
the check ID as the input argument. Then, specify the
ModelAdvisor.Check
Title
and CallbackHandle
properties. The
CallbackHandle
property is the name of the class that you
create to define the edit-time check. For this example,
MyEditTimeChecks
is the package name and
SignalLabel
is the class name. Then, publish the check to a
new folder in the Model Advisor. For this example, the folder name is Demo:
Edit-Time Checks
. Create a defineCheck
function and
include the following code. Save the defineCheck
function to your
working folder.
function defineCheck rec = ModelAdvisor.Check("advisor.edittimecheck.SignalLabel"); rec.Title = 'Check that signals have labels if they are to propagate those labels'; rec.CallbackHandle = 'MyEditTimeChecks.SignalLabels'; mdladvRoot = ModelAdvisor.Root; mdladvRoot.publish(rec,'DEMO: Edit-Time Checks');
Create a class that derives from the ModelAdvisor.EdittimeCheck
abstract base class. For this example,
create a class file named SignalLabel.m
. Copy the following code
into the SignalLabel.m
file and save it to the
+MyEditTimeChecks
folder.
classdef SignalLabels < ModelAdvisor.EdittimeCheck methods function obj=SignalLabels(checkId) obj=obj@ModelAdvisor.EdittimeCheck(checkId); obj.traversalType = edittimecheck.TraversalTypes.BLKITER; end function violation = blockDiscovered(obj, blk) violation = []; ports = get_param(blk,'Ports'); lh = get_param(blk, 'LineHandles'); if strcmp(get_param(blk,'BlockType'),'Outport') for j = 1 : ports(1) if lh.Inport(j) ~= -1 % failure case: no connection allsources = get_param(lh.Inport(j),'SrcPortHandle'); hiliteHandle = get_param(lh.Inport(j), 'DstPortHandle'); if (isempty(allsources) ~= 0) || (isempty(find(allsources==-1,1)) ~= 0) lh_obj = get_param(lh.Inport(j),'Object'); if isempty(lh_obj.Name) if strcmp(lh_obj.signalPropagation,'off') == 1 allsources_parent = get_param(allsources,'Parent'); if strcmp(get_param(allsources_parent,'BlockType'),'Inport') buscreator_outputs = get_param(allsources_parent,'IsBusElementPort'); else buscreator_outputs = 'off'; end if ~strcmp(buscreator_outputs,'on') violation = ModelAdvisor.ResultDetail; ModelAdvisor.ResultDetail.setData(violation, 'Signal',hiliteHandle); violation.Description ='The model does not adhere to the signal label modeling guideline.'; violation.CheckID = obj.checkId; violation.Title = 'Signal Label Missing'; violation.Information = 'This check verifies the presence of signal label.'; violation.Status = 'The following signals do not have a label:'; end end end end end end end end end end
For more information on the code in the
ModelAdvisor.EdittimeCheck
class, see Define Edit-Time Checks to Comply with Conditions That You Specify with the Model Advisor.
The blockDiscovered
method contains an algorithm that defines
check violations. Unlike custom checks that appear only in the Model Advisor, this
algorithm does not contain the find_system
function. The
blockDiscovered
method takes block handles as inputs and
traverses the model, so you do not need the find_system
function
for custom edit-time checks.
For each model element that violates the check, the code creates a
ModelAdvisor.ResultDetail
object. For this example, because
the violations are on signals, the check must use parameters on the line handles of
blocks. To find signals with violations, you must specify the
LineHandles
option. Specifically, for signals that connect to
Outport blocks, this algorithm checks whether the
Name
signal parameter has a value. Then, because the
violation is on a signal, the algorithm highlights the signal by creating a
violation object with the Type
property value set to
Signal
.
Refresh the Model Advisor to update the cache with the new checks on the path.
Advisor.Manager.refresh_customizations
Open the AdvisorCustomizationExample
model.
In Simulink, open the Model Advisor Configuration Editor by clicking the Modeling tab and selecting Model Advisor > Configuration Editor.
Create a custom configuration that consists of the custom edit-time check by deleting every folder except the DEMO: Edit Time Checks folder.
Save the configuration as my_config.json
. When prompted to set
this configuration as the default, click No.
Close the Model Advisor Configuration Editor.
Set the custom configuration to the my_config.json
file by
clicking the Modeling tab and selecting Model Advisor > Edit-Time Checks. In the Configuration Parameters dialog box, set the Model
Advisor configuration file parameter to the path of the configuration
file.
Turn on edit-time checking by selecting the Edit-Time Checks parameter. Close the Model Configuration Parameters dialog box.
To view the edit-time warning, click the signal highlighted in yellow. The signal connecting to the Outport block produces a warning because it does not have a label.
This image shows the Model Advisor report and indicates which
ModelAdvisor.ResultDetail
properties populate each
section:
Version History
Introduced in R2018bR2023b: IsInformer
and IsViolation
properties will be removed
The IsInformer
and IsViolation
properties for
the ModelAdvisor.ResultDetail
class will be removed in a future release.
Specify the severity of Model Advisor check results by using the property
ViolationType
instead.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)