www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/cgTableHistory.m

    classdef cgTableHistory
    %cgTableHistory store table history
    
    %  Copyright 2013 The MathWorks, Inc. and Ford Global Technologies, Inc.
    
    properties
        %Information description of table history item
        Information
    end
    
    properties (SetAccess=private)
        %Values table values
        Values
        %Date date of history entry
        Date
    end

    properties(Dependent,SetAccess=private)
        %VLocks logical matrix of locked cells (full)
        VLocks
        %Mask logical matrix of extrapolation mask (full)
        Mask
    end
    properties(Access=private)
        %pVLocks storage for locked cells (sparse)
        pVLocks
        %pMask storage for extrapolation mask (sparse)
        pMask
    end
    
    methods
        function obj = cgTableHistory(LT,Info)
        %cgTableHistory constructor
        %    cgTableHistory
        if nargin == 2
            obj.Values = get(LT,'values');
            obj.Mask = getExtrapolationMask(LT);
            obj.VLocks = get(LT,'vlocks');
            obj.Information = Info;
        end
        obj.Date = datestr(now,0);
        end
        
        function m = get.Mask(obj)
        m = full(obj.pMask);
        if isempty(m)
            m = false(size(obj.Values));
        end
        end

        function obj = set.Mask(obj,m)
        obj.pMask = sparse(m);

        end
        
        function m = get.VLocks(obj)
        m = full(obj.pVLocks);
        if isempty(m)
            m = false(size(obj.Values));
        end
        
        end

        function obj = set.VLocks(obj,m)
        obj.pVLocks = sparse(m);
        end        

        function [LT,ok] = resetHistory(M,LT)
        
        
        % Check whether a size change will happen and whether this is allowed
        if issizelocked(LT) && ~all(size(M.Values)==size(get(LT,'Values')))
            ok = false;
        else
            ok = true;
            
            mem = get(LT,'memory');
            
            if isa(LT,'cglookupone')
                pNorm = get(LT,'normalizers');
                Norm = info(pNorm);
                [~,ind] = getmemory(Norm,Mem.Date);
                if ~isempty(ind)
                    % get normaliser from history
                    Norm = history_reset(Norm,ind);
                end
                BP = get(Norm,'Breakpoints');
                
                if numel(BP)~=numel(Mem.Values)
                    % breakpoints don't match - this shouldn't happen
                    BP = 0:numel(Mem.Values)-1;
                end
                LT = set(LT,'matrix',[BP(:),M.Values(:)]);
            else
                LT = set(LT,'matrix',M.Values);
            end
            
            % Force the values in and then set the locks
            LT = set(LT, 'vlocks', M.VLocks);
            LT = setExtrapolationMask(LT,M.Mask);
            
            % Add our own memory change on top of the original ones, then use this
            % to overwrite any memory changes that the above commands have added
            Mnew = cgTableHistory(LT,['Reset to values at ',M.Date]);
            mem(end+1) = Mnew;
            LT = set(LT,'memory',mem);
        end
        end
        
        function BPs = getBreakPoints(M,LT)
        
        S = size(M.Values);
        switch getNumAxes(LT)
            case 1
                
                BPs{1} = getNormaliser(M,LT,'x',S(1));
                
            case 2
                BPs = {getNormaliser(M,LT,'y',S(1)), getNormaliser(M,LT,'x',S(2))};

        end
        
        end
        
    end
    
    methods (Static)
        function c = convertFromCell(mem)
        %convertFromCell legacy conversion
        if isempty(mem)
            c = cgTableHistory.empty(1,0);
        else
            c = mem;
            obj = cgTableHistory;
            for i=1:length(mem)
                c{i} = convertFromStruct(obj,mem{i});
            end
            c = [c{:}];
        end
        end
    end
    
end



function obj = convertFromStruct(obj,s)
%convertFromStruct convert from legacy structure
obj.Values = s.Values;
obj.Information = s.Information;
obj.Date = s.Date;

end

function BP = getNormaliser(M,LT,var,Size)
pNormaliser = get(LT,var);
[~,ind] = getmemory(pNormaliser.info,M.Date);
if isempty(ind)
    Norm = pNormaliser.info;
else
    Norm = pNormaliser.history_reset(ind);
end
BP = invert(Norm,(0:Size-1));

end