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

    classdef BdrySlice1Graph < mbcgui.widget.BasicContainer
    %xregbdrygui.BdrySlice1Graph class
    %   xregbdrygui.BdrySlice1Graph extends mbcgui.widget.BasicContainer.
    %
    %    xregbdrygui.BdrySlice1Graph 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'
    %       DataShowing - Property is of type 'bool'
    %       BoundaryPointsVisible - Property is of type 'on/off'
    %       ValidationPointsVisible - Property is of type 'on/off'
    %       Index - Property is of type 'MATLAB array' (read only)
    %
    %    xregbdrygui.BdrySlice1Graph methods:
    %       addListener - Add a listner
    %       dataTooltip - Display a data tool-tip.
    %       setTableData - Scrolling table interface function.
    
    % Copyright 2005-2015 The MathWorks, Inc. and Ford Global Technologies, Inc.
    
    properties (AbortSet, SetObservable)
        %DATASHOWING Property is of type 'bool'
        DataShowing = true;
        %BOUNDARYPOINTSVISIBLE Property is of type 'on/off'
        BoundaryPointsVisible = 'on';
        %VALIDATIONPOINTSVISIBLE Property is of type 'on/off'
        ValidationPointsVisible = 'on';
    end
    
    properties (Access=protected, AbortSet)
        %HAXES Property is of type 'MATLAB array'
        hAxes = [];
        %HRECTANGLES Property is of type 'MATLAB array'
        hRectangles = [];
        %HBLACKDOTS Property is of type 'MATLAB array'
        hBlackDots = [];
        %HREDRINGS Property is of type 'MATLAB array'
        hRedRings = [];
        %HVALIDATIONINSIDE Property is of type 'MATLAB array'
        hValidationInside = [];
        %HVALIDATIONOUTSIDE Property is of type 'MATLAB array'
        hValidationOutside = [];
    end
    
    properties (Access=protected, AbortSet, SetObservable)
        %HLISTENERS Property is of type 'handle vector'
        hListeners = [];
    end
    
    properties (SetAccess=protected, AbortSet)
        %INDEX Property is of type 'MATLAB array' (read only)
        Index = [];
    end
    
    
    events
        BlackDotClicked
    end  % events
    
    methods  % constructor block
        function obj = BdrySlice1Graph( varargin )
        % XREGBDRYGUI.BDRYSLICE1GRAPH class constructor
        
        % Call the inherited constructor
        obj@mbcgui.widget.BasicContainer(varargin{ : }); % converted super class constructor call
        
        % Generate GUI primitives and link together into a layout
        obj.ContentHandle = mbcgui.widget.AxesContainer(...
            'Parent', obj.Parent, ...
            'Visible', obj.Visible, ...
            'Border', [15 40 15 2]);
        obj.hAxes = obj.ContentHandle.AxesHandle;
        set(obj.hAxes,...
            'Box','on',...
            'XGrid','on',...
            'YGrid','off',...
            'YTickLabel', '',...
            'YTick', [], ...
            'XLim', [0, 10], ...
            'YLim', [-1, 1], ...
            'Layer','top',...
            'HitTest', 'off' );
        mbcxlabel( obj.hAxes, '', 'Interpreter', 'none' );
        
        obj.hRectangles = obj.pCreateRectangle( 2, 9 );
        
        obj.hBlackDots = line( ...
            'Parent',  obj.hAxes, ...
            'Visible', 'on',...
            'LineStyle', 'none', ...
            'Marker', '.', ...
            'MarkerEdgeColor', 'k', ...
            'MarkerFaceColor', 'k', ...
            'MarkerSize', 15, ...
            'XData', [2:9, 8.9], ...
            'YData', zeros( 1, 9 ), ...
            'ZData', [], ...
            'ButtonDownFcn', @(s, e) obj.pClickBlackDot );
        
        obj.hRedRings = line(...
            'Parent',  obj.hAxes, ...
            'Visible', 'on',...
            'LineStyle', 'none', ...
            'LineWidth', 2, ...
            'Marker', 'o', ...
            'MarkerEdgeColor', 'r', ...
            'MarkerFaceColor', 'none', ...
            'MarkerSize', 10, ...
            'XData', [2, 9], ...
            'YData', zeros( 1, 2 ), ...
            'ZData', [], ...
            'HitTest', 'off' );
        
        obj.hValidationInside = line( ...
            'Parent',obj.hAxes, ...
            'LineStyle', 'none', ...
            'Marker', '^', ...
            'MarkerFaceColor', [50, 200, 50]/255, ...
            'MarkerSize', 6, ...
            'XData', [], ...
            'YData', [], ...
            'ZData', [], ...
            'HitTest', 'off', ...
            'Visible', obj.ValidationPointsVisible, ...
            'Tag', '');
        
        obj.hValidationOutside = line( ...
            'Parent',obj.hAxes, ...
            'LineStyle', 'none', ...
            'Marker', '^', ...
            'MarkerFaceColor', [200, 50, 50]/255, ...
            'MarkerSize', 6, ...
            'XData', [], ...
            'YData', [], ...
            'ZData', [], ...
            'HitTest', 'off', ...
            'Visible', obj.ValidationPointsVisible, ...
            'Tag', '');
        
        obj.Index = 11:19;
        
        obj.hListeners = [
            event.proplistener( obj, obj.findprop( 'DataShowing' ),           'PostSet', @(s, e) obj.pPostSetVisible )
            event.proplistener( obj, obj.findprop( 'BoundaryPointsVisible' ), 'PostSet', @(s, e) obj.pPostSetBoundaryPointsVisible )
            event.proplistener( obj, obj.findprop( 'ValidationPointsVisible' ), 'PostSet', @(s, e) obj.pPostSetValidationPointsVisible )
            ];
        
        end  % BdrySlice1Graph
        
    end  % constructor block
    
    methods
    end   % set and get functions
    
    methods  % public methods
        %----------------------------------------
        function addListener(obj, hListener)
        %ADDLISTENER Add a listner
        %   ADDLISTENER(OBJ, HLISTENER)
        
        obj.hListeners = [
            obj.hListeners
            hListener
            ];
        
        end  % addListener
        
        %----------------------------------------
        function dataTooltip(obj, string)
        %DATATOOLTIP Display a data tool-tip.
        %   DATATOOLTIP(OBJ, STRING) displays a data tool-tip on the object. The
        %   text of the tool-tip is given by STRING. The tool-tip will be located
        %   at the current point of the axes.
        %
        %   See also xregDisplayDataPatch.
        
        
        xregDisplayDataPatch( obj.hAxes, string, [], false );
        
        end  % dataTooltip
        
        %----------------------------------------
        function pClickBlackDot(obj)
        %PCLICKBLACKDOT Send an event when a black dot is clicked on.
        %   PCLICKBLACKDOT(OBJ)
        
        % Find where the user clicked
        point = get( obj.hAxes, 'CurrentPoint' );
        point = point(1);
        
        % Find the points that are close to where the user click
        x = get( obj.hBlackDots, 'XData' );
        xlim = get( obj.hAxes, 'XLim' );
        tol = (xlim(2)-xlim(1))/30;
        
        distance = abs( x - point );
        nearIndex = distance < tol;
        
        [~, closestIndex] = min( distance );
        
        if ~any( nearIndex ),
            nearIndex = closestIndex;
        end
        
        % Send event
        eventData = xregEventData( struct( ...
            'hGraph', obj, ...
            'Point', point, ...
            'ClosestIndex', obj.Index(closestIndex), ...
            'NearIndex',    obj.Index(nearIndex) ) );
        
        obj.notify( 'BlackDotClicked', eventData  );
        
        end  % pClickBlackDot
        
        %----------------------------------------
        function hRectangle = pCreateRectangle(obj, start, finish)
        %PCREATERECTANGLE Create a rectangle for the graph
        %   HRECTANGLE = PCREATERECTANGLE(OBJ, START, FINISH)
        
        hRectangle = rectangle( ...
            'Parent',  obj.hAxes, ...
            'Visible', 'on', ...
            'Position', [start, -1, finish-start, 2],...
            'FaceColor', [0.5, 0.5, 1], ...
            'HitTest', 'off' );
        
        end  % pCreateRectangle
        
        %----------------------------------------
        function pPostSetBoundaryPointsVisible(obj, ~,~)
        %PPOSTSETBOUNDARYPOINTSVISIBLE Set visibilty of the boundary point line.
        %   PPOSTSETBOUNDARYPOINTSVISIBLE(OBJ, EVT)
        
        set(obj.hRedRings, 'Visible', obj.BoundaryPointsVisible);
        
        end  % pPostSetBoundaryPointsVisible
        
        %----------------------------------------
        function pPostSetValidationPointsVisible(obj)
        %PPOSTSETVALIDATIONPOINTSVISIBLE Set visibilty of the validation data line.
        %   PPOSTSETVALIDATIONPOINTSVISIBLE(OBJ, EVT)
        
        set(obj.hValidationOutside, 'Visible', obj.ValidationPointsVisible)
        set(obj.hValidationInside, 'Visible', obj.ValidationPointsVisible)
        end  % pPostSetValidationPointsVisible
        
        %----------------------------------------
        function setTableData(obj, R, ~, data)
        %SETTABLEDATA Scrolling table interface function.
        %   SETTABLEDATA(OBJ, R, C, DATA)
        
        if obj.DataShowing && ~isempty( data.ConstraintBounds ),
            
            BMS = data.MessageService;
            cif = BMS.getInputFactors;
            
            % Set the axis label
            fn = getFullNames( cif );
            set( get( obj.hAxes, 'XLabel' ), 'String', fn(R) );
            
            % Take the range of the axes from the list of eval points
            x = data.EvaluationPoints{R};
            set(obj.hAxes, 'XLim', [min( x ), max( x )]);
            
            % Constraint Rectangles
            delete( obj.hRectangles(isgraphics(obj.hRectangles) ) );
            
            ends = data.ConstraintBounds{R};
            hRects = cell( 1, size( ends, 2 ) );
            ok = true(size(hRects));
            for i = 1:size( ends, 2 ),
                if ends(1,i)<ends(2,i)
                    hRects{i} = obj.pCreateRectangle( ends(1,i), ends(2,i) );
                else
                    ok(i)=false;
                end
            end
            hRects =  [hRects{ok}];
            
            % Data Points
            i_setXData( obj.hBlackDots, data.getDataPoints( R ) );
            i_setXData( obj.hRedRings,  data.getBoundaryPoints( R ) );
            % Validation Points
            [insideVal, outsideVal] = data.getValidationPoints(R);
            i_setXData(obj.hValidationInside, insideVal);
            set(obj.hValidationInside, 'Tag', 'BdrySlice1ValidationInside')
            i_setXData(obj.hValidationOutside, outsideVal);
            set(obj.hValidationOutside, 'Tag', 'BdrySlice1ValidationOutside')
            obj.Index = data.getDataIndices(R);
            
            obj.BoundaryPointsVisible = BMS.BoundaryPointHighlight;
            obj.ValidationPointsVisible = BMS.ValidationPointHighlight;
            
            % Ensure the order is child is such that the dots and rings appear in
            % front of the rectangles
            set(obj.hAxes, 'Children', [obj.hValidationOutside, obj.hValidationInside, obj.hBlackDots, obj.hRedRings, hRects]);
            
            % Store the rectangle handles in the object
            obj.hRectangles = hRects;
        end
        end  % setTableData
        
        
        
        
    end  % public methods
    
end  % classdef

function i_setXData(obj, xData)
set( obj, ...
    'XData', xData, ...
    'YData', zeros(size(xData)));
end  % i_setXData