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

    function OK=SelectNode(h, p, FORCE)
% SELECTNODE  Switch to specified node in tree
%
%   SelectNode(MB, PTR)
%
%    PTR is a pointer to a modeldev object
%

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

if nargin<3
    FORCE=0;
end

% Check whether we should actually do the select.
if (~h.GUILocked || FORCE) && h.GUIExists && (p~=h.CurrentNode || isnull(p))

    if h.RootNode.isBlank
        % select getting started tab
        h.selectHome(1);
    else
        % select browser tab
        h.selectHome(2);
    end    
    
    % Sets GUILocked to true and returns the previous value of GUILocked so
    % we can reset it before we exit.
    oldGUILock = iSetGUILocked( h, true );
    PR=xregGui.PointerRepository;
    ptrID=PR.stackSetPointer(h.Figure,'watch');
    
    % Somethings we only do if p is not null.
    DOSHOW = isvalid(p);

    if DOSHOW
        % select new tree node and lock down the treeview
        h.treeview( p, 'select');
    end

    if isvalid(h.CurrentNode)
        OK= h.HideNode;
        % Something went wrong during HideNode.
        if ~OK
            iSetGUILocked( h, oldGUILock );
            % restore the pointer
            PR.stackRemovePointer(h.Figure,ptrID);
            % Re-select old node
            h.treeview( h.CurrentNode, 'select' );
            OK = 0;
            return
        end
    else
        OK=1;
    end
    drawnow;

    h.CurrentNode = p;

    % Initialise new view
    if DOSHOW        
        msgID=h.Hand.Figure.StatusBar.addMessage(['Creating display for ' p.name]);
        
        % Switch views - creates view if needed, swaps
        iSwitchView( h, p );

        % call show and view
        h.ShowNode;
        h.ViewNode;

        h.Hand.Figure.StatusBar.removeMessage(msgID);

        % don't allow user to change view too fast
        h.treeview( p, 'select' );
        % flush any graphics here
        drawnow update
    end

    % Reset GUILocked
    iSetGUILocked( h, oldGUILock );
    PR.stackRemovePointer(h.Figure,ptrID);
else
    OK=0;
end

% -------------------------------------------------------------------------
function iSwitchView( h, p )
% Perform card-switching.
ID=p.guid;
% Search for GUID in currently-created list
guids=h.ViewGUIDs;
viewd=h.ViewData;
idx=find( strcmp( ID,guids ) );
% This view needs creating
if isempty(idx)
    % create the new GUI
    idx=length(guids)+1;
    
    h.ViewGUIDs=[guids,{ID}];
    h.ViewMenus=[h.ViewMenus,{[]}];
    
    newp=xregGui.RunTimePointer;
    newp.LinkToObject(h.Figure);
    viewd=[viewd; newp];
    
    info = struct(...
        'ViewIndex', idx, ...
        'Figure', h.Figure, ...
        'ViewParent', h.Hand.Figure.ViewPanel, ...
        'ToolbarParent', h.Hand.Toolbar.Panel);
    [lyt, tblyt, data] = creategui(p.info,info);
    viewd(idx).info = data;
    set(h.ViewCardObj,'numcards',idx);
    set(h.Hand.Toolbar.CardObj,'numcards',idx);
    % poke packstatus for the lyt packgroup without repacking it!
    setBoolPackstatus(lyt,true);
    
    % Attach the layouts to the cardlayouts
    attach(h.ViewCardObj,lyt,idx);
    attach(h.Hand.Toolbar.CardObj, tblyt, idx);
    
    % Update ViewData
    h.ViewData=viewd;
end
% Switch menus
if idx~=h.ViewCurrent
    set(h.ViewCardObj,'Visible','off');
    Nnew=length(h.ViewMenus{idx});
    % Turn the current menus off, and the new menus on.
    set(h.ViewMenus{h.ViewCurrent},'Visible','off');
    set(h.ViewMenus{idx},'Visible','on',{'Position'},num2cell((2:1+Nnew)'));
end
% Update the current view
h.ViewCurrent=idx;
% update the card layouts.
set(h.ViewCardObj,'currentcard',idx,'visible','on');
set(h.Hand.Toolbar.CardObj,'currentcard',idx);


% -------------------------------------------------------------------------
function previousLockStatus = iSetGUILocked( h, newLockStatus )
% Sets GUILocked to newLockStatus, and returns the previous value of
% GUILocked.
previousLockStatus = h.GUILocked;
h.GUILocked = newLockStatus;