www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgtradeoffnode/private/pGuiGetFillExpression.m

    function [pNewFill, ok] = pGuiGetFillExpression(obj, pT)
%PGUIGETFILLEXPRESSION Display dialog for choosing a table's fill item
%
%  [PEXPR, OK] = PGUIGETFILLEXPRESSION(OBJ) displays a modal dialog
%  for choosing a new filling item.  The pointer to the selected item is
%  returned.
%
%  [PEXPR, OK] = PGUIGETFILLEXPRESSION(OBJ, PT) specifies that the
%  expression associated with table PT should initially be selected in the
%  dialog.

%  Copyright 2000-2011 The MathWorks, Inc. and Ford Global Technologies, Inc.


if nargin<2
    pT = xregpointer;
    TblName = '';
else
    TblName = [pT.getname ' '];
end
idx = (pT==obj.Tables);

% get all models and variables in the project
PROJ = project(obj);
ud.pAllModels = getmodels(PROJ);
ud.pAllVar = getvars(PROJ, 'nonconstant');
ud.UsedVar = obj.FillExpressions;
ud.UsedVar(idx) = [];
ud.tradeoff = obj;

hFig = xregdialog('Name', 'Select Filling Item', ...
    'MinimumSize', [205 110]);
xregcenterfigure(hFig, [300 350]);

pGUI = xregGui.RunTimePointer;
pGUI.LinkToObject(hFig);

% Text telling the user to select a filling item
hText = uicontrol('Style', 'text', ...
    'Parent', hFig, ...
    'String', ['Select the item you want to fill table ' TblName 'with:'], ...
    'HorizontalAlignment', 'left');

hOptsFrame = mbcgui.container.layoutpanel(...
    'Parent', hFig, ...
    'Title', 'List options', ...
    'BorderType', 'etchedin');   

% Checkbox for filtering out used items
ud.hCheck = uicontrol('Style', 'checkbox', ...
    'Parent', hOptsFrame, ...
    'String', 'Only show items that are not filling another table', ...
    'Value', 1, ...
    'Callback', {@i_refilter, pGUI});

% Radio buttons for selecting which item type to list
ud.hRadio = xregGui.rbgroup('parent', hOptsFrame, ...
    'nx', 1, 'ny', 3, ...
    'string', {'Display models'; 'Display variables'; 'Display all items'}, ...
    'value', [1;0;0], ...
    'callback', {@i_refilter, pGUI});

% List box for displaying list of items
ud.hList = cgtools.exprList('parent', hFig, ...
    'DisplayTypeColumn', true, ...
    'DisplayHeaderRow', true, ...
    'SelectionStyle', 'single', ...
    'ItemColumnWidth', 0.6);
hDblClickList = handle.listener(ud.hList, 'Open', @i_forceOK);

% Control buttons
hOK = uicontrol('Style', 'pushbutton', ...
    'Parent', hFig, ...
    'String', 'OK', ...
    'Callback', @(s,e)set(hFig, 'Tag', 'ok', 'Visible', 'off') );
hCancel = uicontrol('Style', 'pushbutton', ...
    'Parent', hFig, ...
    'String', 'Cancel', ...
    'Callback', @(s,e)set(hFig, 'Visible', 'off'));
hHelp = cghelpbutton(hFig, 'CGTRADEOFFSETFILL');
pGUI.info = ud;


optsgrid = xreggridbaglayout(hOptsFrame, ...
    'packstatus', 'off', ...
    'dimension', [2 1], ...
    'rowsizes', [60 20], ...
    'gapy', 10, ...
    'border', [5 5 5 3], ...
    'elements', {ud.hRadio, ud.hCheck});
set(hOptsFrame, 'LayoutComponent', {optsgrid});
hLayout = xreggridbaglayout(hFig, ...
    'dimension', [4 4], ...
    'rowsizes', [15 -1 110 25], ...
    'colsizes', [-1 65 65 65], ...
    'gapy', 10, ...
    'gapx', 7, ...
    'border', [7 7 7 10], ...
    'mergeblock', {[1 1], [1 4]}, ...
    'mergeblock', {[2 2], [1 4]}, ...
    'mergeblock', {[3 3], [1 4]}, ...
    'elements', {hText, ud.hList, hOptsFrame, [], ...
    [], [], [], hOK, ...
    [], [], [], hCancel, ...
    [], [], [], hHelp});

hFig.ContentHandle = hLayout;
set(hLayout, 'packstatus', 'on');

% Find out if the current fill expression exists in one of the lists
if ~isnull(pT)
    pFill = getFillExpression(obj, pT);
    if pFill~=0
        if ismember(pFill, ud.pAllVar)
            % Start of set to the variable list
            ud.hRadio.Selected = 2;
        end
        % Set current fill item as selected initially (if possible)
        ud.hList.SelectedItem = pFill;
    end
else
    pFill = mbcpointer(1);
end

% Initialise list
i_refilter([], [], pGUI,pFill)

hFig.showDialog(hOK);
%  Dialog blocks execution here

tg = get(hFig, 'Tag');
ok = false;
if strcmp(tg, 'ok')
    pNewFill = ud.hList.SelectedItem;
    if ~isempty(pNewFill)
        ok = true;
    else
        pNewFill = xregpointer;
    end
else
    pNewFill = xregpointer;
end
delete(hFig);



function i_refilter(~, ~, pUD,pFill)
ud = pUD.info;
group = ud.hRadio.Selected;
removeused = get(ud.hCheck, 'Value');

if nargin<4
    pFill = ud.hList.SelectedItem;
end

switch group
    case 1
        pItems = ud.pAllModels;
    case 2
        pItems = ud.pAllVar;
    case 3
        pItems = [ud.pAllModels, ud.pAllVar];
end
if removeused
    pItems = setdiff(pItems, ud.UsedVar);
end
ud.hList.Items = pItems;
if ismember(pFill,pItems)
     ud.hList.SelectedItem = pFill;
else
     ud.hList.SelectedItem = [];
end


function i_forceOK(src, ~)
set(src.Parent, 'Tag', 'ok', 'Visible', 'off');