www.gusucode.com > mbcmodels 工具箱 matlab 源码程序 > mbcmodels/@xreg3xspline/gui_globalmodpane.m
function lyt=gui_globalmodpane(m,action,figh,p,varargin) % GUI_GLOBALMODPANE Create part of GUI for linear model settings % % LYT=GUI_GLOBALMODPANE(M,'layout',FIG,P) creates a layout object % with callbacks defined for updating the model pointed to by P. % FIG is the figure to create it in. % % LYT=GUI_GLOBALMODPANE(M,'layout',FIG,P,'callback,CBSTR) attaches a % callback string, CBSTR, which is fired when the model definition % is changed. The string may contain the tokens %MODEL% and %POINTER% % which will be replaced with the current model and the pointer before % the callback is executed. % % FIG may also be a current copy of a layout in which case this % existing layout will be used instead of creating a new one. % Copyright 2000-2010 The MathWorks, Inc. and Ford Global Technologies, Inc. switch lower(action) case 'layout' if isa(figh,'xregcontainer') % update layout with new model info i_updatepointer(figh,p); else cbstr=''; if nargin>4 for n=1:2:length(varargin) switch lower(varargin{n}) case 'callback' cbstr=varargin{n+1}; end end end lyt=i_createlyt(figh,p,cbstr); end end return function lyt=i_createlyt(figh,p,cbstr) ud.callback=cbstr; ud.pointer=p; m=p.info; pUD = xregGui.RunTimePointer; pUD.LinkToObject(figh); ud.table = xregMdlGui.PolynomialSplineOrderEditor(... 'Parent', figh,... 'Model', m,... 'ModelChangedCallback', {@iModelChanged, pUD} ); %knot handling bits knts=get(m,'naturalknots'); nknts=length(knts); ud.numknots = mbcgui.widget.Spinner('Parent', figh, ... 'Min',1,... 'Max',50,... 'Rule','int',... 'Value',nknts,... 'Position',[0 0 60 20],... 'ClickIncrement',1,... 'Callback',{@iNumberKnots, pUD},... 'Visible','off'); ud.NumberKnotsLabel=xregGui.labelcontrol('parent',figh,... 'string','Number of knots:',... 'ControlSizeMode', 'absolute',... 'ControlSize', 40,... 'LabelSizeMode', 'relative',... 'position',[0 0 100 15],... 'control', ud.numknots,... 'visible','off'); ud.knots = xregMdlGui.PolynomialSplineKnotEditor( 'Parent', figh,... 'Model', m,... 'ModelChangedCallback',{@iModelChanged, pUD} ); intlvl=get(m,'interact'); % interaction level ud.interact=mbcgui.widget.Spinner('Parent', figh,... 'Min',0, ... 'Max',2,... 'Rule','int',... 'ClickIncrement',1,... 'Position',[0 0 60 20],... 'Callback',{@iInteract, pUD},... 'Value',intlvl,... 'Visible','off'); InteractionLevelLabel = xregGui.labelcontrol('parent',figh,... 'string','Interaction level:',... 'position',[0 0 100 15],... 'ControlSizeMode', 'absolute',... 'ControlSize', 40,... 'LabelSizeMode', 'relative',... 'control', ud.interact,... 'visible','off'); elements = {ud.table,[];... InteractionLevelLabel, ud.knots;... ud.NumberKnotsLabel,[];... [],[];... [],[]}; pUD.info = ud; lyt=xreggridbaglayout(figh,... 'dimension',[5,2],... 'rowsizes',[-1 20 20 15 15],... 'colsizes',[-1 100],... 'gap',5,... 'mergeblock', {[1 1], [1 2]},... 'mergeblock', {[2 5], [2 2]},... 'elements', elements,... 'Userdata', pUD); return function iInteract( src, evt, pUD ) ud = pUD.info; m=ud.pointer.info; p=ud.interact.Value; intlvl=get(m,'interact'); if p~=intlvl set(m,'interact',p); % change coefficients from zeros to default 1:n t=termorder(m); t=max(t); m=update(m,(1:t)'); ud.pointer.info=m; % fire callback if ~isempty(ud.callback) i_firecb(ud.callback,ud.pointer) end end function iNumberKnots( src, evt, pUD ) % get number of knots and alter knot table accordingly ud = pUD.info; m=ud.pointer.info; p=ud.numknots.Value; knts=get(m,'naturalknots'); nknts=length(knts); if p>nknts % add more knots knts(end+1:p)=knts(end); elseif p<nknts % destroy some knts=knts(1:p); else % what are we doing here anyway? return end set(m,'naturalknots',knts); % change coefficients from zeros to default 1:n t=termorder(m); t=max(t); m=update(m,(1:t)'); %update the PolynomialSplineOrderEditor table with the new model. ud.table.Model = m; %update the PolynomialSplineKnotEditor table with the new model. ud.knots.Model = m; ud.pointer.info=m; % fire callback if ~isempty(ud.callback) i_firecb(ud.callback,ud.pointer) end function iModelChanged( src, evt, pUD ) m = evt.data.NewModel; ud = pUD.info; if strcmp( evt.data.Type, 'SplineFactor' ) ud.knots.Model = m; elseif strcmp( evt.data.Type, 'KnotValue' ) % ?? elseif strcmp( evt.data.Type, 'Order' ) % ?? end ud.pointer.info=m; % fire callback if ~isempty(ud.callback) i_firecb(ud.callback,ud.pointer) end function i_updatepointer(lyt,p) % get the panes userdata from the layout pUD = get(lyt,'UserData'); ud = pUD.info; % get the model from the pointer m = p.info; %update the PolynomialSplineOrderEditor table with the new model. ud.table.Model = m; %update the PolynomialSplineKnotEditor table with the new model. ud.knots.Model = m; set(ud.numknots, 'Value', get(m,'numknots')); return function i_firecb(cbstr,ptr) xregcallback(cbstr, [], struct('ModelPointer', ptr))