www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgdatasetnode/factors.m
function varargout = factors(~, Action, varargin) %FACTORS % CB_FUNCHANDLES = FACTORS( DATASETNODE, 'get_callbacks' ) returns a % structure of function handles CB_FUNCHANDLES % Copyright 2000-2009 The MathWorks, Inc. and Ford Global Technologies, Inc. % all we can do here is return the callback structure if nargin>1 && ischar( Action ) switch lower(Action) case 'get_callbacks' varargout{1}= i_GetCallbacks; case 'createpage' [varargout{1:2}] = createPage(varargin{:}); end end %------------------------------------------------------------------ function cb=i_GetCallbacks %------------------------------------------------------------------ cb = []; cb.View = @i_View; cb.Show = @i_Show; cb.Copy = @i_Copy; cb.ExprClick = @i_ExprClick; cb.FactorClick = @i_FactorClick; cb.Selection = @i_Selection; cb.ShowIndex = @i_ShowIndex; function [d,newview]= createPage(d) fcb = i_GetCallbacks; % -------- factors page % This is the page with the callbacks on it newview = struct('ID','factors',... 'label','&Factors',... 'icon','cgdsfactorsbut.bmp',... 'tooltip','Factor Information',... 'card',1,... 'view',fcb.View,... 'show',fcb.Show,... 'copy',fcb.Copy,... 'enablestatus',1,... 'tpselection',fcb.Selection,... 'showindex',fcb.ShowIndex,... 'tplist',1,... 'tpmenu',d.Handles.fm.menu,... 'tpclick',fcb.FactorClick,... 'bmlist',1,... 'bmmenu',d.Handles.fm.menu,... 'tlenable',d.Handles.tm.FactorBits,... 'bmclick',fcb.ExprClick); % NB toolbars already set up by factors - not changed here %----------------------------------------------------------------------- function d = i_Show(d) %----------------------------------------------------------------------- configureExprList(d.Handles.ExprList); page = d.ViewInfo(d.currentviewinfo); configureList(d.Handles.FactorList,... {'Factor' , 'Status' , 'Information'},... [150 , 150, 500],... 'Data Set Factors'); sortList(d.Handles.FactorList,2); d.Handles.FactorList.SelectionCallback = page.tpclick; d.Handles.ExprList.SelectionCallback = page.bmclick; d.Handles.FactorList.ContextMenu = page.tpmenu; d.Handles.ExprList.ContextMenu = page.bmmenu; d.Handles.fm.BmVis = d.Handles.fm.FactorVisBm; %----------------------------------------------------------------------- function d = i_View(d,sel_index) %----------------------------------------------------------------------- if nargin<2 sel_index = -1; end if d.pD.isempty help = {'Data set is empty.', ... '',... 'Select project expressions below',... 'and right-click to add to data set,',... 'or use File -> Import -> Data to fill data set.'}; pr_Message(d,help); else % set up top list display set(d.Handles.TopCard,'currentcard',d.currentcard); % Got to make visible first, otherwise invoke(ensurevisible) fails i_RefreshList(d,-1); end d = pr_RefreshExprList(d,sel_index,'project'); d = i_ExprClick(d); %----------------------------------------------------------------------- function sel = i_Selection(d) %----------------------------------------------------------------------- sel = d.Handles.FactorList.Selected; %----------------------------------------------------------------------- % % Factor view % %----------------------------------------------------------------------- %----------------------------------------------------------------------- % % Selection of new item % - generate appropriate links between lists % %----------------------------------------------------------------------- %----------------------------------------------------------------------- function d = i_ExprClick(d,~) %----------------------------------------------------------------------- i_SetListLinks(d.Handles.ExprList,d.Handles.FactorList); %----------------------------------------------------------------------- function d = i_FactorClick(d,~) %----------------------------------------------------------------------- i_SetListLinks(d.Handles.FactorList,d.Handles.ExprList); %----------------------------------------------------------------------- function i_SetListLinks(List1,List2) %----------------------------------------------------------------------- if List1.RowCount==0 || List2.RowCount==0 % nothing in list return end ind1 = List1.Selected; % Check what is currently selected in other box. % If multi selection, deselect all. if ~isempty(ind1) deselect(List2); end %----------------------------------------------------------------------- function d = i_ShowIndex(d,index) %----------------------------------------------------------------------- % Highlight the thing given in index % (prob. an error) fact_i = d.Exprs.factor_index(index); if fact_i list = d.Handles.FactorList; list.Selected = index; d = i_FactorClick(d); else % Must be in bottom list d.Handles.ExprList.Selected = index; d = i_ExprClick(d); end %----------------------------------------------------------------------- function data = i_Copy(d) %----------------------------------------------------------------------- if d.pD.isempty data = []; else % can't just copy table contents - may have a limit on number % of rows. %Check for selected columns factor_select = d.Handles.FactorList.Selected; cols = d.Exprs.factor_index(factor_select); if isempty(cols) cols = 1:d.pD.get('numfactors'); end data = d.pD.get('data'); data = data(:,cols); factors = d.pD.get('factors'); heads = factors(cols); data={data,heads}; end function d = i_RefreshList(d,select_index) %----------------------------------------------------------------------- list = d.Handles.FactorList; if nargin>1 if select_index<1 select_index = list.Selected; end else select_index = []; end [ListData,IconData,ind] = i_getListData(d); refreshList(list,ListData,IconData,ind,select_index); %----------------------------------------------------------------------- function [ListData,IconData,ind] = i_getListData(d) %----------------------------------------------------------------------- ind = find(d.Exprs.factor_index); op = info(d.pD); names = get(op,'assignednames'); overwrites = get(op,'isoverwrite'); evaluates = get(op,'isevaluation'); factor_type = get(op,'factor_type_names'); linked = isLink(op); data = isDataOnly(op); [~, isoutput] = getIsFactorType(op); ListData = cell(length(ind),3); IconData = cell(length(ind),2); for i = 1:length(ind) fact_i = d.Exprs.factor_index(ind(i)); if linked(fact_i) assigntxt = d.Exprs.types{ind(i)}; elseif data(fact_i) && isoutput(fact_i) assigntxt = 'Output: Data'; elseif isoutput(fact_i) if d.Exprs.eval(ind(i)) assigntxt = ['Output: ' d.Exprs.types{ind(i)}]; else assigntxt = 'Cannot evaluate'; end else assigntxt = factor_type{fact_i}; end mainicon = d.Exprs.tpiconfiles{ind(i)}; if linked(fact_i) assignicon = 'cglink.bmp'; elseif overwrites(fact_i) assignicon = 'cgdsoverwrite.bmp'; elseif evaluates(fact_i) && d.Exprs.eval(ind(i)) assignicon = 'cgdsevaluation.bmp'; else assignicon = ''; end infotext = d.Exprs.infos{ind(i)}; if strcmp(infotext,'In data set') infotext=''; end ListData(i,:) = {names{fact_i},assigntxt,infotext}; IconData(i,:) = {mainicon,assignicon}; end