Mercurial > hg > ltpda
comparison m-toolbox/classes/+utils/@prog/findchildren.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 [childrenHandles] = findchildren(parentHandle,varargin) | |
2 % This function retrieves the handles of all blocks children of a given | |
3 % parent block, whose handle is received as input. | |
4 % | |
5 % $Id: findchildren.m,v 1.2 2008/08/17 04:32:33 nicola Exp $ | |
6 | |
7 | |
8 | |
9 lineHandles = get(parentHandle,'LineHandles'); | |
10 | |
11 if isempty(lineHandles) % the parent block given has no output: it's an ending. | |
12 childrenHandles = []; | |
13 return; | |
14 end | |
15 lineOut1 = lineHandles.Outport; % this is the handle of the line coming out from the parent block. | |
16 | |
17 | |
18 childrenHandles = get(lineOut1,'DstBlockHandle'); % these are the handles of all children blocks. | |
19 | |
20 if(iscell(childrenHandles)), childrenHandles = cell2mat(childrenHandles); end | |
21 | |
22 % Check if the parent given can be effectively a child (used when the | |
23 % findchildren function is called recursively, checking the output of a | |
24 % subsystem): | |
25 if nargin>1 && strcmp(varargin{1},'all'), childrenHandles = [parentHandle; childrenHandles]; end | |
26 | |
27 for i=numel(childrenHandles):-1:1 | |
28 | |
29 if strcmp(get(childrenHandles(i),'BlockType'),'SubSystem') && numel(get(childrenHandles(i),'Blocks'))==3 && numel(utils.prog.find_in_models(childrenHandles(i),'LookUnderMasks','all','BlockType','M-S-Function','FunctionName','ltpdasim'))==1 | |
30 % then this block is a susbsystem containing a ltpdasim function block. It's a real child. The handle must be substituted with the one of the inner function block. | |
31 childrenHandles(i) = utils.prog.find_in_models(childrenHandles(i),'LookUnderMasks','all','BlockType','M-S-Function','FunctionName','ltpdasim'); | |
32 | |
33 elseif strcmp(get(childrenHandles(i),'BlockType'),'M-S-Function') && strcmp(get(childrenHandles(i),'FunctionName'),'ltpdasim') | |
34 % then this block is a ltpdasim function block. It's a real child. The research do not go deeper into this branch, since this child will create a new ltpda obj. | |
35 | |
36 elseif strcmp(get(childrenHandles(i),'BlockType'),'SubSystem') && numel(get(childrenHandles(i),'Blocks'))==3 && numel(utils.prog.find_in_models(childrenHandles(i),'LookUnderMasks','all','BlockType','M-S-Function'))==1 | |
37 % this is a block containing a LTPDA function, but not using ltpdasim. The ltpda obj pass through, the research must look further. | |
38 followingChildren = utils.prog.findchildren(childrenHandles(i)); | |
39 childrenHandles = [childrenHandles;followingChildren]; | |
40 childrenHandles(i)= []; | |
41 | |
42 elseif strcmp(get(childrenHandles(i),'BlockType'),'M-S-Function') && ~strcmp(get(childrenHandles(i),'FunctionName'),'ltpdasim') | |
43 % then this block is a function block (NOT ltpdasim). It can be ignored. | |
44 childrenHandles(i)= []; | |
45 | |
46 elseif strcmp(get(childrenHandles(i),'BlockType'),'Terminator') | |
47 % this is a false child: the terminator do not need the output of the | |
48 % parent block. | |
49 childrenHandles(i)= []; | |
50 | |
51 elseif strcmp(get(childrenHandles(i),'BlockType'),'Mux') | |
52 % this transfer the parent block output to other following blocks: the research must go deeper. | |
53 followingChildren = utils.prog.findchildren(childrenHandles(i)); | |
54 childrenHandles = [childrenHandles;followingChildren]; | |
55 childrenHandles(i)= []; | |
56 | |
57 elseif strcmp(get(childrenHandles(i),'BlockType'),'Goto') | |
58 % this transfer the parent block output to other following blocks; the research must go deeper. | |
59 allFromBlocks = utils.prog.find_in_models(bdroot,'LookUnderMasks','all','BlockType','From','GotoTag',get(childrenHandles(i),'GotoTag')); | |
60 for j=1:numel(allFromBlocks) | |
61 fromHandle = get_param(allFromBlocks{j},'Handle'); | |
62 followingChildren = utils.prog.findchildren(fromHandle); | |
63 childrenHandles = [childrenHandles;followingChildren]; | |
64 end | |
65 childrenHandles(i)= []; | |
66 | |
67 elseif strcmp(get(childrenHandles(i),'BlockType'),'SubSystem') | |
68 % this is a common subsystem: the research must look for all children blocks contained: | |
69 subsystemHandle = childrenHandles(i); | |
70 portConnectivity = get(subsystemHandle,'PortConnectivity'); | |
71 portHandles = get(subsystemHandle,'PortHandles'); | |
72 for portIndex=1:numel(portHandles.Inport) | |
73 if portConnectivity(portIndex).SrcBlock == parentHandle, break; end | |
74 end % the port n° <portIndex> is the one connected to the parent block | |
75 portHandles = find_system(subsystemHandle,'LookUnderMasks','all','BlockType','Inport','Port',num2str(portIndex)); | |
76 for j=1:numel(portHandles) | |
77 followingChildren = utils.prog.findchildren(portHandles(j)); | |
78 childrenHandles = [childrenHandles;followingChildren]; | |
79 end | |
80 childrenHandles(i)= []; | |
81 | |
82 elseif strcmp(get(childrenHandles(i),'BlockType'),'Outport') | |
83 % the line exits a subsystem: the research must continue in the upper level: | |
84 portIndex = get(childrenHandles(i),'Port'); | |
85 subsystemHandle = get_param(get(childrenHandles(i),'Parent'),'Handle'); | |
86 portConnectivity = get(subsystemHandle,'PortConnectivity'); | |
87 for j=1:size(portConnectivity,1) | |
88 if strcmp(portConnectivity(j).Type,portIndex) && isempty(portConnectivity(j).SrcBlock) | |
89 destinationBlock = portConnectivity(j).DstBlock; | |
90 break | |
91 end | |
92 end | |
93 followingChildren = utils.prog.findchildren(destinationBlock,'all'); | |
94 childrenHandles = [childrenHandles;followingChildren]; | |
95 childrenHandles(i)= []; | |
96 | |
97 else | |
98 disp('--- Unknown case, please update function ''utils.prog.findchildren''') | |
99 disp(['The unknown block is: ',getfullname(childrenHandles(i))]) | |
100 disp(['The block has type: ',get(childrenHandles(i),'BlockType')]) | |
101 | |
102 end | |
103 | |
104 end | |
105 | |
106 end | |
107 | |
108 | |
109 | |
110 |