comparison m-toolbox/classes/+utils/@prog/findparent.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 function [parentHandles] = findparent(childHandle,varargin)
2 % This function retrieves the handles of all blocks parents of a given
3 % child block, i.e. all those blocks which must be executed prior to the
4 % given one.
5 % Are considered only 'M-S-Function' blocks, since all others will be
6 % executed anyway.
7 %
8 % $Id: findparent.m,v 1.2 2008/08/16 03:30:35 nicola Exp $
9
10 lineHandles = get(childHandle,'LineHandles');
11 lineIn1 = lineHandles.Inport; % this are all the handles of the lines coming in.
12 parentHandles = get(lineIn1,'SrcBlockHandle'); % these are the handles of all parent blocks.
13
14 if isempty(parentHandles), return; end
15
16 if(iscell(parentHandles)), parentHandles = cell2mat(parentHandles); end
17
18 for i=numel(parentHandles):-1:1
19 if strcmp(get(parentHandles(i),'BlockType'),'From')
20 gotoBlock = utils.prog.find_in_models(bdroot,'LookUnderMasks','all','BlockType','Goto','GotoTag',get(parentHandles(i),'GotoTag'));
21 if numel(gotoBlock)>1
22 disp(['*** Warning; found multiple GOTO blocks with the same associated tag; please check model ',gcs]);
23 gotoBlock = gotoBlock{1};
24 end
25 % Substitute the handle of the 'from' block with the corresponding
26 % 'goto' block:
27 parentHandles(i) = get_param(gotoBlock{1},'Handle');
28 end
29
30 % Let's find recursively all the parents of this parent block:
31 parentHandles = [parentHandles ; utils.prog.findparent(parentHandles(i))];
32
33 % If this parent is a subsystem, all inner block must be added to the list
34 % (but there's no need to look for the parents of all them):
35 if strcmp(get(parentHandles(i),'BlockType'),'SubSystem')
36 innerBlocks = utils.prog.find_in_models(parentHandles(i),'LookUnderMasks','all','BlockType','M-S-Function');
37 for j=1:numel(innerBlocks)
38 parentHandles = [parentHandles; innerBlocks(j)];
39 end
40 % The handle of the subsystem can be discarded:
41 parentHandles(i) = [];
42 elseif ~strcmp(get(parentHandles(i),'BlockType'),'M-S-Function')
43 parentHandles(i) = [];
44 end
45
46 end
47
48 end
49
50
51
52