Copying Simulink masks from multiple blocks to a single block.
28 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Guy Championnet
am 29 Aug. 2016
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);
Antworten (1)
Ryan Chladny
am 2 Aug. 2017
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;
0 Kommentare
Siehe auch
Kategorien
Mehr zu Author Block Masks finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!