www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/@xregdesign/gui_candspace.m
function [dout,ok]=gui_candspace(des,action,figh,ptr,varargin) %GUI_CANDSPACE GUI interface for the candspace settings. % % [D,OK]=GUI_CANDSPACE(D,'figure') creates a blocking figure for editing % the candidate set definitions. % % LYT=GUI_CANDSPACE(D,'layout',FIG,PTR[,'callback',CBSTR]) creates and % returns a layout object containing the gui for editing the design D. FIG % is the figure to place the layout in. PTR is a pointer to the design, % used to maintain a dynamic link with other parts of a GUI. The optional % arguments 'callback',CBSTR may be specified to have a callback function % evaluated whenever the set definition changes. % % The callback string may contain the keywords %OBJECT% and %POINTER% % which will be parsed out and replaced with copies of the design object % and the pointer to the object respectively. % Copyright 2000-2015 The MathWorks, Inc. and Ford Global Technologies, Inc. if nargin<2 action='figure'; end switch lower(action) case 'figure' [dout,ok]=i_createfig(des); case 'layout' dout=i_createlyt(figh,ptr,varargin{:}); ok=1; case 'finalise' i_finalise(figh); end function [dout,ok]=i_createfig(des) % create figure dlg=mbcgui.container.Dialog('Name','Candidate Set',... 'Size',[370 380],... 'HelpCode','xreg_desCandSet',... 'Resize','off'); figh = dlg.Figure; % There are problems changing design candidate settings when % constraints are present, so they are temporarily removed here. saved_c=des.constraints; des.constraints=[]; ptr=xregpointer(des); dlg.Content=i_createlyt(figh,ptr,'callback',@iFireFig); dlg.ValidationFcn = @() validateCandSpace(dlg,ptr); tg=dlg.showDialog(); if strcmp(tg,'OK') dout=ptr.info; dout.constraints=saved_c; dout=EvalConstraints(dout); ok=1; else des.constraints=saved_c; dout=des; ok=0; end % free pointer freeptr(ptr); delete(dlg); function OK = validateCandSpace(dlg,ptr) i_finalise(dlg.Content) dout=ptr.info; if ~checkcandsize(dout) % warn user btn=questdlg(sprintf(['These candidate settings define a large candidate set (%d points). ' ... 'Too large a set may lock up your computer if used with constraints. Do you want to ' ... 'continue or go back and alter the settings?'], ncand(dout)),... 'Warning','Continue','Alter','Alter'); OK = strcmp(btn,'Continue'); else OK = true; end function [lyt,cptr]=i_createlyt(figh,ptr,varargin) if ~isa(figh,'xregcontainer') csI=csetinterface; csI=set(csI,'typefilter',0); ud.pointer=ptr; ud.cspointer= xregGui.RunTimePointer(candspace(ud.pointer.info)); ud.cspointer.LinkToObject(figh); ud.figure=figh; ud.funcs=get(csI,'classNames'); ud.lytsdone=zeros(1,length(ud.funcs)); ud.model=model(ud.pointer.info); % used for coding/invcoding, not changed ud.txt1=uicontrol('Style','text',... 'Parent',figh,... 'String','Generation algorithm:',... 'HorizontalAlignment','left',... 'Visible','off',... 'Enable','inactive'); ud.popup=uicontrol('Parent',figh,... 'Style','popupmenu',... 'String',get(csI,'FullNames'),... 'UserData',xregdesign,... 'BackgroundColor','w',... 'Visible','off'); ud.reps=uicontrol('Parent',figh,... 'Style','checkbox',... 'String','Allow replicated points in design',... 'Visible','off'); ud.candsize=mbcgui.widget.IconText('Parent',figh,... 'String','Unconstrained candidate set size:',... 'Visible','off',... 'Tag','CandSizeText'); udh=ud.txt1; set(ud.popup,'Callback',{@i_algchng,udh}); set(ud.reps,'Callback',{@i_reps,udh}); ud.callback=''; ud.updatenow=1; if nargin>2 for n=1:2:length(varargin) switch lower(varargin{n}) case 'callback' ud.callback=varargin{n+1}; end end end ud.optsframe=mbcgui.container.layoutpanel(... 'Parent', figh,... 'Visible','off',... 'Title','Options',... 'BorderType', 'etchedin', ... 'LayoutBorder',[10 10 10 5]); ud.crd=xregcardlayout(ud.optsframe,... 'numcards',length(ud.funcs),... 'packstatus','off'); set(ud.optsframe, 'LayoutComponent', ud.crd); lyt=xreggridbaglayout(figh,'correctalg','on',... 'dimension',[9 3],... 'rowsizes',[3 15 2 5 15,3 20 10 -1],... 'colsizes',[105 150 -1],... 'gapx',10,... 'mergeblock',{[7 7],[1 2]},... 'mergeblock',{[9 9],[1 3]},... 'mergeblock',{[1 3],[2 2]},... 'mergeblock',{[5 5],[1 2]},... 'elements',{[],ud.txt1,[],[],ud.candsize,[],ud.reps,[],ud.optsframe,ud.popup},... 'userdata',udh); ud.layout=lyt; else % update using given layout udh=get(figh,'UserData'); ud=get(udh,'UserData'); ud.pointer=ptr; if nargin>2 for n=1:2:length(varargin) switch lower(varargin{n}) case 'callback' ud.callback=varargin{n+1}; end end end lyt=figh; end ud=i_setvalues(ud); set(udh,'UserData',ud); cptr=ud.cspointer; function ud=i_setvalues(ud) des=ud.pointer.info; % reps checkbox set(ud.reps,'Value',allowreps(des)); % decide alg type popval=find(strcmp(class(des.candset),ud.funcs)); set(ud.popup,'Value',popval); if ~ud.lytsdone(popval) % create options and attach lyt=propertypage(ud.cspointer.info,'layout',ud.optsframe,'callback',{@i_csetchng,ud.txt1}); lyt=propertypage(ud.cspointer.info,'update',lyt,ud.cspointer,ud.model); attach(ud.crd,lyt,popval); set(lyt,'packstatus','on'); ud.lytsdone(popval)=1; else % update current lyt=getcard(ud.crd,popval); propertypage(ud.cspointer.info,'update',lyt{1},ud.cspointer,ud.model); end % select popval page set(ud.crd,'currentcard',popval); n = npoints(ud.cspointer.info); if n>=flintmax; ic = 'error'; elseif n> 1e8 ic = 'warning'; else ic=''; end set(ud.candsize,... 'String',sprintf('Unconstrained candidate set size: %10.6g',n ),... 'Icon',ic) function i_algchng(~,~,udh) ud=get(udh,'UserData'); des=ud.pointer.info; cs=ud.cspointer.info; popval=get(ud.popup,'Value'); if get(ud.crd,'currentcard')==popval return end fig = ancestor(ud.figure,'figure'); set(fig,'Pointer','watch'); CS=toCandidateSet(cs); cs=feval(ud.funcs{popval},CS); ud.cspointer.info=cs; des.candset=cs; des.designindex(:)=0; des.candstate=des.candstate+1; ud.pointer.info=des; if ~ud.lytsdone(popval) % create options and attach lyt=propertypage(cs,'layout',ud.optsframe,'callback',{@i_csetchng,ud.txt1}); lyt=propertypage(cs,'update',lyt,ud.cspointer,ud.model); attach(ud.crd,lyt,popval); set(lyt,'packstatus','on'); ud.lytsdone(popval)=1; else % update current lyt=getcard(ud.crd,popval); propertypage(cs,'update',lyt{1},ud.cspointer,ud.model); end % select popval page set(ud.crd,'currentcard',popval); set(udh,'UserData',ud); if ~isempty(ud.callback) i_firecb(ud); end set(fig,'Pointer','arrow'); function i_firecb(ud) xregcallback(ud.callback,[],[]); n = npoints(ud.cspointer.info); if n>=flintmax; ic = 'error'; elseif n> 1e8 ic = 'warning'; else ic=''; end set(ud.candsize,... 'String',sprintf('Unconstrained candidate set size: %10.6g',n ),... 'Icon',ic) function i_reps(~,~,udh) ud=get(udh,'UserData'); ud.pointer.info=allowreps(ud.pointer.info,get(ud.reps,'Value')); if ~isempty(ud.callback) i_firecb(ud); end function i_csetchng(~,~,udh) % Candidate set property page has been altered ud=get(udh,'UserData'); des=ud.pointer.info; des.candset=ud.cspointer.info; des.designindex(:)=0; des.candstate=des.candstate+1; ud.pointer.info=des; if ~isempty(ud.callback) i_firecb(ud); end function i_finalise(lyt) % finalise the cset selection. % get handle to ud udh=get(lyt,'UserData'); ud=get(udh,'UserData'); crds=getcard(ud.crd,get(ud.crd,'currentcard')); propertypage(ud.cspointer.info,'finalise',crds{1}); if ~isGenerated(ud.cspointer.info) ud.cspointer.info = generate(ud.cspointer.info); end function iFireFig(~,~)