www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/+cageview/+optimoutput/ParetoViewCell.m

    classdef ParetoViewCell < mbcgui.widget.BasicContainer
    %cageview.optimoutput.ParetoViewCell class
    %   cageview.optimoutput.ParetoViewCell extends mbcgui.widget.BasicContainer.
    %
    %    cageview.optimoutput.ParetoViewCell 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'
    %       LabelEdgeAxes - Property is of type 'bool'
    %       Hittest - Property is of type 'on/off'
    %
    %    cageview.optimoutput.ParetoViewCell methods:
    %       setTableData - Table drawing interface function
    
    %  Copyright 2005-2016 The MathWorks, Inc.
    
    properties (AbortSet)
        %LABELEDGEAXES Property is of type 'bool'
        LabelEdgeAxes
    end
    
    properties (AbortSet, SetObservable)
        %HITTEST Property is of type 'on/off'
        HitTest = 'off';
    end
    
    properties (Access=protected, AbortSet)
        %HAXES Property is of type 'MATLAB array'
        hAxes = [];
        %HGREENLINE Property is of type 'MATLAB array'
        hGreenLine = [];
        %HORANGELINE Property is of type 'MATLAB array'
        hOrangeLine = [];
        %HREDLINE Property is of type 'MATLAB array'
        hRedLine = [];
        %HSELECTEDLINE Property is of type 'MATLAB array'
        hSelectedLine = [];
        %HSELECTEDSOLUTIONLINE Property is of type 'MATLAB array'
        hSelectedSolutionLine = [];
    end
    
    
    events
        SelectionChangeRequest
    end  % events
    
    methods  % constructor block
        function obj = ParetoViewCell(varargin)
        %ParetoViewCell Constructor for ParetoViewCell objects
        %  OBJ = ParetoViewCell(PROP, VAL, ...)
        
        % Call the inherited constructor
        obj@mbcgui.widget.BasicContainer(varargin{ : }); % converted super class constructor call
        
        obj.ContentHandle = mbcgui.widget.AxesContainer(...
            'Parent', obj.Parent, ...
            'Visible', obj.Visible, ...
            'Border', [15 10 15 10]);
        obj.hAxes = obj.ContentHandle.AxesHandle;
        set(obj.hAxes, ...
            'HitTest', obj.HitTest, ...
            'Layer', 'top', ...
            'Units', 'pixels', ...
            'XTickLabel', '', ...
            'YTickLabel', '', ...
            'Box', 'on', ...
            'XGrid', 'on', ...
            'YGrid', 'on');
        
        selcol = [0.5 0.5 0.5];
        obj.hSelectedLine = line('Parent', obj.hAxes, ...
            'HitTest', 'off', ...
            'LineStyle', 'none', ...
            'Marker', 'o', ...
            'MarkerEdgeColor', selcol, ...
            'MarkerFaceColor', selcol, ...
            'MarkerSize', 10, ...
            'XData', [], ...
            'YData', [], ...
            'ZData', []);
        xregGui.setLegendData(obj.hSelectedLine, false);
        
        mbcgui.hgclassesutil.setNotPickable(obj.hSelectedLine);
        
        % Create the lines for the solution points
        obj.hRedLine = line('Parent', obj.hAxes,...
            'Tag', 'RedLine',...
            'Clipping','off',...
            'LineStyle', 'none', ...
            'Marker', 'o', ...
            'MarkerSize', 6, ...
            'MarkerFaceColor', 'r', ...
            'MarkerEdgeColor', 'k', ...
            'Color', 'r', ...
            'XData', [],...
            'YData', [],...
            'ZData', [],...
            'ButtonDownFcn', {@i_selectsol, obj});
        xregGui.setLegendData(obj.hRedLine, 'Red objective value');
        
        cOrange = [1 0.69 0.39];
        obj.hOrangeLine = line('Parent', obj.hAxes,...
            'Tag', 'OrangeLine',...
            'Clipping','off',...
            'LineStyle', 'none', ...
            'Marker', '^', ...
            'MarkerSize', 6, ...
            'MarkerFaceColor', cOrange, ...
            'MarkerEdgeColor', 'k', ...
            'Color', cOrange, ...
            'XData', [],...
            'YData', [],...
            'ZData', [],...
            'ButtonDownFcn', {@i_selectsol, obj});
        xregGui.setLegendData(obj.hOrangeLine, 'Orange objective value');
        
        obj.hGreenLine = line('Parent', obj.hAxes,...
            'Tag', 'GreenLine',...
            'Clipping','off',...
            'LineStyle', 'none', ...
            'Marker', 's', ...
            'MarkerSize', 6, ...
            'MarkerFaceColor', 'g', ...
            'MarkerEdgeColor', 'k', ...
            'Color', 'g', ...
            'XData', [],...
            'YData', [],...
            'ZData', [],...
            'ButtonDownFcn', {@i_selectsol, obj});
        xregGui.setLegendData(obj.hGreenLine, 'Green objective value');
        
        solcol = [0.5 1 1];
        obj.hSelectedSolutionLine = line('Parent', obj.hAxes, ...
            'HitTest', 'off', ...
            'Clipping','off',...
            'LineStyle', 'none', ...
            'Marker', 'p', ...
            'MarkerEdgeColor', 'k', ...
            'MarkerFaceColor', solcol, ...
            'MarkerSize', 14, ...
            'XData', [], ...
            'YData', [], ...
            'ZData', []);
        xregGui.setLegendData(obj.hSelectedSolutionLine, false);
        mbcgui.hgclassesutil.setNotPickable(obj.hSelectedSolutionLine);
        
        obj.addPropertyListeners('HitTest', {@iSetHitTest, obj.hAxes});
        end  % ParetoViewCell
        
    end  % constructor block
    
    methods
    end   % set and get functions
    
    methods  % public methods
        %----------------------------------------
        function setTableData(obj, R, C, dataobj)
        %SETTABLEDATA Table drawing interface function
        %  SETTABLEDATA(OBJ, ROW, COL, DATA) where DATA should be a structure
        %  containing the fields xdata, ydata, xlim, ylim, xvalue and yvalue.
        
        data = dataobj.getCellData(R, C);
        
        if isempty(data.xdata)
            SC = xregGui.SystemColorsDbl;
            set(obj.hAxes, ...
                'XLim', data.xlim, ...
                'YLim', data.ylim, ...
                'XGrid', 'off', ...
                'YGrid', 'off', ...
                'Color', SC.CTRL_BG);
            set(obj.hGreenLine, 'XData', [], 'YData', [], 'ZData', []);
            set(obj.hOrangeLine, 'XData', [], 'YData', [], 'ZData', []);
            set(obj.hRedLine, 'XData', [], 'YData', [], 'ZData', []);
            set(obj.hSelectedLine, 'XData', [] , 'YData', [],'ZData',[]);
            set(obj.hSelectedSolutionLine, 'XData', [] , 'YData', [],'ZData',[]);
            set(obj.hAxes,'Visible','off');
        else
            set(obj.hAxes,'Visible','on');
            set(obj.hAxes, ...
                'XLim', data.xlim, ...
                'YLim', data.ylim, ...
                'XGrid', 'on', ...
                'YGrid', 'on',...
                'Color', 'w');
            set(obj.hGreenLine, ...
                'XData', data.xdata(1,:), ...
                'YData', data.ydata(1,:), ...
                'ZData', zeros(1,size(data.ydata,2)));
            
            set(obj.hOrangeLine, ...
                'XData', data.xdata(2,:), ...
                'YData', data.ydata(2,:), ...
                'ZData', zeros(1,size(data.ydata,2)));
            set(obj.hRedLine, ...
                'XData', data.xdata(3,:), ...
                'YData', data.ydata(3,:), ...
                'ZData', zeros(1,size(data.ydata,2)));
            
            xsel = find(isfinite(data.xdata(:,data.SelectedPoints)),1,'first');
            if ~isempty(xsel)
                set(obj.hSelectedLine, ...
                    'XData', data.xdata(xsel,data.SelectedPoints) , ...
                    'YData', data.ydata(xsel,data.SelectedPoints), ...
                    'ZData',-ones(size(data.SelectedPoints)));
            else
                set(obj.hSelectedLine, 'XData', [] , 'YData', [],'ZData',[]);
            end
            
            set(obj.hSelectedSolutionLine, 'XData', [] , 'YData', [],'ZData',[]);
            if data.Solution
                xsel = find(isfinite(data.xdata(:,data.Solution)),1,'first');
                if ~isempty(xsel)
                    set(obj.hSelectedSolutionLine, ...
                        'XData', data.xdata(xsel,data.Solution) , ...
                        'YData', data.ydata(xsel,data.Solution), ...
                        'ZData',-ones(size(data.Solution)));
                end
            end
            
        end
        if obj.LabelEdgeAxes
            % Use extra data to add tick labels and axes labels if this set of axes
            % is at an edge of the table.  This functionality is used for printing
            % the graphs
            if ~isempty(data.ylabel)
                set(obj.hAxes, 'YTickLabelMode', 'auto');
                mbcylabel(obj.hAxes, data.ylabel, 'Interpreter', 'none');
            else
                set(obj.hAxes, 'YTickLabel', {});
                mbcylabel(obj.hAxes, '');
            end
            if ~isempty(data.xlabel)
                set(obj.hAxes, 'XTickLabelMode', 'auto');
                mbcxlabel(obj.hAxes, data.xlabel, 'Interpreter', 'none');
            else
                set(obj.hAxes, 'XTickLabel', {});
                mbcxlabel(obj.hAxes, '');
            end
        end
        
        end  % setTableData
        
    end  % public methods
    
end  % classdef

function i_selectsol(src, ~, obj)
hAx = get(src, 'Parent');

% Get hit point
pt = get(hAx, 'CurrentPoint');
pt = pt(1,1:2);

% Get target points
xd = get(src, 'XData');
yd = get(src, 'YData');

% Normalize values
xl = get(hAx, 'XLim');
yl = get(hAx, 'YLim');

% Find index of closest point
dx = (xd-pt(1))./(xl(2)-xl(1));
dy = (yd-pt(2))./(yl(2)-yl(1));
d = dx.^2 + dy.^2;
[~, idx] = min(d);

% Send event to notify View of the requested selection
data = xregEventData(struct('Index', idx));
obj.notify('SelectionChangeRequest', data);
end  % i_selectsol

function iSetHitTest(~, evt, h)
set(h, 'HitTest', evt.AffectedObject.HitTest);
end  % iSetHittest