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

    function obj = setListData(obj, items, names, iconfiles)
%SETLISTDATA Update the list with new information.
%
%   OBJ = SETLISTDATA(OBJ, ITEMS, NAMES, ICONS)

%   Copyright 2005 The MathWorks, Inc.

obj.Items = items;
obj.Names = names;

ReplaceTypes= {'Model','Variable','Feature','Table','Normalizer'};
types = pveceval( items, @getCageType );
isreplacetype = ismember(types,ReplaceTypes);

replaceitems = cell(size(items));
replacenames = cell(size(items));
transferactions = zeros(size(items));

src = obj.FromProject.UpdateConnections();
srcIndex = findptrs( src, items );
ismajoritem = src.IsMajorItem( srcIndex );

if ~isempty( obj.CageProject )
    dst = obj.CageProject.UpdateConnections();
else
    dst = [];
end

for n = 1:length( items )
    if ~isempty( dst )
        if isreplacetype(n) && ismajoritem(n)
            replacementPossible = true;
            % find items of the same type in dst
            possibleReplaceIndex = find( dst, 'type', types{n} );

            % for each of these see if we can replace
            replaceallowed = true( size( possibleReplaceIndex ) );
            for m = 1:length( possibleReplaceIndex )
                srcData = src.pData( srcIndex(n) ).info;
                dstData = dst.pData( possibleReplaceIndex(m) ).info;
                replaceallowed(m) = canReplace( dstData, srcData );
            end
            % only keep items which can be replaced.
            possibleReplaceIndex = possibleReplaceIndex(replaceallowed);
            
            % get their names, and find one with the same name
            replaceitems{n} = dst.Names(possibleReplaceIndex);       
            exactmatch = strcmp( replaceitems{n}, obj.Names{n} );
        else
            replacementPossible = false;
        end
    else
        replacementPossible = false;
    end
    
    if replacementPossible
        % default to replacing the item with the same name
        if any( exactmatch )
            transferactions(n) = 1;
            replacenames{n} = dst.Names(possibleReplaceIndex(exactmatch));
        else
            transferactions(n) = 0;
            replacenames{n} = obj.Names(n);
        end
    else
        replaceitems{n} = {};
        transferactions(n) = 0;
        replacenames{n} = obj.Names(n);
    end
end

obj.TransferAction = transferactions;
obj.ReplaceNames = replacenames;    
obj.Peer.setData( obj.Names, iconfiles, obj.TransferAction, replaceitems, obj.ReplaceNames );
return;