Matlab Simulink allows you to create masked blocks. These highly customizable block types are supported by the itemis Model Viewer. A mask defines a user interface for entering block properties combined with a custom graphical visualization of the masked Simulink block. The visualization is defined by special drawing commands. The mask hides the block’s contents, making it appear to the user as an atomic block with its own parameter dialog box and icon. The minimal required Simulink model version for block mask support is 8.0 (Release 2012b).
To create and edit masked blocks, Matlab Simulink provides a Mask Editor. In the Mask Editor the user defines a new visual block representation with some kind of drawing commands. The API provides different functions to display strings, render images or plot some coordinates. Additionally, it allows access to predefined parameters and gives you the option to define local variables.
Furthermore, the user can define a script to initialize parameters defined in masked blocks. The user can enter any valid MATLAB expression, consisting of MATLAB functions and scripts, operators, and variables defined in the mask and Matlab workspace. The initialization script is executed and interpreted by Simulink before the drawing commands are executed in order to render the custom visualization. This behavior enables the user to do some complex calculations and store the results in mask parameters which can be accessed later by the drawing commands to render the visual.
Due to Simulinks scripting functions, masked blocks can become very complex. The itemis Model Viewer supports the visualization of masked blocks with custom drawing scripts.
In most cases masked blocks are displayed simply as you would expect. If the block displays three question marks, it is an indicator that information for the correct display of the block is missing. Reasons for this can be unsupported drawing commands in the display script or missing mask parameters which are necessary for the complete interpretation of the script.
If your script contains unsupported commands, it may be possible to replace them with supported commands. You can find a list of supported drawing commands here.
Complex calculations within the drawing script that use unsupported commands could, for example, be moved to the initialization script part in order to assign the return values of the calculations to a mask parameter. The drawing script can then access this parameter. The parameter can also be exported so that the visualization can also be displayed in the Model Viewer. Further reasons for the export of mask parameters can be found in this chapter.
As described earlier the user can use an initialization script within the mask editor to define mask parameters which can be used within expressions in the drawing command script.
To be able to process the commands completely – especially values of mask parameters, it is necessary to export these parameters from the masked blocks. For this purpose the Model Viewer provides an export script which must be executed by the user within Matlab. The script collects the mask parameters for each masked block and workspace parameters and stores them in a file which is located in the same folder as the root model file. The model file name with the extension “.ymvd” is used as the export file name. The serialization format is JSON. Chapter 4.2.1 describes how the export script is installed and used.
As described in the previous chapter, the initialized mask parameters of a block can be exported from Matlab. If a masked block defines such parameters and they have been exported, these are listed in the Properties View.
The picture above shows the Properties View of a masked block. For this block, a mask parameter ‘param1’ with the value 0 was exported.
The parser parses the drawing command script so that the interpreter can process it, using a delegate for rendering the graphics. Most of the icon drawing commands are already supported. These include:
As you can see, most of the icon drawing commands and corresponding parameters supported by MATLAB Simulink can be interpreted. Unsupported arguments are ignored, and the block_icon() command is not yet implemented.