?? xietiao.m
字號:
function varargout = xietiao( varargin )
% this module edit the parameters .
% February 2004
% $Revision: 1.00 $
if (nargin == 0) | isstruct( varargin{1} ) % LAUNCH GUI
if nargin == 1
T_SimulationData = varargin{1} ;
else
T_SimulationData = [] ;
end
% find if have the same figure, and close it .
OldFigure = findobj( 'type', 'figure', 'Tag', 'xietiao' ) ;
if ishandle( OldFigure )
close( OldFigure ) ;
end
% init the variables .
FigureWidth = 500 ;
FigureHeight = 400 ;
TabSpace = 10 ;
TextHeight = 20 ;
% generate a new figure .
FigureHandle = figure( 'Visible', 'off' ) ;
set( FigureHandle, 'Units' , 'pixels', 'Position', [150 150 500 300], ...
'Name', '協調性約束', ...
'Tag', 'xietiao', ...
'FileName' , '' ,...
'MenuBar' , 'none' ,...
'NumberTitle' , 'off' ,...
'Resize', 'off', ...
'windowstyle', 'normal', ...
'Visible', 'off' ) ;
% generate the menu .
generate_MenuContent( FigureHandle ) ;
% generate the uicontrols .
generate_FigureContent( FigureHandle ) ;
% save the T_SimulationData .
setappdata( FigureHandle, 'T_SimulationData', T_SimulationData ) ;
% display the figure .
movegui( FigureHandle, 'center' ) ;
% set( findobj( FigureHandle, 'Type', 'uicontrol' ), 'Units', 'normalized' ) ;
set( FigureHandle, 'Visible', 'on' ) ;
% init the data .
init_FigureContent( FigureHandle ) ;
if nargout > 0
varargout{1} = FigureHandle;
end
elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK
global SET_DEBUG_VALUE_IN_SIMULATOR ;
if isempty( SET_DEBUG_VALUE_IN_SIMULATOR ) | ~isnumeric( SET_DEBUG_VALUE_IN_SIMULATOR )
SET_DEBUG_VALUE_IN_SIMULATOR = 0 ;
else
end
if SET_DEBUG_VALUE_IN_SIMULATOR == 1 ;
if (nargout)
[varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard
else
feval(varargin{:}); % FEVAL switchyard
end
else
try
if (nargout)
[varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard
else
feval(varargin{:}); % FEVAL switchyard
end
catch
disp(lasterr);
end
end
end
% ------------------------------------------------------------
function generate_MenuContent( FigureHandle ) ;
% generate the file menu .
% ------------------------------------------------------------
MenuHandle = uimenu( 'Parent', FigureHandle, 'Label', '文件(&F)' ) ;
% define the parameters of the menus .
MenuLabel = { '打開(&O)'; '退出(&E)' } ;
% add Polygon at 2003.10.13 .
MenuTag = { 'MenuOpenResult'; 'MenuClose' } ;
MenuCallback = { ['T_Youhua( ''MenuOpenHistory_Callback'', gcbf)']; ...
['close all;'] } ;
SeparatorGroup = { 'off'; 'on' } ;
% generate the uimenus of file .
for num = 1: length( MenuTag )
% for num = 3
UimenuHandle(num) = uimenu( MenuHandle ) ;
set( UimenuHandle(num), 'Tag' , MenuTag{num} , ...
'Callback' , MenuCallback{num} , ...
'Label' , MenuLabel{num} , ...
'Separator', SeparatorGroup{num} ) ;
end
% generate the parameter menu .
% ------------------------------------------------------------
MenuHandle = uimenu( FigureHandle, 'Label', '參數(&P)' ) ;
% define the parameters of the menus .
MenuLabel = { '導入(&L)'; '保存(&E)' } ;
% add Polygon at 2003.10.13 .
MenuTag = { 'MenuLoadData'; 'MenuSaveData' } ;
MenuCallback = { ...
['xietiao( ''LoadData_Callback'', gcbo)']; ...
['xietiao( ''SaveData_Callback'', gcbo)']; } ;
SeparatorGroup = { 'off'; 'on' } ;
% generate the uimenus of file .
for num = 1: length( MenuTag )
UimenuHandle(num) = uimenu( MenuHandle ) ;
set( UimenuHandle(num), 'Tag' , MenuTag{num} , ...
'Callback' , MenuCallback{num} , ...
'Label' , MenuLabel{num} , ...
'Separator', SeparatorGroup{num} ) ;
end
% generate the parameter menu .
% ------------------------------------------------------------
MenuHandle = uimenu( FigureHandle, 'Label', '幫助(&H)', 'Enable', 'on' ) ;
% define the parameters of the menus .
MenuLabel = { '幫助(&P)'; '演示(&D)'; '關于(&A)';'時鐘(&S)' } ;
% add Polygon at 2003.10.13 .
MenuTag = { 'MenuHelp'; 'MenuDemo'; 'MenuAbout';'shijian' } ;
MenuCallback = { ...
['T_Youhua( ''MenuHelp_Callback'', gcbo)']; ...
['T_Youhua( ''MenuDemo_Callback'', gcbo)']; ...
['T_Youhua( ''MenuAbout_Callback'', gcbo)'];...
['T_Youhua( ''shizhong'', gcbo)']} ;
SeparatorGroup = { 'off'; 'on'; 'on'; 'on' } ;
% generate the uimenus of file .
for num = 1: length( MenuTag )
UimenuHandle(num) = uimenu( MenuHandle ) ;
set( UimenuHandle(num), 'Tag' , MenuTag{num} , ...
'Callback' , MenuCallback{num} , ...
'Label' , MenuLabel{num} , ...
'Separator', SeparatorGroup{num} ) ;
end
% ------------------------------------------------------------
function generate_FigureContent( FigureHandle )
% generate the uicontrols .
% init the variables .
FigureWidth = 500 ;
FigureHeight = 400 ;
TabSpace = 10 ;
TextHeight = 22 ;
ChangeYPos = 30 ;
% reset the figure's size .
set( FigureHandle, 'Units', 'pixels', ...
'Position', [150 150 FigureWidth FigureHeight], ...
'DoubleBuffer', 'on' ) ;
% generate the axes to plot lines .
AxesHandle = axes( 'Parent', FigureHandle, 'Units' , 'normalized' , ...
'Position', [0 0 1 1], 'Visible', 'off', ...
'Xlim', [0 FigureWidth], 'Ylim', [0 FigureHeight] ) ;
% get the color of the figure .
FigureColor = get( FigureHandle, 'Color' ) ;
% reset the default value of the uicontrols .
set(FigureHandle,'defaultuicontrolunits','normalized');
set(FigureHandle,'defaultuicontrolfontname','隸書');
set(FigureHandle,'defaultuicontrolBackgroundColor', FigureColor );
% define the first frame .
FrameXPos = TabSpace * 2 ;
FrameWidth = FigureWidth - TabSpace * 4 ;
FrameHeight = FigureHeight - TabSpace * 8 ;
FrameYPos = FigureHeight - FrameHeight - TabSpace * 2 ;
Frame1Position = [FrameXPos FrameYPos FrameWidth FrameHeight] ;
% generate a frame .
TitleHandle = uicontrol(FigureHandle,'style','frame', 'Units','pixels',...
'position',Frame1Position );
TextXPos = Frame1Position(1) + TabSpace ;
TextYPos = Frame1Position(2) + TabSpace ;
TextWidth = Frame1Position(3) - TabSpace * 2 ;
TextHeight = Frame1Position(4) - TabSpace * 2 ;
TextPosition = [TextXPos TextYPos TextWidth TextHeight] ;
% subtitle:
TextHandle = uicontrol(FigureHandle, 'Style','text', 'Units','pixels',...
'position',TextPosition, 'Horizontal','left',...
'string', {[' 輸入C點與車廂底板最小距離 d ']}, 'fontsize',12 );
edit1 = uicontrol(FigureHandle, 'Style', 'edit', 'Units','pixels',...
'position', [50 300 100 30], 'Horizontal','left', 'BackgroundColor', [1 1 1], ...
'Tag','edit1' , ...
'String', 0, 'FontSize',13, ...
'Callback', ['xietiao(''edit1_Callback'',gcbo)'] ) ;
TextXPos = Frame1Position(1) + TabSpace ;
TextYPos = Frame1Position(2) + TabSpace -100;
TextWidth = Frame1Position(3) - TabSpace * 2 ;
TextHeight = Frame1Position(4) - TabSpace * 2 ;
TextPosition = [TextXPos TextYPos TextWidth TextHeight] ;
% subtitle:
TextHandle = uicontrol(FigureHandle, 'Style','text', 'Units','pixels',...
'position',[50 80 400 30], 'Horizontal','left',...
'string', {['最小距離: d']}, 'fontsize',13 );
ButtonWidth = 80 ;
ButtonHeight = 25 ;
ButtonXPos = FigureWidth - ButtonWidth - TabSpace * 3 ;
ButtonYPos = TabSpace * 2 ;;
ButtonPosition = [ButtonXPos ButtonYPos ButtonWidth ButtonHeight] ;
% generate the pushbutton: Close .
ButtonHandle = uicontrol( 'Parent', FigureHandle, 'Units', 'Pixels', 'Position', ButtonPosition, ...
'Style', 'pushbutton', 'string', '關閉', 'Fontsize',12, 'Callback', ['xietiao(''close_Callback'',gcbo)'] ) ;
handles = guihandles( FigureHandle ) ;
guidata( FigureHandle, handles ) ;
% --------------------------------------------------------------------------
function init_FigureContent( h )
handles = guidata( h ) ;
T_SimulationData = getappdata( handles.xietiao, 'T_SimulationData' ) ;
% open the next figure .
if isempty( T_SimulationData )
T_SimulationData = T_Youhua( 'Get_DefaultT_SimulationData' ) ;
% save the data .
end
set(handles.edit1,'string',T_SimulationData.d);
% --------------------------------------------------------------------------
% --------------------------------------------------------------------------
function edit1_Callback( h )
handles = guidata( h ) ;
% get the T_SimulationData .
T_SimulationData = getappdata( handles.xietiao, 'T_SimulationData' ) ;
d = str2double(get(handles.edit1, 'String'));
if isnan(d)
set(handles.edit1, 'String', 0);
errordlg('Input must be a number','Error');
end
T_SimulationData.d=d;
setappdata( handles.xietiao, 'T_SimulationData', T_SimulationData ) ;
% -------------------------------------------------------------------------
% -
%---------------------------------------------------------------
function LoadData_Callback( h )
handles = guidata( h ) ;
PromptString = '選擇數據文件.' ;
WarningString1 = '文件格式出錯。 ' ;
WarningString2 = '選擇的文件不是正確的數據文件。 ' ;
[ FileName , PathName ] = uigetfile( {'*.mat','數據文件(*.mat)'}, PromptString ) ;
if FileName == 0
return ;
else
[TempPathName, FileName, FileTypeName, Version] = fileparts( FileName ) ;
if ~strcmp( FileTypeName, '.mat' ) ;
warndlg( WarningString1, '警告', 'modal' ) ;
return ;
end
SaveFile = fullfile( PathName, [FileName, FileTypeName, Version] ) ;
end
T_SimulationData = [] ;
try
load( SaveFile, 'T_SimulationData' ) ;
catch
end
if isempty( T_SimulationData ) | ~isstruct( T_SimulationData );
warndlg( WarningString1, '警告', 'modal' ) ;
return ;
end
% save the data .
setappdata( handles.xietiao, 'T_SimulationData', T_SimulationData ) ;
% display the new data .
init_FigureContent( h ) ;
% --------------------------------------------------------------------------
function SaveData_Callback( h )
handles = guidata( h ) ;
% get the T_SimulationData .
T_SimulationData = getappdata( handles.xietiao, 'T_SimulationData' ) ;
PromptString = '保存數據文件.' ;
MessageString = '保存數據文件成功。 ' ;
[ FileName , PathName ] = uiputfile( {'*.mat','數據文件(*.mat)'}, PromptString ) ;
if FileName == 0
return ;
else
[TempPathName, FileName, FileTypeName, Version] = fileparts( FileName ) ;
if ~strcmp( FileTypeName, '.mat' ) ;
FileTypeName = '.mat' ;
else
end
SaveFile = fullfile( PathName, [FileName, FileTypeName, Version] ) ;
end
% save the result file .
save( SaveFile, 'T_SimulationData' ) ;
msgbox( MessageString ) ;
% --------------------------------------------------------------------------
function close_Callback( h )
handles = guidata( h ) ;
% get the T_SimulationData .
T_SimulationData = getappdata( handles.xietiao, 'T_SimulationData' ) ;
% open the next figure .
if isempty( T_SimulationData )
T_SimulationData = T_Youhua( 'Get_DefaultT_SimulationData' ) ;
% save the data .
end
Youhua( T_SimulationData ) ;
% close the current figure .
pause(0) ;
close( handles.xietiao ) ;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -