www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgtradeoffnode/guiAddNewTable.m
function [obj, ok] = guiAddNewTable(obj) %GUIADDNEWTABLE Create a new table and add to the tradeoff % % [OBJ, OK] = GUIADDNEWTABLE(OBJ) creates a new table and adds it to the % tradeoff. If the tradeoff already contains tables, the user will be % asked for a table name and a value to initialise it with. If the % tradeoff is empty, they will be presented with the standard new 2D table % dialog. In both cases there will also be an input for specifying the % fill item. % Copyright 2000-2010 The MathWorks, Inc. and Ford Global Technologies, Inc. PROJ = project(obj); hFig = xregdialog('Name', 'Table Setup', ... 'Resize', 'off'); if numTables(obj)==0 xregcenterfigure(hFig, [300 218]); % Use the standard 2D table creation panel for setting up a new table hTableEdit = cgexprgui.TableCreator('Parent', hFig, ... 'Dimensions', 2, ... 'VariableDictionary', getdd(PROJ)); else % Pop up a small dialog that just asks for a name and default value SC = xregGui.SystemColorsDbl; xregcenterfigure(hFig, [300 157]); hName = xregGui.labelcontrol('parent',hFig,... 'labelsize',70,... 'labelsizemode','absolute',... 'string','Name:',... 'controlsize',1,... 'controlsizemode','relative',... 'gap',5,... 'Control',uicontrol('Parent',hFig,... 'Style','edit',... 'String', 'New_2D_Table', ... 'UserData', 'New_2D_Table', ... 'BackgroundColor',SC.WINDOW_BG,... 'HorizontalAlignment','left',... 'Callback',@i_disallowempty)); hValue = xregGui.labelcontrol('parent',hFig,... 'labelsize',70,... 'labelsizemode','absolute',... 'string','Initial value:',... 'controlsize',75,... 'controlsizemode','absolute',... 'gap',5,... 'Control',mbcgui.widget.Spinner('Parent', hFig)); % Construct a layout for the cut-down table editing elements hTableEdit = xreggridbaglayout(hFig, ... 'packstatus', 'off', ... 'dimension', [2 1], ... 'rowsizes', [20 20], ... 'gapy', 6, ... 'elements', {hName, hValue}); end % Construct the table-filling UI items hFill = xregGui.labelcontrol('parent',hFig,... 'labelsize',70,... 'labelsizemode','absolute',... 'string','Fill table with:',... 'controlsize',1,... 'controlsizemode','relative',... 'gap',5,... 'Control',uicontrol('Parent',hFig,... 'Style','edit',... 'HorizontalAlignment','left', ... 'UserData', xregpointer, ... 'Enable', 'inactive')); hFillSelect = uicontrol('Parent', hFig, ... 'Style', 'pushbutton', ... 'String', 'Select...', ... 'Callback', {@i_selectfillitem, hFill, obj}); hFillClear = uicontrol('Parent', hFig, ... 'Style', 'pushbutton', ... 'String', 'Clear', ... 'Callback', {@i_clearfillitem, hFill}); % 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, 'Tag', 'cancel', 'Visible', 'off')); hHelp = cghelpbutton(hFig, 'CGTRADEOFFNEWTABLE'); % Main Layout layout = xreggridbaglayout(hFig, ... 'packstatus', 'off', ... 'dimension', [9, 4], ... 'rowsizes', [-1 6 3 20 2 3 25 15 25], ... 'colsizes', [-1 65 65 65], ... 'gapx', 7, ... 'border', [7 7 7 7], ... 'mergeblock', {[1 1], [1 4]}, ... 'mergeblock', {[4 4], [1 3]}, ... 'mergeblock', {[3 5], [4 4]}, ... 'elements', {hTableEdit, [], [], hFill, [], [], [], [], [], ... [], [], [], [], [], [], [], [], hOK, ... [], [], [], [], [], [], [], [], hCancel, ... [], [], hFillSelect, [], [], [], hFillClear, [], hHelp}); hFig.ContentHandle = layout; set(layout, 'packstatus', 'on'); hFig.showDialog(hOK); tg = get(hFig, 'Tag'); ok = false; if strcmp(tg, 'ok') if numTables(obj)==0 pT = hTableEdit.createTable; ok = canAddTable(obj, pT); pNx = pT.get('x'); pNy = pT.get('y'); if ok % Add items to project and tradeoff addtoproject(obj, pNx); addtoproject(obj, pNy); addtoproject(obj, pT); [obj, ok] = addTable(obj, pT, true); else freeptr([pT pNx pNy]); end else Name = get(hName.Control, 'String'); Value = get(hValue.Control, 'Value'); [obj, pT, ok] = addNewTable(obj, Name, Value); end pNewFill = get(hFill.Control, 'UserData'); if ~isnull(pNewFill) obj = setFillExpression(obj, pT, pNewFill); end end delete(hFig); function i_disallowempty(src,evt) % Prevent user from having an invalid string in the edit box str = get(src,'String'); if ~isvarname(str) set(src,'String',get(src,'UserData')); else set(src,'UserData',str); end function i_selectfillitem(src, evt, hFill, obj) [pNewFill, ok] = pGuiGetFillExpression(obj); if ok set(hFill.Control, 'UserData', pNewFill); set(hFill.Control, 'String', pNewFill.getname); end function i_clearfillitem(src, evt, hFill) set(hFill.Control, 'UserData', xregpointer); set(hFill.Control, 'String', '');