www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/+cageview/+optimoutput/StatsView.m
classdef StatsView < mbcgui.multiview.View %cageview.optimoutput.StatsView class % cageview.optimoutput.StatsView extends mbcgui.multiview.View. % % cageview.optimoutput.StatsView 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.StatsView methods: % gettitle - Return string to use as title for view % redraw - Redraw the stats information table % refreshAcceptable - Update acceptable stats value % Copyright 2005-2015 The MathWorks, Inc. properties (Access=protected, AbortSet) %HINFOTABLE Property is of type 'MATLAB array' hInfoTable = []; end methods % constructor block function obj = StatsView(varargin) %StatsView Constructor for StatsView % OBJ = StatsView(PROP, VALUE) constructs a class that displays % algorithm output statistics and information. % Call the inherited constructor obj@mbcgui.multiview.View(varargin{ : }); % converted super class constructor call obj.hInfoTable = mbcgui.table.InfoPane('Parent', obj.Parent, ... 'Position', obj.Position, ... 'SplitPosition', 0.6, ... 'UIContextMenu',obj.UIContextMenu,... 'Visible', obj.Visible); obj.ContentHandle = obj.hInfoTable; if ~isempty(obj.MessageService) obj.pPostSetMessageService; end obj.addListeners(event.listener(obj.hInfoTable, 'ButtonDown', @i_passonbtndown)); function i_passonbtndown(~, ~) % pass on ButtonDown event obj.notify('ButtonDown'); end end end % constructor block methods end % set and get functions methods % public methods %---------------------------------------- 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 = 'Solution Information'; end % gettitle %---------------------------------------- function redraw(obj) %REDRAW Redraw the stats information table % REDRAW(OBJ) re-displays all of the output statistics for the currently % selected run. if obj.hasData RunIdx = obj.MessageService.getFocusRun; SolIdx = obj.MessageService.getFocusSolution; if RunIdx>0 out = obj.MessageService.getOptimOutput; Status = getExitFlag(out, RunIdx, SolIdx); Msg = getErrMsg(out, RunIdx, SolIdx); if isAcceptable(out, RunIdx, SolIdx) Accept = 'Yes'; else Accept = 'No'; end Stats = getOutput(out, RunIdx, SolIdx); StatNames = fieldnames(Stats); StatData = struct2cell(Stats); inf = [{'Accept', Accept;... 'Exit flag', Status; ... 'Exit message', Msg}; ... StatNames, StatData]; % Convert non-char data to strings for n = 1:size(inf,1) if isnumeric(inf{n,2}) if isvector(inf{n,2}) % num2str puts a lots of spaces in to vectors. mbcprettify % makes a better job in this case inf{n,2} = prettify(inf{n,2}, -1); else inf{n,2} = num2str(inf{n,2}); end else try % Attempt to convert to string using char inf{n,2} = char(inf{n,2}); catch Sz = size(inf{n,2}); SzStr = sprintf('%dx', Sz); inf{n,2} = sprintf('<%s %s>', SzStr(1:end-1), class(inf{n,2})); end end end else inf = cell(0,2); end else inf = cell(0,2); end obj.hInfoTable.ListText = inf; end % redraw %---------------------------------------- function refreshAcceptable(obj) %REFRESHACCEPTABLE Update acceptable stats value % REFRESHACCEPTABLE(OBJ) updates the list data field that is labelled % "Accept". ListData = obj.hInfoTable.ListText; if obj.hasData AcceptIdx = find(strcmp('Accept', ListData(:,1)), 1); RunIdx = obj.MessageService.getFocusRun; SolIdx = obj.MessageService.getFocusSolution; if RunIdx>0 && ~isempty(AcceptIdx) out = obj.MessageService.getOptimOutput; if isAcceptable(out, RunIdx, SolIdx) Accept = 'Yes'; else Accept = 'No'; end ListData{AcceptIdx,2} = Accept; end end obj.hInfoTable.ListText = ListData; end % refreshAcceptable 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 RedrawFcn = {@i_refresh, obj}; obj.addMessageServiceListener( {'ObjectChanged', ... 'AcceptableChanged', ... 'SliceDirectionChanged', ... 'CurrentFocusChanged'}, ... {RedrawFcn, ... {@i_refreshAccept, obj}, ... RedrawFcn, ... RedrawFcn, ...` RedrawFcn}); end obj.redraw; end % pPostSetMessageService end end % classdef function i_refresh(~, ~, obj) % Refresh all the information obj.redraw; end % i_refresh function i_refreshAccept(~, ~, obj) obj.refreshAcceptable; end % i_refreshAccept