www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgprojconnections/delete.m

    function A = delete(A,CurrentItem)
%DELETE delete item from CAGE Project
%
% A = delete(A,CurrentItem)

%  Copyright 2004-2009 The MathWorks, Inc.

if ~isnumeric(CurrentItem)
    % pointer input
    [OKnode,locNode]= ismember(CurrentItem,A.pNode);
    [OKdata,locData]= ismember(CurrentItem,A.pData);
    CurrentItem= union(locNode(OKnode),locData(OKdata));
end

if ~CanDelete(A,CurrentItem)
    % check we can delete object
    error(message('mbc:cgprojconnections:InvalidOperation'))
end


if length(CurrentItem)>1
    % need to sort expressions 
    [~,ind]= sort(A,'reverse',CurrentItem);
    CurrentItem = CurrentItem(ind);
end

pItems= MainPtrList(A,CurrentItem);
% store connections in project for use during deletion
UpdateConnections(info(A.Project),A);

for i=1:length(CurrentItem)
    % delete objects one by one
    item= getItem(A,pItems(i));
    A= iDeleteObject(A,item);
end



function A= iDeleteObject(A,item)

CGP= info(A.Project);

switch A.Type{item}
    case {'Calibration Constant','Constraint'}
        % cal constants and constraints are not 1st class CAGE objects so
        % are only deleted when single owner is deleted
    case 'Variable'
        p= A.pData(item);
        % needs to be deleted from data dictionary
        pDD= getdd(CGP);
        pDD.info= remove(pDD.info,p);
        % update connections item
        A= getConnections(info(A.Project));
    otherwise

        p= A.pNode(item);

        if isvalid(p)
            % delete node - the main deletion occurs in
            % cgprojconnections/deletenode
            delete(p.info);
            
            A= getConnections(info(A.Project));
        else
            % already deleted
            warning(message('mbc:cgprojconnections:InvalidPointerReference'));
        end
end