www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/+xregdatagui/TestSelector.m

    classdef TestSelector < xregdatagui.AbstractDataView
    %xregdatagui.TestSelector class
    %   xregdatagui.TestSelector extends xregdatagui.AbstractDataView.
    %
    %    xregdatagui.TestSelector properties:
    %       Parent - Property is of type 'MATLAB array'
    %       Position - Property is of type 'rect'
    %       Enable - Property is of type 'on/off'
    %       Visible - Property is of type 'on/off'
    %       Userdata - Property is of type 'MATLAB array'
    %       Tag - Property is of type 'string'
    %       MessageService - Property is of type 'handle' (read only)
    %       Container - Property is of type 'handle'
    %       UIContextMenu - Property is of type 'MATLAB array'
    %       Listeners - Property is of type 'handle vector' (read only)
    %       ListHandle - Property is of type 'MATLAB array' (read only)
    %
    %    xregdatagui.TestSelector methods:
    %       gettitle - view title
    %       pGetListviewIndex - gets the currently selected index from the listview
    %       pUpdateDisplay - complete update of the view display
    %       pdmsDataTypeChangedUpdate - event handler for the dmsDataTypeChanged event
    %       pssTestsChangedUpdate - PSSTESTCHANGEDUPDATE updates the view on receipt of a "RecordsChanged"
    %       pssfSweepNotesChangedUpdate - respond to a change in the sweep notes
    
    %  Copyright 2015 The MathWorks, Inc. and Ford Global Technologies, Inc.
    
    properties (SetAccess=private)
        %ListHandle mbcwidgets.List
        ListHandle
        %ShowTests tests are being shown (for two-stage data)
        ShowTests = true;
    end
    
    methods  % constructor block
        function obj = TestSelector(varargin)
        %NotesInfoView constructor
        %
        %  OUT = NotesInfoView(VARARGIN)
        %
        
        % Do the setup stuff from inside the abstractDataView constructor
        obj@xregdatagui.AbstractDataView(varargin{ : }); % converted super class constructor call
        
        
        pCreateListview(obj)
        
        set(obj.ListHandle,'SelectionChangedCallback',@obj.onSelectTest)
       

        obj.pUpdateDisplay
        end  % notesinfoview
        
    end  % constructor block
    
    methods
    end   % set and get functions
    
    methods  % public methods
        
        %----------------------------------------
        function index = pGetListviewIndex(obj, multiSelect)
        %PGETLISTVIEWINDEX gets the currently selected index from the listview
        %
        %  OUT = PGETLISTVIEWINDEX(IN)
        
        if nargin < 2
            multiSelect = true;
        end
        
        index = obj.ListHandle.getSelectedRows;
        
        if length(index) > 1 && ~multiSelect
            index = index(1);
        end
        
        end  % pGetListviewIndex
        
        function pCreateListview(obj)
        %PCREATELISTVIEW function to create listviews for derived classes
        %   PCREATELISTVIEW(OBJ)
        
        pnl = mbcgui.container.titlebarpanel('Parent',obj.Parent,...
            'UIContextMenu',obj.UIContextMenu,...
            'BarTitle','Test Selector');
        
        control = mbcwidgets.List('Parent',pnl,...
            'UIContextMenu',obj.UIContextMenu,...
            'SelectionMode','MultiRow');
        pnl.ContentHandle = control;
        obj.ListHandle = control;
        obj.ContentHandle = pnl;
        
        end  % pCreateListview        
        
        %----------------------------------------
        function pUpdateDisplay(obj)
        %PUPDATEDISPLAY complete update of the view display
        %   PUPDATEDISPLAY(OBJ)
        
        if hasData(obj.MessageService)
            % Simulate a data type changed update
            obj.pdmsDataTypeChangedUpdate;
            % Check the class of the current data object
            if obj.MessageService.isaSSF
                obj.updateListview;
            end
        end
        end  % pUpdateDisplay             
        
        %----------------------------------------
        function pdmsDataTypeChangedUpdate(obj, ~,~)
        %PDMSDATATYPECHANGEDUPDATE event handler for the dmsDataTypeChanged event
        %   PDMSDATATYPECHANGEDUPDATE(OBJ, EVENT)
        
        % Find the ssfFiltersChanged listener
        ssfListeners = obj.MessageService.findListeners(obj.Listeners, 'SweepsetFilter');
        
        % If the dataObject is a sweepsetfilter then...
        if obj.MessageService.isaSSF
            % Turn on the sweepsetfilter listener
            [ssfListeners.Enabled]=deal(true);
        else
            % Clear the view
            obj.ListHandle.Peer.setData([]);
            % Turn off the sweepsetfilter listener
            [ssfListeners.Enabled]=deal(false);
        end
        end  % pdmsDataTypeChangedUpdate
        
        %----------------------------------------
        function pssTestsChangedUpdate(obj, ~,~)
        %PSSTESTCHANGEDUPDATE updates the view on receipt of a "TestsChanged" event from the DMS
        %  PSSTESTCHANGEDUPDATE(OBJ)
        
        ms = obj.MessageService;
        obj.ShowTests = ~isempty(ms.DataObject) && ~ms.isOneStage;
        % pssfSweepNotesChanged to recreate the correct list of test numbers
        obj.updateListview();
        end  % pssTestsChangedUpdate
        
        function pSelectedTestsChangedUpdate(obj,~,~)
        %pSelectedTestsChangedUpdate listener for selected test update
        % change row selection
        if obj.ShowTests
            selectRows(obj.ListHandle,obj.MessageService.SelectedTests);
        end
        end
        
        %----------------------------------------
        function updateListview(obj, ~,~)
        %updateListview respond to a change in the sweep notes
        %   PSSFSWEEPNOTESCHANGEDUPDATE(OBJ, EVENT)
        
        
        ms = obj.MessageService;
        ssf = ms.SweepsetFilter;
        ss = ms.Sweepset;
        
        if ~obj.ShowTests || ms.isOneStage
            % clear any data in list
            obj.ShowTests = false;
            obj.ListHandle.setData([]);
            return
        end
        % Convert quickly to a series of strings
        testnums = testnum(ss);
        
        % Update the filter information listbox
        % Get the sweep notes from the data
        notes = get(ssf, 'sweepnotes');
        % Remove invalid notes
        OK = [notes.OK];
        % Check those that are valid to see if they have any sweeps that they apply
        % to?
        OK(OK) = OK(OK) & any([notes(OK).lAppliesTo]);
        % Only keep those notes that are OK
        notes = notes(OK);
        
        numNotes = length(notes);
        numTests = size(ss, 3);
        
        % Make sure there are thr correct number of rows
        % Get the colors of the notes
        NoteColor = i_MATLAB2MSColor(vertcat(notes.noteColor));
        
        Data = cell(numTests,numNotes+1);
        % default black
        for i = 1:numTests
            Data{i,1}= testnums(i);
            for j = 1:numNotes
                if notes(j).lAppliesTo(i)
                    Data{i,j+1}=char(notes(j).noteString);
                end
            end
        end
        
        if ms.isaTSSF
            % add test plan global variables to list
            globalvars = globalsignalnames(ms.TestplanSweepsetFilter);
        elseif ms.isaSSF
            % use test group variables
            tdef = get(ssf, 'defineTests');
            if ~isempty(tdef)
                globalvars = tdef.variable;
                globalvars(strcmp(globalvars,'#rec'))=[];
            else
                globalvars = {};
            end
        else
            % sweepset
            globalvars = {};
        end
        if ~isempty(globalvars)
            S = mean(ss(:,globalvars));
            if isequal(S,testnums(:))
                % don't show the test numbers twice
                globalvars = {};
                Xg = cell(size(Data,1),0);
            else
                Xg = num2cell(S);
            end
            Data = [Data(:,1) Xg Data(:,2:end)];
        end
        ColNames = [{'Test'},globalvars(:)',repmat({''},1,numNotes)];
        Widths = [50*ones(1,length(globalvars)+1) 100*ones(1,numNotes)];

        % add color for non-note columns
        NoteColor = [repmat([0 0 0],length(ColNames)-numNotes,1);NoteColor];
        obj.ListHandle.Peer.setData(Data);
        obj.ListHandle.setColumnData(ColNames);
        obj.ListHandle.setColumnWidths(Widths);
        obj.ListHandle.Peer.setColumnColors(NoteColor(:,1),NoteColor(:,2),NoteColor(:,3));
        
        selectRows(obj.ListHandle, ms.SelectedTests);
        end  % pssfSweepNotesChangedUpdate
        
    end  % public methods
    
    methods (Hidden) % possibly private or hidden
        %----------------------------------------
        function pPostSetDataMessageService(obj, ~,~)
        %PPOSTSETDATAMESSAGESERVICE setup MessageService listeners
        %    PPOSTSETDATAMESSAGESERVICE(OBJ, SRC, EVT)
        
        % Call the super pPostSetDataMessageService
        pPostSetDataMessageService@xregdatagui.AbstractDataView(obj);
        
        dms = obj.MessageService;
        
        dmsListeners = [...
            event.listener(dms, 'dmsDataTypeChanged',    @obj.pdmsDataTypeChangedUpdate);...
            event.listener(dms, 'ssfSweepNotesChanged',  @obj.updateListview);...
            event.listener(dms, 'SelectedTestsChanged',  @obj.pSelectedTestsChangedUpdate);...
            event.listener(dms, 'ssTestsChanged',        @obj.pssTestsChangedUpdate);...
            ];
        
        obj.Listeners = [obj.Listeners; dmsListeners];
        end  % pPostSetDataMessageService
        
        function onSelectTest(obj,~, evt)
        %onSelectTest select test
        indices = evt.data.SelectedDataRows;
        if ~obj.MessageService.isOneStage && ~isempty(indices)
            % only select tests for two-stage data
            busy(obj.MessageService,'Selecting test');
            obj.MessageService.setSelectedTests(indices)
            idle(obj.MessageService);
        end
        
        end  % i_itemClick
        
    end  % possibly private or hidden
    
end  % classdef


function MScolor = i_MATLAB2MSColor(MATLABcolor)
%i_MATLAB2MSColor Java color triple
if ~isempty(MATLABcolor)
    red   = round(255 * MATLABcolor(:,1));
    green = round(255 * MATLABcolor(:,2));
    blue  = round(255 * MATLABcolor(:,3));
    
    % HACK to get round MS Listview displaying pure blue as black
    MScolor = [ red green blue ];
else
    MScolor= zeros(0,3);
end
end  % i_MATLAB2MSColor