www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/guiConTwostage.m
function [con, fitOptions, ok,HasChanged] = guiConTwostage( con, fitOptions,varargin ) %GUICONTWOSTAGE % % [con, ok,HasChanged] = guiConTwostage( con ) % Copyright 2008-2011 The MathWorks, Inc. and Ford Global Technologies, Inc. fsize = [600,500]; figh = xregdialog('name','Local Boundary Model Setup',... 'resize','off'); if nargin==4 && strcmpi(varargin{1},'parent') xregcenterfigure(figh, fsize,varargin{2}) else xregcenterfigure(figh, fsize) end T.isValidObject = true; T.fitOptions = fitOptions; T.constraint = con; p = xregGui.RunTimePointer(T); ud.Listener=handle.listener(p,findprop(classhandle(p),'info'),'PropertyPostSet',@iUpdate); p.LinkToObject(figh); % add ok, cancel okbtn = uicontrol('Style','pushbutton',... 'Parent',figh,... 'String','OK',... 'Callback', {@close, figh, 'ok'} ); cancbtn = uicontrol('Style','pushbutton',... 'Parent',figh,... 'String','Cancel',... 'Callback', {@close, figh, 'cancel'} ); helpbtn = mv_helpbutton(figh,'xreg_bdrymodeleditor'); lyt = i_createlyt(figh,p); ud.brd = xreggridbaglayout(figh, 'dimension',[2 4], ... 'rowsizes',[-1 25], ... 'border',[7 7 7 10], ... 'colsizes', [-1 65 65 65], ... 'gapx', 7, ... 'gapy', 10, ... 'mergeblock', {[1 1], [1 4]}, ... 'elements',{lyt,[], [],okbtn, [],cancbtn, [],helpbtn}); ud.figure=figh; figh.LayoutManager = ud.brd; set(ud.brd, 'packstatus', 'on'); set(lyt,'Visible','on'); HasChanged = true; set(figh,'UserData',ud); figh.showDialog(okbtn); tg = get(figh,'Tag'); if strcmp(tg, 'ok') % Call finalise on chosen class T = p.info; con = T.constraint; fitOptions = T.fitOptions; ok = T.isValidObject; else HasChanged = false; ok = false; end delete(figh); function close( ~, ~, fig, tag ) set( fig, 'Visible', 'off', 'Tag', tag ); end %------------------------------------------------------------ % SUBFUNCTION i_createlyt %------------------------------------------------------------ function lyt = i_createlyt(figh,p,varargin) if ~isa(figh,'xregcontainer') % list of model classes pUD = xregGui.RunTimePointer; pUD.LinkToObject(figh); ud.pointer = p; ud.figure = figh; ud.Group = {typename(contwostage),typename(conswitch)}; SC = xregGui.SystemColorsDbl; ud.class = uicontrol('Parent',figh,... 'Style','popupmenu',... 'Tag', 'ModelClassesPopup',... 'String',ud.Group,... 'Interruptible','off', ... 'BackgroundColor', SC.WINDOW_BG, ... 'Callback', {@i_classchng,pUD}); label = xregGui.labelcontrol('Parent', figh, ... 'string', 'Global evaluation:', ... 'LabelSizeMode', 'absolute', ... 'LabelSize', 120, ... 'Gap', 0, ... 'ControlSize', 150, ... 'Control', ud.class); crd = xregcardlayout(figh,'numcards',length(ud.Group)); ud.cardsdone = false(1,length(ud.Group)); ud.cards = crd; [lyt, ud.callback] = pCreateChooserLayout( con, figh, label, crd, true ); else pUD = get(figh, 'UserData'); ud = pUD.info; figh = get(figh,'Parent'); end ud=i_setvalues(ud,figh); pUD.info = ud; end %------------------------------------------------------------ % SUBFUNCTION i_setvalues %------------------------------------------------------------ function ud = i_setvalues(ud,figh) % Decide which card to show % Ask the gui_globalmodsetup which level it is operating at con = ud.pointer.info.constraint; val = find( strncmp( typename( con ),ud.Group,length(typename( con )) ) ); set(ud.class,'Value',val); if ~ud.cardsdone(val) % need to create card lyt = guiTypeLayout(con, figh,ud.pointer); attach(ud.cards,lyt,val); ud.cardsdone(val) = 1; else % update existing layout lyt = getcard(ud.cards,val); lyt = lyt{1}; guiTypeLayout(con, lyt,ud.pointer); end set(ud.cards,'currentcard',val); ud.callback(con); end %------------------------------------------------------------ % SUBFUNCTION i_classchng %------------------------------------------------------------ function i_classchng(~, ~, pUD) ud = pUD.info; val = get(ud.class,'Value'); if val~=get(ud.cards,'currentcard') set(ud.figure,'Pointer','watch'); %change needed T = ud.pointer.info; con = T.constraint; % try to create new model class switch val case 1 con = contwostage(con); fitOptions = getFitOptions(con,'all'); case 2 con = conswitch(con); fitOptions = getFitOptions(con,'all'); end T.fitOptions = fitOptions; T.constraint = con; ud.pointer.info = T; % update options space if ~ud.cardsdone(val) % need to create card set(ud.cards, 'packstatus', 'off'); lyt = guiTypeLayout(con,ud.figure,ud.pointer); attach(ud.cards,lyt,val); ud.cardsdone(val) = 1; else % update existing layout lyt = getcard(ud.cards,val); lyt = lyt{1}; lyt = guiTypeLayout(con,lyt,ud.pointer); end set(ud.cards,'packstatus','on', 'currentcard',val); pUD.info = ud; set(ud.figure,'Pointer','arrow'); ud.callback( con ); end end function iUpdate(~,~) T = p.info; if T.isValidObject set(okbtn,'Enable','on') HasChanged = true; else set(okbtn,'Enable','off') end end end