0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 function g_UpdateInports(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 % Update the MaskDisplay and the number of inports when the user
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 % changes the params from Simulink.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 global params
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 paramKey = varargin{1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 if numel(paramKey)>7 && strcmpi(paramKey(1:7),'addPar_'), paramKey(1:7)=[]; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 % List of parameters coming from Simulink:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 simKey = {};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 for i=1:nparams(params)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 if isa(params.params(i).val,'char') && strcmp(params.params(i).val,'-->')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 name = params.params(i).key;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 try if strcmpi(name(1:7),'addPar_'), name(1:7)=[]; end; catch, end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 simKey{end+1} = name;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 elseif isa(params.params(i).val,'cell') && isa(params.params(i).val{1},'char') && strcmp(params.params(i).val{1},'-->')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 name = params.params(i).key;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 try if strcmpi(name(1:7),'addPar_'), name(1:7)=[]; end; catch, end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 simKey{end+1} = name;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 % ===================================================================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 % If varargin{2}==2 no block has been added or subtracted, just
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 % renamed an existing param; the only thing to perform is update the
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 % drawing command.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 if varargin{2}~=2
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 % Remove ALL inner inport blocks.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 if varargin{2}==-1, simKey2remove = [simKey,{paramKey}]; else simKey2remove = simKey; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 for i=1:numel(simKey2remove)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 try %#ok<ALIGN>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 block2delete = utils.prog.find_in_models(gcb,'SearchDepth',1,'LookUnderMasks','all','Name',lower(simKey2remove{i}));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 if numel(block2delete)>1, block2delete(1)=[]; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 blockLines = get_param(block2delete{1},'LineHandles');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 if (blockLines.Outport(1)~=-1 && ~isempty(blockLines.Outport(1))), delete_line(blockLines.Outport(1)); end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 delete_block(block2delete);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 catch, end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 % Add ALL inner inport blocks anew:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 for i=1:numel(simKey)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 newBlock = add_block('simulink/Sources/In1', [gcb,'/Inport1'],'MakeNameUnique','on');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 nameAlreadyPresent = utils.prog.find_in_models(gcb,'SearchDepth',1,'LookUnderMasks','all','Name',lower(simKey{i}));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 if ~isempty(nameAlreadyPresent)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 for j=1:numel(nameAlreadyPresent)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 if ~strcmp(nameAlreadyPresent{j},gcb),
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 set_param(nameAlreadyPresent{j},'Name',[lower(simKey{i}),'_fun']);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 set(newBlock,'Name',lower(simKey{i}))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 % Now update the inner structure of lines and mux.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 muxblock = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Mux');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 try %#ok<ALIGN>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 muxLines = get_param(muxblock{1},'LineHandles');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61 for k=1:numel(muxLines.Inport), if (muxLines.Inport(k)~=-1 && ~isempty(muxLines.Inport(k))), delete_line(muxLines.Inport(k)); end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 for k=1:numel(muxLines.Outport), if (muxLines.Outport(k)~=-1 && ~isempty(muxLines.Outport(k))), delete_line(muxLines.Outport(k)); end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 catch, end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 delete_block(muxblock);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 inports = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Inport');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 fakeInp = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Ground');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 inports = [fakeInp;inports];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 if numel(inports)>1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 muxblock = add_block('built-in/Mux', [gcb,'/Mux']);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73 set(muxblock,'Position',[70 , 10 , 73 , 150])
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 set(muxblock,'Inputs',num2str(numel(inports)))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76 for k=1:numel(inports)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 inports{k}=get_param(inports{k},'Handle');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78 blkLines = get(inports{k},'LineHandles');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 for j=1:numel(blkLines.Outport), if (blkLines.Outport(j)~=-1 && ~isempty(blkLines.Outport(j))), delete_line(blkLines.Outport(j)); end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 set(inports{k},'Position',[10 , 10+30*(k-1) , 30 , 30+30*(k-1)])
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 set(inports{k},'Tag',num2str(k))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 if numel(inports)>1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 add_line(gcb,[get(inports{k},'Name'),'/1'],[get(muxblock,'Name'),'/',num2str(k)]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87 funcBlock = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','M-S-Function');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88 funcBlock = get_param(funcBlock,'Name');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89 if numel(inports)>1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90 add_line(gcb,[get(muxblock,'Name'),'/1'],[funcBlock{1},'/1']);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92 add_line(gcb,[get(inports{1},'Name'),'/1'],[funcBlock{1},'/1']);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96 % ===================================================================
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98 % Updating the drawing command for the block Mask:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99 fakeInp = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Ground');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100 drawingCom = '';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101 if numel(simKey)>0 % then there are params 'from simulink' added
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102 if numel(fakeInp)>0 || strcmp(get_param(gcbh,'Tag'),'arithmetic'), currInp=1; else currInp=str2double(get(findobj('Tag','numbDataInputs'),'String'))+1; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103 for nn=1:numel(simKey)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104 drawingCom = [drawingCom,'port_label(''input'',',num2str(currInp),',''',lower(simKey{1}),''');'];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
105 simKey(1) = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
106 currInp = currInp+1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
107 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
108 else % then the only inport is the regular one
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
109 funcBlock = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','M-S-Function');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
110 funcName = get_param(funcBlock{1},'Tag');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
111 if numel(funcName)>6 && strcmp(funcName(1:6),'ltpda_'), funcName(1:6)=[]; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
112 drawingCom = strcat('disp(''',lower(funcName),''')');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
113 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
114 set(gcbh,'MaskDisplay',drawingCom)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
115
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
116 end
|