www.gusucode.com > mbctools 工具箱 matlab 源码程序 > mbctools/@mdevtestplan/private/DataCardOne.m
function lyt=DataCardOne(fH, iFace,LocalData) %DATACARDONE wizard pane for selecting modelling data source % % lyt=DataCardOne(T, fH, iFace) creates a layout for selecting % the test plan modelling data as part of the data selection wizard. % Copyright 2000-2016 The MathWorks, Inc. and Ford Global Technologies, Inc. % get up-to-date object if isa(fH,'xregcontainer') % Have we been called to create the layout or simply update? lyt = fH; ud = get(lyt, 'UserData'); T= info(ud.pointer); else T= info(LocalData.pointer); [lyt,ud]= iCreateLayout(T,fH,iFace,LocalData); infoStr = ['Select the data set to fit models to. Choose ',... 'whether to use all the data set or to match the data to a design.']; lyt = xreglayerlayout( fH,... 'Elements', {mbcgui.container.InfoPane( 'Parent', fH,... 'Visible', 'off',... 'Title', 'Data and Design',... 'InfoString', infoStr,... 'Center', lyt )} ); ud.pointer = address(T); % next and finish routines ud.nextFcn = @iCardNext; end % set values [ud,~] = i_setValues(info(T),ud,iFace); % data editor set(ud.DataEditor,'Value',ud.ModelData.OpenDataEditor) feval(iFace.setFinishButton, 0); set(lyt, 'UserData', ud); %-------------------------------------------------------------------------- function i_Update(iFace) T = i_select([], [], iFace); if T.DataLink~=0 ud = feval(iFace.getCardUserdata); if get(ud.RadioDes(1),'Value') DataDesign(T); end else % shouldn't be able to get here now errordlg('You must load a new dataset.','Data Error','modal'); end %-------------------------------------------------------------------------- function [nextCardID,LocalData] = iCardNext(layoutUD, iFace) % set next wizard card i_Update(iFace); LocalData.pointer = layoutUD.pointer; LocalData.ModelData = layoutUD.ModelData; nextCardID = @DataCardTwo; %-------------------------------------------------------------------------- function [lyt,ud]= iCreateLayout(~,fH,iFace,ud) % set wizard size iFace.setWizardSize( [600, 350] ); set(fH,'Resize','off') % create layout SC = xregGui.SystemColorsDbl; desPanel = mbcgui.container.layoutpanel('Parent',fH,... 'Title','Design',... 'BorderType', 'etchedin', ... 'LayoutBorder', [10 10 10 3]); % Design controls ud.RadioDes(2,1)= uicontrol('Parent',desPanel,... 'Style','radiobutton',... 'String','Match selected data to design',... 'Callback',{@i_DesignType,iFace,2}); ud.RadioDes(1,1)= uicontrol('Parent',desPanel,... 'Style','radiobutton',... 'String','No design, use all selected data',... 'Callback',{@i_DesignType,iFace,1}); ud.DesignList = uicontrol('Parent',desPanel,... 'Style','popupmenu',... 'BackgroundColor', SC.WINDOW_BG,... 'String',{[]},... 'Callback',{@i_SelectDesign,iFace}); ud.DesignLabel = xregGui.labelcontrol('parent', desPanel, ... 'String', 'All designs:', ... 'LabelSizeMode', 'absolute', ... 'ControlSizeMode', 'absolute', ... 'LabelSize', 85, ... 'ControlSize', 250, ... 'Control', ud.DesignList); designLyt = xreggridbaglayout(desPanel, ... 'packstatus', 'off', ... 'dimension', [4 2], ... 'colsizes', [15 -1], ... 'rowsizes', [15 0 15 20], ... 'gapy', 2, ... 'mergeblock', {[1 1], [1 2]}, ... 'mergeblock', {[3 3], [1 2]}, ... 'elements', {ud.RadioDes(1), [], ud.RadioDes(2), [], ... [], [], [], ud.DesignLabel}); set(desPanel,'LayoutComponent',{designLyt}); ud.DataSelector = tpsetup.DatasetSelector(fH,ud.ModelData); % Layouts % main layout mainlyt = xreggridbaglayout(fH,... 'border',[7 0 7 0],... 'dimension',[3 1],... 'rowsizes',[135 100 -1],... 'gapy',2,... 'elements',{ud.DataSelector.Layout,desPanel, []}); ud.DataEditor= xreguicontrol('Parent', fH,... 'Visible', 'off', ... 'Style', 'checkbox',... 'HorizontalAlignment','right',... 'Value',1,... 'Callback',{@iDoOpenEditor,ud.ModelData},... 'String', 'Open Data Editor on completion'); lyt= xreggridbaglayout(fH, ... 'border',[7 0 7 7],... 'dimension', [2, 3], ... 'rowsizes', [-1 15], ... 'colsizes', [240 80 -1], ... 'gapy', 5, ... 'gapx',10,... 'mergeblock', {[1 1], [1 3]}, ... 'elements',{mainlyt [] ,[],[], [],ud.DataEditor}); ud.Listeners = [event.proplistener(ud.ModelData,... findprop(ud.ModelData,'ValidationType'),'PostSet',... @(h,evt) onValidationTypeChange(h,evt,iFace)); event.proplistener(ud.ModelData,... findprop(ud.ModelData,'pData'),'PostSet',... @(h,evt) selectData(h,evt,iFace))]; %-------------------------------------------------------------------------- function [ud,T] = i_setValues(T,ud,iFace) ud.ModelData.Selected = info(T); update(ud.DataSelector) feval(iFace.setNextButton, T.DataLink~=0); % set up design list for matching [desNames,selIndex,~,T] = i_DesignList(T); set(ud.DesignList,... 'String',desNames,'Value',selIndex); SC = xregGui.SystemColorsDbl; if isExpData(T.DesignDev) % disable design list as we are just using data if isempty(desNames) % disable radio buttons if there are no designs set(ud.RadioDes(2),'Enable','off'); end set(ud.DesignList,'Enable','off', 'BackgroundColor', SC.CTRL_BG,... 'String',{'<none>'},'Value',1); set(ud.DesignLabel,'Enable','off'); set(ud.RadioDes,{'Value'},{1 0}') else % matching to a design set(ud.DesignList,'Enable','on', 'BackgroundColor', SC.WINDOW_BG); set(ud.DesignLabel,'Enable','on'); set(ud.RadioDes,{'Value'},{0 1}') % open the data editor ud.ModelData.OpenDataEditor = true; end %-------------------------------------------------------------------------- function [desNames, selIndex, desIndex, T]= i_DesignList(T) % get design list [desList,chosen] = DesignList(T.DesignDev); desList = desList(2:end); desNames = cell(size(desList)); ok = false(size(desList)); for i=1:length(desList); % designs can't be empty ok(i) = size(desList{i},1)>0; desNames{i} = name(desList{i}); end % remove zero size designs desNames = desNames(ok); if ~isempty(desNames) && chosen<=1 % select first available design selIndex = 1; desIndex = find(ok,1)+1; % make sure that a design is chosen T.DesignDev(end) = setBestDesign(T.DesignDev(end),chosen) ; xregpointer(T); else % indices to design tree desIndex = find( ok )+1; % index for list of available designs selIndex = sum( ok(1:chosen-1) ); end %-------------------------------------------------------------------------- function T = i_select(~, ~,iFace) % select dataset ud = feval(iFace.getCardUserdata); T = info(ud.pointer); % update selected test plan d = ud.ModelData.pData; sel = ~isnull(d); if sel % enable next button feval(iFace.setNextButton, 1); % If we've changed the data object we need to 'unmatch' the testplan so % we correctly detect that the change has happened is % pAssessDataChanges. if ~ismember( d, T.DataLink ) % make copy of pointer T.DataLink = d; T = setmatched( T, false ); xregpointer(T); end end %-------------------------------------------------------------------------- function i_SelectDesign(~,~,iFace) % select a new design - this is equivalent of selecting a design as best in % the design editor ud = feval(iFace.getCardUserdata); T = info(ud.pointer); [~,~,desIndex,T] = i_DesignList(T); [~,chosen] = DesignList(T.DesignDev); NewDesign = get(ud.DesignList,'Value'); if desIndex(NewDesign)~= chosen % select design from list and set it to best in the design tree T.DesignDev(end)= setBestDesign(T.DesignDev(end),desIndex(NewDesign)); xregpointer(T); end %-------------------------------------------------------------------------- function i_DesignType(h,evt,iFace,Type) % change from use a design to use data via the radio buttons ud = feval(iFace.getCardUserdata); T = info(ud.pointer); % toggle radio buttons by setting them all off and then turning on the one % which was selected (Type) set(ud.RadioDes,'Value',0); set(ud.RadioDes(Type),'Value',1); SC = xregGui.SystemColorsDbl; switch Type case 1 % data set(ud.DesignList,'Enable','off','BackgroundColor', SC.CTRL_BG); set(ud.DesignLabel,'Enable','off'); T.DesignDev(end)= setBestDesign(T.DesignDev(end),1); xregpointer(T); case 2 % match to design set(ud.DesignList,'Enable','on','BackgroundColor', SC.WINDOW_BG); set(ud.DesignLabel,'Enable','on'); % always open the data editor selecting matching to a design ud.ModelData.OpenDataEditor = true; set(ud.DataEditor,'Value',ud.ModelData.OpenDataEditor) % match to design if isExpData(T.DesignDev(end)); % delete old data design i_SelectDesign(h,evt,iFace); if any(strcmp(ud.ModelData.ValidationType,{'random','last'})) ud.ModelData.ValidationType = 'none'; end end end function onValidationTypeChange(~,~,iFace) % change validation type - random and last are not allowed when matching to a design ud = feval(iFace.getCardUserdata); if any(strcmp(ud.ModelData.ValidationType,{'random','last'})) && get(ud.RadioDes(2),'Value'); i_DesignType(ud.RadioDes(1),[],iFace,1) end %-------------------------------------------------------------------------- function selectData(~,~,iFace) % load new data set ud = feval(iFace.getCardUserdata); if isfield(ud,'DataSelector') T = info(ud.pointer); % set current values ud = i_setValues(T, ud,iFace); % this doesn't work when there are two xregwizards open feval(iFace.setCardUserdata,ud); i_select([], [],iFace); end %-------------------------------------------------------------------------- %-------------------------------------------------------------------------- function iDoOpenEditor(h,~,ModelData) % update runtime pointer ModelData.OpenDataEditor = get(h,'Value');