comparison m-toolbox/classes/@ssm/setBlockProperties.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 % SETBLOCKPROPERTIES Sets the specified properties of the specified SSM blocks.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: SETBLOCKPROPERTIES Sets properties of the specified SSM blocks.
5 %
6 % CALL: obj = obj.setBlockProtperties(...
7 % 'FIELD', 'inputs', 'BLOCKS', 'ALL', ... % or a cellstr to indicate the blocks
8 % 'NEW_NAMES', {'names'...}, 'NEW_DESCRIPTIONS');
9 %
10 % blockname may be a double, a string or a cell-array of strings of size 1
11 % newBlockDescription may be a string or a cell-array of strings
12 %
13 % <a href="matlab:utils.helper.displayMethodInfo('ssm', 'setBlockProperties')">Parameters Description</a>
14 %
15 % VERSION: $Id: setBlockProperties.m,v 1.5 2011/04/08 08:56:23 hewitson Exp $
16 %
17 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18
19 function varargout = setBlockProperties(varargin)
20
21 %%% Check if this is a call for parameters
22 if utils.helper.isinfocall(varargin{:})
23 varargout{1} = getInfo(varargin{3});
24 return
25 end
26
27 import utils.const.*
28 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
29
30 % Collect input variable names
31 in_names = cell(size(varargin));
32 for ii = 1:nargin,in_names{ii} = inputname(ii);end
33
34 [ssms, ssm_invars, rest] = utils.helper.collect_objects(varargin(:), 'ssm', in_names);
35 [pl, invars2, rest] = utils.helper.collect_objects(rest(:), 'plist');
36 if ~isempty(rest)
37 pl = combine(pl, plist(rest{:}));
38 end
39 pl = combine(pl, getDefaultPlist());
40
41 %%% Internal call: Only one object + don't look for a plist
42 internal = strcmp(varargin{end}, 'internal');
43
44 sys = copy(ssms, nargout);
45
46 %% parameters
47
48 field = pl.find('field');
49 blockIds = pl.find('blocks');
50 newDescriptions = pl.find('NEW_DESCRIPTIONS');
51 newNames = pl.find('NEW_NAMES');
52
53 if ischar(newDescriptions)
54 newDescriptions = {newDescriptions};
55 end
56 if ischar(newNames)
57 newNames = {newNames};
58 end
59
60 % Some error checking....
61 if isempty(field)
62 error('### Please specify the field of the block to modify');
63 end
64
65 %% Loop over the input ssm objects
66 for kk = 1:numel(sys)
67 block = sys(kk).(field);
68
69 [pos, logic] = block.findBlockWithNames(blockIds, 'do warning');
70 if ~isempty(newDescriptions)
71 if numel(newDescriptions) ~= numel(pos)
72 error('### Please specify one new description per block');
73 end
74 for ii=1:numel(pos)
75 block(pos(ii)).setBlockDescriptions(newDescriptions{ii});
76 end
77 end
78 if ~isempty(newNames)
79 if numel(newNames) ~= numel(pos)
80 error('### Please specify one new description per block');
81 end
82 for ii=1:numel(pos)
83 block(pos(ii)).setBlockNames(newNames{ii});
84 end
85 end
86 if ~internal
87 % append history step
88 sys(kk).addHistory(getInfo('None'), pl, ssm_invars(kk), sys(kk).hist);
89 end
90 end % End loop over block IDs
91
92 %% Set output
93 if nargout == numel(sys)
94 for ii = 1:numel(sys)
95 varargout{ii} = sys(ii);
96 end
97 else
98 varargout{1} = sys;
99 end
100 end
101
102 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103 % Local Functions %
104 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
105
106 %--------------------------------------------------------------------------
107 % Get Info Object
108 %--------------------------------------------------------------------------
109
110 function ii = getInfo(varargin)
111 if nargin == 1 && strcmpi(varargin{1}, 'None')
112 sets = {};
113 pl = [];
114 else
115 sets = {'Default'};
116 pl = getDefaultPlist;
117 end
118 % Build info object
119 ii = minfo(mfilename, 'ssm', 'ltpda', utils.const.categories.helper, '$Id: setBlockProperties.m,v 1.5 2011/04/08 08:56:23 hewitson Exp $', sets, pl);
120 end
121
122 %--------------------------------------------------------------------------
123 % Get Default Plist
124 %--------------------------------------------------------------------------
125
126 function plo = getDefaultPlist()
127 plo = plist();
128
129 % type
130 p = param({'field', 'The field being changed'}, {1, {'inputs', 'outputs', 'states'}, paramValue.SINGLE});
131 plo.append(p);
132
133 % blocks
134 p = param({'BLOCKS', 'Identifiers (cellstr of block names or "ALL") of the blocks you want to modify'}, paramValue.EMPTY_CELL);
135 plo.append(p);
136
137 % descriptions
138 p = param({'new_descriptions', 'The new description(s) you want to set to the block(s). Use a cell-array, one entry for each block.'}, ...
139 paramValue.EMPTY_CELL);
140 plo.append(p);
141
142 % names
143 p = param({'new_names', 'The new names(s) you want to set to the block(s). Use a cell-array, one entry for each block.'}, ...
144 paramValue.EMPTY_CELL);
145 plo.append(p);
146
147 end
148