Effacer les filtres
Effacer les filtres

Promote parameter and add it to tab programatically

6 vues (au cours des 30 derniers jours)
Jiri Dostal
Jiri Dostal le 1 Fév 2017
Commenté : Timo Dörsam le 29 Sep 2023
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 commentaires
Kristian
Kristian le 9 Avr 2017
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
Saeid Saeidi le 10 Mai 2017
unfortunately I have got the same Problem and yet not found any solution even after spending a whole day and exploring the documentation...

Connectez-vous pour commenter.

Réponse acceptée

Milan Assuied
Milan Assuied le 16 Août 2017
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 commentaires
Mikhail
Mikhail le 8 Fév 2018
In R2017b, you can do supply 'Container' to addParameter, so you won't need moveTo.
Timo Dörsam
Timo Dörsam le 29 Sep 2023
How to align the new parameter in the container, to a specific position?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Simulink Functions dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by