www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgpointobjective/generateEditorPages.m
function hInfo = generateEditorPages(obj, hPropGroup, pProj, Optim) %GENERATEEDITORPAGES Generate standard editor pages for the item % % HINFO = GENERATEEDITORPAGES(OBJ, HGROUP, PPROJ, OPTIM) creates % DialogPageInfo objects for the editor pages of the point objective. % Copyright 2005-2015 The MathWorks, Inc. and Ford Global Technologies, Inc. hInfo = mbcgui.dialog.PageInfo( ... 'PageGroup', hPropGroup, ... 'Name', 'General', ... 'HelpHandler', 'cghelptool', ... 'HelpCode', 'CGOBJECTIVEGUI', ... 'CreateCallback', @(hInfo, evt) i_createlyt(hInfo,evt, pProj, Optim, obj)); function i_createlyt(hInfo, ~,pProj, Optim, obj) hParent = hInfo.Parent; % Gather list of all models in the project ud.AllModelPtrs = pProj.getmodels; ud.Optim = Optim; ModelLabel = xreguicontrol('Parent',hParent,... 'HitTest','off',... 'Enable','inactive',... 'Visible','off',... 'Style','text',... 'String','Available models:',... 'HorizontalAlignment','left'); ud.ModelList = cgtools.exprList('Parent', hParent, ... 'Visible', 'off', ... 'ItemHeaderText', 'Model', ... 'ItemColumnWidth', .6); ud.SelModel = xreguicontrol('Parent',hParent,... 'HitTest','off',... 'Enable','inactive',... 'Visible','off',... 'Style','text',... 'String','Selected model:',... 'HorizontalAlignment','left'); TypeLabel = xreguicontrol('Parent',hParent,... 'HitTest','off',... 'Enable','inactive',... 'Visible','off',... 'Style','text',... 'String','Objective type:',... 'HorizontalAlignment','left'); ud.ObjectiveType = cgoptimgui.objectivetypeselector(obj, 'Parent', hParent); L = xreggridbaglayout(hParent,... 'dimension',[6 4],... 'colsizes',[300 0 100 -1],... 'rowsizes',[15 2 60 -1 5 15],... 'gapx', 15, ... 'mergeblock',{[3 4],[1 1]}, ... 'mergeblock',{[6 6],[1 3]}, ... 'mergeblock',{[1 1],[2 3]}, ... 'elements',{ModelLabel, [], ud.ModelList, [], [], ud.SelModel, ... TypeLabel, [], [], [], [], [], ... [], [], ud.ObjectiveType}); ud.DisplayUpdater = event.listener(hInfo.PageGroup, 'ObjectChanged', @(h,evt) i_update(hInfo)); ud.ObjectiveTypeList = event.listener(ud.ObjectiveType, 'ObjectiveTypeChanged', @(h,evt) i_changetype(hInfo)); ud.ModelSelList = handle.listener(ud.ModelList, 'SelectionChanged', @(h,evt) i_selmodel(h,evt,hInfo)); hInfo.UserData = ud; hInfo.setUI(L); i_setvalues(hInfo); function i_update(hInfo) i_setvalues(hInfo); function i_setvalues(hInfo) ud = hInfo.UserData; obj = hInfo.getObject; ud.ObjectiveType.optimObjective = obj; typeval = find( strcmp( ud.ObjectiveType.objectiveType,{ 'Minimize', 'Maximize', 'Helper' } ) ); set(ud.ModelList, 'Items', i_filtermodels(ud.AllModelPtrs, ud.Optim, typeval), ... 'SelectedItems', getExpression(obj)); i_updateselstring(hInfo); function i_updateselstring(hInfo) ud = hInfo.UserData; obj = hInfo.getObject; pM = getExpression(obj); if isvalid(pM) set(ud.SelModel, 'String', sprintf('Selected model: %s', pM.getname)); else set(ud.SelModel, 'String', 'Selected model:'); end function pFiltered = i_filtermodels(pM, Optim, typeval) if typeval==3 pFiltered = pM; else % only allowed models that share an input with free variables OK = false(size(pM)); pFree = get(Optim, 'values'); objM = infoarray(pM); for n = 1:numel(OK) pModInputs = getinports(objM{n}); OK(n) = anymember(pFree, pModInputs); end pFiltered = pM(OK); end function i_changetype(hInfo) ud = hInfo.UserData; obj = ud.ObjectiveType.optimObjective; i_quietupdateobject(hInfo, obj); function i_selmodel(src, ~, hInfo) obj = hInfo.getObject; ud = hInfo.UserData; newval = get(src, 'SelectedItems'); if ~isempty(newval) && isvalid(newval) obj = setExpression(obj, newval); else obj = setExpression(obj, xregpointer); end ud.ObjectiveType.optimObjective = obj; i_quietupdateobject(hInfo, obj); i_updateselstring(hInfo); % Utility that updates the object in the group without firing callbacks % internally function i_quietupdateobject(hInfo, obj) ud = hInfo.UserData; ud.DisplayUpdater.Enabled = false; hInfo.updateObject(obj); ud.DisplayUpdater.Enabled = true;