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

    classdef TestSelector < xregbdrygui.AbstractBdryView
    %xregbdrygui.TestSelector class
    %   xregbdrygui.TestSelector extends xregbdrygui.AbstractBdryView.
    %
    %    xregbdrygui.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'
    %       Options - Property is of type 'handle vector'
    %       Actions - Property is of type 'handle vector'
    %       UIContextMenu - Property is of type 'MATLAB array'
    %       hRadioGroup - Property is of type 'handle' (read only)
    %       hClickEdit - Property is of type 'MATLAB array' (read only)
    %       hLabel - Property is of type 'handle' (read only)
    %       hButton - Property is of type 'MATLAB array' (read only)
    %
    
    % Copyright 2005-2015 The MathWorks, Inc. and Ford Global Technologies, Inc.
    
    properties (SetAccess=protected, AbortSet, SetObservable)
        %HRADIOGROUP Property is of type 'handle' (read only)
        hRadioGroup = [];
        %HCLICKEDIT Property is of type 'MATLAB array' (read only)
        hClickEdit = [];
        %HLABEL Property is of type 'handle' (read only)
        hLabel = [];
        %HBUTTON Property is of type 'MATLAB array' (read only)
        hButton = [];
    end
    
    
    methods  % constructor block
        function obj = TestSelector( varargin )
        %XREGBDRYGUI.TESTSELECTOR class constructor
        
        % Call the inherited constructor
        obj@xregbdrygui.AbstractBdryView(varargin{ : }); % converted super class constructor call
        
        % Setup the UI and layout
        panel = mbcgui.container.titlebarpanel(...
            'Parent', obj.Parent, ...
            'Visible', obj.Visible, ...
            'BarTitle', 'Test Selector');
        
        obj.hRadioGroup = xregGui.rbgroup( ...
            'parent', panel,...
            'nx', 1,...
            'ny', 2,...
            'string', {'Response'; 'Local'},...
            'Selected',2,...
            'callback', @(s, e) obj.changeViewMode );
        
        obj.hClickEdit = mbcgui.widget.Spinner( ...
            'Parent', panel, ...
            'Rule', 'list', ...
            'List', 0, ... % This is set once the BMS has a root node
            'Callback', @(s, e) obj.nextTest );
        obj.hLabel = xregGui.labelcontrol('parent',  panel, ...
            'String', 'Test:', ...
            'Control', obj.hClickEdit, ...
            'controlsize', 60);
        obj.hButton = uicontrol(...
            'Parent', panel,...
            'Style','pushbutton',...
            'String','Select Test...',...
            'Interruptible','off',...
            'Callback', @(s, e) obj.pSelectTest );
        
        lyt = xreggridbaglayout( panel,...
            'Dimension', [3, 2], ...
            'RowSizes', [-1, 20, 25], ...
            'ColSizes', [-1, 85], ...
            'GapY', 5, ...
            'border', [7, 7, 7, 7],...
            'MergeBlock', {[1, 1], [1, 2]}, ...
            'MergeBlock', {[2, 2], [1, 2]}, ...
            'elements', { ...
            obj.hRadioGroup, []; ...
            obj.hLabel,      []; ...
            [],              obj.hButton;} );
        
        set(panel ,'ContentHandle', {lyt});
        obj.ContentHandle = panel;
        
        obj.pPostSetMessageService;
        obj.pRootChanged
        
        end  % TestSelector
        
    end  % constructor block
    
    methods
        %----------------------------------------
        function nextTest(obj)
        %nextTest Respond to the user selecting to view the next test
        %  nextTest(OBJ)
        
        BMS = obj.MessageService;
        if isempty( BMS )
            return
        end
        
        list = obj.pGetTestNumbers;
        
        % Tell the boundary message service
        BMS.CurrentTest = find( list == obj.hClickEdit.Value );
        BMS.sendEvent( 'ConstraintChange' );
        
        end  % nextTest

        %----------------------------------------
        function changeViewMode(obj)
        %changeViewMode A short description of the function
        %
        %  changeViewMode(OBJ)
        %
        %  See also XREGBDRYGUI.TESTSELECTOR.
        
        
        BMS = obj.MessageService;
        if isempty( BMS )
            return
        end
        
        mode = find( obj.hRadioGroup.Value );
        switch mode,
            case 1,
                BMS.ViewMode = 'Response';
            case 2,
                BMS.ViewMode = 'Local';
            otherwise
                warning(message('mbc:xregbdrygui:TestSelector:InvalidState'));
        end
        BMS.sendEvent( 'ConstraintChange' );
        
        end  % changeViewMode
        
    end
    
    methods (Access=protected) % protected methods

        
        %----------------------------------------
        function list = pGetTestNumbers(obj)
        %PGETTESTNUMBERS Get the current list of test numbers from the view
        %   LIST = PGETTESTNUMBERS(OBJ)
        
        % Get the list of test numbers
        clickedit = obj.hClickEdit;
        if strcmpi( get( clickedit, 'Rule' ), 'List' ),
            list = get( clickedit, 'List' );
        else
            min = get( clickedit, 'Min' );
            max = get( clickedit, 'Max' );
            inc = get( clickedit, 'ClickIncrement' );
            list = min:inc:max;
        end
        
        end  % pGetTestNumbers
        
        %----------------------------------------
        function pNodeChanged(obj)
        %PNODECHANGED Respond to a change in the current node
        %  PNODECHANGED(OBJ)
        %  Enable or disable the controls according to the number of stages in the
        %  current constraint.
        
        
        BMS = obj.MessageService;
        if isempty( BMS )
            return
        end
        cn = BMS.CurrentNode;
        if isempty( cn )
            return
        end
        
        if cn.istwostage,
            % Enable all controls
            obj.hRadioGroup.Enable = 'on';
            obj.pViewModeChanged;
        else
            % Disable all controls
            set(obj.hButton, 'Enable', 'off');
            obj.hLabel.Enable      = 'off';
            obj.hRadioGroup.Enable = 'off';
        end
        
        end  % pNodeChanged
        
        %----------------------------------------
        function pPostSetMessageService(obj)
        %PPOSTSETMESSAGESERVICE Respond to change of MessageService
        %  PPOSTSETMESSAGESERVICE(OBJ) is called when the MessageService property
        %  is changed.
        %
        %  See also XREGBDRYGUI.TESTSELECTOR.
        
        
        % Clear the listeners
        obj.clearMessageServiceListeners;
        
        % Add new listeners
        bms = obj.MessageService;
        
        obj.addMessageServiceListener( event.listener(bms,'ViewModeChange', @(src, evt) obj.pViewModeChanged) );
        obj.addMessageServiceListener( event.listener(bms,'ViewTestChange', @(src, evt) obj.pViewTestChanged) );
        
        obj.addMessageServiceListener( event.listener(bms,'RootChange', @(src, evt) obj.pRootChanged) );
        obj.addMessageServiceListener( event.listener(bms,'NodeChange', @(src, evt) obj.pNodeChanged) );
        
        end  % pPostSetMessageService
        
        %----------------------------------------
        function pRootChanged(obj)
        %PROOTCHANGED Respond to a change the root node of the bdry dev tree
        %  PROOTCHANGED(OBJ)
        %
        %  Look at the two-stage data, extract the test names and set the list in
        %  the click edit control
        
        if obj.hasData,
            bms = obj.MessageService;
            % Get the two stage data from the root node and extract the test
            % numbers from there
            ss = bms.Root.getdata( 'stage', 'response' );
            tn = testnum( ss );
            obj.hClickEdit.List = tn;
            bms.CurrentTest = 1;
        else
            % There is no data.
            % -- Set the list for the click edit to have only one value, 0
            obj.hClickEdit.List = 0;
            bms.CurrentTest = 0; %#ok<STRNU>
        end
        
        end  % pRootChanged
        
        %----------------------------------------
        function pSelectTest(obj)
        %PSELECTTEST (GUI) Select the test to be viewed
        %  PSELECTTEST(OBJ)
        
        
        BMS = obj.MessageService;
        if isempty( BMS ),
            return
        end
        
        % Popup a dialog for the user to select a test from a list of possible
        % tests.
        % Put the chosen test number into test click edit widget and call
        % BMS.CurrentTest to display the new test
        
        % Get the list of test numbers
        list = obj.pGetTestNumbers;
        
        % Get the initial value
        value = BMS.CurrentTest;
        if isempty( value )
            value = 1;
        else
            value = find( list == value );
        end
        
        % Throw up a list dialog
        [value, ok] = mv_listdlg( ...
            'ListString', num2str( list(:) ), ...
            'SelectionMode', 'Single', ...
            'InitialValue', value, ...
            'Name', 'Test Selector', ...
            'OkString', 'OK', ...
            'uh', 25, ...
            'ffs', 3 );
        
        % Update the test numbers
        if ok
            BMS.CurrentTest = value;
            BMS.sendEvent( 'ConstraintChange' );
        end
        
        end  % pSelectTest
        
        %----------------------------------------
        function pViewModeChanged(obj)
        %PVIEWMODECHANGED Respond to a change in the view mode
        %  PVIEWMODECHANGED(OBJ)
        
        BMS = obj.MessageService;
        if isempty( BMS )
            return
        end
        
        switch BMS.ViewMode
            case 'Response'
                obj.hLabel.Enable  = 'off';
                set(obj.hButton, 'Enable', 'off');
                obj.hRadioGroup.value = [1;0];
                obj.hRadioGroup.Selected = 1;
            case 'Local'
                obj.hLabel.Enable  = 'on';
                set(obj.hButton, 'Enable', 'on');
                obj.hRadioGroup.value = [0;1];
                obj.hRadioGroup.Selected = 2;
            otherwise
                warning(message('mbc:xregbdrygui:TestSelector:InvalidState1'));
        end
        
        end  % pViewModeChanged
        
        %----------------------------------------
        function pViewTestChanged(obj)
        %PVIEWTESTCHANGED Respond to a change in the test being viewed
        %  PVIEWTESTCHANGED(OBJ)
        
        BMS = obj.MessageService;
        if isempty( BMS ),
            return
        end
        
        list = obj.pGetTestNumbers;
        
        obj.hClickEdit.Value = list(BMS.CurrentTest);
        
        end  % pViewTestChanged
        
    end  % protected methods
    
end  % classdef