Package: ModelAdvisor
Defines result detail objects
In the check callback function, ModelAdvisor.ResultDetail
objects are
created for each model element returned by the find_system()
API,
such as a collection of blocks that violate a check.
ResultDetailObjs
objects are saved as a
ResultDetails
property of the ModelAdvisor.Check
class.
This example shows result details that correspond to the execution of check "Check
whether block names appear below blocks" in the slvnvdemo_mdladv
example model. To review the definition of the check, open the
sl_customization.m
file from the example model and see the sample
code for ModelAdvisor.Check('com.mathworks.sample.Check0')
.
From the slvnvdemo_mdladv
example model, open the
sl_customization.m
file. In the check callback
function, the find_system()
API returns
model elements in the system
that meet a specified
criteria. In this example, the function returns blocks whose name does not
appear below the block (violationBlks
).
% find all blocks whose name does not appear below blocks violationBlks = find_system(system, 'Type','block',... 'NamePlacement','alternate',... 'ShowName', 'on');
ModelAdvisor.ResultDetail
creates
ResultDetailObjs
for each model element returned by the
find_system
API. When
violationBlks
is empty, the
ElementResults
collection consists of a single object.
The Name,Value
pairs define the collection for a
nonviolated check. For this type of collection, the
Simulink.ModelAdvisor.setCheckResultStatus(true)
method
specifies that the check is not violated and displays
Passed
on the Model Advisor.
In this code sample, the find_system
API does not
identify any blocks whose name appears below the block, therefore
ElementResults
provides information content only.
% Results when no blocks % violate the check if isempty(violationBlks) ElementResults = ModelAdvisor.ResultDetail; ElementResults.IsInformer = true; ElementResults.Title = 'Identify blocks where the name is not displayed below the block.'; ElementResults.Information = 'Verifies that the name appears below the block.'; 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);
This example shows the ModelAdvisor.ResultDetail
properties
for ElementResults
when check "Check whether block names
appear below blocks" is not violated.
ElementResults = ResultDetail with properties: IsInformer = 1 Description = 'Identify blocks where the name is not displayed below the block.' Title = 'Check whether block names appear below blocks' Information = 'Verifies that the name appears below the block.' Status = 'All blocks have names displayed below the block.'
When the find_system
API returns a list of model
elements that meet specified criteria, the
ModelAdvisor.ResultDetail
class creates a
ResultDetailObjs
object for each element in
violationBlks
. The Name,Value
pairs define ElementResults
as a collection of objects
that violate the check. For this collection, the
Simulink.ModelAdvisor.setCheckResultStatus(false)
method specifies that the check is violated and displays
Warning
or Failed
on the Model
Advisor. The Simulink.ModelAdvisor.setActionEnable(true)
method enables the ability to fix the check violation issue from the Model
Advisor.
In this code sample, the find_system
API returns a
list of blocks whose name appears below the block.
ElementResults
includes each
ResultDetailObjs
object that violates the check and
provides a recommended action message for fixing the check violation.
% Create results when blocks violate the check else ElementResults(1,numel(violationBlks))=ModelAdvisor.ResultDetail; for i=1:numel(ElementResults) ElementResults(i).setData(violationBlks{i}); ElementResults.Title = 'Identify blocks where the name is not displayed below the block.'; ElementResults.Information = 'Verifies that the name appears below the block.'; ElementResults.Description = 'Identify blocks where the name is not displayed below the block.'; ElementResults.Status = 'The following blocks have names that do not display below the blocks:'; ElementResults.RecAction = 'Change the location such that the block name is below the block.'; end mdladvObj.setCheckResultStatus(false); mdladvObj.setActionEnable(true);
This example shows the ModelAdvisor.ResultDetail
properties
for ElementResults
when check "Check whether block names
appear below blocks" is violated.
ElementResults = ResultDetail with properties: IsInformer = 0; Description = 'Identify blocks where the name is not displayed below the block.'; Title = 'Check whether block names appear below blocks'; Information = 'Verifies that the name appears below the block.'; Status = 'The following blocks have names that do not display below the blocks:'; RecAction = 'Change the location such that the block name is below the block.'
The ModelAdvisor.Check.setResultDetails
method associates
the results with the check (CheckObj
).
% Associate the results with the check
CheckObj.setResultDetails([CheckObj.ResultDetails, ElementResults]);
After executing the check, you can view the results in the Model Advisor
as a collection, such as by recommended action, block, or subsystem. To
define this report style, specify 'DetailStyle
' as the
callback style in the ModelAdvisor.Check.setCallbackFcn
method.
% Define Model Advisor check "Check whether block names appear % below blocks". rec = ModelAdvisor.Check('com.mathworks.sample.Check0'); rec.Title = 'Check whether block names appear below blocks (recommended check style)'; rec.TitleTips = 'Example new style callback (recommended check style)'; rec.setCallbackFcn(@SampleNewCheckStyleCallback,'None', 'DetailStyle');