www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/+xregdatagui/mergeOptions.m
function varargout = mergeOptions(action,varargin) %mergeOptions user interface for merge options % outputUD = mergeOptions('figure',localData,Owner); % create modal dialog with merge options. outputUD is a structure % with fields sweepset and filename. The input Owner can be a figure % handle or [] with the default set to [] if it is omitted. % layout = mergeOptions('layout',Parent,localData); % create merge options page for import wizard % [localData,OK] = mergeOptions('finalise',layoutUD); % get final options for merge page in xregwizard. localData is a % structure with fields newSweepset and filename % Copyright 2015-2015 The MathWorks, Inc. and Ford Global Technologies, Inc. switch action case 'figure' % create modal dialog [varargout{1:2}] = dialog(varargin{:}); case 'layout' % create layout for xregwizard varargout{1} = createLayout(varargin{:}); case 'finalise' % finalise xregwizard output [varargout{1:2}] = finalise(varargin{:}); end function [outputUD,OK] = dialog(localData,Owner) %dialog create modal merge dialog % [outputUD,OK] = dialog(localData,Owner) outputUD is a structure % with fields sweepset and filename. The input Owner can be a figure % handle or [] with the default set to [] if it is omitted. if nargin<2 Owner = []; end dlg = mbcgui.container.Dialog('Name','Merge Data',... 'Owner',Owner,... 'Size',[400 200],... 'Buttons','OK_CANCEL'); dlg.Content = createLayout(dlg.Figure,localData); closeAction = dlg.showDialog(); if strcmp(closeAction,'OK') OK = true; % get updated sweepset from layout userdata layoutUD = get(dlg.Content, 'UserData'); localData = finalise(layoutUD); outputUD.sweepset = localData.newSweepset; outputUD.filename = localData.filename; else outputUD = []; OK = false; end delete(dlg); function layout = createLayout(Parent,localData) %createLayout create layour for wizard or dialog % layout = createLayout(Parent,localData) % Parent can be a graphics handle or a layout. The layout option is used % when a wizard page is reused. localData is a structure with fields % mergeSweepset, newSweepset and filename. % Have we been called to create the layout or simply update? if isa(Parent, 'xregcontainer') % layout = Parent; layoutUD = get(layout, 'UserData'); else % create new layout txSelect = uicontrol('Parent', Parent,... 'Style', 'text',... 'String', 'Merge data with current data.',... 'Visible', 'off',... 'HorizontalAlignment', 'left'); rbGroup = xregGui.rbgroup('parent', Parent,... 'nx', 1,... 'ny', 4,... 'String', {'Append new records (all variable names and units match current data)' 'Append new records (add NaNs to unmatched variables)' 'Add new variables to current data' 'Overwrite current data'}); layout = xreggridbaglayout(Parent,... 'dimension', [3 1],... 'elements', {txSelect rbGroup []},... 'rowsizes', [20 60 -1],... 'border', [10 0 10 10],... 'gapy', 5,... 'gapx', 5); layoutUD.rbGroup = rbGroup; layoutUD.filename = ''; layoutUD.newSweepset = sweepset; layoutUD.mergeSweepset = []; end if nargin > 1 % initialise layoutUD from input layoutUD.newSweepset = localData.newSweepset; layoutUD.mergeSweepset = localData.mergeSweepset; layoutUD.filename = localData.filename; end set(layout, 'UserData', layoutUD); updateOptions(layoutUD) function updateOptions(layoutUD) %updateOptions enable allowed merge operations EnableArray = true(size(layoutUD.rbGroup.String)); newSS = layoutUD.newSweepset; mergeSS = layoutUD.mergeSweepset; [~,EnableArray(1)] = append(mergeSS,newSS,'strict'); [~,EnableArray(2)] = append(mergeSS,newSS); [~,EnableArray(3)] = align(mergeSS,newSS); set(layoutUD.rbGroup,'EnableArray',EnableArray,'Selected',find(EnableArray,1)); %------------------------------------------------------------------------ function [localData,OK] = finalise(layoutUD) %finalise get results on completion of dialog or wizard % [localData,OK] = finalise(layoutUD) % localData is a structure with fields newSweepset and filename % Attempt selected merge mergeType = layoutUD.rbGroup.Selected; newSS = layoutUD.newSweepset; mergeSS = layoutUD.mergeSweepset; try switch mergeType case 1 % append with strict matching [localData.newSweepset, OK, msg] = append(mergeSS, newSS,'strict'); localData.filename = char(get(mergeSS, 'FileName'), layoutUD.filename); case 2 [localData.newSweepset, OK, msg] = append(mergeSS, newSS); localData.filename = char(get(mergeSS, 'FileName'), layoutUD.filename); case 3 % Align merge needs common variable names [localData.newSweepset, OK, msg] = align(mergeSS, newSS); localData.filename = char(get(mergeSS, 'FileName'), layoutUD.filename); case 4 % overwrite OK = 1; localData.newSweepset = newSS; localData.filename = layoutUD.filename; otherwise return end catch ME OK = 0; msg = sprintf('Merge failed due to unexpected error: %s',ME.message)'; end if ~OK if ~isempty(msg) % The Data Loading Function returned some sort of error message uiwait(errordlg(msg, 'Data Loading Error', 'modal')); end return end localData.mergeSweepset = [];