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

    function out = propertypage(obj,action,varargin)
%PROPERTYPAGE Create a property gui for the sobol sequence
%
%   This should be overloaded by child classes
%
%   Interface:  Lyt=propertypage(cs,'layout',fig);
%               Lyt=propertypage(cs,'update',lyt,p_cs,model);
%               Lyt=propertypage(cs,'enable',lyt,enstate);

%  Copyright 2007-2015 The MathWorks, Inc.

switch lower(action)
    case 'layout'
        out=i_createlyt(obj, varargin{:});
    case 'update'
        out=i_update(varargin{:});
    case 'finalise'
        out=i_finalise(varargin{:});
    case 'enable'
        out=i_setenable(varargin{:});
end


function lyt = i_createlyt(obj, figh,varargin)

pUD = xregGui.RunTimePointer;

% create new layout in figure
ud.pointer = [];
ud.figure = figh;
ud.model = [];
ud.callback = '';
ud.editablePoints = true;

for n = 1:2:length(varargin)
    switch lower(varargin{n})
        case 'callback'
            ud.callback = varargin{n+1};
        case 'editablepoints'
            ud.editablePoints = varargin{n+1};
    end
end

if ud.editablePoints
    ud.Size = mbcgui.widget.Spinner('Parent', figh,...
        'Min',2,...
        'Max',2^53,...
        'ClickIncrement',10,...
        'Rule','int', ...
        'Callback',{@iNChange,pUD});
else
    ud.Size = uicontrol('Parent', figh, ...
        'Style', 'text', ...
        'String', '', ...
        'HorizontalAlignment','left');
end
ud.SizeLabel = xregGui.labelcontrol('parent',figh,...
    'string','Sequence size:',...
    'ControlSize', 70, ...
    'LabelSizeMode', 'absolute', ...
    'LabelSize', 90, ...
    'Control', ud.Size);
ud.SkipMode = xregGui.rbgroup('Parent', figh, ...
    'nx', 1, 'ny', 3, ...
    'String', {'No skip'; ...
    'Skip initial 2^k points'; ...
    'Custom skip:'}, ...
    'Callback', {@iSkipModeChange, pUD});
ud.Skip  = mbcgui.widget.Spinner('Parent', figh, ...
    'Rule', 'int', ...
    'Min', 0, ...
    'Callback', {@iSkipChange, pUD});
    
ud.Scramble = uicontrol('Parent',figh,...
    'Style','checkbox',...
    'String','Apply Matousek Affine Owen scramble',...
    'Callback',{@iScrambleChange,pUD});

[ud.RangeTable, ud.RangeTableUpdate] = pRangeEditor(obj, figh, ...
    ud.pointer, ud.model, ud.callback);
ud.RangeLabel = uicontrol('Parent',figh, ...
    'Style', 'text', ...
    'HorizontalAlignment', 'left', ...
    'String', 'Range of values:');

SkipLyt = xreggridbaglayout(figh, ...
    'dimension', [2 1], ...
    'rowsizes', [-1 20], ...
    'elements', {[], ud.Skip});
lyt = xreggridbaglayout(figh, ...
    'userdata', pUD, ...
    'dimension', [8 3], ...
    'rowsizes', [20 10 60 10 15 10 15 -1], ...
    'colsizes', [140 70 -1], ...
    'mergeblock', {[1 1], [1 2]}, ...
    'mergeblock', {[5 5], [1 2]}, ...
    'mergeblock', {[7 7], [1 2]}, ...
    'mergeblock', {[8 8], [1 3]}, ...
    'elements', {ud.SizeLabel, [], ...
    ud.SkipMode, [], ud.Scramble, [], ud.RangeLabel, ud.RangeTable, ...
    [], [], SkipLyt});

ud.layout = lyt;
pUD.info = ud;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% External update function.                          %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function lyt = i_update(lyt,p,m)
pUD = get(lyt, 'UserData');

% update current layout
ud = pUD.info;
ud.pointer = p;
ud.model = m;
ud = i_setvalues(ud);
pUD.info = ud;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Set all strings, values etc from data in ud  %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function ud = i_setvalues(ud)
cs = ud.pointer.info;

% Set values from cs into the UI
if ud.editablePoints
    set(ud.Size,'Value',get(cs,'n'));
else
    set(ud.Size,'String',sprintf('%d', get(cs,'n')));
end
set(ud.Scramble, 'Value', ~isempty(get(cs, 'Scramble')));

SkipM = get(cs, 'SkipMode');
RBvals = [1 3 2 3];   % Radiobutton to use for each mode
SkipSel = RBvals(SkipM+1);
set(ud.SkipMode, 'Selected', SkipSel);
set(ud.Skip, 'Value', get(cs, 'Skip'));
if SkipSel==3
    set(ud.Skip, 'Enable', 'on');
else
    set(ud.Skip, 'Enable','off');
end

% Set up the range table
ud.RangeTableUpdate(ud.pointer, ud.model);


function lyt=i_finalise(lyt)
pUD = get(lyt, 'UserData');
ud = pUD.info;
if ~isempty(ud.pointer)
    cs = ud.pointer.info;
        
    % Generate the object if it needs to be.
    if ~isGenerated(cs)
        cs = generate(cs);
    end
       
    ud.pointer.info = cs;
end


function lyt = i_setenable(lyt,state)
pUD = get(lyt,'UserData');
ud = pUD.info;
set(ud.SizeLabel, 'Enable', state);
set(ud.Scramble, 'Enable', state);
set(ud.RangeTable, 'Enable', state);
set(ud.SkipMode, 'Enable', state);
set(ud.Skip, 'Enable', state);



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Callbacks from each object %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function iNChange(obj,nul,pUD)
ud = pUD.info;
val = get(ud.Size,'Value');
ud.pointer.info = set(ud.pointer.info,'N',val);
xregcallback(ud.callback,ud.layout,[]);


function iScrambleChange(obj,nul,pUD)
ud = pUD.info;
val = get(ud.Scramble,'Value');
cs = ud.pointer.info;
if val
    cs = set(cs, 'Scramble', 'MatousekAffineOwen');
else
    cs = set(cs, 'Scramble', '');
end
ud.pointer.info = cs;
xregcallback(ud.callback,ud.layout,[]);


function iSkipModeChange(src, evt, pUD)
ud = pUD.info;
val = get(ud.SkipMode,'Selected');
Modes = [0 2 3];
cs = ud.pointer.info;
cs = set(cs, 'SkipMode', Modes(val));
if val==3
    cs = set(cs, 'Skip', ud.Skip.Value);
    
    % Enable the custom skip edit
    set(ud.Skip, 'Enable', 'on');
    
else
    % Disable the custom ckip edit
    set(ud.Skip, 'Enable', 'off');
end
ud.pointer.info = cs;
xregcallback(ud.callback,ud.layout,[]);


function iSkipChange(src, evt, pUD)
ud = pUD.info;
val = ud.Skip.Value;
cs = ud.pointer.info;
cs = set(cs, 'Skip', val);
ud.pointer.info = cs;
xregcallback(ud.callback,ud.layout,[]);