Main Content

Add Dynamic Behavior to Masked Icons

Using Graphical Icon Editor, you can add dynamic behavior to masked block icons:

  • Render multiple variations of the same block icon using parts.

  • Hide or unhide elements in the icon based on block parameters or mask parameters.

  • Position icon elements relatively using layout constraints.

  • View the evaluated value of a block parameter on the block icon.

  • Create a block icon that dynamically changes size when you resize the block.

Render Multiple Variations of Same Block Icon Using Parts

Use parts in Graphical Icon Editor to store multiple variations of a block icon in a single file. The parts enable you to efficiently organize multiple variations of an image without the need to keep track of multiple files. Create each variation in a separate part. Each variation is visible based on conditions you place on the block or mask parameters.

Consider a masked Subsystem block with the popup parameter set to portSelection. The block icon changes based on the value you select for portSelection in the Block Parameters dialog box. If you specify the No. of Ports as 3, an image of a three-switch port appears on the block icon. If you specify the No. of Ports as 4, an image of a four-switch port appears on the block icon

layer variations

To create block icon variations using parts:

  1. Create a mask on the Subsystem block.

  2. In the Mask Editor, in the Controls pane, click Popup to create a popup parameter. In the Property Editor pane, double-click the cell to the right of Type options and select List of options. Add two rows, specify both the Description and Value for the first row as 3, and specify both the Description and Value for the second row as 4. Click Save. mask editor parameter

  3. In the Icon tab, click Drawing Commands and select Graphical.

  4. Create an icon with a four-switch port. Double-click the parts name to rename the part as Four_switch_port.

  5. Click duplicate to duplicate the part. Modify the duplicated part to show a three-switch port. Rename the part as Three_switch_port. add parts

  6. To control when a particular parts appears as the block icon, enter parts conditions based on the corresponding block parameters by clicking condition visibility icon. In this example, specify the conditions as portSelection == 3 for Three_switch_port and portSelection == 4 for the part Four_switch_port. Click OK.

    set the visibility condition

  7. In the Block Parameters dialog box, change the value of the No. of Ports parameter. Observe how the block icon changes based on the value you select for the parameter.

    image variation based on block parameter

Hide or Unhide Elements in the Icon Based on Block Parameters or Mask Parameters

Hide or unhide elements in the icon by applying certain conditions to the block parameters.

For example, consider a Gain block with matrix values. The elements in the Gain block appear and disappear based on the conditions set on the block parameter.

hide elements based on block parameters

Set the condition in the following figure where the element uvec in the Gain block is visible only when the value of the Multiplication parameter is Matrix_Ku_Vector.

Note

Visibility conditions support JavaScript expressions only.

visible condition set to multType==Matrix_Ku_Vector

Position Elements Relatively Using Layout Constraints

Layout constraints help you to position each icon element relative to other icon elements on the canvas or the canvas itself. To set layout constraints on the icon elements, select the element, right-click and select Set Layout Constraints. In the Layout Constraints tab, select the source and relative elements from the drop-down in the pinning panel. Select the Source element and the Relative to element. Pin both the Source element and the Relative to element using the pinning panel. Specify the Offset. Click More to specify complex conditions to position the elements.

pin the source and relative to elements

Click Preview in Model to see the effect of layout constraints.

You can also set complex conditions in layout constraints, for example, you can force the left bracket of the matrix in the mask icon of the Gain block to be three pixels to the left of the first element of the matrix.

To set this complex condition:

  1. Right-click the leftBracket and select Set Layout Constraints.

  2. In the Layout Constraints tab, click More

  3. Set matrix.left-3, matrix.top, andmatrix.bottom in Right, Top and Bottom respectively.

Layout constraints for the left bracket element

Text Parameterization

You can view the evaluated value of a block parameter on the block icon. Enter the block parameter name or a placeholder in Parameter/Value that will return the text or value during simulation. To see the evaluated value of a block parameter on the block icon, preview the icon on the Simulink canvas.

For example, to display a parameter value on a block icon:

  1. Create a mask on the block.

  2. In the Parameters & Dialog tab, create a mask parameter Speed and specify the value as 120.

    text-parameterization

  3. On the Icon tab, click Drawing Commands and select Graphical.

  4. Create a text element in the canvas. Right-click the text element and select Parameterize.

    select parameterize option

  5. In the Text Parameterization panel, select Dynamic Text and enter the parameter name, Speedin Parameter/Value.

    parameter value in text parameterization

  6. Click Editing Behavior. Select Parameter in Edit Handler list and specify the Parameter Name as Speed.

    editing behavior

  7. Click Preview in Model and observe that the value of the parameter is displayed on the icon.

    text parameterization preview

Display Elements That Fit Size of Icon

You can create a block icon that dynamically changes sizes when you resize the block.

To group elements under first-fit, select the element in the canvas, right-click and select Convert to First Fit.

For example, the following figure shows a Gain block with four elements of different sizes grouped under a first-fit element. When you resize the block, the element that fits in the size of the Gain block appears as the icon of the block.

To group elements under first-fit, select the element in the canvas, right-click and select Convert to First Fit.

first fit

Related Topics