📄 accelopt.m
字号:
function dlg_h = accelopt(sbCmd, model_h)
% ACCELOPT generated by MKDLG 31-Mar-93, 12:13:12 AM.
% ACCELOPT creates and manages the 'Accelerator Options...'
% dialog for a SIMULINK block diagram.
%
% Rick Spada 11-26-92
% Copyright (c) 1990-94 by The MathWorks, Inc.
% no arguments implies create the dialog
if nargin==0,
sbCmd='create';
model_h=get_param(get_param,'handle');
elseif nargin==1,
dlg_h=gcf;
uictl_arr=get(dlg_h,'User');
if nargin < 2,
model_h=uictl_arr(length(uictl_arr));
end;
end;
%
%-----------------------------------------------------------------
% The following switchboard commands, defined by sbCmd, are
% accepted by accelopt:
%
% 'create' - create the dialog
% 'Compile command' - change the 'Compile command'
% 'Done' - close the dialog
% 'Revert' - revert the dialog to its original state
% 'Help' - present the help dialog
% 'motion' - mouse motion callback
% 'Name check'
%
% anything else is simply ignored...
%-----------------------------------------------------------------
%
%
%--- C R E A T E -------------------------------------------------
%
%
if strcmp(sbCmd,'create'),
% first check to see if a dialog already exists, if so, and
% it's a valid figure handle, just bring it forward
dlg_h=get_param(model_h,'Accelerator options dialog');
if ~isempty(dlg_h),
if ~isempty(find(dlg_h==get(0,'Children'))),
figure(dlg_h);
return;
end;
end;
% Compute the font characteristics, and from that the dialog
% position.
fontSize=get(0,'DefaultTextFontSize');
colW=fontSize+1;
rowH=1.33*(fontSize+2);
margin=max(rowH,colW);
screenSize=get(0,'ScreenSize');
dlgPos=round([(screenSize(1)+screenSize(3)-25*colW)/2,...
(screenSize(2)+screenSize(4)-4*rowH)/2,...
colW*25+margin,...
rowH*4.6+margin]);
dlgWidth=dlgPos(3);
dlgHeight=dlgPos(4);
modelName=get_param(model_h,'name');
dlgName=[get_param(model_h,'name'),' - Accelerator Options'];
% set some defaults to eliminate visible changes
defBG=get(0,'DefaultuicontrolBackgroundColor');
defFigColor=get(0,'DefaultFigureColor');
defFigNumberTitle=get(0,'DefaultFigureNumberTitle');
set(0,'DefaultFigureColor',defBG,...
'DefaultFigureNumberTitle','off');
% Create a figure for the dialog.
dlg_h = figure('Position',dlgPos,... % position the dialog
'Visible','off',... % make it visible
'Name',dlgName,... % give the dialog a name
'MenuBar','none',... % no menu bar
'NextPlot','New',... % prevent plot from overwriting it
'Units','Pixel',... % pixel coordinates
'DefaultTextFontName','Helvetica',... % use helvetica for the font
'DefaultTextFontSize',12); % use point size 12
set(0,'DefaultFigureColor',defFigColor,...
'DefaultFigureNumberTitle',defFigNumberTitle);
% Create the uicontrols
uictl_arr = -1 * ones(1,5);
% --------------------+ Item 1 +--------------------
% Create a uicontrol of type 'Frame'
h = uicontrol(dlg_h,...
'Style','Frame',...
'Units','norm',...
'BackgroundColor',get(0,'DefaultuicontrolBackgroundColor'),...
'String','dummy',...
'Position',[(0*colW + margin/2)/dlgWidth,...
(2*rowH + margin/2)/dlgHeight,...
25*colW/dlgWidth,...
2.2*rowH/dlgHeight]);
% Accumulate this control into the uictl array
uictl_arr(1) = h;
% --------------------+ Item 2 +--------------------
% Create a uicontrol of type 'Text'
h = uicontrol(dlg_h,...
'Style','Text',...
'Units','norm',...
'BackgroundColor',get(0,'DefaultuicontrolBackgroundColor'),...
'String',' Compile command',...
'Position',[(0.5*colW + margin/2)/dlgWidth,...
(3.6*rowH + margin/2)/dlgHeight,...
9.8*colW/dlgWidth,...
1.1*rowH/dlgHeight]);
% Set the property list
set(h, 'HorizontalAlignment', 'Left');
% Accumulate this control into the uictl array
uictl_arr(2) = h;
% --------------------+ Item 3 +--------------------
% Create a uicontrol of type 'Edit'
h = uicontrol(dlg_h,...
'Style','Edit',...
'Units','norm',...
'BackgroundColor',get(0,'DefaultuicontrolBackgroundColor'),...
'HorizontalAlignment','Left',...
'String','dummy',...
'Position',[(0.5*colW + margin/2)/dlgWidth,...
(2.5*rowH + margin/2)/dlgHeight,...
24*colW/dlgWidth,...
1.1*rowH/dlgHeight]);
% Edit boxes have their background set to white
set (h,'BackgroundColor',[1, 1, 1]);
% Set the property list
cmd=get_param(model_h,'Compile command');
set(h,'String',cmd,'UserData',cmd);
% Accumulate this control into the uictl array
uictl_arr(3) = h;
% --------------------+ Item 4 +--------------------
% Create a uicontrol of type 'PushButton'
h = uicontrol(dlg_h,...
'Style','PushButton',...
'Units','norm',...
'BackgroundColor',get(0,'DefaultuicontrolBackgroundColor'),...
'String','Help',...
'Position',[(0*colW + margin/2)/dlgWidth,...
(0*rowH + margin/2)/dlgHeight,...
7*colW/dlgWidth,...
1.1*rowH/dlgHeight]);
% Accumulate this control into the uictl array
uictl_arr(4) = h;
% --------------------+ Item 5 +--------------------
% Create a uicontrol of type 'PushButton'
h = uicontrol(dlg_h,...
'Style','PushButton',...
'Units','norm',...
'BackgroundColor',get(0,'DefaultuicontrolBackgroundColor'),...
'String','Revert',...
'Position',[(9*colW + margin/2)/dlgWidth,...
(0*rowH + margin/2)/dlgHeight,...
7*colW/dlgWidth,...
1.1*rowH/dlgHeight]);
% Accumulate this control into the uictl array
uictl_arr(5) = h;
% --------------------+ Item 6 +--------------------
% Create a uicontrol of type 'PushButton'
h = uicontrol(dlg_h,...
'Style','PushButton',...
'Units','norm',...
'BackgroundColor',get(0,'DefaultuicontrolBackgroundColor'),...
'String','Done',...
'Position',[(18*colW + margin/2)/dlgWidth,...
(0*rowH + margin/2)/dlgHeight,...
7*colW/dlgWidth,...
1.1*rowH/dlgHeight]);
% Set the property list
set(h, 'Enable','on');
% Accumulate this control into the uictl array
uictl_arr(6) = h;
% -------------------------------------------------------
% Add the callbacks.
nameCheckCB='accelopt(''Name check'');';
set(dlg_h,'KeyPressFcn',nameCheckCB,...
'WindowButtonDownFcn',nameCheckCB,...
'WindowButtonUpFcn',nameCheckCB,...
'ButtonDownFcn',nameCheckCB);
set(uictl_arr(3),'Callback','accelopt(''Compile command'');');
set(uictl_arr(4),'Callback','accelopt(''Help'');');
set(uictl_arr(5),'Callback','accelopt(''Revert'');');
set(uictl_arr(6),'Callback','accelopt(''Done'');');
% -------------------------------------------------------
% Add the block diagram handle to the uictl_arr
uictl_arr=[uictl_arr,model_h];
% stuff the uicontrols into the 'UserData' property of the figure
set(dlg_h,'Visible','on','UserData',uictl_arr);
return;
end % create
%
%-----------------------------------------------------------------
%
%--- N A M E C H E C K -----------------------------------------
% For all other commands, make sure that the name presented in
% the dialog is consistent with the name of the block diagram.
% It is quite possible that the user has save the block diagram
% under a different name.
%
dlgName=[get_param(model_h,'name'),' - Accelerator Options'];
if ~strcmp(dlgName,get(dlg_h,'Name')),
set(dlg_h,'Name',dlgName);
end;
%
%-----------------------------------------------------------------
%
%--- C O M P I L E C O M M A N D ------------------------------
%
%
if strcmp(sbCmd,'Compile command'),
compileCommand=get(gco,'String');
set_param(model_h,'Compile command',compileCommand);
return;
end % Compile command
%
%-----------------------------------------------------------------
%
%--- D O N E -----------------------------------------------------
%
%
if strcmp(sbCmd,'Done'),
% make the dialog invisible while I save the current settings
set(dlg_h,'Visible','Off');
% save the current settings of the important players in their
% 'UserData' for the Revert call
set(uictl_arr(3),'User',get(uictl_arr(3),'String'));
return;
end;
%
%-----------------------------------------------------------------
%
%--- R E V E R T -------------------------------------------------
%
%
if strcmp(sbCmd,'Revert'),
% get the original 'Compile command'
compileCommand=get(uictl_arr(3),'UserData');
% first take care of the block diagram's parameters
set_param(model_h,'Compile command',compileCommand);
% now the Edit box
set(uictl_arr(3),'String',compileCommand);
return;
end;
%
%-----------------------------------------------------------------
%
%--- H E L P -----------------------------------------------------
%
%
if strcmp(sbCmd,'Help'),
% call the help dialog for the accelerator options
helpdlg('accelopt.hlp', 'Accelerator Options Help');
return;
end;
%
%-----------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -