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

    function [dout,ok]=gui_reset(d,action,figh,ptr,varargin)
%GUI_RESET GUI for reinitialising design
%
%  [D,OK]=GUI_RESET(D) brings up a gui for reinitialising a design.
%  D=GUI_RESET(D,'layout',figh,ptr,callback) create the layout version.
%  OK=GUI_RESET(D,'finalise',lyt)  finalises the layout and returns an ok
%  flag.

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



if nargin<2
    action='create';
end

switch lower(action)
    case 'layout'
        dout=i_createlyt(d,figh,ptr,varargin{:});
        ok=1;
    case 'create'
        [dout,ok]=i_createfig(d);
    case 'finalise'
        dout=i_finalise(figh);

end




function [dout,ok]=i_createfig(d)
% precheck the design to make sure it will initialise
minp=min_points(d);
if isempty(minp)
    h=errordlg(['No points were found that will initialize this design with valid ',...
        'factor settings.  Check that the candidate set has not been over-constrained'],...
        'Error','modal');
    waitfor(h);
    dout=d;
    ok=0;
    return
end

dlg=mbcgui.container.Dialog('Name','Reset Design',...
    'Tag','design_reinit',...
    'Size',[310 300],...
    'Resize','off');
figh = dlg.Figure;
ptr= xregGui.RunTimePointer(d);
dlg.Content = i_createlyt(d,figh,ptr);


tg=dlg.showDialog();
if strcmpi(tg,'ok')
    i_finalise(dlg.Content);   % apply the re-init
    dout=ptr.info;
    ok=1;
else
    dout=d;
    ok=0;
end
delete(dlg);




function mainlyt=i_createlyt(des,figh,ptr,varargin)

if ~isa(figh,'xregcontainer')
    if nargin>3
        if strcmpi(varargin{1},'callback')
            cbstr=varargin{2};
        else
            cbstr='';
        end
    else
        cbstr='';
    end
    ud.fromcurrent=0;
    ud.totalp=0;
    ud.callback=cbstr;
    ud.pointer=ptr;
    ud.minp=0;

    udptr=xregGui.RunTimePointer;
    
    optsframe = mbcgui.container.layoutpanel(...
        'Parent', figh, ...
        'Title','Initial points from current design',...
        'BorderType', 'etchedin', ...
        'LayoutBorder',[10 10 10 5]);
    addframe = mbcgui.container.layoutpanel(...
        'Parent', figh, ...
        'Title','Additional design points',...
        'BorderType', 'etchedin', ...
        'LayoutBorder',[10 10 10 5]);
    
    % Limit size to the maximum matrix allowed in Matlab
    maxtotalp = floor(2^32/nfactors(des));
    ud.rbg=xregGui.rbgroup('parent',optsframe,...
        'nx',1,'ny',3,...
        'string',{'Replace the current points with a new initial design';...
        'Augment the current design with additional points';...
        'Keep only the fixed points from the current design'},...
        'gapy',2,...
        'callback',{@i_radioclick,udptr});
    txt(1)=uicontrol('Style','text',...
        'Parent',addframe,...
        'String','Points from current design:',...
        'HorizontalAlignment','left');
    txt(2)=uicontrol('Style','text',...
        'Parent',addframe,...
        'String','Minimum additional points required:',...
        'HorizontalAlignment','left');
    txt(3)=uicontrol('Style','text',...
        'Parent',addframe,...
        'String','Optional additional points:',...
        'HorizontalAlignment','left');
    txt(4)=uicontrol('Style','text',...
        'Parent',addframe,...
        'String','Total number of points:',...
        'HorizontalAlignment','left',...
        'FontWeight','bold');

    ud.current=uicontrol('Style','text',...
        'Parent',addframe,...
        'HorizontalAlignment','right');
    ud.minextra=uicontrol('Style','text',...
        'Parent',addframe,...
        'HorizontalAlignment','right');
    ud.extra =  mbcgui.widget.Spinner('Parent',addframe,...
        'Min',0,...
        'ClickIncrement',1,...
        'Rule','int',...
        'Callback',{@i_extraclick,udptr});
    ud.total = mbcgui.widget.Spinner('Parent',addframe,...
        'Min',0,...
        'Max', maxtotalp, ...
        'ClickIncrement',1,...
        'Rule','int',...
        'FontWeight', 'bold', ...
        'Callback',{@i_totalclick,udptr});


    grd=xreggridbaglayout(optsframe,...
        'dimension',[1 1],...
        'rowsizes',64,...
        'elements',{ud.rbg});
    set(optsframe, 'LayoutComponent', {grd});

    grd=xreggridbaglayout(addframe,'dimension',[11 3],...
        'rowsizes',[15 5 15 5 3 15 2 5 3 15 2],...
        'colsizes',[170 50 10],...
        'gapx',10,...
        'mergeblock',{[5 7],[2 3]},...
        'mergeblock',{[9 11],[2 3]},...
        'elements',{txt(1),[],txt(2),[],[],txt(3),[],[],[],txt(4),[],...
        ud.current,[],ud.minextra,[],ud.extra,[],[],[],ud.total});
    set(addframe, 'LayoutComponent', {grd});

    mainlyt=xreggridlayout(figh,'correctalg','on',...
        'dimension',[2 1],...
        'gapy',10,...
        'elements',{optsframe,addframe},...
        'userdata',udptr);
    udptr.info=ud;
    i_initud(udptr);
    i_radioclick([],[],udptr);
