www.gusucode.com > mbcview 工具箱matlab源码程序 > mbcview/@cgdatasetnode/private/pr_makeProjectDisplay.m
function Exprs = pr_makeProjectDisplay(Exprs,opptr,nd,IL,opt) % Exprs = pr_makeProjectDisplay(Exprs,opptr,node,opt) % % 1 x x x = build parents of exprlist and list of vectors % x 1 x x = check evaluation of exprlist and dataset % x x 1 x = build icon list % Copyright 2000-2013 The MathWorks, Inc. and Ford Global Technologies, Inc. if nargin<5 opt = Exprs.recalc; end nd = info(nd); do_exprlist = (opt(1)~=0); do_checkeval = (opt(2)~=0); do_buildgui = (opt(3)~=0); if do_exprlist % Search project for all pointers; % build up list of node pointers; get parent list for each ptr. % % This stuff may not change between calls, so preserve a copy % (building the parent list may take some time) Exprs = i_GetListStuff(Exprs,nd); end if do_checkeval % Check evaluation of everything in project. % Only need to check this when something has changed [check,need] = check_eval(opptr.info,Exprs.Eptrs,Exprs.Eparents); Exprs.Echeck = check; Exprs.Eneed = need; end if do_buildgui % Build up list of names, icons, types, infos, for display. % This one will change more frequently. Exprs = i_DoDisplay(Exprs,opptr,IL); end Exprs.UnitFilter = ''; Exprs.plot_index = []; Exprs.recalc = [0 0 0 0]; %----------------------------------------------------------------------- function Exprs = i_GetListStuff(Exprs,nd) %----------------------------------------------------------------------- % Get list of everything in project [ndlist,ptrlist] = i_GetList(nd); objarray = infoarray(ptrlist); nms = cell(size(objarray)); prnts = cell(size(objarray)); for n = 1:length(objarray) nms{n} = getname(objarray{n}); prnts{n} = getsource(objarray{n}); end Exprs.Enames = nms; Exprs.Eparents = prnts; Exprs.Eptrs = ptrlist; Exprs.ENptrs = ndlist; %----------------------------------------------------------------------- function [ndlist,plist] = i_GetList(nd) %----------------------------------------------------------------------- pr = project(nd); % Get everything else in the project A = getConnections(pr); ok = isvalid(A.pData); ok(ok) = parrayeval(A.pData(ok),@isdsvariable,{},@false); % remove features that are filled with this dataset (this would create a circular dependency) opptr = getdata(nd); isfeat = strcmp(A.Type,'Feature') & ok; if any(isfeat) ok(isfeat) = parrayeval(A.pData(isfeat),@(f) isFeatureOK(f,opptr),{},@false); end ndlist = A.pNode(ok); plist = A.pData(ok); % node is data dictionary variable ndlist(ismember( plist, listptrs(info(getdd(pr))))) = getdd(pr); plist(isnull(ndlist)) = []; ndlist(isnull(ndlist)) = []; function OK = isFeatureOK(f,ptrlist) OK = ~any(ismember(getDependentPtrs(f),ptrlist)); %----------------------------------------------------------------------- function Exprs = i_DoDisplay(Exprs,opptr,~) %----------------------------------------------------------------------- % Combine project and dataset into one list Exprs = i_CombineDSandPR(Exprs,opptr); % Get some useful flags flags = i_getFlags(Exprs,opptr); inds = struct('outind',[],'dsind',[],'prind',[],'featureind',[],'ErrPtrs',[],'ddind',[]); infostr = cell(1, length(Exprs.ptrs)); icons = zeros(1, length(Exprs.ptrs)); iconfiles = cell(1, length(Exprs.ptrs)); typestr = infostr; hoppt = opptr.info; % Items that are only in the dataset will have no associated project node DSonly = ~flags.nvalid; for n = find(DSonly) [iconfiles{n}, typestr{n}, infostr{n}, inds] = ... i_DatasetOnly(n, Exprs, hoppt, inds, flags); end % Create information for items in the project [iconfiles(flags.nvalid),typestr(flags.nvalid), infostr(flags.nvalid), inds] = ... i_Project(find(flags.nvalid), Exprs, hoppt, inds, flags); inds.dsind = find(Exprs.factor_index>0); % Check for: overwrite and link (these override normal icons) tpiconfiles = iconfiles; for n = inds.dsind if flags.overwrites(Exprs.factor_index(n)) if flags.valid(n) && ~flags.indd(n) typestr{n} = ['Data set overwrites ' typestr{n}]; tpiconfiles{n}='cgdsoverwrite.bmp'; end end if flags.islink(Exprs.factor_index(n)) iconfiles{n}='cglink.bmp'; linkptr = getlink(hoppt, Exprs.factor_index(n)); typestr{n} = ['Linked to ' linkptr.getname]; end end Exprs.infos = infostr; Exprs.iconfiles = iconfiles; Exprs.tpiconfiles = tpiconfiles; Exprs.types = typestr; Exprs.units = cell(size(typestr)); Exprs.unitchar = repmat({''}, size(typestr)); Exprs.FilterIndex = {inds.prind inds.outind inds.featureind inds.dsind inds.ddind}; Exprs.ErrPtrs = inds.ErrPtrs; %----------------------------------------------------------------------- function Exprs = i_CombineDSandPR(Exprs,opptr) %----------------------------------------------------------------------- % Combine project expression list with factors; % Remove repeated ptrs. %------ dataset [o_check,o_need,o_parents] = check_eval(opptr.info); ptrlist = opptr.get('ptrlist'); % Build up the main lists of ptrs, nodeptrs, names, parents, eval status [keep,opnptr,Exprs.Emap] = i_CheckRepeats(Exprs.Eptrs,Exprs.ENptrs,ptrlist); [in_i,out_i] = getFactorTypes(opptr.info); seen = [in_i out_i]; factors = opptr.get('factors'); Exprs.ptrs = [ptrlist(seen) Exprs.Eptrs(keep)]; Exprs.Nptrs = [opnptr(seen) Exprs.ENptrs(keep)]; Exprs.names = [factors(seen) Exprs.Enames(keep)]; Exprs.parents = [o_parents(seen) Exprs.Eparents(keep)]; Exprs.eval = [o_check(seen) Exprs.Echeck(keep)]; Exprs.need_ptrs = [o_need(seen) Exprs.Eneed(keep)]; % mark expressions which are factors Exprs.factor_index = [seen zeros(1,length(keep))]; Exprs.shown_factors = zeros(1,length(ptrlist)); Exprs.shown_factors(seen) = 1:length(seen); % Set up the blank fields to be filled with display stuff Exprs.infos = []; Exprs.icons = []; Exprs.tpicons = []; Exprs.types = []; Exprs.units = []; Exprs.unitchar = []; %----------------------------------------------------------------------- function [keep,nptr,map] = i_CheckRepeats(Eptrs,Nptrs,ptrlist) %----------------------------------------------------------------------- % Remove ptrs which are in dataset from expression list. % Build node list for factors, by matching with project ptr. keep = find(~ismember(Eptrs,ptrlist)); map = zeros(1,length(Eptrs)); map(keep) = length(ptrlist) + (1:length(keep)); % Get nodes for each dataset pointer nptr = null(xregpointer, size(ptrlist)); [hasnode, nodeidx] = ismember(ptrlist, Eptrs); nptr(hasnode) = Nptrs(nodeidx(hasnode)); %----------------------------------------------------------------------- function flags = i_getFlags(Exprs,opptr) %----------------------------------------------------------------------- flags = []; % Get some useful flags for each factor hoppt = opptr.info; flags.overwrites = get(hoppt, 'isoverwrite'); flags.opunits = get(hoppt, 'Units'); flags.islink = isLink(hoppt); [flags.isinput,flags.isoutput,flags.isignored] = getIsFactorType(hoppt); % And for everything if isempty(Exprs.ptrs) flags.valid= []; flags.nvalid = []; else flags.valid = isvalid(Exprs.ptrs); flags.nvalid = isvalid(Exprs.Nptrs); end flags.indd = zeros(1,length(flags.valid)); indd = pveceval(Exprs.ptrs(flags.valid), @isddvariable); flags.indd(flags.valid) = [indd{:}]; flags.modeltype = cgtypes.cgmodeltype; flags.featuretype = cgtypes.cgfeaturetype; %----------------------------------------------------------------------- function [iconfile,type,info,inds] = i_DatasetOnly(idx,Exprs,hoppt,inds,flags) %----------------------------------------------------------------------- fact_i = Exprs.factor_index(idx); info = ''; % Only in dataset; not in project if flags.valid(idx) if isUniqueToDataset(hoppt, fact_i) [iserr, pL, pR] = i_isErrorExpr(Exprs.ptrs(idx)); if iserr iconfile = 'cgdserror.bmp'; inds.ErrPtrs = [inds.ErrPtrs; idx double([pL pR])]; info = Exprs.ptrs(idx).char; else iconfile = 'cgdatasetnode.bmp'; end else % Does not have a node; but created from Cage. % Something gone wrong! info = '** Not in project **'; iconfile = 'cross.bmp'; end elseif flags.isignored(fact_i) iconfile = 'cgdsignore.bmp'; else iconfile = 'cgdatasetnode.bmp'; end if flags.isinput(fact_i) type = 'Data set Input'; info = 'Unassigned'; elseif flags.isoutput(fact_i) type = 'Data Set'; inds.outind = [inds.outind idx]; else type = 'X Ignored'; end % ------ info about required inputs if ~Exprs.eval(idx) if ~isempty(Exprs.need_ptrs{idx}) info = i_InputsRequired('Inputs required', Exprs.need_ptrs{idx}); end end %------------------------------------------------------------------ function [iserr,l,r] = i_isErrorExpr(ptr) %------------------------------------------------------------------ iserr = false; l = []; r = []; hObj = ptr.info; if isa(hObj, 'cgsubexpr') l = get(hObj, 'left'); r = get(hObj, 'right'); if length(l)==1 && isvalid(l) && length(r)==1 && isvalid(r) iserr = true; end end %----------------------------------------------------------------------- function [iconfiles,types,infos,inds] = i_Project(idx,Exprs,~,inds,flags) %----------------------------------------------------------------------- iconfiles = pveceval(Exprs.ptrs(idx), @iconfile); types = pveceval(Exprs.ptrs(idx), @gettype); infos = repmat({''}, size(idx)); inDS = Exprs.factor_index(idx)>0; infos(inDS) = {'In data set'}; infos(~Exprs.eval(idx) & flags.indd(idx) & inDS) = {'No data assigned to variable'}; infos(~Exprs.eval(idx) & flags.indd(idx) & ~inDS) = {'Not in data set'}; gen_requirements = (~Exprs.eval(idx) & ~flags.indd(idx)); for n = find(gen_requirements) infos{n} = i_InputsRequired('Inputs required', Exprs.need_ptrs{idx(n)}); end inds.prind = [inds.prind idx]; inds.ddind = [inds.ddind idx(logical(flags.indd(idx)))]; inds.outind = [inds.outind idx(~flags.indd(idx))]; ismodel = pveceval(Exprs.ptrs(idx), @isa, 'cgmodexpr'); isfeature = pveceval(Exprs.ptrs(idx), @isa, 'cgfeature'); isfeature = [isfeature{:}]; inds.featureind = [inds.featureind, idx([ismodel{:}] & isfeature)]; %----------------------------------------------------------------------- function str = i_InputsRequired(str1,ptrs) %----------------------------------------------------------------------- if ~isempty(ptrs) names = pveceval(ptrs, @getname); str = [str1, ': ', sprintf('%s, ', names{:})]; str = str(1:end-2); else str = [str1, ': none']; end