www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgoptimtablefiller/guiFillOptions.m
function varargout = guiFillOptions(otf,Action,P,varargin) %GUIFILLOPTIONS gui for rules and locks settings on table filler % varargout = guiFillOptions(otf,Action,P,varargin) % Action is 'create','updategui','updatedata' % Copyright 2009-2010 The MathWorks, Inc. and Ford Global Technologies, Inc. switch Action case 'create' varargout{1} = createLayout(otf,P,varargin{:}); case 'updategui' updateGui(otf,P) case 'updatedata' varargout{1} = updateData(otf,P); end function Lyt = createLayout(~,P,fh,iFace) P.cInfeas = uicontrol('Parent',fh,... 'Style','checkbox',... 'Visible','off',... 'Value', 1, ... 'Tag','CheckAcceptable',... 'String','Use acceptable solutions only'); P.cFillTradeOffs = uicontrol('Parent',fh,... 'Style','checkbox',... 'Value', 1, ... 'Visible','off',... 'Tag','CheckTradeoff',... 'String','Update tradeoffs'); P.cUseTableLocks = uicontrol('Parent',fh,... 'Style','checkbox',... 'Value', 1, ... 'Visible','off',... 'Tag','CheckUseLocks',... 'String','Use locked table values in extrapolation'); P.cUseTableMask = uicontrol('Parent',fh,... 'Style','checkbox',... 'Value', 1, ... 'Visible','off',... 'Tag','CheckUseMask',... 'String','Use existing extrapolation mask in fill'); CheckLyt= xreggridbaglayout('parent', fh, ... 'dimension', [2 2], ... 'rowsizes',[15 15],... 'gapx', 2, ... 'elements', {P.cInfeas,P.cFillTradeOffs,P.cUseTableLocks,P.cUseTableMask}); t= uicontrol('Parent',fh,... 'Style','text',... 'Visible','off',... 'HorizontalAlignment','left',... 'String','Filter rules for tables:'); P.RuleTable = mbcwidgets.List( ... 'parent', fh,... 'Editable', true, ... 'ValueChangedCallback',{@iEditRule,P,iFace},... 'SelectionMode', 'SingleCell'); P.RuleTable.Peer.setColumnData( {'Table','Output Column','Filter Rule'} ); P.RuleTable.Peer.setColumnWidths( [100 100 200] ) P.RuleTable.Peer.setIconBaseLocation(cgrespath); P.RuleTable.Peer.setEditableColumns(2); P.FillItemsList = cgtools.exprList('parent', fh, ... 'displaytypecolumn', false, ... 'itemheadertext', 'Filter Rule Inputs'); P.FillItemsList.Display.SelectionMode = 'SingleCell'; Lyt= xreggridbaglayout('parent', fh, ... 'dimension', [4 2], ... 'rowsizes', [35 5 15 -1], ... 'colratios',[2 1],... 'gapx', 10, ... 'mergeblock',{[1 1],[1 2]},... 'elements', {CheckLyt,[],t P.RuleTable,... [],[],[],P.FillItemsList}); function updateGui(otf,P) %UPDATEGUI update UI controls for checkboxes and rules table set(P.cInfeas,'Value', getUseAcceptableOnly(otf)) pTOs = getTradeOffs(otf,P.Data.Project); if ~isempty(pTOs) set(P.cFillTradeOffs,'Value', otf.filltradeoffs,'Enable','on') else set(P.cFillTradeOffs,'Value', 0,'Enable','off') end set(P.cUseTableMask,'Value', otf.includemask) set(P.cUseTableLocks,'Value', otf.includelocks) iUpdateTable(otf,P) function iUpdateTable(otf,P) n = length(otf.tables); % update HasValidRules array to keep track of valid rules P.HasValidRules = true(1,n); TableNames = pveceval(otf.tables(:),@getname); FillNames = pveceval(otf.fillfactors(:),@getname); Rules = cell(n,1); TableIcon = cell(n,1); FillIcon = cell(n,1); for i=1:n TableIcon{i}= otf.tables(i).iconfile; FillIcon{i}= otf.fillfactors(i).iconfile; if ~isempty(otf.filterfcns{i}) % get expression from function model Rules{i} = char(get(otf.filterfcns{i},'model')); else % make rule a space to turn on editor Rules{i} = ''; end end P.RuleTable.Peer.setData([TableNames FillNames Rules]); P.RuleTable.Peer.setIconData(TableIcon,0); P.RuleTable.Peer.setIconData(FillIcon,1); P.FillItemsList.Items = P.Data.FillItems; function otf = updateData(otf,P) otf = setUseAcceptableOnly(otf,logical(get(P.cInfeas,'Value'))); otf.filltradeoffs = get(P.cFillTradeOffs,'Value'); otf.includelocks = get(P.cUseTableLocks,'Value'); otf.includemask = get(P.cUseTableMask,'Value'); function iEditRule(~,evt,P,iFace) F = P.Data; RuleNo = evt.data.Rows; Rule = evt.data.NewValue; if ~isempty(deblank(Rule)) msg = 'The filter function must be a valid MATLAB expression.'; try [otf,OK] = setfilterfcn(F.Filler,RuleNo,Rule,F.FillItems); if OK % check filter function [seldata, ~, ~, coninds] = getExportData(otf, F.OptimOutput, F.Project, true); [filldata,msg] = pGetTableData(otf, seldata, coninds, F.FillItems, RuleNo); OK = ~isempty(filldata); if ~OK && isempty(msg) msg = 'The filter function must select some of the solution.'; end else msg = 'The filter function must have at least one input.'; end if OK F.Filler = otf; else uiwait(errordlg(msg,'Invalid Filter Rule','modal')) end catch ME uiwait(errordlg(sprintf('%s \n%s',msg,ME.message),... 'Invalid Filter Rule','modal')) OK = false; end P.HasValidRules(RuleNo) = OK; else % clear rule F.Filler.filterfcns{RuleNo} = ''; % an empty rule is always valid P.HasValidRules(RuleNo) = true; end enableFinish(P,iFace);