www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/@xregtools/@MBrowser/Close.m

    function Close(srcobj,~,h)
%CLOSE Close the MBrowser
%
%  h.Close

%  Copyright 2000-2015 The MathWorks, Inc. and Ford Global Technologies, Inc.


% just delete figure

if nargin<2
    h = srcobj;
end

if h.GUIExists
    ProjectPtr = h.RootNode;
    cnode = h.CurrentNode;
    try
        OK = h.SelectNode(xregpointer);
    catch
        OK = 0;
    end
    
    try
        % Attempt to save state of UI
        s.TreeSplit=get(h.Hand.Figure.LRsplit,'split');
        s.ListSplit=get(h.Hand.Figure.UDsplit,'split');
        s.ToolbarSplit=get(h.Hand.Figure.TBsplit,'split');
        setpref(mbcprefs('mbc'),'ModelBrowser',s);
    catch
        warning(message('mbc:xregtools:MBrowser:InvalidState'));    
    end
    
    if OK
        
        ProjectPtr.setmodified(h.FileModified);
        try
            [MP,msg,cancel]= close(ProjectPtr.info,0,cnode);
        catch
            warning(message('mbc:xregtools:MBrowser:InvalidState2'));
            msg = '';
            cancel = true;
        end
        if isempty(msg) && ~cancel
            try
                % make sure figures close
                h.destroyallsubfigures;
            catch
                warning(message('mbc:xregtools:MBrowser:InvalidState1'));
            end
        
            try
                delete(MP);
            catch
                warning(message('mbc:xregtools:MBrowser:InvalidState3'));
            end
            
            try
                % close figures
                hDE=findobj(allchild(0),'flat','Tag','DOEeditor');
                delete(hDE);
                hData=findobj(allchild(0),'flat','Tag','dataEditor');
                delete(hData);   
                hBdry=findobj(allchild(0),'flat','Tag','BoundaryEditor');
                delete(hBdry);                    
                hStep= findobj(allchild(0),'flat','Tag','stepwisefig');
                hDOE= findobj(allchild(0),'flat','Tag','DOEtool');
                delete([hDOE;hStep]);
            catch
                warning(message('mbc:xregtools:MBrowser:InvalidState4'));
            end
            
            try
                delete(h.Figure);
            catch
                warning(message('mbc:xregtools:MBrowser:InvalidState5'));
            end

            try
                % run shutdown tasks
                xreg_shutdown;
            catch
                warning(message('mbc:xregtools:MBrowser:InvalidState6'));
            end
        else
            % only show the error message if the user did not click cancel
            if ~cancel
                hD = errordlg(msg, 'File Error', 'modal');
                waitfor(hD);
            end
            % attempt to reselect old currentnode
            h.SelectNode(cnode);
        end
    else
        % check pointers
        if ~isvalid(ProjectPtr)
            warning(message('mbc:xregtools:MBrowser:InvalidState7'));
            delete(h.Figure);
        end
    end
    
end