www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/@xregdesign/gui_merge.m
function [desout, ok, exist] = gui_merge(des, cDesigns, idxSelection) %GUI_MERGE Open a dialog for merging designs % % [DES, OK, EXIST] = GUI_MERGE(DES, DESIGNLIST, INITIALSEL) displays a % dialog for merging designs. DESIGNLIST is a cell array of designs that % can be selected from for merging. INITIALSEL is a list of indices into % this list which defines the initial selection that the dialog will % display. The input DES is not used. % % The output DES is the merged design. OK indicates whether any operation % has taken place and EXIST indicates whether the user has asked for this to % be a new design or placed into an existing design. If EXIST is 0 then % it should be a new design. If EXIST is non-zero then it is the index % into the original DESIGNLIST that DES should replace. % Copyright 2000-2015 The MathWorks, Inc. and Ford Global Technologies, Inc. dlg = mbcgui.container.Dialog('Name', 'Merge Designs',... 'Buttons','OK_CANCEL',... 'Size',[500 350]); fig = dlg.Figure; p = xregGui.RunTimePointer; p.LinkToObject(fig); sc = mbcgui.util.SystemColorsDbl; ud.ListPrompt = uicontrol('Parent', fig, ... 'Style', 'text', ... 'String', 'Select two or more designs to merge:', ... 'HorizontalAlignment', 'left'); ud.List = xregdesgui.DesignList('Parent', fig, ... 'Designs', cDesigns, ... 'SelectedIndex', idxSelection); ud.mergeNew = uicontrol('Parent', fig, ... 'Style', 'radiobutton', ... 'String', 'Merge to new design', ... 'Value', 1, ... 'Enable', 'off'); ud.mergeExist = uicontrol('Parent', fig, ... 'Style', 'radiobutton', ... 'String', 'Merge to existing design', ... 'Enable', 'off'); base = uicontrol('Parent', fig, ... 'Style', 'popupmenu', ... 'String', ' ', ... 'Value', 1, ... 'BackgroundColor', sc.WINDOW_BG); ud.newBase = xregGui.labelcontrol('parent', fig, ... 'Control', base, ... 'labelsizemode', 'absolute', ... 'labelsize', 120, ... 'controlsizemode', 'relative', ... 'controlsize', 1, ... 'string', 'Base new design on:'); base = uicontrol('Parent', fig, ... 'Style', 'popupmenu', ... 'String', ' ', ... 'Value', 1, ... 'BackgroundColor', sc.WINDOW_BG); ud.existBase = xregGui.labelcontrol('parent', fig, ... 'Control', base, ... 'labelsizemode', 'absolute', ... 'labelsize', 120, ... 'controlsizemode', 'relative', ... 'controlsize', 1, ... 'string', 'Copy points into design:'); set(ud.newBase.Control, 'Callback', {@i_popvalSync, ud.existBase.Control}); set(ud.existBase.Control, 'Callback', {@i_popvalSync, ud.newBase.Control}); set(ud.mergeNew, 'Callback', {@i_radioExclusive, ud.mergeExist, ud.newBase, ud.existBase}); set(ud.mergeExist, 'Callback', {@i_radioExclusive, ud.mergeNew, ud.existBase, ud.newBase}); ud.ListListener = event.listener(ud.List, 'DesignSelected', @(h,evt) i_DesignSelection(h,evt, p,dlg)); p.info = ud; dlg.Content = xreggridbaglayout(fig, ... 'dimension', [7 2], ... 'rowsizes', [15 -1 0 20 21 20 21], ... 'colsizes', [20 -1], ... 'gapy', 5, ... 'gapx', 7, ... 'mergeblock', {[1 1], [1 2]}, ... 'mergeblock', {[2 2], [1 2]}, ... 'mergeblock', {[4 4], [1 2]}, ... 'mergeblock', {[6 6], [1 2]},... 'elements', {ud.ListPrompt, ud.List, [], ud.mergeNew, [], ud.mergeExist,[], ... [], [], [], [], ud.newBase, [], ud.existBase}); i_DesignSelection(ud.List, [], p,dlg); tg = dlg.showDialog(); ok = false; exist = 0; if strcmp(tg, 'OK') [desout, ok, exist] = i_finalise(p); if ~ok desout = des; end else desout = des; end delete(dlg); function i_DesignSelection(src, ~, p,dlg) selDes = src.SelectedDesigns; ud = p.info; if length(selDes)<2 % Disable the OK route disableButtons(dlg,'OK'); set([ud.mergeNew, ud.mergeExist], 'Enable', 'off'); set([ud.newBase, ud.existBase], 'Enable', 'off'); set([ud.newBase.Control, ud.existBase.Control], 'String', ' ', 'Value', 1); else enableButtons(dlg,'OK'); set([ud.mergeNew, ud.mergeExist], 'Enable', 'on'); if get(ud.mergeNew, 'Value') set([ud.newBase, ud.existBase], {'Enable'}, {'on';'off'}); else set([ud.newBase, ud.existBase], {'Enable'}, {'off';'on'}); end popstr = cell(1, length(selDes)); for n = 1:length(popstr) popstr{n} = name(selDes{n}); end set([ud.newBase.Control, ud.existBase.Control], 'String', popstr, 'Value', 1); end function i_popvalSync(src, ~, hOther) set(hOther, 'Value', get(src, 'Value')); function i_radioExclusive(src, ~, hOtherRadio, hThisPopup, hOtherPopup) set(src, 'Value', 1); set(hOtherRadio, 'Value', 0); set(hOtherPopup, 'Enable', 'off'); set(hThisPopup, 'Enable', 'on'); function [des, ok, exist] = i_finalise(p) ud = p.info; mergedes = ud.List.SelectedDesigns; if length(mergedes)<2 ok = false; exist = 0; des = []; else ok = true; primaryidx = get(ud.newBase.Control, 'Value'); des = mergedes{primaryidx}; mergedes(primaryidx) = []; des = mergedesigns(des, mergedes{:}); if get(ud.mergeNew, 'Value') exist = 0; else exist = ud.List.SelectedIndex(primaryidx); end end