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

    classdef ObjGraphView < mbcgui.multiview.View
    %cageview.optimoutput.ObjGraphView class
    %   cageview.optimoutput.ObjGraphView extends mbcgui.multiview.View.
    %
    %    cageview.optimoutput.ObjGraphView 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'
    %       DisplayConstraints - Property is of type 'bool'
    %
    %    cageview.optimoutput.ObjGraphView methods:
    %       canPrint - Check whether component can be printed
    %       createDefaultWindowContainer - Create an appropriate container for the view
    %       gettitle - Return string to use as title for view
    %       printSize - Returns the preferred printing size for the component
    %       printCopy - Create a printer-friendly copy of pairwiseproj
    %       redraw - Redraw the objective table
    
    %  Copyright 2005-2016 The MathWorks, Inc.
    
    properties (AbortSet, SetObservable)
        %DISPLAYCONSTRAINTS Property is of type 'bool'
        DisplayConstraints = true;
    end
    
    properties (Access=protected, AbortSet)
        %HTABLE Property is of type 'handle'
        hTable = [];
        %CONACTION Property is of type 'handle'
        ConAction = [];
    end
    
    methods  % constructor block
        function obj = ObjGraphView(varargin)
        %ObjGraphView Constructor for ObjGraphView
        %  OBJ = ObjGraphView(PROP, VALUE) constructs a class that displays the
        %  objective value slices from a multi-objective optimization.
        
        % Call the inherited constructor
        obj@mbcgui.multiview.View(varargin{ : }); % converted super class constructor call
        
        data = cageview.optimoutput.ObjGraphViewData;
        obj.hTable = mbcgui.widget.ClassicTable('Parent',obj.Parent, ...
            'Visible', obj.Visible, ...
            'ShowRowHeaders',true, ...
            'ShowColumnHeaders',true,...
            'RowHeaderWidth', 65,...
            'ColumnHeaderWidth', 60,...
            'MinimumCellSize', [150 150],...
            'UseVectorDrawMethod',false,...
            'MainConstructor',@i_createMainObject,...
            'RowConstructor', @i_createRowHeadObject,...
            'ColumnConstructor', @i_createColHeadObject, ...
            'MainData', data, ...
            'RowHeaderData', data, ...
            'ColumnHeaderData', data, ...
            'RowGap', 0, ...
            'ColumnGap',0, ...
            'ColumnHeaderPosition', 'bottom', ...
            'MaximumObjectCacheSize', 15);
        obj.hTable.TopLeftCorner = obj.hTable.newCornerComponent('panel');
        obj.hTable.BottomRightCorner = obj.hTable.newCornerComponent;
        
        % Provide data with table handle so it can cache data efficiently
        data.hTable = obj.hTable;
        
        obj.addListeners(event.listener(data, 'YLimUpdated', mbcutils.callback(@i_ylimrepaint, obj.hTable)));
        
        % Add a spacer object that makes room for viewing an exponent on the top
        % graph
        Spacer = obj.hTable.newCornerComponent('panel');
        Cards = xregcardlayout(obj.Parent, ...
            'Visible', obj.Visible, ...
            'CurrentCard', 2, ...
            'NumCards', 2);
        attach(Cards, Spacer, 1);
        G = xreggridbaglayout(obj.Parent, ...
            'Dimension', [2 2], ...
            'Rowsizes', [10 -1], ...
            'ColSizes', [65 -1], ...
            'MergeBlock', {[2 2], [1 2]}, ...
            'Elements', {Cards, obj.hTable});
        obj.ContentHandle = G;
        obj.addListeners( ...
            event.listener(obj.hTable, ...
            'DisplaySizeChanged', mbcutils.callback(@i_spacervisible, Cards)));
        
        % Create option action options
        AG = mbcgui.actions.ActionGroup('', '&Graph Size');
        AG.MenuType = 'submenu';
        A1 = mbcgui.actions.ToggleAction({@i_setgraphsize, obj.hTable, 0, AG}, ...
            '&Display All Graphs');
        A2 = mbcgui.actions.ToggleAction({@i_setgraphsize, obj.hTable, 100, AG}, ...
            '&Small');
        A3 = mbcgui.actions.ToggleAction({@i_setgraphsize, obj.hTable, 150, AG}, ...
            '&Medium');
        A3.Selected = true;
        A4 = mbcgui.actions.ToggleAction({@i_setgraphsize, obj.hTable, 200, AG}, ...
            '&Large');
        AG.Actions = [A1 A2 A3 A4];
        
        ACon = mbcgui.actions.ToggleAction({@i_actiondisplaycon, obj}, 'Display &Constraints');
        ACon.Selected = obj.DisplayConstraints;
        
        obj.Options.Actions = [AG, ACon];
        obj.ConAction = ACon;
        
        if ~isempty(obj.MessageService)
            obj.pPostSetMessageService;
        end
        
        obj.addPropertyListeners({'DisplayConstraints'}, {{@i_setdisplaycon, obj.hTable}});
        end  % ObjGraphView
        
    end  % constructor block
    
    methods  % public methods
        %----------------------------------------
        function out = canPrint(obj) 
        %CANPRINT Check whether component can be printed
        %  CANPRINT(OBJ) returns true if 10x10 grid or less
        
        d = obj.hTable.MainData;
        out = hasData(obj) && d.getRowCount<=10 && d.getColumnCount<=10;
        
        end  % canPrint
        
        %----------------------------------------
        function hPane = createDefaultWindowContainer(obj,PanelHandle)
        %CREATEDEFAULTWINDOWCONTAINER Create an appropriate container for the view
        %  HCONAINER = CREATEDEFAULTWINDOWCONTAINER(OBJ) creates and returns a
        %  handle to a ViewContainer that has been set up to contain OBJ.  The
        %  container should be appropriate for viewing OBJ in a standard
        %  application window.  The default implementation creates a
        %  PanelTitleViewContainer.
        
        if nargin>1
            % User suplied Panel
            Parent = get(PanelHandle,'Parent');
            OtherArgs = {'PanelHandle',PanelHandle};
        else
            % Use the View's parent
            Parent = get(View,'Parent');
            OtherArgs = {};
        end
        
        SC = xregGui.SystemColorsDbl;
        hPane = mbcgui.multiview.PanelTitleViewContainer( ...
            'Parent', Parent, ...
            'Visible', obj.Visible, ...
            'BackgroundColor', SC.CTRL_BG, ...
            'View', obj,...
            OtherArgs{:});
        
        end  % createDefaultWindowContainer
        
        %----------------------------------------
        function str = gettitle(obj) %#ok<MANU>
        %GETTITLE Return string to use as title for view
        %  STR = GETTITLE(OBJ) returns a string that should be used as a title for
        %  the container the view sits in.
        
        str = 'Objective Graphs';
        
        end  % gettitle
        
        %----------------------------------------
        function redraw(obj)
        %REDRAW Redraw the objective table
        %   REDRAW(OBJ) redraws all of the objective graphs
        
        obj.hTable.MainData.MessageService = obj.MessageService;
        obj.hTable.MainData.reset;
        obj.hTable.update;
        
        end  % redraw
        
        %----------------------------------------
        function sz = printSize(obj)
        %PRINTSIZE Returns the preferred printing size for the component
        %  SZ = PRINTSIZE(OBJ) returns a two element vector containing the
        %  preferred width and height for printing the component.  This method
        %  scales the current screen size so that each graph maintains its aspect
        %  ratio.
        
        % Get size of central table region
        sz = obj.Position(3:4) - [65 50];
        
        % Scale size by number of missing graphs
        nShowing = obj.hTable.getDisplaySize;
        nTotal = [obj.hTable.MainData.getRowCount, obj.hTable.MainData.getColumnCount];
        if all(nShowing>0)
            sz = sz.*fliplr(nTotal./nShowing);
        end
        
        end  % printSize
        
        %----------------------------------------
        function newobj = printCopy(obj, fig)
        %PRINTCOPY Create a printer-friendly copy of pairwiseproj
        %  LYT = PRINTCOPY(OBJ,FIG)
        
        % Evaluate data for all cells now since they will need to be all shown
        data = obj.hTable.MainData;
        data.fillDataCache;
        
        % Copy data for the exported graph set
        newdata = data.copy;
        
        % Create a new table
        newtable = mbcgui.widget.ClassicTable('Parent',fig, ...
            'Position',fig.Position,...
            'ShowRowHeaders',false, ...
            'ShowColumnHeaders',false,...
            'MinimumCellSize', [0 0],...
            'UseVectorDrawMethod',false,...
            'MainConstructor',@i_createMainObjectPrintable,...
            'MainData', newdata, ...
            'RowGap', 0,'ColumnGap',0);
        
        newobj = xreglayerlayout(fig, ...
            'border', [40 35 0 0], ...
            'elements', {newtable});
        end  % printcopy        
        
    end  % public methods
    
    methods (Access=protected)
        %----------------------------------------
        function pPostSetMessageService(obj)
        %PPOSTSETMESSAGESERVICE Method that is called when the message service is set
        %  PPOSTSETMESSAGESERVICE(OBJ) is called in response to a new message
        %  service being set in the object.
        
        pPostSetMessageService@mbcgui.multiview.View(obj)
        
        if ~isempty(obj.MessageService)
            % Add redraw events
            obj.addMessageServiceListener( {'ObjectChanged', ...
                'SliceDirectionChanged', ...
                'CurrentFocusChanged', ...
                'FeasibleToleranceChanged'}, ...
                {{@i_refresh, obj}, ...
                {@i_refresh, obj}, ...
                {@i_refresh, obj}, ...
                {@i_refresh, obj}});
        end
        
        i_refresh([], [], obj);
        end  % pPostSetMessageService
        
        %----------------------------------------
        function flg = pShowConstraints(obj)
        %PSHOWCONSTRAINTS Check whether constraints should be shown.
        %   PSHOWCONSTRAINTS(OBJ) returns true if constraints should be calculated
        %   and displayed.  This value will depend on both the user-settable option
        %   and the number of constraint evaluations that would be needed to
        %   display them.
        
        flg = obj.DisplayConstraints && obj.ConAction.Enabled;
        
        end  % pShowConstraints
        
    end
    
