Dynamic Mask Dialogs
When configuring a Simulink block, you usually use a
graphical user interface (GUI). In this post I’m going to investigate the
basics of programming a dynamic GUI using the mask editor.
The Saturation block features
In <a
href="https://blogs.mathworks.com/seth/2008/08/05/advanced-masking-concepts/">my
last post, I introduced the example of a Saturation block that can use
fixed limits set in the mask dialog or dynamic limits set via input signals.
Here is an animation of the mask GUI that configures the block for these
different modes.
When the Upper and Lower Limit Sources are internal, the
block has a single input port. When the Upper/Lower Limit Source is set to
external, the block grows additional ports to accept signals that provide those
limits.
Mask dialogs can associate actions with its components. Most
Simulink block GUIs have a standard row of buttons along the bottom. These four
buttons provide a consistent interface for Simulink blocks, and when you use
the mask editor, you get them free.
- OK – apply changes and dismiss the GUI
- Cancel – abandon changes made in the GUI and do not change the block
- Help – display documentation for the block
- Apply – apply changes made in the GUI
% uplimsrc_cb Dialog Callback
function uplimsrc_cb(blk)
en = get_param(blk,'MaskEnables'<span style='font-size:12.0pt;font-family:"Courier New";color:black'>);
switch get_param(blk,'uplimsrc')
case 'external'
en{2} = 'off';
case 'internal'
en{2} = 'on';
otherwise
disp('Should never get here'<span style='font-size:12.0pt;font-family:"Courier New";color:black'>)
end
set_param(blk,'MaskEnables',en)
When you click on the uplimsrc popup and change it, this callback fires. The callback:- Gets the MaskEnables, which is a cell array of on/off values, one for each parameter
- Assigns the second element (corresponding to uplim) to off if uplimsrc is external, on if uplimsrc is internal
- Sets the MaskEnables to use the updated on/off values
- Category:
- Masking
Comments
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.