-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathsaGetLineDominantBlock.m
More file actions
46 lines (45 loc) · 1.35 KB
/
saGetLineDominantBlock.m
File metadata and controls
46 lines (45 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function blocks = saGetLineDominantBlock(lnhdl, direction)
if nargin<2
direction = 'downstream'
end
domblks = [];
ndomblks = [];
if lnhdl<0
blocks.Dominant = domblks;
blocks.Recessive = ndomblks;
return;
end
switch direction
case 'downstream'
dstblks = unique(get_param(lnhdl, 'DstBlockHandle'));
dstpts = get_param(lnhdl, 'DstPortHandle');
srcpt = get_param(lnhdl, 'SrcPortHandle');
dstpts(dstpts<0) = [];
for i=1:numel(dstblks)
if dstblks(i)<0 continue; end
dstblklns = get_param(dstblks(i), 'LineHandles');
inlns = dstblklns.Inport(dstblklns.Inport>0);
insrcpts = get_param(inlns, 'SrcPortHandle');
if iscell(insrcpts)
srcpts = unique(cell2mat(insrcpts));
end
if isequal(srcpt, insrcpts)
domblks = [domblks; dstblks(i)];
else
ndomblks = [ndomblks; dstblks(i)];
end
end
case 'upstream'
srcblk = get_param(lnhdl, 'SrcBlockHandle');
if srcblk<0 return; end
srcblklns = get_param(srcblk, 'LineHandles');
if ~any(srcblklns.Outport>0 & srcblklns.Outport~=lnhdl)
domblks = srcblk;
else
ndomblks = srcblk;
end
otherwise
end
blocks.Dominant = domblks;
blocks.Recessive = ndomblks;
end