www.gusucode.com > mbcexpr 工具箱 matlab 源码程序 > mbcexpr/@cgslparser/checkTableReuse.m
function [IsNew,ptr,Inputs] = checkTableReuse(obj,b,blockname,Inputs) %checkTableReuse check reuse of table % [IsNew,ptr,Inputs] = checkTableReuse(obj,b,blockname,Inputs) % Copyright 2012-2012 The MathWorks, Inc. and Ford Global Technologies, Inc. % find table in project ptr = findItem(obj.Project.info,'Type','Table','Name',blockname); if isempty(ptr) % look in PointerList for tables created in this parse plist = obj.PointerList(~isnull(obj.PointerList)); InPointerList = strcmp(pveceval(plist,@getname),blockname) & parrayeval(plist,@(t) istable(t),{},@false); if nnz(InPointerList) ptr = plist(InPointerList); ptr = ptr(1); end end if ~isempty(ptr) && length(getinputs(ptr.info))==length(Inputs) % table has same number of inputs LT = ptr.info; pNorm = getinputs(ptr.info); % found table of correct size IsNew = false; if ~hasSameInputs(obj,LT,pNorm,Inputs); msg = sprintf('The table %s is used by other features or in other parts of this feature. The inputs to %s have been redefined.',... getname(LT),getname(LT)); hilite_system( b ); resp = questdlg([msg,' Do you want to create a new table, reconnect this table with new connections, or cancel?'],... 'Table Definition',... 'New Table','Reconnect','Cancel','New Table'); hilite_system( b, 'none'); switch resp case 'New Table' IsNew = true; fprintf('Duplicate table %s\n',getname(LT)) case 'Reconnect' % rewire existing normaliser inputs Inputs = updateNormaliserInputs(LT,Inputs,pNorm); case 'Cancel' obj.assert(msg,b) end else % rewire existing normaliser inputs Inputs = updateNormaliserInputs(LT,Inputs,pNorm); end else IsNew = true; end function OK = hasSameInputs(obj,LT,pNorm,pInp) %hasSameInputs check table has same inputs when parsing (normaliser might not exist) if isa(LT,'cglookupone') OK = strcmp(charlist(pInp.info,true),charlist(info(pNorm.getinputs),true)); else OK = true; if obj.OldTableInputOrder && length(pNorm)>1 % inputs are [x,y] in old style pInp = pInp([2 1 3:end]); end for i=1:length(pNorm) if isa(pInp(i).info,'cgnormaliser') % Simulink provides normaliser so compare on normalisers OK = OK && strcmp(charlist(pInp(i).info,true),charlist(pNorm(i).info,true)); else % Simulink normaliser is part of table block so compare on inputs to normalisers OK = OK && strcmp(charlist(pInp(i).info,true),charlist(info(pNorm(i).getinputs),true)); end end end function Inputs = updateNormaliserInputs(LT,Inputs,pNorm) %updateNormaliserInputs rewire existing normaliser inputs if reusing tables based on names if ~isa(LT,'cglookupone') %cglookupone don't have separate normalisers for i=1:length(Inputs) if ~isa(info(Inputs(i)),'cgnormaliser') % use normaliser from existing CAGE table unless Simulink provides one and % rewire normalisers pNorm(i).info = setX(pNorm(i).info,Inputs(i)); Inputs(i) = pNorm(i); end end end