www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/+mbcmodelview/+ptbypt/InfoPane.m

    classdef InfoPane < mbcgui.multiview.View
    %InfoPane information on RHS of point-by-point model view
    
    %  Copyright 2015 The MathWorks, Inc. and Ford Global Technologies, Inc.
    
    properties(SetAccess=private)
        %SummaryTable local summary statistics table
        SummaryTable
        %PooledStatistics pooled statistics (all tests) table
        PooledStatistics
        %hNotes note edit box
        hNotes
        %hColor color selector
        hColor
        %OperatingPoints operating points table
        OperatingPoints
    end
    
    methods
        function obj= InfoPane(varargin)
        %InfoPane - constructor
        obj@mbcgui.multiview.View(varargin{:})
        create(obj)
        addMessageServiceListener(obj, 'NodeUpdated',@obj.onNodeUpdated)
        end
        
        function update(obj)
        %update main update method
        updateOperatingPoints(obj)
        % this is called to update the diagnosticstats and PooledStatistics table
        % is is called from local_response.m
        ms = obj.MessageService;
        % which stats does the popup say we need?
        if ms.Status
            % update the top (DiagnosticStats) table
            updateTable(obj.SummaryTable, ms.ModelDev, 1, ...
                ms.CurrentTest, ms.Model, ms.XData(ms.DataOK,:), ms.YData(ms.DataOK));
        else
            obj.SummaryTable.Peer.clearTable();

        end
        % and the PooledStatistics table
        updateTable( obj.PooledStatistics, ms.ModelDev );
        
        %  sweep notes
        [Notes,Color] = SweepNotes(ms.ModelDev,ms.CurrentTest);
        
        set(obj.hNotes,'String',Notes);
        set(obj.hColor,'BackgroundColor',Color);
        
        end
    end
    
    methods(Access=private)
        
        function onNodeUpdated(obj,~,~)
        update(obj)
        end
        
        function onNoteEdited(obj,h,~)
        %onNoteEdited edit test note 
        NewNote= get(h,'String');
        ms = obj.MessageService;
        SweepNotes(ms.ModelDev,ms.CurrentTest,NewNote);
        [~,Color] = SweepNotes(ms.ModelDev,ms.CurrentTest);
        set(obj.hColor,'BackgroundColor',Color);

        end
        function onColorSelected(obj,~,~)
        %onColorSelected select test note color
        NewNote= get(obj.hNotes,'String');
        NewColor= uisetcolor(get(obj.hColor,'BackgroundColor'),'Set Test Number Color');
        if all(size(NewColor)==[1 3])
            ms = obj.MessageService;
            SweepNotes(ms.ModelDev,ms.CurrentTest,NewNote,NewColor);
            set(obj.hColor,'BackgroundColor',NewColor);
        end
        end
        
        
        function create(obj)
        %--------------------------------------------------
        % Table & Popupmenu of diagnostic stats
        %--------------------------------------------------
        
        ViewParent = mbcgui.container.layoutpanel(...
            'Parent', obj.Parent, ...
            'LayoutBorder', [1 0 1 0]);
        
        hGlobal = mbcgui.container.layoutpanel(...
            'Parent', ViewParent, ...
            'BorderType', 'etchedin', ...
            'LayoutBorder', [5 5 5 5], ...
            'Title', 'Operating point');
        
        obj.OperatingPoints = mbcwidgets.Table2D('extendednumeric',...
            'Parent',hGlobal,...
            'ShowHeaderSelection', false,...
            'Editable', false);        
        obj.OperatingPoints.Peer.setRowHeaderWidth( 100 );
        obj.OperatingPoints.Peer.setCornerAsBlank();
        set(hGlobal, 'LayoutComponent', {obj.OperatingPoints});

        diagnosticLyt = mbcgui.container.layoutpanel(...
            'Parent', ViewParent, ...
            'BorderType', 'etchedin', ...
            'LayoutBorder',[5 5 5 5],...
            'Title', 'Local summary statistics');
        tbl = xregtools.DiagnosticStatsTable( 'mdev_local', [],...
            'Parent', diagnosticLyt );
        
        set(diagnosticLyt, 'LayoutComponent', {tbl});
        
        obj.SummaryTable = tbl;
        
        %--------------------------------------------------
        % Table of summary stats
        %--------------------------------------------------
        % transposed version
        summaryLyt = mbcgui.container.layoutpanel(...
            'Parent', ViewParent, ...
            'BorderType', 'etchedin', ...
            'Title', 'Pooled statistics');
        Stbl=xregtools.SummaryStatsTable( 'Parent', summaryLyt );
        lyt = xreglayerlayout(summaryLyt, ...
            'border', [5 5 5 5], ...
            'elements', {Stbl});
        set(summaryLyt, 'LayoutComponent', {lyt});
        
        obj.PooledStatistics = Stbl;
        
        
        %--------------------------------------------------
        % Sweep notes Layout
        %--------------------------------------------------
        notesLyt = mbcgui.container.layoutpanel(...
            'Parent', ViewParent, ...
            'BorderType', 'etchedin', ...
            'Title', 'Test notes', ...
            'LayoutBorder', [2 2 2 2]);
        obj.hNotes=uicontrol('Parent',notesLyt,...
            'Style','edit',...
            'Min',0,'Max',2,...
            'HorizontalAlignment','left',...
            'BackgroundColor','w',...
            'Tag', 'testNotes',...
            'Callback',@obj.onNoteEdited);
        txt=uicontrol('Parent',notesLyt,...
            'Style','text',...
            'String','Test number color:',...
            'HorizontalAlignment','left');
        csetup=uicontrol('Parent',notesLyt,...
            'Style','push',...
            'String','Set Color...',...
            'Tag', 'SetNoteColor',...
            'Callback',@obj.onColorSelected);
        obj.hColor=uicontrol('Parent',notesLyt,...
            'Style','text',...
            'HorizontalAlignment','left');
        
        lyt = xreggridbaglayout(notesLyt, ...
            'dimension', [5 3], ...
            'rowsizes', [-1 3 3 20 2], ...
            'gapx', 10, ...
            'colsizes', [120 15 80], ...
            'mergeblock', {[1 1], [1 3]}, ...
            'mergeblock', {[3 4], [2 2]}, ...
            'mergeblock', {[3 4], [3 3]}, ...
            'elements', {obj.hNotes, [], [], txt, [], ...
            [], [], obj.hColor, [], [], ...
            [], [], csetup});
        set(notesLyt, 'LayoutComponent', {lyt});
        lyt = xreggridlayout(ViewParent,...
            'dimension',[4,1],...
            'gapy',8,...
            'correctalg','on',...
            'rowsizes',[100,-1, 100, 80],...
            'elements',{hGlobal, diagnosticLyt,summaryLyt,notesLyt});
        
        set(ViewParent,'LayoutComponent',lyt);
        obj.ContentHandle = ViewParent;
        end
        
        function updateOperatingPoints(obj)
        %updateOperatingPoints update global variable table
        ms = obj.MessageService;
        
        [Xtp,Ytp]= getdata(mdevtestplan(ms.ModelDev),'FIT');
        yg = Ytp(:,get(Xtp{2},'Name'),ms.CurrentTest);
        labs= get(yg,'Name')';
        head= {'Value','Std Error'};
        Stats= [mean(yg)' std(yg{1},[],1)'];
        
        Tbl = obj.OperatingPoints;
        % any NaN cells are invisible as well
        InvisibleIndex = isnan( Stats );
        %store up the set calls so we only have to redraw the table once.
        Tbl.Peer.setStoreSwingCalls( true );
        obj.OperatingPoints.Peer.setRowData( labs );
        if isempty( head )
            Tbl.Peer.setDisplayColumnHeaders( false );
        else
            Tbl.Peer.setDisplayColumnHeaders( true );
            Tbl.Peer.setColumnData( head );
        end
        Tbl.Peer.setTableData( Stats );
        Tbl.Peer.setCellVisible( ~InvisibleIndex );
        % flush all the set calls we have been storing.
        Tbl.Peer.setStoreSwingCalls( false );
        
        end
        
    end
end