www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/+cageview/+optimoutput/ParetoView.m
classdef ParetoView < mbcgui.multiview.View %cageview.optimoutput.ParetoView class % cageview.optimoutput.ParetoView extends mbcgui.multiview.View. % % cageview.optimoutput.ParetoView 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' % % cageview.optimoutput.ParetoView 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 % Copyright 2005-2016 The MathWorks, Inc. properties (Access=protected, AbortSet) %HTABLE Property is of type 'handle' hTable = []; end methods % constructor block function obj = ParetoView(varargin) %ParetoView Constructor for ParetoView % OBJ = ParetoView(PROP, VALUE) constructs a class that displays the % pareto front from a multi-objective optimization. % Call the inherited constructor obj@mbcgui.multiview.View(varargin{ : }); % converted super class constructor call Data = cageview.optimoutput.ParetoViewData; obj.hTable = mbcgui.widget.ClassicTable('Parent',obj.Parent, ... 'Visible', obj.Visible, ... 'ShowRowHeaders',true, ... 'ShowColumnHeaders',true,... 'RowHeaderWidth', 65,... 'ColumnHeaderWidth', 50,... 'MinimumCellSize', [150 150],... 'UseVectorDrawMethod',false,... 'MainConstructor',@(P) i_createMainObject(P, obj),... 'RowConstructor', @i_createRowHeadObject,... 'ColumnConstructor', @i_createColHeadObject, ... 'RowGap', 0, ... 'ColumnGap',0, ... 'ColumnHeaderPosition', 'bottom', ... 'MaximumObjectCacheSize', 15, ... 'MainData', Data, ... 'RowHeaderData', Data, ... 'ColumnHeaderData', Data); obj.hTable.TopLeftCorner = obj.hTable.newCornerComponent('panel'); obj.hTable.BottomRightCorner = obj.hTable.newCornerComponent; % 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); obj.addListeners( ... event.listener(obj.hTable, ... 'DisplaySizeChanged',@(h,evt)i_spacervisible(h,evt,Cards))); 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; if ~isempty(obj.MessageService) obj.pPostSetMessageService; end % 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]; AGDisplay = mbcgui.actions.ActionGroup('', '&Results to Display'); AGDisplay.MenuType = 'submenu'; Adisp1 = mbcgui.actions.ToggleAction({@i_setdisplaydata, 'All', obj,obj.hTable}, '&All'); Adisp2 = mbcgui.actions.ToggleAction({@i_setdisplaydata, 'Acceptable', obj,obj.hTable}, 'A&cceptable'); Adisp3 = mbcgui.actions.ToggleAction({@i_setdisplaydata, 'Green', obj,obj.hTable}, '&Green'); Adisp4 = mbcgui.actions.ToggleAction({@i_setdisplaydata, 'Orange', obj,obj.hTable}, '&Orange'); Adisp5 = mbcgui.actions.ToggleAction({@i_setdisplaydata, 'Red', obj,obj.hTable}, '&Red'); AGDisplay.Actions = [Adisp1 Adisp2 Adisp3 Adisp4 Adisp5]; Adisp1.Selected = true; obj.Options.Actions = [AG AGDisplay]; end % ParetoView % Functions that construct the display objects end % constructor block methods % public methods %---------------------------------------- function out = canPrint(obj) %#ok<MANU> %CANPRINT Check whether component can be printed % CANPRINT(OBJ) returns true for designview components. out = true; 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 = 'Pareto Graphs'; end % gettitle %---------------------------------------- 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) % Create a new table data = obj.hTable.MainData; newdata = data.copy; newtable = mbcgui.widget.ClassicTable('Parent',fig, ... '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', ... 'RunFocusChanged', ... 'SelectedSolutionChanged',... 'SolutionIndexChanged', ... 'WeightsChanged',... 'AcceptableChanged'}, ... {{@i_refresh, obj.hTable}, ... {@i_refresh, obj.hTable}, ... {@i_refresh, obj.hTable}, ... {@i_refresh, obj.hTable}, ... {@i_solchange, obj.hTable}, ... {@i_targetedchange, obj, obj.hTable, 'weightedsolution'},... {@i_refresh, obj.hTable}}); end obj.hTable.MainData.MessageService = obj.MessageService; reset(obj.hTable.MainData); obj.hTable.update; end % pPostSetMessageService end end % classdef function h = i_createMainObject(P, obj) h = cageview.optimoutput.ParetoViewCell('Parent',P, 'Visible','off'); L = event.listener(h, 'SelectionChangeRequest', @(h,evt) i_changesol(h,evt,obj)); h.addListeners(L); 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_changesol(~, evt, obj) if obj.hasData obj.MessageService.setCurrentSolution(evt.Data.Index); end end % i_changesol function i_setgraphsize(src, ~, hTable, size, AG) hTable.MinimumCellSize = [size size]; set(AG.Actions, 'Selected', false); src.Selected = true; end % i_setgraphsize function i_setdisplaydata(~, ~,Results,obj,hTable) DisplayActions = obj.Options(2).Actions; set(DisplayActions, 'Selected', false); hTable.MainData.DisplayResults = Results; switch Results case 'Acceptable' DisplayActions(2).Selected = true; case 'Green' DisplayActions(3).Selected = true; case 'Orange' DisplayActions(4).Selected = true; case 'Red' DisplayActions(5).Selected = true; otherwise DisplayActions(1).Selected = true; end hTable.MainData.DisplayResults = Results; % Refresh all the table data reset(hTable.MainData); hTable.update; end % i_setdisplaydata % 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(~, ~, hTable) % Refresh all the table data reset(hTable.MainData); hTable.update; end % i_refresh function i_solchange(~, ~, hTable) % The selection has changed, so the graphs need to be redrawn but the data % is the same hTable.repaint; end % i_solchange function i_targetedchange(~, ~, obj, hTable, target) if strcmpi(obj.MessageService.CurrentSliceDirection,target) % Only redraw if the specified target view is currently being used reset(hTable.MainData); hTable.update; end end % i_targetedchange function h = i_createMainObjectPrintable(P) h = cageview.optimoutput.ParetoViewCell('Parent',P, ... 'Visible','off', ... 'LabelEdgeAxes', true, ... 'HitTest', 'on'); end % i_createMainObjectPrintable