Reputation: 1750
I have a simulink masked block, I can open the mask using open_system(gcb)
and I can close it using 'close_system(gcb)`.
However, any unsaved parameter will be erased. Is there any way to ensure mask parameters are saved ? Like, clicking on Apply button or OK button ?
My matlab version is 2011b, the Simulink.Mask framework is not available in this version.
Thanks
Upvotes: 0
Views: 2573
Reputation: 1750
Here is a working solution:
First you have to get the block dialog:
function blockDialog = getBlockDialog( blockHandle )
blockDialog = [];
allOpenDialogs = DAStudio.ToolRoot.getOpenDialogs;
for index = 1:length( allOpenDialogs )
dialogSource = allOpenDialogs( index ).getDialogSource;
if isa(dialogSource, 'Simulink.SLDialogSource')
dialogSourceSID = Simulink.ID.getSID( dialogSource.get_param('handle') );
if isequal(dialogSourceSID, Simulink.ID.getSID( blockHandle ))
blockDialog = allOpenDialogs( index );
break;
end
end
end
end
Second you have to get the block widget:
function blockWidget = getBlockWidget( blockDialog)
blockWidget = [];
if ~isempty( blockDialog )
blockWidget = DAStudio.imDialog.getIMWidgets( blockDialog );
end
end
And last you perform the wanted action on the dialog using the widget:
function clickBlockOk( blockHandle )
blockDialog = getBlockDialog( blockHandle );
blockWidget = getBlockWidget( blockDialog );
if ~isempty(blockWidget)
blockWidget.clickOk( blockDialog );
end
end
function clickBlockApply( blockHandle )
blockDialog = getBlockDialog( blockHandle );
blockWidget = getBlockWidget( blockDialog );
if ~isempty(blockWidget)
blockWidget.clickApply( blockDialog );
end
end
In the widget you can find others functions like clickHelp, clickRevert, clickCustomButton.
What is really weird is that you need the dialog to get the widget but you still need the dialog to interact with it using the widget .... this is something that I do not get architecturally, but there's maybe a reason about it.
Upvotes: 1