www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/@xregdesign/gui_round.m

    function [des, ok] = gui_round(des)
%GUI_ROUND Display a dialog for rounding a design factor
%
%  [DES, OK] = GUI_ROUND(DES) displays a dialog that allows the user to
%  round a factor in the design.
%
%  See also: XREGDESIGN/ROUNDFACTOR.

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


SC = xregGui.SystemColorsDbl;
dlg = mbcgui.container.Dialog('Name', 'Round Design',...
    'Buttons','OK_CANCEL',...
    'Size',[350 170]);
hFig = dlg.Figure;

f = factors(des);
pUD = xregGui.RunTimePointer;
pUD.LinkToObject(hFig);

hFactPopup = uicontrol('Parent', hFig, ...
    'Style', 'popupmenu', ...
    'String', f, ...
    'Value', 1, ...
    'BackgroundColor', SC.WINDOW_BG);
hFactLabel = xregGui.labelcontrol('parent', hFig, ...
    'String', 'Round factor:', ...
    'LabelSize', 90, ...
    'LabelSizeMode', 'absolute', ...
    'ControlSize', 1, ...
    'ControlSizeMode', 'relative', ...
    'Control', hFactPopup);

hRoundPopup = uicontrol('Parent', hFig, ...
    'Style', 'popupmenu', ...
    'String', {'Fixed interval'; 'Significant figures'; 'Specified levels'}, ...
    'Value', 1, ...
    'BackgroundColor', SC.WINDOW_BG, ...
    'Callback', {@i_enablesetting, pUD});
hRoundLabel = xregGui.labelcontrol('parent', hFig, ...
    'String', 'Rounding mode:', ...
    'LabelSize', 90, ...
    'LabelSizeMode', 'absolute', ...
    'ControlSize', 1, ...
    'ControlSizeMode', 'relative', ...
    'Control', hRoundPopup);

optsframe = mbcgui.container.layoutpanel(...
    'Parent', hFig, ...
    'Title','Rounding options',...
    'BorderType', 'etchedin', ...
    'LayoutBorder',[10 10 10 5]);

hIntervalEdit = mbcgui.widget.Spinner('Parent', optsframe, ...
    'Min', eps, ...
    'Value', 1);
hIntervalLabel = xregGui.labelcontrol('parent', optsframe, ...
    'String', 'Interval:', ...
    'LabelSize', 45, ...
    'LabelSizeMode', 'absolute', ...
    'ControlSize', 70, ...
    'ControlSizeMode', 'absolute', ...
    'Control', hIntervalEdit);

hOffsetEdit = mbcgui.widget.Spinner('Parent', optsframe, ...
    'Value', 0);
hOffsetLabel = xregGui.labelcontrol('parent', optsframe, ...
    'String', 'Offset:', ...
    'LabelSize', 45, ...
    'LabelSizeMode', 'absolute', ...
    'ControlSize', 70, ...
    'ControlSizeMode', 'absolute', ...
    'Control', hOffsetEdit);

hSigFigEdit = mbcgui.widget.Spinner('Parent', optsframe, ...
    'Min', 1, ...
    'Rule', 'int', ...
    'Value', 3);
hSigFigLabel = xregGui.labelcontrol('parent', optsframe, ...
    'String', 'Significant figures:', ...
    'LabelSize', 100, ...
    'LabelSizeMode', 'absolute', ...
    'ControlSize', 70, ...
    'ControlSizeMode', 'absolute', ...
    'Control', hSigFigEdit);

L = designlimits(des, 'natural');
defaultStr = sprintf('linspace(%g, %g, 11)', L{1}(1), L{1}(2));
hLevelsEdit = uicontrol('Parent', optsframe, ...
    'Style', 'edit', ...
    'HorizontalAlignment', 'right', ...
    'BackgroundColor', SC.WINDOW_BG, ...
    'String', defaultStr);
hLevelsLabel = xregGui.labelcontrol('parent', optsframe, ...
    'String', 'Level values:', ...
    'LabelSize', 70, ...
    'LabelSizeMode', 'absolute', ...
    'ControlSize', 1, ...
    'ControlSizeMode', 'relative', ...
    'Control', hLevelsEdit);

intervalLyt = xreggridbaglayout(optsframe, ...
    'dimension', [1 2], ...
    'rowsizes', 20, ...
    'colsizes', [120 120], ...
    'gapx', 15, ...
    'elements', {hIntervalLabel, hOffsetLabel});
sigfigLyt = xreggridbaglayout(optsframe, ...
    'dimension', [1 1], ...
    'rowsizes', 20, ...
    'elements', {hSigFigLabel});
levelsLyt = xreggridbaglayout(optsframe, ...
    'dimension', [1 1], ...
    'rowsizes', 20, ...
    'elements', {hLevelsLabel});
ud.optsLyt = xregcardlayout(optsframe, ...
    'NumCards', 3);
attach(ud.optsLyt, intervalLyt, 1);
attach(ud.optsLyt, sigfigLyt, 2);
attach(ud.optsLyt, levelsLyt, 3);
set(optsframe, 'LayoutComponent', {ud.optsLyt});

dlg.Content = xreggridbaglayout(hFig, ...
    'dimension', [3 1], ...
    'rowsizes', [22 22 -1], ...
    'gapy', 10, ...
    'elements', {hFactLabel, hRoundLabel, optsframe});


pUD.info = ud;


tg = dlg.showDialog();
ok = false;
if strcmpi(tg, 'ok')
    factind = get(hFactPopup, 'Value');
    method = get(hRoundPopup, 'Value');
    if method==1
        opt = [hIntervalEdit.Value, hOffsetEdit.Value];
        des = roundfactor(des, factind, 'nearest', opt);
        
    elseif method==2
        opt = hSigFigEdit.Value;
        des = roundfactor(des, factind, 'sigfig', opt);
        
    elseif method==3
        opt = str2num(get(hLevelsEdit, 'String'));
        des = roundfactor(des, factind, 'tolevels', opt);
        
    end 
    ok = true;
end
delete(dlg);



function i_enablesetting(src, evt, pUD)
ud = pUD.info;

val = get(src, 'Value');
set(ud.optsLyt, 'CurrentCard', val);