Copying Simulink masks from multiple blocks to a single block.

조회 수: 9 (최근 30일)
Stuart
Stuart 2014년 2월 2일
답변: Ryan Chladny 2017년 8월 2일
Hi,
When using HDL coder you can't have masked subsystems under a subsystem with a mask, in other words there can be only one mask in a model. What I would like to do is programmatically copy masks from lower subsystems to the highest level masked subsystem I have. I can use find_system(' modelname ','Mask','on')to find masked blocks and use the commands:
pSource = Simulink.Mask.get( srcBlockName )
pDest = Simulink.Mask.create(destBlockName)
pDest.copy(pSource)
To get a mask and copy a mask from one block to another. However, pDest.copy(pSource) replaces any existing mask. What I would like to do is if masks already exists add the new mask as a separate tab. That way all my masks could be at the top level and exist as separate tabs for "neatness" although not absolutely necessary.
Any help appreciated
Thanks
Stuart
  댓글 수: 1
Guy Championnet
Guy Championnet 2016년 8월 29일
Hi,
I needed to do something very similar, so I wrote the following function:
function [ ] = CopyMaskDialogElementsFromTo(pSourceMask,pSrcDialogElement,pDestMask,pDestDialogElement)
% Recursively copy the content of the mask pSourceMask under dialog element pSrcDialogElement
% to the mask pDestMask under dialog element pDestDialogElement
for i=1:size(pSrcDialogElement.DialogControls,2)
switch class(pSrcDialogElement.DialogControls(i))
case 'Simulink.dialog.Text'
tmpDialogCtrlObject=pDestDialogElement.addDialogControl('Type','text',...
'Name',pSrcDialogElement.DialogControls(i).Name,...
'Prompt',pSrcDialogElement.DialogControls(i).Prompt,...
'WordWrap',pSrcDialogElement.DialogControls(i).WordWrap,...
'Row',pSrcDialogElement.DialogControls(i).Row);
tmpDialogCtrlObject.Enabled = pSrcDialogElement.DialogControls(i).Enabled;
tmpDialogCtrlObject.Visible = pSrcDialogElement.DialogControls(i).Visible;
case 'Simulink.dialog.Tab'
tmpDialogCtrlObject=pDestDialogElement.addDialogControl('Type','tab',...
'Name',pSrcDialogElement.DialogControls(i).Name,...
'Prompt',pSrcDialogElement.DialogControls(i).Prompt);
CopyMaskDialogElementsFromTo( pSourceMask,pSrcDialogElement.DialogControls(i),pDestMask,tmpDialogCtrlObject)
tmpDialogCtrlObject.Enabled = pSrcDialogElement.DialogControls(i).Enabled;
tmpDialogCtrlObject.Visible = pSrcDialogElement.DialogControls(i).Visible;
case 'Simulink.dialog.TabContainer'
tmpDialogCtrlObject=pDestDialogElement.addDialogControl('Type','tabcontainer',...
'Name',pSrcDialogElement.DialogControls(i).Name,...
'Row',pSrcDialogElement.DialogControls(i).Row);
CopyMaskDialogElementsFromTo( pSourceMask,pSrcDialogElement.DialogControls(i),pDestMask,tmpDialogCtrlObject)
tmpDialogCtrlObject.Enabled = pSrcDialogElement.DialogControls(i).Enabled;
tmpDialogCtrlObject.Visible = pSrcDialogElement.DialogControls(i).Visible;
case 'Simulink.dialog.Panel'
tmpDialogCtrlObject=pDestDialogElement.addDialogControl('Type','panel',...
'Name',pSrcDialogElement.DialogControls(i).Name,...
'Row',pSrcDialogElement.DialogControls(i).Row);
CopyMaskDialogElementsFromTo( pSourceMask,pSrcDialogElement.DialogControls(i),pDestMask,tmpDialogCtrlObject)
tmpDialogCtrlObject.Enabled = pSrcDialogElement.DialogControls(i).Enabled;
tmpDialogCtrlObject.Visible = pSrcDialogElement.DialogControls(i).Visible;
case 'Simulink.dialog.Image'
tmpDialogCtrlObject=pDestDialogElement.addDialogControl('Type','image',...
'Name',pSrcDialogElement.DialogControls(i).Name,...
'FilePath',pSrcDialogElement.DialogControls(i).FilePath,...
'Row',pSrcDialogElement.DialogControls(i).Row);
tmpDialogCtrlObject.Enabled = pSrcDialogElement.DialogControls(i).Enabled;
tmpDialogCtrlObject.Visible = pSrcDialogElement.DialogControls(i).Visible;
case 'Simulink.dialog.Hyperlink'
tmpDialogCtrlObject=pDestDialogElement.addDialogControl('Type','hyperlink',...
'Name',pSrcDialogElement.DialogControls(i).Name,...
'Prompt',pSrcDialogElement.DialogControls(i).Prompt,...
'Callback',pSrcDialogElement.DialogControls(i).Callback,...
'Row',pSrcDialogElement.DialogControls(i).Row);
tmpDialogCtrlObject.Enabled = pSrcDialogElement.DialogControls(i).Enabled;
tmpDialogCtrlObject.Visible = pSrcDialogElement.DialogControls(i).Visible;
case 'Simulink.dialog.Group'
tmpDialogCtrlObject=pDestDialogElement.addDialogControl('Type','group',...
'Name',pSrcDialogElement.DialogControls(i).Name,...
'Prompt',pSrcDialogElement.DialogControls(i).Prompt,...
'Row',pSrcDialogElement.DialogControls(i).Row);
CopyMaskDialogElementsFromTo( pSourceMask,pSrcDialogElement.DialogControls(i),pDestMask,tmpDialogCtrlObject)
tmpDialogCtrlObject.Enabled = pSrcDialogElement.DialogControls(i).Enabled;
tmpDialogCtrlObject.Visible = pSrcDialogElement.DialogControls(i).Visible;
case 'Simulink.dialog.Button'
tmpDialogCtrlObject=pDestDialogElement.addDialogControl('Type','pushbutton',...
'Name',pSrcDialogElement.DialogControls(i).Name,...
'Prompt',pSrcDialogElement.DialogControls(i).Prompt,...
'Callback',pSrcDialogElement.DialogControls(i).Callback,...
'Row',pSrcDialogElement.DialogControls(i).Row,...
'FilePath',pSrcDialogElement.DialogControls(i).FilePath);
tmpDialogCtrlObject.Enabled = pSrcDialogElement.DialogControls(i).Enabled;
tmpDialogCtrlObject.Visible = pSrcDialogElement.DialogControls(i).Visible;
case {'Simulink.dialog.parameter.Edit','Simulink.dialog.parameter.Max','Simulink.dialog.parameter.Min','Simulink.dialog.parameter.Popup'}
tmpParamObject = pSourceMask.getParameter(pSrcDialogElement.DialogControls(i).Name);
pDestMask.addParameter('Type',tmpParamObject.Type,...
'TypeOptions',tmpParamObject.TypeOptions,...
'Name',tmpParamObject.Name,...
'Prompt',tmpParamObject.Prompt,...
'Value',tmpParamObject.Value,...
'Evaluate',tmpParamObject.Evaluate,...
'Tunable',tmpParamObject.Tunable,...
'NeverSave',tmpParamObject.NeverSave,...
'Internal',tmpParamObject.Internal,...
'Enabled',tmpParamObject.Enabled,...
'Visible',tmpParamObject.Visible,...
'ToolTip',tmpParamObject.ToolTip,...
'Callback',tmpParamObject.Callback);
tmpDialogCtrlObject = pDestMask.getDialogControl(pSrcDialogElement.DialogControls(i).Name);
tmpDialogCtrlObject.moveTo(pDestDialogElement);
tmpDialogCtrlObject.PromptLocation = pSrcDialogElement.DialogControls(i).PromptLocation;
tmpDialogCtrlObject.Row = pSrcDialogElement.DialogControls(i).Row;
case {'Simulink.dialog.parameter.CheckBox', 'Simulink.dialog.parameter.Control', 'Simulink.dialog.parameter.RadioButton'}
tmpParamObject = pSourceMask.getParameter(pSrcDialogElement.DialogControls(i).Name);
pDestMask.addParameter('Type',tmpParamObject.Type,...
'TypeOptions',tmpParamObject.TypeOptions,...
'Name',tmpParamObject.Name,...
'Prompt',tmpParamObject.Prompt,...
'Value',tmpParamObject.Value,...
'Evaluate',tmpParamObject.Evaluate,...
'Tunable',tmpParamObject.Tunable,...
'NeverSave',tmpParamObject.NeverSave,...
'Internal',tmpParamObject.Internal,...
'Enabled',tmpParamObject.Enabled,...
'Visible',tmpParamObject.Visible,...
'ToolTip',tmpParamObject.ToolTip,...
'Callback',tmpParamObject.Callback);
tmpDialogCtrlObject = pDestMask.getDialogControl(pSrcDialogElement.DialogControls(i).Name);
tmpDialogCtrlObject.moveTo(pDestDialogElement);
tmpDialogCtrlObject.Row = pSrcDialogElement.DialogControls(i).Row;
otherwise
disp(['Unknown type:', class(pSrcDialogElement.DialogControls(i))])
end
end
end
To call the function, you need to get the source/destination block pointers and the dialog controls pointers to copy from/to.
pSourceMask = Simulink.Mask.get('sys/blockFrom');
pDestMask = Simulink.Mask.get('sys/blockTo');
[pSrcDialogElement, ~] = pSourceMask.getDialogControl('ParameterGroupVar');
[pDestDialogElement, ~] = pDestMask.getDialogControl('AddUnderThisTab');
CopyMaskDialogElementsFromTo( pSourceMask,pSrcDialogElement,pDestMask,pDestDialogElement);

댓글을 달려면 로그인하십시오.

답변 (1개)

Ryan Chladny
Ryan Chladny 2017년 8월 2일
Nice function Guy and thanks for posting. I would only suggest that you include a switch case for the CollapsiblePanel dialog type now as well found in the later releases (same as Panel).
case 'Simulink.dialog.CollapsiblePanel'
tmpDialogCtrlObject=pDestDialogElement.addDialogControl('Type','panel',...
'Name',pSrcDialogElement.DialogControls(i).Name,...
'Row',pSrcDialogElement.DialogControls(i).Row);
CopyMaskDialogElementsFromTo( pSourceMask,pSrcDialogElement.DialogControls(i),pDestMask,tmpDialogCtrlObject)
tmpDialogCtrlObject.Enabled = pSrcDialogElement.DialogControls(i).Enabled;
tmpDialogCtrlObject.Visible = pSrcDialogElement.DialogControls(i).Visible;

카테고리

Help CenterFile Exchange에서 Author Block Masks에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by