⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xieliao.m

📁 大量遗传算法实现程序
💻 M
字号:
function  varargout = xieliao( 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', 'xieliao' ) ;
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', 'xieliao', ...
        '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 = { ...
    ['xieliao( ''LoadData_Callback'', gcbo)']; ...
    ['xieliao( ''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', {['  输入油缸最大行程']}, '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', ['xieliao(''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', {['油缸最大行程: S']}, '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', ['xieliao(''close_Callback'',gcbo)'] ) ;


handles = guihandles( FigureHandle ) ;
guidata( FigureHandle, handles ) ;




% --------------------------------------------------------------------------
function  init_FigureContent( h )
       
handles = guidata( h ) ;

T_SimulationData = getappdata( handles.xieliao, '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.S);


% --------------------------------------------------------------------------






% --------------------------------------------------------------------------
function  edit1_Callback( h )
       
handles = guidata( h ) ;
% get the T_SimulationData .
T_SimulationData = getappdata( handles.xieliao, 'T_SimulationData' ) ;
S = str2double(get(handles.edit1, 'String'));
if isnan(S)
    set(handles.edit1, 'String', 0);
    errordlg('Input must be a number','Error');
end
T_SimulationData.S=S;
setappdata( handles.xieliao, '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.xieliao, '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.xieliao, '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.xieliao, '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.xieliao ) ;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -