www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/+xregdatagui/AbstractGraphView.m
classdef AbstractGraphView < xregdatagui.AbstractDataView %xregdatagui.abstractgraphview class % xregdatagui.AbstractGraphView extends xregdatagui.AbstractDataView. % % xregdatagui.AbstractGraphView 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' (read only) % Container - Property is of type 'handle' % UIContextMenu - Property is of type 'MATLAB array' % Listeners - Property is of type 'handle vector' (read only) % % xregdatagui.AbstractGraphView methods: % canPrint - Check whether component can be printed % gettitle - A short description of the function % pUpdateDisplay - complete update of the view display % pdmsDataTypeChangedUpdate - event handler for the dmsDataTypeChanged event % printSize - Returns the preferred printing size for the component % printcopy - copy the layout to the newfigure % pssDataChangedUpdate - updates the view on receipt of a "ssDataChanged" % pssNamesChangedUpdate - Updates the view on receipt of a name-change event % Copyright 2015-2016 The MathWorks, Inc. and Ford Global Technologies, Inc. properties (SetAccess=protected, AbortSet) %GRAPHOBJECT Property is of type 'MATLAB array' GraphObject = []; end properties %SelectAllTests select all tests for display SelectAllTests = false; end methods % constructor block function obj = AbstractGraphView(varargin) %ABSTRACTGRAPHVIEW abstractgraphview constructor % OUT = ABSTRACTGRAPHVIEW(IN) % Do the setup stuff from inside the abstractDataView constructor obj@xregdatagui.AbstractDataView(varargin{ : }); % converted super class constructor call % Create the graphical objects and put in the panel G = obj.pCreateDisplay(obj.Parent); obj.GraphObject = G; ss = obj.MessageService.Sweepset; % Update the display obj.pUpdateDisplay; % Define the viewer options obj.Options.Actions = [mbcgui.actions.StatefulAction(@obj.onModifyGraphProperties,... '&Properties...','Properties') mbcgui.actions.ToggleAction(@obj.onSelectAllTests,... '&Select All Tests','Select all tests')]; obj.Options.Actions(2).Selected = obj.SelectAllTests; end % abstractgraphview end % constructor block methods end % set and get functions methods % public methods %---------------------------------------- function out = canPrint(obj) %#ok<MANU> %CANPRINT Check whether component can be printed % CANPRINT(OBJ) returns true for abstractgraphview components. out = true; end % canPrint %---------------------------------------- function [out] = gettitle(in) %#ok<MANU> %GETTITLE get view title % OUT = GETTITLE(IN) out = 'Graph Title'; end % gettitle %---------------------------------------- function pUpdateDisplay(obj) %PUPDATEDISPLAY complete update of the view display % PUPDATEDISPLAY(OBJ) if hasData(obj.MessageService) % Check the class of the current data object if isobject(obj.MessageService.DataObject) % Update the names and the data obj.pssNamesChangedUpdate; obj.pssDataChangedUpdate; end end end % pUpdateDisplay %---------------------------------------- function pdmsDataTypeChangedUpdate(obj, ~,~) %PDMSDATATYPECHANGEDUPDATE event handler for the dmsDataTypeChanged event % PDMSDATATYPECHANGEDUPDATE(OBJ, SRC, EVT) % Find the ssfFiltersChanged listener ssListeners = obj.MessageService.findListeners(obj.Listeners, 'sweepset'); % If the dataObject isn't a sweepset then... if ~isobject(obj.MessageService.DataObject) % Clear the graph data and selected test index set(obj.GraphObject, 'Data', []); % Turn off the sweepset listener [ssListeners.Enabled] = deal(false); else % Turn on the sweepset listener [ssListeners.Enabled] = deal(true); end end % pdmsDataTypeChangedUpdate %---------------------------------------- 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. % Add 50 pixels to the height to allow room for a title sz =printSize@xregdatagui.AbstractDataView(obj) + [0 50]; end % printSize %---------------------------------------- function layout = printCopy(obj, newFigure) %PRINTCOPY copy the layout to the newfigure % LAYOUT = PRINTCOPY(OBJ, FIGURE) % Add a title titleH = axestext(newFigure, ... 'string',[obj.gettitle ' for "' obj.MessageService.ObjectName '"'],... 'fontsize', 11,... 'fontweight', 'bold',... 'HorizontalAlignment', 'center',... 'VerticalAlignment', 'middle',... 'interpreter', 'none'); graphlayout = printcopy(obj.GraphObject, newFigure); layout = xreggridbaglayout(newFigure, ... 'Dimension', [2 1], ... 'Rowsizes', [25 -1], ... 'gapy', 20, ... 'border', [0 0 0 5], ... 'elements', {titleH, graphlayout}); end % printcopy %---------------------------------------- function pssDataChangedUpdate(obj, ~,~) %PSSDATACHANGEDUPDATE updates the view on receipt of a "ssDataChanged" event from the DMS % PSSDATACHANGEDUPDATE(OBJ, SRC, EVT) dms = obj.MessageService; if obj.SelectAllTests Ysweepset = dms.Sweepset; else Ysweepset = dms.Sweepset(:, :, dms.SelectedTests); end % Display only the selected tests set(obj.GraphObject, 'Data', double(Ysweepset),'factors',get(Ysweepset,'varlabels')); end % pssDataChangedUpdate %---------------------------------------- function pssNamesChangedUpdate(obj, ~,~) %PSSNAMESCHANGEDUPDATE Updates the view on receipt of a name-change event % PSSNAMESCHANGEDUPDATE(OBJ) % Update the names of the items in the graph names = get(obj.MessageService.Sweepset, 'varlabels'); set(obj.GraphObject, 'factors', names); % Update data if no update is pending in the queue if ~obj.MessageService.isEventPending('ssDataChanged') obj.pssDataChangedUpdate; end end % pssNamesChangedUpdate function pssTestsChangedUpdate(obj,~,~) %pssTestsChangedUpdate test definition changed if obj.MessageService.isOneStage % hide test selector and controls obj.SelectAllTests = false; % disable select all tests set(obj.Options.Actions(2),'Enabled',true,'Selected',false,'Enabled',false); else % enable select all tests and separate test selection set(obj.Options.Actions(2),'Enabled',true); end if ~any(strcmp(obj.MessageService.EventQueue, 'ssDataChanged')) obj.pssDataChangedUpdate(); end end end % public methods methods (Hidden) % possibly private or hidden %---------------------------------------- function pPostSetDataMessageService(obj, ~) %PPOSTSETDATAMESSAGESERVICE set up MessageService listeners % PPOSTSETDATAMESSAGESERVICE(OBJ, EVENT) % Call the super pPostSetDataMessageService pPostSetDataMessageService@xregdatagui.AbstractDataView(obj); dms = obj.MessageService; dmsListeners = [... event.listener(dms, 'dmsDataTypeChanged', @obj.pdmsDataTypeChangedUpdate);... event.listener(dms, 'ssNamesChanged', @obj.pssNamesChangedUpdate);... event.listener(dms, 'ssDataChanged', @obj.pssDataChangedUpdate);... event.listener(dms, 'ssTestsChanged', @obj.pssTestsChangedUpdate);... event.listener(dms, 'SelectedTestsChanged', @obj.pssDataChangedUpdate);... ]; obj.Listeners = [obj.Listeners(:) ; dmsListeners(:)]; end % pPostSetDataMessageService function onModifyGraphProperties(obj,~,~) %onModifyGraphProperties Open the preferences GUI prefsgui(obj.GraphObject); end function onSelectAllTests(obj,~,~) %onSelectAllTests action callback to select all tests obj.SelectAllTests = ~obj.SelectAllTests; obj.pssDataChangedUpdate(); end end % possibly private or hidden end % classdef