else
    % update with new pointer
    mainlyt=figh;
    udptr=get(mainlyt,'UserData');
    ud=udptr.info;
    ud.pointer=ptr;
    udptr.info=ud;
    i_radioclick([],[],udptr);
end



function i_initud(p)
ud=p.info;
des=ud.pointer.info;

minp=min_points(des);
if isempty(minp)
    minp=0;
end
ud.minp=minp;

% decide which options in radio-button group are available
if npoints(des)
    if length(fixpoints(des))
        envect=[1;1;1];
        sel=2;
    else
        envect=[1;1;0];
        sel=2;
    end
else
    envect=[1;0;0];
    sel=1;
end
set(ud.rbg,'enablearray',envect,'selected',sel);

val=get(ud.rbg,'Selected');
switch val
    case 1
        ud.fromcurrent=0;
    case 2
        ud.fromcurrent=npoints(des);
    case 3
        ud.fromcurrent=length(fixpoints(des));
end

ud.totalp=max(ud.minp,ud.fromcurrent)+ud.extra.Value;
p.info=ud;



function i_extraclick(src,evt,p)
ud = p.info;
ud.totalp = max(ud.minp,ud.fromcurrent)+ud.extra.Value;
p.info = ud;
ud.total.Value = ud.totalp;


function i_totalclick(src,evt,p)
ud = p.info;
ud.totalp = ud.total.Value;
p.info = ud;
needed = max(0,ud.minp-ud.fromcurrent);
extra = max(0,ud.totalp-ud.fromcurrent-needed);
ud.extra.Value = extra;


function i_radioclick(src,evt,p)
ud=p.info;
des=ud.pointer.info;
% try to keep total number of points the same
val=get(ud.rbg,'Selected');
switch val
    case 1
        ud.fromcurrent=0;
    case 2
        ud.fromcurrent=npoints(des);
    case 3
        ud.fromcurrent=length(fixpoints(des));
end
needed=max(0,ud.minp-ud.fromcurrent);
extra=max(0,ud.totalp-ud.fromcurrent-needed);
maxtotalp = floor(2^32/nfactors(des));
set(ud.extra, 'Max', maxtotalp-ud.fromcurrent-needed, 'Value', extra);

ud.totalp=ud.fromcurrent+needed+extra;
set(ud.total, 'Min', max(ud.minp,ud.fromcurrent), 'Value', ud.totalp);

set([ud.current;ud.minextra],{'String'},...
    {sprintf(' %d',ud.fromcurrent); sprintf(' %d',needed)});
p.info=ud;



function ok=i_finalise(lyt)
ptr=get(lyt,'UserData');
ud=ptr.info;
val=get(ud.rbg,'Selected');
des=ud.pointer.info;

ok=0;
n=0;
while ~ok && n<=10
    n=n+1;
    switch val
        case 1
            des=clear(des);
            des=augment(des,ud.totalp);
        case 2
            np=max(0,ud.minp-ud.fromcurrent)+ud.extra.Value;
            des=augment(des,np);
        case 3
            des=deletefreepoints(des);
            np=max(0,ud.minp-ud.fromcurrent)+ud.extra.Value;
            des=augment(des,np);
    end
    ok=rankcheck(des);
end

ud.pointer.info=des;
xregcallback(ud.callback);