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

    classdef cgNormaliserHistory
    %cgTableHistory store table history

     %  Copyright 2013-2013 The MathWorks, Inc. and Ford Global Technologies, Inc.
   
    
    properties
        %Information comment in history
        Information
    end    
    
    
    properties (SetAccess=private)
        %Breakpoints normalizer breakpoints
        Breakpoints
        %Values normalizer indices
        Values
        %Date Date of change
        Date
    end
    
    properties(Dependent,SetAccess=private)
        %BPLocks breakpoint locks
        BPLocks
    end
    properties(Access=private)
        %pBPLocks breakpoint locks store
        pBPLocks
    end    
    
    
    methods
        function M = cgNormaliserHistory(Norm,Info)
        %cgNormaliserHistory constructor
        if nargin == 2
            
            M.Breakpoints = get(Norm,'Breakpoints');
            M.Values = get(Norm,'Values');
            M.BPLocks = get(Norm,'BPLocks');
            M.Information = Info;
        end
        M.Date = datestr(now,0);
        end
        
        function locks = get.BPLocks(M)
        locks = full(M.pBPLocks);
        if isempty(locks)
            locks = false(size(M.Values));
        end
        
        end

        function M = set.BPLocks(M,locks)
        % store as sparse
        M.pBPLocks = sparse(locks);
        end             
        
        function vals = get.Values(M)
        
        vals = M.Values;
        while any(diff(vals)<0)
            % make sure that values are non-decreasing
            d = find(diff(vals)<0);
            vals(d+1) = vals(d);
        end
        end
        
        function vals = get.Breakpoints(M)
        
        vals = M.Breakpoints;
        while any(diff(vals)<0)
            % make sure that breakpoints are non-decreasing
            d = find(diff(vals)<0);
            vals(d+1) = vals(d);
        end
        end
        
        function [Norm,ok] = resetHistory(M,Norm)
        %resetHistory reset normalizer history
        if issizelocked(Norm) && ~all(size(M.Values)==size(get(Norm,'Values')))
            ok = false;
        else
            ok = true;
            mem = get(Norm,'memory');
            Norm = set(Norm, 'matrix', [M.Breakpoints(:), M.Values(:)]);
            if isempty(M.BPLocks)
                bplocks = zeros(size(M.Values));
            else
                bplocks = M.BPLocks;
            end
            Norm = set(Norm, 'bplocks', bplocks);
            
            % 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 = cgNormaliserHistory(Norm,['Reset to values at ',thisDate]);
            mem(end+1) = Mnew;
            Norm = set(Norm,'memory',mem);
        end
        end
        
    end
    
    methods (Static)
        function c = convertFromCell(mem)
        %convertFromCell legacy conversion
        if isempty(mem)
            c = cgNormaliserHistory.empty(1,0);
        else
            c = mem;
            obj = cgNormaliserHistory;
            for i=1:length(mem)
                c{i} = convertFromStruct(obj,mem{i});
            end
            c = [c{:}];
        end
        end
    end    
    
end


function obj = convertFromStruct(obj,s)

obj.Values = s.Values;
if isfield(s,'Breakpoints')
    obj.Breakpoints = s.Breakpoints;
else
    % make breakpoints equal breakpoints (convertToStatic did not store breakpoints)
    obj.Breakpoints = s.Values;
end
if isempty(obj.Values) && ~isempty(obj.Breakpoints)
    obj.Values = (0:length(obj.Breakpoints)-1)';
end
obj.Information = s.Information;
obj.Date = s.Date;

end