Promote parameter and add it to tab programatically
7 次查看(过去 30 天)
显示 更早的评论
Hello, I'm trying to create a mask of a 'parent' block in which the masks of 'child' blocks would appear as tabs (with all parameters promoted to the parent mask). First I create a tab:
parentMask = Simulink.Mask.get(parentBlock);
tabs = parentMask.addDialogControl('tabcontainer','tabCont');
tab = tabs.addDialogControl('tab','tab');
Now I'm trying to promote parameter from child and add it to the tab:
childMask = Simulink.Mask.get(childBlock);
param = childMask.Parameters(1); %for simplicity
and now I'm stuck in adding the parameter to the tab
props = {'Type','promote',...
'TypeOptions',{[get_param(childBlock,'Name'),'/',param.Name],... %not documented?, guessed by reverse-engineering
'Name',param.Name,...
'Prompt',param.Prompt,...
'TabName',tab.Name};
parentMask.addParameter(props{:});
but I get: Warning: 'TabName' cannot be set for 'system/parentBlock' as it will be removed in a future release. Use tab dialog controls to add parameters to tabs
I could not figure out a way how to add parameters to the tab as suggested by the hint. It is not documented (yet?).
1) How do I add any parameter to tab programmatically?
2) Or better, in the object world, is there a chance to promote a parameter just by passing its handle, for example by:
tab.addParameter('Type','promote',param)
There are also some bugs I've found on the way:
- example from https://nl.mathworks.com/help/simulink/slref/simulink.maskparameter.set.html does not work ('TabName' property)
- properties in https://nl.mathworks.com/help/simulink/slref/simulink.mask.adddialogcontrol.html contain a strange 'Filepath' property, probably just instead of 'TabName'
- there is no way how to discover/remove dialog controls without knowing their name. Magically, however, https://nl.mathworks.com/help/simulink/ug/control-masks-programmatically.html contains undocumented method getDialogControls, which can serve the purpose. Or by another undocumented way by invoking parentMask.DialogControls property.
The object-oriented way to mask creation is a big step towards user-friendliness when it comes to mask creation. I hope resolving these issues will help to move the cause further.
Thank you.
2 个评论
Kristian
2017-4-9
The actual question has not been answered yet. I have the same issue and cannot assign any parameter to a specific tab yet because there is no documentation but only the remark "You can change the location of these parameters on the dialog in a subsequent step." here without clarifying how to do that. This is really odd.
Even more odd ... if you finally find "TabName" somwhere (e.g. here) you get the following in the command window:
Warning: 'TabName' cannot be set for 'XYZ' as it will be
removed in a future release. Use tab dialog controls to add parameters to tabs
Okay ... so why is this in the official documentation for the current release?
Please advise how to perform the mentioned action. The intended result is even shown on the page linked above:
So there must be a way. Or is this fake only?
Saeid Saeidi
2017-5-10
unfortunately I have got the same Problem and yet not found any solution even after spending a whole day and exploring the documentation...
采纳的回答
Milan Assuied
2017-8-16
The 2017 documentation is incomplete and fail to provide the actual way of doing it.
The 2014b documentation however is complete. Here is what is missing:
6 - Move the mask parameters you created previously to the first tab.
opt1 = maskobj.getDialogControl('option1');
opt2 = maskobj.getDialogControl('option2');
opt1.moveTo(tab1);
opt2.moveTo(tab1);
I am also giving you an MWE with an edit field and a popup:
block = 'Untitled1/Atomic Subsystem';
wMask = Simulink.Mask.get(block);
if ~isempty(wMask)
wMask.delete();
end
wMask = Simulink.Mask.create(block);
wMask.addDialogControl('tabcontainer','tabContainer');
wTabContainer = wMask.getDialogControl('tabContainer');
wTab1 = wTabContainer.addDialogControl('tab', 'Tab1');
wTab2 = wTabContainer.addDialogControl('tab', 'Tab2');
wTab1.Prompt = 'Programatically added tab1';
wTab2.Prompt = 'Programatically added tab2';
wTextOnFirst = wTab1.addDialogControl('text', 'textOnFirst');
wTextOnFirst.Prompt = 'Some text on the first tab';
wTextOnSecond = wTab2.addDialogControl('text', 'textOnSecond');
wTextOnSecond.Prompt = 'Some text on the first tab';
wField = wMask.addParameter('Name', 'TextField' ...
, 'Type', 'edit'...
, 'Prompt', 'Programatically added text field'...
, 'Value', 'Toto'...
, 'Evaluate', 'on'...
, 'Tunable', 'off'...
, 'Enabled', 'on'...
, 'Visible', 'on'...
, 'Callback', 'disp( get_param(gcb, ''TextField''))');
wPopup = wMask.addParameter('Name', 'PopupField' ...
, 'Type', 'popup'...
, 'Prompt', 'Programatically added popup field'...
, 'TypeOptions', {'Value1', 'Value2', 'Value3'}...
, 'Evaluate', 'on'...
, 'Tunable', 'off'...
, 'Enabled', 'on'...
, 'Visible', 'on'...
, 'Callback', 'disp( get_param(gcb, ''PopupField''))');
wFieldDialog = wMask.getDialogControl('TextField');
wPopupDialog = wMask.getDialogControl('PopupField');
wFieldDialog.moveTo(wTab1);
wPopupDialog.moveTo(wTab2);
2 个评论
Mikhail
2018-2-8
In R2017b, you can do supply 'Container' to addParameter, so you won't need moveTo.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Author Block Masks 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!