end  % classdef

function h = i_createMainObject(P)
h = cageview.optimoutput.ObjGraphViewCell('Parent',P, 'Visible','off');
end  % i_createMainObject

function h = i_createRowHeadObject(P)
h = mbcgui.widget.SharedAxisHeader('Parent', P, ...
    'Visible', 'off', ...
    'Orientation', 'vertical', ...
    'AxisEdgeOffset', 10, ...
    'AxisFrontOffset', 8);
end  % i_createRowHeadObject

function h = i_createColHeadObject(P)
h = mbcgui.widget.SharedAxisHeader('Parent', P, ...
    'Visible', 'off', ...
    'Orientation', 'horizontal', ...
    'AxisEdgeOffset', 15, ...
    'AxisFrontOffset', 8);
end  % i_createColHeadObject

function i_setgraphsize(src, ~, hTable, size, AG)
hTable.MinimumCellSize = [size size];
set(AG.Actions, 'Selected', false);
src.Selected = true;
end  % i_setgraphsize

function i_actiondisplaycon(src, ~, obj)
obj.DisplayConstraints = src.Selected;
end  % i_actiondisplaycon

function i_setdisplaycon(~, evt, hTable)
hTable.MainData.DisplayConstraints = evt.AffectedObject.DisplayConstraints;
hTable.repaint;
end  % i_setdisplaycon

% Repaint table rows if a ylim is altered when new sweeps are calculated
function i_ylimrepaint(~, evt, hTable)
hTable.paintRows(evt.data.Rows);
end  % i_ylimrepaint

% Set spacer visibility to match that of the corner component
function i_spacervisible(src, ~, Cards)
sz = src.getDisplaySize;
if any(sz>0)
    set(Cards, 'CurrentCard', 1);
else
    set(Cards, 'CurrentCard', 2);
end
end  % i_spacervisible

function i_refresh(~, ~, obj)
% Refresh all the table data
obj.redraw;
end  % i_refresh

function h = i_createMainObjectPrintable(P)
h = cageview.optimoutput.ObjGraphViewCell('Parent',P, ...
    'LabelEdgeAxes', true, ...
    'HitTest', 'on');
end  % i_createMainObjectPrintable