www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/+xregbdrygui/BdryMessageService.m
classdef BdryMessageService < mbcgui.multiview.AbstractMessageService %xregbdrygui.BdryMessageService class % xregbdrygui.BdryMessageService extends mbcgui.multiview.AbstractMessageService. % % xregbdrygui.BdryMessageService properties: % Root - Property is of type 'MATLAB array' (read only) % CurrentNode - Property is of type 'MATLAB array' (read only) % BoundaryPointHighlight - Property is of type 'on/off' % ValidationPointHighlight - Property is of type 'on/off' % ViewMode - Property is of type 'MATLAB array' % CurrentTest - Property is of type 'MATLAB array' % % xregbdrygui.BdryMessageService methods: % getBoundaryPoints - Get boundary points from bdry dev tree for current view point % getConstraint - Get constraint from bdry dev tree for current view point % getDataName - Get a name for the data being displayed % getDataPoints - Get data from bdry dev tree for current view point % getInputFactors - Get input factors from bdrydev tree for current view point % getValidationPoints - Get validation data from bdry dev tree for current view point % guiSelectPoint - (GUI) for the user to select a data point. % hasData - Check whether the MessageService contains viewable data % sendEvent - Send an event via the boundary message service % setCurrentNode - Set the root node for a boundary dev tree in the Boundary Message Service % setRoot - Set the root node for a boundary dev tree in the Boundary Message Service % Copyright 2005-2015 The MathWorks, Inc. and Ford Global Technologies, Inc. properties (AbortSet, SetObservable) %BOUNDARYPOINTHIGHLIGHT Property is of type 'on/off' BoundaryPointHighlight = 'off'; %VALIDATIONPOINTHIGHLIGHT Property is of type 'on/off' ValidationPointHighlight = 'off'; %VIEWMODE Property is of type 'MATLAB array' ViewMode = 'Local'; %CURRENTTEST Property is of type 'MATLAB array' CurrentTest = []; end properties (Access=protected, AbortSet, SetObservable) %INTERNALLISTENERS Property is of type 'handle vector' InternalListeners = []; end properties (SetAccess=protected, AbortSet, SetObservable) %ROOT Property is of type 'MATLAB array' (read only) Root = []; %CURRENTNODE Property is of type 'MATLAB array' (read only) CurrentNode = []; end events (NotifyAccess=private) RootChange NodeChange TreeChange NameChange BestChange ConstraintChange BoundaryPointsHighlight ValidationPointsToggled ViewModeChange ViewTestChange Busy Idle end % events methods % constructor block function obj = BdryMessageService( varargin ) % XREGBDRYGUI.BDRYMESSAGESERVICE class constructor % Attach listeners to properties obj.InternalListeners = [ event.proplistener(obj, obj.findprop( 'BoundaryPointHighlight' ), 'PostSet', ... @(s, e) sendEvent( obj, 'BoundaryPointsHighlight' ) ) ... % event.proplistener(obj, obj.findprop( 'ValidationPointHighlight' ), 'PostSet', ... @(s, e) sendEvent( obj, 'ValidationPointsToggled' ) ) ... % event.proplistener(obj, obj.findprop( 'ViewMode' ), 'PostSet', ... @(s, e) sendEvent( obj, 'ViewModeChange' ) ) ... % event.proplistener(obj, obj.findprop( 'CurrentTest' ), 'PostSet', ... @(s, e) sendEvent( obj, 'ViewTestChange' ) ) ]; end % BdryMessageService end % constructor block methods function set.ViewMode(obj,value) obj.ViewMode = i_CheckViewMode(obj,value); end end % set and get functions methods % public methods %---------------------------------------- function ind = getBoundaryPoints(obj) %GETBOUNDARYPOINTS Get boundary points from bdry dev tree for current view point % IND = GETBOUNDARYPOINTS(OBJ) is a vector of indices into the data for % the current view for points that are boundary points. % % See also XREGBDRYGUI.BDRYMESSAGESERVICE. % XREGBDRYGUI.BDRYMESSAGESERVICE/GETDATAPOINTS. if obj.hasData, cn = obj.CurrentNode; ind = cn.getBoundaryPoints; if ~isempty( ind ) && cn.istwostage switch lower( obj.ViewMode ), case 'local', % Get the indices for the current test ind = ind{obj.CurrentTest}; case 'response' ss = cn.getdata( 'stage', 'response' ); ts = tstart( ss ) - 1; for i = 1:length( ind ), ind{i} = ind{i} + ts(i); end ind = cat( 1, ind{:} ); otherwise error(message('mbc:xregbdrygui:BdryMessageService:InvalidState')); end end else ind = []; end end % getBoundaryPoints %---------------------------------------- function con = getConstraint(obj) %GETCONSTRAINT Get constraint from bdry dev tree for current view point % CON = GETCONSTRAINT(OBJ) % % See also XREGBDRYGUI.BDRYMESSAGESERVICE. if obj.hasData, cn = obj.CurrentNode; if cn.istwostage && strcmpi( obj.ViewMode, 'Local' ), con = cn.localconstraint( obj.CurrentTest ); else con = cn.getconstraint( size( obj.getDataPoints, 2 ) ); end else con = []; end end % getConstraint %---------------------------------------- function nm = getDataName(obj) %GETDATANAME Get a name for the data being displayed % NM = GETDATANAME(OBJ) returns a string that is the name of the data % that is being encapsulated by the message service. The name of the % current design is returned for the designpackage. % % See also XREGBDRYGUI.BDRYMESSAGESERVICE. if obj.hasData, nm = obj.Root.name; else nm = '<Unknown>'; end end % getDataName %---------------------------------------- function X = getDataPoints(obj) %GETDATAPOINTS Get data from bdry dev tree for current view point % X = GETDATAPOINTS(OBJ) % X will be a nPoints by nFactors matrix of double. The data returned will % be appropriate for the view, i.e., filtered by response vs local and the % correct test. % % See also XREGBDRYGUI.BDRYMESSAGESERVICE. if obj.hasData cn = obj.CurrentNode; if cn.istwostage if strcmpi(obj.ViewMode, 'local') data = getdata(cn.info, 'stage', 'Local', 'testId', obj.CurrentTest); else data = getdata(cn.info, 'stage', 'Response'); end else data = getdata(cn.info); end X = double( data ); else X = []; end end % getDataPoints %---------------------------------------- function cif = getInputFactors(obj) %GETINPUTFACTORS Get input factors from bdrydev tree for current view point % % CIF = GETINPUTFACTORS(OBJ) % % CIF will be a CONINPUTFACTOR object will be appropriate for the current % view, i.e., filtered by response vs local. % % See also XREGBDRYGUI.BDRYMESSAGESERVICE, CONIPUTFACTOR. if obj.hasData, cn = obj.CurrentNode; con = obj.getConstraint; if isempty(con) if cn.istwostage switch lower( obj.ViewMode ), case 'local', cif = cn.getInputFactors( 1 ); case 'response' cif = cn.getInputFactors( 0 ); otherwise error(message('mbc:xregbdrygui:BdryMessageService:InvalidState')); end else cif = cn.getInputFactors; end else % get inputs from constraint cif = getInputFactors(con); end else cif = []; end end % getInputFactors %---------------------------------------- function [X, inside] = getValidationPoints(obj) %GETVALIDATIONPOINTS Get validation data from bdry dev tree for current view point % [X, INSIDE] = GETVALIDATIONPOINTS(OBJ) % X will be a nPoints by nFactors matrix of double. The data returned will % be appropriate for the view, i.e., filtered by response vs local and the % correct test. % % INSIDE will be a vector of nPoints booleans indicating whether the ith % X value is inside the boundary. % % See also XREGBDRYGUI.BDRYMESSAGESERVICE. cn = obj.CurrentNode; if isempty(cn) X = []; inside = []; else if cn.istwostage if strcmpi(obj.ViewMode, 'local') valData = getvalidationdata(cn.info, 'stage', 'Local', 'testId', obj.CurrentTest); else valData = getvalidationdata(cn.info, 'stage', 'Response'); end else valData = getvalidationdata(cn.info); end X = double( valData ); inside = isValidationInside(obj,X); end end % getValidationPoints %---------------------------------------- function [point, index] = guiSelectPoint(obj) %GUISELECTPOINT (GUI) for the user to select a data point. % [POINT, INDEX] = GUISELECTPOINT(OBJ) % POINT is the point chosen % INDEX is the index of the point from the data set. point = []; index = []; if obj.hasData, X = getDataPoints( obj ); nX = size( X, 1 ); list = num2str( [(1:nX).', X], 4 ); % Throw up a list dialog [index, ok] = mv_listdlg( ... 'ListString', list, ... 'SelectionMode', 'Single', ... 'InitialValue', 1, ... 'ListSize', [320 300], ... % [width height] of listbox in pixels 'Name', 'Select Data Point', ... 'OkString', 'OK', ... 'uh', 25, ... 'ffs', 3 ); if ok, point = X(index,:); end end end % guiSelectPoint %---------------------------------------- function tf = hasData(obj) %HASDATA Check whether the MessageService contains viewable data % TF = HASDATA(OBJ) returns true if the BdryMessagerService object contains % a data object that can provide any viewing data. % % See also XREGBDRYGUI.BDRYMESSAGESERVICE. tf = ~isempty( obj.Root ); end % hasData %---------------------------------------- function sendEvent(obj, event) %SENDEVENT Send an event via the boundary message service % SENDEVENT(OBJ, EVENT) % Allows objects outside the boundary message service to send events via % the message service. Because the message service holds pointers to some % data, e.g., the root node and the current node, some views, etc., may % change the content of the data without changing the pointer to the data. % This method allows those objects to notify other objects about the % change. % % See also XREGBDRYGUI.BDRYMESSAGESERVICE. notify( obj, event ); end % sendEvent %---------------------------------------- function setCurrentNode(obj, cn) %SETCURRENTNODE Set the root node for a boundary dev tree in the Boundary Message Service % SETCURRENTNODE(OBJ, CN) % % See also XREGBDRYGUI.BDRYMESSAGESERVICE. if isempty( cn ), obj.CurrentNode = []; elseif isa( cn, 'xregpointer' ), obj.CurrentNode = cn; elseif isa( cn, 'xregbdrynode' ) obj.CurrentNode = address( cn ); else warning(message('mbc:BdryMessageService:InvalidArgument')); return end sendEvent( obj, 'NodeChange' ); sendEvent( obj, 'ConstraintChange' ); sendEvent( obj, 'NameChange' ); end % setCurrentNode %---------------------------------------- function setRoot(obj, root) %SETROOT Set the root node for a boundary dev tree in the Boundary Message Service % SETROOT(OBJ, ROOT) % SETROOT(OBJ, []) % % See also XREGBDRYGUI.BDRYMESSAGESERVICE. if isempty( root ), obj.Root = []; obj.CurrentNode = []; elseif isa( root, 'xregpointer' ), obj.Root = root; obj.CurrentNode = root; elseif isa( root, 'xregbdryroot' ) obj.Root = address( root ); obj.CurrentNode = address( root ); else warning(message('mbc:BdryMessageService:InvalidArgument1')); return end sendEvent( obj, 'RootChange' ); sendEvent( obj, 'NodeChange' ); sendEvent( obj, 'ConstraintChange' ); sendEvent( obj, 'NameChange' ); end % setRoot function busy(obj,msg) %busy send event that MessageService is busy % busy(obj,msg) if nargin<2 msg = ''; end data.Message = msg; evt = xregEventData(data); notify(obj,'Busy',evt); end function idle(obj) %idle send event that MessageService is idle % idle(obj) notify(obj,'Idle'); end end % public methods end % classdef function vm = i_CheckViewMode( obj, vm ) %#ok<INUSL> if ~ischar( vm ) || ~ismember( vm, {'Response', 'Local'} ), error(message('mbc:xregbdrygui:BdryMessageService:InvalidPropertyValue')); end end % i_CheckViewMode function inside = isValidationInside(BMS,X) % work out if the validation data is inside the constraint constraint = BMS.getConstraint; m = size(X, 1); if ~isempty(constraint) inside = isInside(constraint, X, true(m,1)); else inside = false(m,1); end end % isValidationInside