Create a custom edit-time check that checks the position of a Trigger
block within a subsystem. This check requires the finishedTraversal
method because it must specify violation information after it checks the position of
blocks in a subsystem.
Obtain a model to try out the Model Advisor check.
Save the model to your working folder. Close the model.
To register the custom 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,
defineCheck
is the check definition function. Create the
sl_customization
function and save it to your working
folder.
Create the check definition function. Inside the function, create a ModelAdvisor.Check
object and specify the Check ID as an 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 TriggerBlockPosition
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. For this example, create a
defineCheck
function and include the code below in it. Save the
defineCheck
function to your working folder.
Create a class that derives from the ModelAdvisor.EdittimeCheck
abstract base class. For this example, create a class file named
TriggerBlockPosition.m
. Copy the code below into the
TriggerBlockPosition.m
file. Then, create a folder named
+MyEditTimeChecks
and save the
TriggerBlockPosition.m
file in that folder. The class must be in a
folder that has the same name as the package name.
The TriggerBlockPosition
class defines three methods:
TriggerBlockPosition
, blockDiscovered
, and
finishedTraversal
. The TriggerBlockPosition
method sets the CheckId
and TraversalType
properties. This check has a traversal type of
edittimecheck.TraversalTypes.ACTIVEGRAPH
because it must check
other blocks in the same subsystem as the Trigger block. The
blockDiscovered
method checks the position of
Trigger blocks within subsystems. The
finishedTraversal
method checks whether the position of these
Trigger blocks are higher than other blocks in a subsystem.
Refresh the Model Advisor to update the cache with the new check on the path.
Open the AdvisorCustomizationExample
model.
Open the Model Advisor Configuration Editor by clicking the
Modeling tab and selecting Model Advisor >
Configuration Editor or by entering this command at the command
prompt:
Create a custom configuration consisting of the custom edit-time check. Save the
configuration as my_config2.json
. Close the Model Advisor
Configuration Editor. Set the custom configuration to the
my_config2.json
file.
Turn on edit-time checking by clicking the Modeling tab and
selecting Model Advisor > Edit Time checks. After the Configuration
Parameters dialog box opens, select the Edit-Time Checks parameter.
Alternatively, you can enter this command at the command prompt:
To view the edit-time warnings, click the blocks highlighted in yellow.
In the Amplifier subsystem, the Trigger block does not produce
an edit-time warning because it is the top-most block in the subsystem. If you move the
Trigger block below another block, the produces an edit-time warning.