www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/+cgoptimgui/objectivetypeselector.m
classdef objectivetypeselector < mbcgui.widget.BasicContainer %cgoptimgui.objectivetypeselector class % cgoptimgui.objectivetypeselector extends mbcgui.widget.BasicContainer. % % cgoptimgui.objectivetypeselector 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' % Display - Property is of type 'MATLAB array' (read only) % optimObjective - Property is of type 'MATLAB array' % objectiveType - Property is of type 'MATLAB array' (read only) % Copyright 2000-2015 The MathWorks, Inc. and Ford Global Technologies, Inc. properties (AbortSet, SetObservable) %OPTIMOBJECTIVE Property is of type 'MATLAB array' optimObjective = { 'on', 'on', 'on' }; end properties (Access=protected, AbortSet, SetObservable) %RADIOBTNS Property is of type 'MATLAB array' radiobtns = [ ]; %LISTENERS Property is of type 'handle vector' listeners = []; end properties (SetAccess=protected, AbortSet, SetObservable) %OBJECTIVETYPE Property is of type 'MATLAB array' (read only) objectiveType = 'maximum'; end events ObjectiveTypeChanged end % events methods % constructor block function obj = objectivetypeselector(varargin) %OBJECTIVETYPESELECTOR Constructor for objectivetypeselector object % OBJ = OBJECTIVETYPESELECTOR(OPTIMOBJ) constructs an % OBJECTIVETYPESELECTOR object. This component allows a user to select % whether the objective, OPTIMOBJ, is to be minimised , maximised or used % as a helper function. % % OBJ = OBJECTIVETYPESELECTOR(OBJTYPE, PROP, VAL, ...) constructs % an OBJECTIVETYPESELECTOR object where graphical properties can be set % via PROP, VAL pairs. % Allow the construction of an empty object % Call the inherited constructor obj@mbcgui.widget.BasicContainer(varargin{ 2:end }); % converted super class constructor call if nargin>0 % Store the enable status of each objective type obj.optimObjective = varargin{1}; % Create the display obj.pCreateDisplay; % Update the object to reflect the new objective obj.pPostSetOptimObjective; % Create listeners obj.listeners = event.proplistener(obj, findprop(obj, 'optimObjective'), ... 'PostSet', @(src, evt) pPostSetOptimObjective(obj)); end end % objectivetypeselector end % constructor block methods function set.optimObjective(obj,value) obj.optimObjective = i_checkoptimObjective(obj,value); end end % set and get functions methods (Access=protected) %---------------------------------------- function pCreateDisplay(obj) %PCREATEDISPLAY Private GUI component creation method if isempty(obj.Parent) f = figure; obj.Parent = f; end obj.radiobtns = xregGui.rbgroup('parent', obj.Parent, ... 'Visible', obj.Visible, ... 'nx', 1, ... 'ny', 3, ... 'string', {'Minimize'; 'Maximize'; 'Helper'}, ... 'Callback', @i_changetype); lytrb = xreggridbaglayout(obj.Parent,... 'colsizes', 80, ... 'rowsizes', 60, ... 'dimension',[1 1],... 'elements',{obj.radiobtns}); obj.ContentHandle = lytrb; function i_changetype(src, ~) obj.pDisableListeners; settings = {'minimize', 'maximize', 'helper'}; newval = get(src, 'Selected'); obj.optimObjective = setObjectiveType(obj.optimObjective, settings{newval}); notify(obj, 'ObjectiveTypeChanged'); obj.pEnableListeners; end end %---------------------------------------- function pDisableListeners(obj) %PDISABLELISTENERS Private method to disable listeners [obj.listeners.Enabled] = deal(false); end % pDisableListeners %---------------------------------------- function pEnableListeners(obj) %PENABLELISTENERS Private method to enable listeners [obj.listeners.Enabled] = deal(true); end % pEnableListeners %---------------------------------------- function pPostSetOptimObjective(obj) %PPOSTSETOPTIMOBJECTIVE Update the object after a new objective set % Get information about the new objective tp = getObjectiveType(obj.optimObjective); typeval = find( strcmp( tp,{ 'Minimize', 'Maximize', 'Helper' } ) ); canalter = canChangeType(obj.optimObjective); % Update the radio buttons typeen = repmat(canalter,3,1); if typeval~=3 % Force Helper option to be off typeen(3) = false; end typeen(typeval) = true; set(obj.radiobtns, 'Selected', typeval, 'EnableArray', typeen); end % pPostSetOptimObjective end end % classdef function val = i_checkoptimObjective(~, val) %-------------------------------------------------------------------------- if ~isa(val, 'cgoptimobjective') error(message('mbc:cgoptimgui:objectivetypeselector:InvalidPropertyValue')); end end % i_checkoptimObjective