www.gusucode.com > mbcmodels 工具箱 matlab 源码程序 > mbcmodels/@localtruncps/gui_localmodopts.m

    function [m,ok] = gui_localmodopts(m,action,fig,p)
%GUI_LOCALMODOPTS Local model options dialog
%
%   [M,OK]=GUI_LOCALMODOPTS(M) creates a modal dialog for setting up
%   options specific to the current local model class.  This function is
%   the default, creating a simple 'No options available dialog'.  Overload
%   it in local models which have additional options such as spline order.
%
%   LYT=GUI_LOCALMODOPTS(M,'layout',FIG,P) creates and returns a layout in
%   figure FIG, based around altering the model in the pointer P.  This
%   interface must be supported by overloaded methods.  FIG may also be an
%   existing layout object in which case the layout is updated with fresh
%   information from the model in P.

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


if nargin<2
    action='figure';
end

switch lower(action)
    case 'figure'
        [m,ok] = gui_localmodoptsdlg(m);
    case 'layout'
        m=i_createlyt(fig,p);
end


function lyt=i_createlyt(figh,p)

if ~isa(figh,'xregcontainer')
    ud.pointer=p;
    ud.figh=figh;
    text1=uicontrol('Parent',figh,...
        'Style','text',...
        'Visible','off',...
        'String','Order:',...
        'HorizontalAlignment','left',...
        'Position',[0 0 90 15]);
    ud.loword=uicontrol('Parent',figh,...
        'Style','edit',...
        'Visible','off',...
        'BackgroundColor','w',...
        'Interruptible','off',...
        'Position',[0 0 50 20]);
    % only one knot for now
    text2=uicontrol('Parent',figh,...
        'Style','text',...
        'String','Number of knots:',...
        'Visible','off',...
        'HorizontalAlignment','left',...
        'Position',[0 0 90 15]);
    ud.knots=uicontrol('Parent',figh,...
        'Style','edit',...
        'Visible','off',...
        'BackgroundColor','w',...
        'Interruptible','off',...
        'Position',[0 0 50 20]);

    % only one knot for now
    ud.terms=uicontrol('Parent',figh,...
        'Style','push',...
        'Visible','off',...
        'String','Polynomial...',...
        'Interruptible','off',...
        'Position',[0 0 70 25]);

    % callbacks
    set(ud.loword,'Callback',{@i_ordchng, ud.loword});
    set(ud.knots,'Callback',{@i_knotchng, ud.loword});
    set(ud.terms,'Callback',{@i_termsel, ud.loword});

    flw1=xregflowlayout(figh,...
        'gap',5,...
        'border',[-5 0 0 0],...
        'orientation','left/center',...
        'elements',{text1,ud.loword,ud.terms});
    flw2=xregflowlayout(figh,...
        'gap',5,...
        'border',[-5 0 0 0],...
        'orientation','left/center',...
        'elements',{text2,ud.knots});
    lyt=xreggridbaglayout(figh, ...
        'dimension',[2,1],...
        'rowsizes', [25 20], ...
        'gap',10, ...
        'elements',{flw1,flw2},...
        'border',[0 0 0 0]);
    set(ud.loword,'UserData',ud);
else
    el = get(figh,'elements');
    el=get(el{1},'elements');
    ud=get(el{2},'UserData');
    ud.pointer=p;
    set(el{2},'UserData',ud);
    lyt=figh;
end
i_setvalues(ud,p);



function i_setvalues(ud,p)
m = p.info;
ord = get(m,'order');
k = length(get(m,'knot'));
set(ud.loword,'String',ord-1);
set(ud.knots,'String',k);


function i_ordchng(~, ~, udh)
ud = get(udh,'UserData');

val=str2num(get(ud.loword,'String'));
m=ud.pointer.info;
ord=get(m,'order');
% check val
if isempty(val) || length(val)>1 || val~=floor(val) ...
        || val<1
    % minimum order is one
    set(ud.loword,'String',ord-1);
else
    % order is one more than display
    m=set(m,'order',val+1);
    ud.pointer.info= m ;
end


function i_knotchng(~, ~, udh)
ud=get(udh,'UserData');

val=str2num(get(ud.knots,'String')); %#ok<*ST2NM>
m=ud.pointer.info;
k=length(m.knots);
% check val
if isempty(val) || length(val)>1 || val~=floor(val) ...
        || val<1
    set(ud.knots,'String',k);
elseif val~=k
    set(m,'knot',zeros(val,1));
    m= SetFeat(m,'default');
    ud.pointer.info=m;
end


function i_termsel(~, ~, udh)

ud=get(udh,'UserData');
m=ud.pointer.info;

dlg = mbcgui.container.Dialog('Name','Polynomial Terms',...
    'Size',[220 200],...
    'Tag','LocalOpts',...
    'Buttons','OK_CANCEL',...
    'Resize','off');
figh = dlg.Figure;

frm = mbcgui.container.layoutpanel(...
    'Parent', figh, ...
    'BorderType', 'etchedin');
tsel= term_selector(frm,'frame.visible','off');
% The layoutpanel does not like the xregtable classes because they violate
% the interface by overriding size.
L = xreglayerlayout(frm, 'elements', {tsel});
set(frm, 'LayoutComponent', {L});

poly= polynom(m);
tsstat= getstatus(m); %#ok<*DGETST>
model(tsel,poly);

dlg.Content =frm;
closeMode = dlg.showDialog();
if strcmp(closeMode, 'OK')
    mout = model(tsel);
    polyst = getstatus(mout);
    polyst(polyst==3) = 1;
    np = length(polyst);
    if ~all(tsstat(1:np)==polyst)
        tsstat(1:np) = polyst;
        m.xreglinear= set(m.xreglinear,'status',tsstat);
        m = DelFeat(m,':');
        [~,Defaults,values] = features(m);
        m = AddFeat(m,values,Defaults);
        ud.pointer.info = m;
    end
end
delete(dlg);