www.gusucode.com > mbcdesign 工具箱 matlab 源码程序 > mbcdesign/@xregdesign/gui_generateClassical.m
function [dout,ok] = gui_generateClassical(d) %gui_generateClassical GUI for choosing a pre-defined classical design. % % [DOUT,OK]=gui_generateClassical(D) invokes a dialog to choose a % pre-defined design classical design. % Copyright 2000-2015 The MathWorks, Inc. and Ford Global Technologies, Inc. if npoints(d) % do an add/overwrite dialog [action,ok]=designAugmentReplaceGUI(d); if ~ok dout=d; return end else action=1; end % Display a list of all designs for this type nm='Classical Design Browser'; htag='xreg_desClassical'; dlg = mbcgui.container.Dialog('Name', nm, ... 'HelpCode', htag, ... 'PersistPosition', true, ... 'Tag', 'DesignBrowser', ... 'ContentBorder', [7 0 7 10], ... 'Size', [700 450]); dlg.Figure.MinimumSize = [600 380]; fH = dlg.Figure; p=xregpointer([]); [lyt,GUI_STATE]=i_createlyt(fH,p,d); if GUI_STATE EN_STATE = true; else EN_STATE = false; end dlg.Enabled = EN_STATE; dlg.Content = lyt; Result = dlg.showDialog(); if strcmp(Result,'OK') ok=1; i_finalise(lyt); cs=p.info; else ok=0; end freeptr(p); delete(dlg); % Use the new candidate set or do a no-op if ~ok dout = d; else ActionStrs = {'replace', 'add', 'replacefree'}; dout = ClassicDesign(d,cs,ActionStrs{action},'constrain'); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Function to create the browser GUI % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [lyt, GUI_STATE]=i_createlyt(fH, p, d) ud.pointer = p; ud.figure = fH; ud.model = model(d); c = constraints(d); if isempty(c) ud.constraints = []; else ud.constraints = reset(c); % keep this constraints object lightweight end ud.design = d; ud.autopreview = true; ud.ispreviewed = false; % Get list of candidateset objects csI=csetinterface; csI=set(csI,'typefilter',2); csI=set(csI,'nffilter',nfactors(d)); viewlist=get(csI,'fullnames'); ud.createlist=get(csI,'classnames'); ud.cards=zeros(1,length(ud.createlist)); if ~isempty(viewlist) % available designs to choose from GUI_STATE=true; ENABLE_SETTING='on'; [s,info]=getstyle(d); if (s-1) == 2 % use the current settings as default but reset the candidateset ud.pointer.info=reset(info); ind=find( strcmp( class( info ),ud.createlist ) ); if isempty(ind) ind=1; end else tgt=gettarget(ud.model); csP=candidateset(tgt); ud.pointer.info=feval(ud.createlist{1},csP); ind=1; end else % no available designs GUI_STATE=false; ENABLE_SETTING='off'; ind=1; viewlist={''}; end sc=xregGui.SystemColorsDbl; ud.typepop=uicontrol('Parent',fH,... 'Tag', 'DesignStylePopup',... 'Style','popupmenu',... 'Enable',ENABLE_SETTING,... 'Value',ind,... 'String',viewlist,... 'Interruptible','off',... 'BackgroundColor',sc.WINDOW_BG); ud.typetxt = xregGui.labelcontrol('Parent', fH, ... 'LabelSizeMode', 'absolute', ... 'LabelSize', 70, ... 'ControlSize', 180, ... 'String', 'Design type:', ... 'Control', ud.typepop, ... 'Enable', ENABLE_SETTING); ud.optsframe = mbcgui.container.layoutpanel(... 'Parent', fH, ... 'Title','Options',... 'BorderType', 'etchedin', ... 'LayoutBorder',[10 10 10 5]); ud.previewframe = mbcgui.container.layoutpanel(... 'Parent', fH, ... 'Title','Preview',... 'BorderType', 'etchedin', ... 'LayoutBorder',[10 10 10 5]); ud.PreviewCheck = uicontrol('Parent',ud.previewframe,... 'Style','checkbox',... 'String','Automatically update preview',... 'Enable',ENABLE_SETTING,... 'Value', 1, ... 'Tag', 'AutoUpdate'); ud.NoPreviewText = uicontrol('Parent',ud.previewframe,... 'Style','text',... 'HorizontalAlignment','center', ... 'String', 'Press Generate to create a preview of the currently selected design.'); NoPreviewLyt = xreglayerlayout(ud.previewframe, ... 'elements', {ud.NoPreviewText}, ... 'border', [50 40 50 40]); udh=ud.typetxt; if GUI_STATE proplyt=propertypage(p.info,'layout',ud.optsframe,'callback',{@i_optschange,ud.typetxt}); crd=xregcardlayout(ud.optsframe,'numcards',1, 'packstatus', 'off'); attach(crd,proplyt,1); else crd=uicontrol('Parent',ud.optsframe,... 'Visible','off',... 'Style','text',... 'Enable','inactive',... 'HorizontalAlignment','left',... 'String',['There are no design styles of this type available that are compatible with',... ' your current settings. Please try a different type of design, or change the number',... ' of input factors in your experiment.']); end ud.cardlay=crd; set(ud.optsframe, 'LayoutComponent', {crd}) ud.tabbedPreview = mbcgui.graph.TabbedGraphs(ud.previewframe, d.nfactors); ud.previewcards = xregcardlayout(ud.previewframe, 'numcards', 2); attach(ud.previewcards,ud.tabbedPreview,1); attach(ud.previewcards,NoPreviewLyt,2); GenGrid = xreggridbaglayout(ud.previewframe, ... 'dimension', [1 1], ... 'gapx', 15, ... 'elements', {ud.PreviewCheck}); % create size of design labels in preview frame ud.npointstotaltxt = uicontrol('Parent',ud.previewframe,... 'Style','text',... 'Enable',ENABLE_SETTING,... 'HorizontalAlignment','left'); ud.npointscontxt = uicontrol('Parent',ud.previewframe,... 'Style','text',... 'Enable',ENABLE_SETTING,... 'HorizontalAlignment','left'); ud.TotalPointsLbl = xregGui.labelcontrol('Parent', ud.previewframe, ... 'LabelAlignment', 'right', ... 'String', 'Size of unconstrained design:', ... 'Control', ud.npointstotaltxt); ud.ConPointsLbl = xregGui.labelcontrol('Parent', ud.previewframe, ... 'LabelAlignment', 'right', ... 'String', 'Size of constrained design:', ... 'Control', ud.npointscontxt); % layout preview frame grd=xreggridbaglayout(ud.previewframe, ... 'dimension',[9 2],... 'rowsizes',[25 10 15 2 15 10 2 -1 25], ... 'colsizes', [222 -1], ... 'mergeblock', {[1 1], [1 2]}, ... 'mergeblock', {[7 9], [1 2]}, ... 'elements',{GenGrid, [], ud.TotalPointsLbl, [], ud.ConPointsLbl, [], ud.previewcards, [], [], ... [], [], [], [], [], [], [], [], []}); optsLayout = ud.optsframe; set(ud.previewframe, 'LayoutComponent', {grd}); lyt=xreggridbaglayout(fH, ... 'dimension',[2 3],... 'rowsizes',[20 -1], ... 'colsizes', [350 300 -1], ... 'gap',10, ... 'mergeblock', {[1 1], [1 3]}, ... 'mergeblock', {[2 2], [2 3]}, ... 'elements',{ud.typetxt, optsLayout, [], ud.previewframe}); set(ud.typepop,'Callback',{@i_typechange,udh}); set(ud.PreviewCheck,'Callback',{@i_prevchange,udh}); if GUI_STATE ud.cards(ind) = 1; end ud.GUI_STATE=GUI_STATE; ud=i_setvalsinit(ud); ud=i_setvalues(ud); set(udh,'UserData',ud); function ud=i_setvalsinit(ud) % Check whether to start with the preview pane active ud.autopreview = ud.pointer.checkPreview; set(ud.PreviewCheck, 'Value', ud.autopreview); ud = i_switchpreview(ud); if ud.GUI_STATE nf=ud.pointer.nfactors; if nf>=2 % Start on the 2D tab ud.tabbedPreview.selectTab(2); if ud.autopreview set(ud.previewcards, 'CurrentCard', 1); end end end % initialise factor names in graph objects if ud.GUI_STATE symb=get(ud.model,'symbol'); ud.tabbedPreview.setFactors(symb); end function ud=i_setvalues(ud) val=get(ud.typepop,'Value'); if val>0 && ud.GUI_STATE % check and create property page if ~ud.cards(val) nc=get(ud.cardlay,'numcards'); set(ud.cardlay,'numcards',nc+1); proplyt=propertypage(ud.pointer.info,'layout',ud.optsframe,'callback',{@i_optschange,ud.typetxt}, 'editablePoints', false); attach(ud.cardlay,proplyt,nc+1); ud.cards(val)=nc+1; else proplyt=getcard(ud.cardlay,ud.cards(val)); proplyt=proplyt{1}; end % update propertypage propertypage(ud.pointer.info,'update',proplyt,ud.pointer,ud.model); set(proplyt,'packstatus','on'); set(ud.cardlay,'currentcard',ud.cards(val)); % update constrained points spinner ud.constrainedpoints.Value = npoints(ud.pointer.info); end if ud.autopreview % update preview if ud.GUI_STATE ud=i_dopreview(ud); end elseif ud.ispreviewed % Turn off preview as it is now assumed to be invalid ud.ispreviewed = false; ud = i_switchpreview(ud); end % Redraw the preview panel function ud = i_dopreview(ud, Regen) if nargin<2 Regen = false; end % Apply the current design settings proplyt=getcard(ud.cardlay); propertypage(ud.pointer.info,'apply',proplyt{1}); if Regen ud.pointer.info = reset(ud.pointer.info); end % Call generate on the candidateset if required. fig = ud.figure; oldpointer = get(fig, 'pointer'); set(fig, 'pointer', 'watch') resetPointer = onCleanup(@()set(fig, 'pointer', oldpointer)); drawnow; ud = generateCandidateSet(ud); cs = ud.pointer.info; propertypage(ud.pointer.info,'update',proplyt{1},ud.pointer,ud.model); % get design points data=fullset(cs); lims=limits(cs); if ~isempty(ud.constraints) % apply constraints to points [~, in] = isInside( ud.constraints, invcode( ud.model, data ) ); data=data(in,:); end if ~isempty(data) % check data isn't outside limits and adjust limits if necessary - CCD % designs do this lims(:,1)=min(lims(:,1),min(data,[],1)'); lims(:,2)=max(lims(:,2),max(data,[],1)'); end % invcode data data=invcode(ud.model,data); lims=num2cell(invcode(ud.model,lims')',2); npCon=size(data,1); setEnableStatus(ud, ud.autopreview) np = npoints(ud.pointer.info); set(ud.npointstotaltxt,'String',sprintf('%d',np)); set(ud.npointscontxt,'String',sprintf('%d',npCon)); ud.tabbedPreview.setData(data, lims); ud.ispreviewed = true; % Enable/Disable the preview panel function ud = i_switchpreview(ud, TurnOn) if nargin<2 TurnOn = ud.autopreview; end if TurnOn set(ud.previewcards, 'CurrentCard', 1); else set(ud.previewcards, 'CurrentCard', 2); end setEnableStatus(ud, TurnOn) function setEnableStatus(ud, turnOn) if turnOn set(ud.TotalPointsLbl, 'Enable', 'on'); if isempty(ud.constraints) set(ud.ConPointsLbl, 'Enable', 'off'); else set(ud.ConPointsLbl, 'Enable', 'on'); end else % Ensure it is disabled set(ud.ConPointsLbl, 'Enable', 'off'); set(ud.TotalPointsLbl, 'Enable', 'off'); end function i_finalise(lyt) % finalise the cset selection. % get handle to ud udh=lyt2udh(lyt); ud=get(udh,'UserData'); crd=getcard(ud.cardlay); propertypage(ud.pointer.info,'finalise',crd{1}); % Ensure point set is generated if ~isGenerated(ud.pointer.info) ud = generateCandidateSet(ud); end set(udh,'UserData', ud); function h=lyt2udh(lyt) % return udh for a lyt el=get(lyt,'elements'); h=el{1}; %%%%%%%%%%%%% % Callbacks % %%%%%%%%%%%%% function i_typechange(~,~,udh) ud=get(udh,'UserData'); val=get(ud.typepop,'Value'); if ud.cards(val)~=get(ud.cardlay,'currentcard') ud.pointer.info=feval(ud.createlist{val},toCandidateSet(ud.pointer.info)); ud=i_setvalues(ud); set(udh,'UserData',ud); end function i_optschange(~,~,udh) ud=get(udh,'UserData'); if ud.autopreview ud = i_dopreview(ud); elseif ud.ispreviewed % Turn off preview ud.ispreviewed = false; ud = i_switchpreview(ud); end set(udh,'UserData',ud); function i_prevchange(~, ~, udh) ud=get(udh,'UserData'); DoPrev = get(ud.PreviewCheck, 'Value'); if DoPrev ud.autopreview = true; ud = i_dopreview(ud, false); ud = i_switchpreview(ud); else % Toggle auto-previewing off but leave the current preview still % visible ud.autopreview = false; end set(udh,'UserData',ud); function ud = generateCandidateSet(ud) cs = ud.pointer.info; cs = generate(cs); % update the property page ud.pointer.info = cs;