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

    function A = update(A,p)
%UPDATE update connections for item
%
% A = update(A,p)

%  Copyright 2007-2008 The MathWorks, Inc.

Index = iFindPtr(A,p);
    
if ~all(Index)
    % add any new items
    A = add(A,p(Index==0));
    Index = iFindPtr(A,p);
end

ItemsToRemove= false(1,length(A.Names));
for i= 1:length(p)
    if Index(i)~=0
        pind = p(i);

        idx = Index(i);
        
        % update name 
        A.Names{idx} = pind.getname;
        % update connections
        [pNode,pData,pDep] = getConnections(pind.info);
        pDep = pDep{1};
        [OK,loc]= ismember(pDep,A.pData);
        % old connection
        OldUnconnected = getUnconnected(A,idx);
        A.Connections(idx,:) = false;
        if ~all(OK)
            % add any connections which are not in project
            % these will be added as non major items in the connections
            A = add(A,pDep(~OK),false);
            Index = iFindPtr(A,p);
            idx = Index(i);
            [OK,loc]= ismember(pDep,A.pData);
        end
        % remove old connections to non major items that are not used.
        A.Connections(idx,loc)= true;
        % find any items that need to be remove from connections. That is
        % any items that are no longer connected to this item.
        ItemsToRemove( setdiff(OldUnconnected,getUnconnected(A,idx)) ) = true;
    end
end

if any(ItemsToRemove)
    % pointers should have already been freed.
    A = removeItems(A,ItemsToRemove);
end


function Index = iFindPtr(A,p)


Index = zeros(1,length(p));
for i=1:length(p)
    idx = find(A,'pointer',p(i));
    if ~isempty(idx)
       Index(i) = idx; 
    end
end