comparison m-toolbox/m/gui/gltpda/g_numberDataInput.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 g_numberDataInput(hObject,varargin)
2 % Called whenever the user changes the number of data inputs:
3
4 global params
5
6 if nargin>2
7 prevNumb = varargin{1};
8 newNumb = varargin{2};
9 else
10 prevNumb = get(hObject,'UserData');
11 newNumb = str2double(get(hObject,'String'));
12 if isnan(newNumb), set(hObject,'String',num2str(prevNumb)); return; end
13 end
14
15 fakeInp = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Ground');
16 if ~isempty(fakeInp) && newNumb>0
17 blockLines = get_param(fakeInp{1},'LineHandles');
18 if (blockLines.Outport(1)~=-1 && ~isempty(blockLines.Outport(1))), delete_line(blockLines.Outport(1)); end
19 delete_block(fakeInp{1})
20 end
21
22 dataInports = find_system(gcb,'SearchDepth',1,'LookUnderMasks','all','BlockType','Inport');
23
24 paramFromSimulink = 0;
25 for ii=1:nparams(params)
26 paramvals{ii} = params.params(ii).val;
27 if isa(paramvals{ii},'char') && numel(paramvals{ii})>2 && strcmp(paramvals{ii},'-->'), paramFromSimulink = paramFromSimulink + 1; end
28 end
29
30 % To set the proper port number for parameters inport:
31 for ii=1:paramFromSimulink
32 set_param(dataInports{end-paramFromSimulink+ii},'Port',num2str(newNumb+11));
33 end
34 % To avoid considering inports for parameters:
35 dataInports(end-paramFromSimulink+1:end) = [];
36
37 % To remove all previous data inports:
38 for ii=1:numel(dataInports)
39 try %#ok<ALIGN>
40 blockLines = get_param(dataInports{ii},'LineHandles');
41 if (blockLines.Outport(1)~=-1 && ~isempty(blockLines.Outport(1))), delete_line(blockLines.Outport(1)); end
42 delete_block(dataInports{ii});
43 catch, end
44 end
45
46 % To add new inports for all data expected:
47 if newNumb==0, add_block('simulink/Sources/Ground', [gcb,'/data_input'],'MakeNameUnique','on','Name','data'); end
48 for ii=1:newNumb
49 newBlock = add_block('simulink/Sources/In1', [gcb,'/Inport1'],'MakeNameUnique','on','Name',['data',num2str(ii)]);
50 set_param(newBlock,'Port',num2str(ii));
51 end
52
53 g_UpdateInports('',1)
54
55 end