www.gusucode.com > mbcdata 工具箱 matlab 源码程序 > mbcdata/@cgoptimdatasetfiller/guiSetUp.m
function [obj, OK,View] = guiSetUp(obj, pOut, pPROJ) %GUISETUP Set up the required tables for filling via a GUI % % [NEWOTF, OK] = GUISETUP(OTFIN, pOUT, pPROJ) launches a dialog to allow % a data set to be configured which will be filled from the supplied % optimization results. % % See also CGOPTIMDATASETFILLER % Copyright 2006-2015 The MathWorks, Inc. % Check the optimization results - if they are not valid, return % immediately. dlgTitle = 'Export To Data Set'; OK = guiSetUpCheck(obj, pOut, pPROJ, dlgTitle); if ~OK return end % Create a run time pointer to store useful info hInfo = xregGui.RunTimePointer; % Figure dlgSize = [470 370]; hDlg = mbcgui.container.Dialog('Name', dlgTitle, ... 'Tag', 'ExportToDataset', ... 'Buttons', 'OK_CANCEL',... 'Size', dlgSize, ... 'PersistPosition', false, ... 'Resize', 'off', ... 'ContentBorder', zeros(1, 4)); hFig = hDlg.Figure; % Introduction string txt = uicontrol('Parent', hFig, ... 'String', 'Select target data set:', ... 'Style', 'text', ... 'HorizontalAlignment', 'left'); % New data set ud.rbNew = uicontrol('Parent', hFig, ... 'String', 'New:', ... 'Style', 'radio', ... 'UserData', 1, ... 'Value', 1, ... 'Callback', {@i_rbGroupChange, hInfo}); ud.newDatasetName = uniquename(pPROJ.info, 'New_Dataset'); ud.edDatasetName = uicontrol('Parent', hFig, ... 'String', ud.newDatasetName, ... 'Style', 'edit', ... 'Enable', 'on', .... 'HorizontalAlignment', 'left', ... 'Callback', {@i_editChange, hInfo}, ... 'BackgroundColor', 'w'); % Modify existing data set ud.rbModifyExisting = uicontrol('Parent', hFig, ... 'String', 'Modify existing:', ... 'Style', 'radio', ... 'UserData', 2, ... 'Value', 0, ... 'Callback', {@i_rbGroupChange, hInfo}); ud.hTab = mbcwidgets.Table1D('list', ... 'Parent', hFig, ... 'SelectionMode', 'SingleRow', ... 'Enable', 'off', ... 'SelectionChangedCallback', {@i_tableChange, hInfo}, ... 'Visible', 'on'); ud.popAction = xregGui.labelcontrol('parent', hFig, ... 'visible','on', ... 'enable', 'off', ... 'string','Action:', ... 'labelsizemode','absolute', ... 'labelsize', 40, ... 'controlsizemode','absolute', ... 'controlsize', 120, ... 'gap', 5, ... 'Control',uicontrol('Parent', hFig, ... 'String', {'Append', 'Overwrite'}, ... 'Tag', 'actionPopup', ... 'Style', 'popup', ... 'Callback', '', ... 'BackgroundColor', 'w', ... 'Visible','on')); % Check box to indicate acceptability cUseAcceptable = uicontrol('Parent', hFig, ... 'Style', 'checkbox', ... 'Value', 1, ... 'String', 'Use acceptable solutions only'); if getNumSolutions(pOut.info) > 1 cAllSolutions = uicontrol('Parent', hFig, ... 'Style', 'popupmenu', ... 'Tag', 'selectionPopup', ... 'Value', 1, ... 'BackgroundColor','w',... 'String', {'Selected Solutions','All Solutions'}); hAllSolutions = xregGui.labelcontrol('Parent', hFig, ... 'String', 'Solutions to export:', ... 'LabelSizeMode', 'absolute', ... 'LabelSize', 100, ... 'ControlSizeMode', 'absolute', ... 'ControlSize', 120, ... 'Gap', 5, ... 'Control', cAllSolutions); if ~hasSelectedSolution(pOut.info) set( cAllSolutions ,'Enable','off', 'Value',2 ) end hAllSolSize = 22; else hAllSolSize = 2; hAllSolutions = []; end cViewDataset = uicontrol('Parent', hFig, ... 'Style', 'checkbox', ... 'Value', 1, ... 'String', 'View data set'); % Main layout mainLyt = xreggridbaglayout(hFig, ... 'border', [10 10 10 10], ... 'packstatus', 'on', ... 'dimension', [10 4], ... 'rowsizes', [15 15 20 15 -1 25 5 15 hAllSolSize 20], ... 'colsizes', [20 175 -1 160], ... 'gapy', 5, ... 'mergeblock', {[1 1], [1 4]}, ... 'mergeblock', {[2 2], [1 4]}, ... 'mergeblock', {[4 4], [1 4]}, ... 'mergeblock', {[5 5], [2 4]}, ... 'mergeblock', {[6 6], [1 4]}, ... 'mergeblock', {[8 8], [1 4]}, ... 'mergeblock', {[9 9], [1 3]}, ... 'mergeblock', {[10 10], [1 3]}, ... 'elements', {txt, ud.rbNew, [], ud.rbModifyExisting, [], [], [], cUseAcceptable, hAllSolutions, cViewDataset,... [], [], ud.edDatasetName, [], ud.hTab, [], [], [], [], [], ... [], [], [], [], [], [], [], [], [], [], ... [], [], [], [], [], ud.popAction, [], [], [], []}); hDlg.Content = mainLyt; % Initialise GUI ud.pOut = pOut; ud.pPROJ = pPROJ; ud.projConn = UpdateConnections(pPROJ.info); ud.pExistingDatasets = i_fillTable(obj, ud); if isempty(ud.pExistingDatasets) set(ud.rbModifyExisting, 'Enable', 'off'); end ud.hDlg = hDlg; % Set user data hInfo.info = ud; % Launch GUI closeMode = hDlg.showDialog; % Dialog blocks here until OK/Ccl/Close ud = hInfo.info; if strcmp(closeMode, 'OK') OK = true; if i_getSelectedRadioBtn(ud) == 1 % Exporting to new data set obj.FillAction = 1; obj.NewDatasetName = ud.newDatasetName; else % Appending or overwriting data to an existing data set. obj.FillAction = get(get(ud.popAction, 'Control'), 'Value') + 1; obj.pDataset = ud.pExistingDatasets(ud.hTab.getSelectedRows); end % Set use acceptable status useAcceptable = logical(get(cUseAcceptable, 'Value')); obj = setUseAcceptableOnly(obj, useAcceptable); if ~isempty(hAllSolutions) useAllSolutions = logical(get(cAllSolutions, 'Value')==2); obj = setUseAllSolutions(obj, useAllSolutions); end View = get(cViewDataset,'Value'); else OK = false; View = false; end delete(hDlg); %-------------------------------------------------------------------------- function i_rbGroupChange(src, evt, hInfo) %-------------------------------------------------------------------------- % Get the user data ud = hInfo.info; % Selected radio button Sel = get(src, 'UserData'); % Set enabled state of controls and select data set if Sel == 1 set([ud.rbNew; ud.rbModifyExisting], {'Value'}, num2cell([1; 0])); set(ud.edDatasetName, 'Enable', 'on'); ud.popAction.enable = 'off'; ud.hTab.enable = 'off'; else set([ud.rbNew; ud.rbModifyExisting], {'Value'}, num2cell([0; 1])); set(ud.edDatasetName, 'Enable', 'off'); ud.popAction.enable = 'on'; ud.hTab.enable = 'on'; end % Set user data hInfo.info = ud; % Set enabled state of OK button i_enableOK(hInfo); %-------------------------------------------------------------------------- function i_editChange(src, evt, hInfo) %-------------------------------------------------------------------------- % Get user data ud = hInfo.info; % Get new data set name newdsName = get(src, 'String'); % Disallow edit if it is not a valid ML name. Make the name unique in the % project. if isvarname(newdsName) ud.newDatasetName = newdsName; else set(src, 'String', ud.newDatasetName); end % Set user data hInfo.info = ud; %-------------------------------------------------------------------------- function i_tableChange(src, evt, hInfo) %-------------------------------------------------------------------------- % Set enabled state of OK button i_enableOK(hInfo); %-------------------------------------------------------------------------- function pOp = i_fillTable(obj, ud) %-------------------------------------------------------------------------- % Set the columns props = {'Name', 'Rows', 'Columns'}; ud.hTab.Peer.setColumnData(props); ud.hTab.Peer.setColumnWidths([150, 60, 215]); % Retrieve data pOp = i_getPossibleDatasets(obj, ud); opNames = pveceval(pOp, @getname); opRows = pveceval(pOp, @get, 'numpoints'); opFactors = pveceval(pOp, @get, 'factors'); opFactors = cellfun(@(x) i_getFactorNames(x), opFactors, ... 'UniformOutput', false); info = [opNames', opRows', opFactors']; % Set icon information ud.hTab.Peer.setIconBaseLocation(cgrespath); icons = repmat({'cgdatasetnode.bmp'}, length(pOp), 1); % Set data in table ud.hTab.Peer.setData( info, icons ); %-------------------------------------------------------------------------- function pOp = i_getPossibleDatasets(obj, ud) %-------------------------------------------------------------------------- % Find all the data sets in the project pOp = ud.projConn.pData(find(ud.projConn, 'type', 'Dataset')); % Get the optimization input result columns [pOptimInput, optimInputNames] = getInputExpression(obj, ud.pOut, ud.pPROJ); idxOptimPtrs = isvalid(pOptimInput); % Return those data sets that share some inputs or external data with the % optimization results nPossOp = length(pOp); idxCanAdd = true(1, nPossOp); for i = 1:nPossOp % Find all inputs in data set factor_type = get(pOp(i).info, 'factor_type'); ptrlist = get(pOp(i).info, 'ptrlist'); inpPtrs = ptrlist(factor_type == 1); % Find the data sets that can be added idx = findptrs(inpPtrs, pOptimInput(idxOptimPtrs)); if any(idx) % There are inputs in common with optim results. Do not need to % check external data. idxCanAdd(i) = true; else % Check to see if there's external data columns in common with % optimization results grid_flag = get(pOp(i).info, 'grid_flag'); factor_type = get(pOp(i).info, 'factor_type'); extIdxTarget = grid_flag == 7 & factor_type == 2; extNames = get(pOp(i).info, 'orig_name'); extNames = extNames(extIdxTarget); extNames = intersect(optimInputNames, extNames); if isempty(extNames) idxCanAdd(i) = false; else idxCanAdd(i) = true; end end end pOp = pOp(idxCanAdd); %-------------------------------------------------------------------------- function factorNames = i_getFactorNames(factorNames) %-------------------------------------------------------------------------- nFactors = length(factorNames); factorNames = char(factorNames); if nFactors > 1 comma = ', '; factorNames = [factorNames, comma(ones(nFactors, 1), :)]'; factorNames = factorNames(1:end-2); factorNames = regexprep(factorNames, '[ \t]*,', ','); end %-------------------------------------------------------------------------- function i_enableOK(hInfo) %-------------------------------------------------------------------------- % Get user data ud = hInfo.info; % Set Enable state if i_getSelectedRadioBtn(ud) == 1 || ~isempty(ud.hTab.getSelectedRows) ud.hDlg.enableButtons('OK'); else ud.hDlg.disableButtons('OK'); end %-------------------------------------------------------------------------- function selRad = i_getSelectedRadioBtn(ud) %-------------------------------------------------------------------------- if get(ud.rbNew, 'Value') selRad = 1; else selRad = 2; end