www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/@testplansweepsetfilter/toleranceEditDlg.m

    function [OK, newTolerance] = toleranceEditDlg(tssf, hParent)
%TOLERANCEEDITDLG A short description of the function
%    [OK, newTolerance] = toleranceEditDlg(tssf, hParent)

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

% Create runtime pointers to hold relevant data
pHandles = xregGui.RunTimePointer;

dlg = mbcgui.container.Dialog('Name', 'Tolerance Editor',...
    'Buttons','OK_CANCEL_HELP',...
    'Owner',hParent,...
    'HelpCode','xreg_data_toleranceEditor',...
    'Resize','off',...
    'Tag', 'tssfToleranceEditor');
f = dlg.Figure;

pHandles.LinkToObject(f);

% Create the layout (based on the data)
[layout, preferredSize] = i_createLayout(f, pHandles, tssf);
dlg.Size = preferredSize;

% Center the figure on the parent figure
xregcenterfigure(f, preferredSize, hParent);
dlg.Content = layout;

% Set the visibility and wait for it to change
% Get the return
closeMode = dlg.showDialog();
if strcmp(closeMode,'OK')
    newTolerance = i_getTolerances(pHandles);
    OK = true;
else
    OK = false;
    newTolerance = tssf.tolerance;
end
delete(f);

% --------------------------------------------------------------------
% Function i_createLayout
% --------------------------------------------------------------------
function [layout, preferredSize] = i_createLayout(f, pHandles, tssf)

pHandles.info.figure = f;

factorNames = globalsignalnames(tssf);
tolerances  = tssf.tolerance;
numFactors = length(factorNames);

% Create the text and edit controls for the array
labels = cell(1,numFactors);
for i = 1:numFactors
    % Create the Edit Control
    pHandles.info.Edit{i} = uicontrol('Parent', f,...
        'Style', 'edit',...
        'BackgroundColor', 'w',...
        'String', num2str(tolerances(i)),...
        'UserData',tolerances(i),...
        'Callback', @(h,evt) xregCheckIsNum(h,'range',[0 Inf]));
    
    labels{i} = xregGui.labelcontrol('parent', f,...
        'LabelSizeMode', 'Relative',...
        'ControlSizeMode', 'Absolute',...
        'LabelAlignment', 'left',...
        'ControlSize', 100,...
        'LabelSize', 1,...
        'Control', pHandles.info.Edit{i},...
        'String', factorNames{i});
end
    

layout = xreggridbaglayout(f,...
    'dimension', [numFactors + 2, 3],...
    'elements', [repmat({[]}, 1,numFactors + 3)  labels],...
    'rowsizes', [-1 20*ones(1, numFactors) -1],...
    'gap', 5,...
    'colsizes', [-1 180 -1]);

preferredSize = [250 numFactors*25 + 60];

% --------------------------------------------------------------------
function values = i_getTolerances(pHandles)
% Pre-initialse the output
values = zeros(1, length(pHandles.info.Edit));
% Iterate over the edit boxes getting the values in turn
for i = 1:length(values)
    % Convert each in turn
    values(i) = str2double(get(pHandles.info.Edit{i}, 'String'));
end