Mask Linked Blocks
Simulink® libraries can contain blocks that have masks. An example of this type of block is the Ramp block. These blocks become library links when copied to a model or another library. You can add a mask on this linked block. If this linked block is in a library and copied again, you can add another mask to this new linked block thus creating a stack of masks. Masking linked blocks allows you to add a custom interface to the link blocks similar to other Simulink blocks.
You can also apply a mask to a block, then include the block in a library. Masking a block that is later included in a library requires no special provisions. For more information, see Create Custom Library.
The block mask that is present as part of the library is the base mask. A derived mask is the one created on top of the base mask.
For example, in the figure, Library A contains Block A, which has a Mask A. Block A is copied to Library B, and Mask B is added to it. When Block A is copied to Library B, a library link from Library B to Library A is created.
Block B is then copied to a model, and Mask C is added to it. This creates a library link from Block C to Library B. Block C now has Mask A, Mask B, and Mask C. Mask C is the derived mask and Mask B is the base mask.
For Block C:
Mask parameter names are unique in the stack.
You can set mask parameters for Mask B and Mask C.
Mask B and Mask C inherit
MaskType
andMaskSelfModifiable
parameters from Mask A.Mask initialization code for Mask C executes first, followed by Mask B and Mask A.
Variables are resolved starting from the mask immediately above the current mask in the stack. If the current mask is the top mask, it follows the regular variable resolution rules.
Creating or changing a library block mask changes the block interface in all models that access the block using a library reference, but has no effect on instances of the block that exist as separate copies.
To view related example, see Dynamic Masked Subsystem.
Guidelines for Mask Parameters
You cannot use same names for the mask parameters. The exception is the
Promote
type mask parameter, for which the name is inherited and is the same as that of the parameter promoted to it.You cannot set mask parameters for masks below the base mask. Mask parameters for masks below the base mask are inherited from the library.
Mask Behavior for Masked, Linked Blocks
The following are some of the behaviors that are important to understand about masked, linked blocks.
The
MaskType
and theMaskSelfModifiable
parameters are inherited from the base mask.The mask display code for the derived mask executes first, followed by the display code for the masks below it until we come across a mask whose
MaskIconFrame
parameter is set toopaque
.The mask initialization code for the derived mask executes first, followed by the initialization code for the masks below it.
Variables are resolved starting from the mask immediately above the current mask in the stack. If the current mask is the top mask, the regular variable resolution rules apply.
When you save a Simulink model or library containing a block with multiple masks, using Save > Export Model to > Previous Version on the Simulation tab, the
Sourceblock
parameter is modified to point to the library block having the bottom-most mask.The following occurs when you disable, break, or reestablish links to libraries:
If you disable the link to the library block, the entire mask hierarchy is saved to the model file so that the block can act as a standalone block.
If you break the link to the library block, the block becomes a standalone block.
If you reestablish the link after disabling by doing a restore, all changes to the mask are discarded. If you mask subsystems, you must reestablish the link after disabling by doing a push. When you do a push, subsystem changes are pushed to the library block and top mask changes are pushed to the immediate library.
Mask a Linked Block
Step 1: Create Custom Library with Masked Linked Block
In the Simulink Library Browser, click the arrow next to and select New Library.
Open the Ramp block in the Library editor window.
Select the Ramp block and on the Block tab, in the Mask group, click Create Mask.
The Mask Editor opens.
In the Icons pane, type:
plot ([0:10],[0,1:10])
In the Parameter & Dialog pane, select Promote to promote the
Slope
andInitial Output
parameters.Click OK.
Rename the block to Derived Ramp block.
Step 2: Add a Mask to the Masked, Link Block
In the Simulink Library Browser, click the arrow next to and select New Model. The Model editor window opens.
Drag the Derived Ramp block from the Library editor to the Model editor.
The Derived Ramp block in the model has multiple masks on it. You can set parameters of the derived mask.
Step 3: View Masks Below the Top Mask
Right-click the Derived Ramp block in the model and select Mask > View Base Mask. This opens the Mask Editor displaying the base mask definition.