www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgtools/@cgbrowser/AddItem.m

    function AddItem(h,TP,Index,GotoItem)
%ADDITEM add item to CAGE project
%
% AddItem(h,TP,Index,GotoItem)

%  Copyright 2008-2010 The MathWorks, Inc. and Ford Global Technologies, Inc.

if nargin<3
    Index= 1;
end
if nargin<4
    GotoItem = true;
end

add = TP.Actions.add(Index);
createfcn = add.fcn;

% Allow addition of more than one object at once
if ~isempty(createfcn)
    if h.lock
        PR = xregGui.PointerRepository;
        ptrID = PR.stackSetPointer(h.Figure,'watch');
        msgID = h.addStatusMsg('Creating new item...');
        objp = feval(createfcn);
        Nitems = length(objp);
        if Nitems
            if Nitems>1
                hwait = xregGui.waitdlg('parent',h.Figure, ...
                    'message','Creating new item...');
                set(hwait.waitbar,'Min',0,'Max',Nitems+1);
            end

            ndP = null(xregpointer, 1, Nitems);
            for n =1:Nitems
                if objp(n).isa('cgnode')
                    ndP(n) = objp(n);
                else
                    ndP(n)=cgnode(objp(n).info,[],objp(n),1);
                end
                if Nitems>1
                    set(hwait,'message',['Created ' ndP(n).name '...']);
                    hwait.waitbar.value = n;
                end
            end

            if Nitems>1
                set(hwait,'message','Adding new items to project...');
            end

            % Use current node as addition point, or the root if this is
            % null
            prnt = h.CurrentNode;
            if isnull(prnt);
                prnt = h.RootNode;
            end
            
            % Add items to project
            addnodestoproject(prnt.info,ndP);

            if Nitems>1
                delete(hwait);
            end

            if GotoItem
                % Go to new node
                h.gotonode(ndP(1),xregpointer);
            end
        end
        h.removeStatusMsg(msgID);
        PR.stackRemovePointer(h.Figure,ptrID);
        h.unlock;
    end
end