Mercurial > hg > ltpda
comparison m-toolbox/classes/@collection/addObjects.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 % ADDOBJECTS adds the given objects to the collection. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: ADDOBJECTS adds the given objects to the collection. | |
5 % | |
6 % CALL: col = addObjects(col, obj1, obj2, ...) | |
7 % obj = obj.addObjects(plist('objs', objects); | |
8 % | |
9 % <a href="matlab:utils.helper.displayMethodInfo('collection', 'addObjects')">Parameters Description</a> | |
10 % | |
11 % VERSION: $Id: addObjects.m,v 1.16 2011/04/08 08:56:21 hewitson Exp $ | |
12 % | |
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
14 | |
15 function varargout = addObjects(varargin) | |
16 | |
17 %%% Check if this is a call for parameters | |
18 if utils.helper.isinfocall(varargin{:}) | |
19 varargout{1} = getInfo(varargin{3}); | |
20 return | |
21 end | |
22 | |
23 %%% Internal call: Only one object + don't look for a plist | |
24 if strcmp(varargin{end}, 'internal') | |
25 | |
26 %%% decide whether we modify the first object, or create a new one. | |
27 varargin{1} = copy(varargin{1}, nargout); | |
28 | |
29 for ii = 1:numel(varargin{1}) | |
30 for kk=1:numel(varargin{2}) | |
31 if isa(varargin{2}{kk}, 'ltpda_uo') | |
32 varargin{1}(ii).objs = [varargin{1}(ii).objs; num2cell(reshape(varargin{2}{kk}, [], 1))]; | |
33 end | |
34 end | |
35 end | |
36 varargout{1} = varargin{1}; | |
37 return | |
38 end | |
39 | |
40 import utils.const.* | |
41 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
42 | |
43 % Collect input variable names | |
44 in_names = cell(size(varargin)); | |
45 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
46 | |
47 % Collect all ltpdauoh objects | |
48 [cols, cols_invars, rest] = utils.helper.collect_objects(varargin(:), 'collection', in_names); | |
49 | |
50 % Identify the objects which should go into the collection. | |
51 [inobjs, plConfig] = collection.identifyInsideObjs(rest); | |
52 | |
53 % Decide on a deep copy or a modify | |
54 cols = copy(cols, nargout); | |
55 | |
56 % Loop over all collection objects objects | |
57 for j=1:numel(cols) | |
58 histories = []; | |
59 inplists = []; | |
60 | |
61 % Add new inside objects. | |
62 cols(j).objs = [cols(j).objs, inobjs]; | |
63 | |
64 % The history of the objects with history will go into the history of | |
65 % the collection and the inside PLISTs must go into the plistUsed | |
66 % because they doesn't have history. | |
67 for rr=1:numel(inobjs) | |
68 if isa(inobjs{rr}, 'ltpda_uoh') | |
69 histories = [histories inobjs{rr}.hist]; | |
70 else | |
71 inplists = [inplists inobjs{rr}]; | |
72 end | |
73 end | |
74 | |
75 if ~isempty(inplists) | |
76 plh = plConfig.combine(plist('objs', {inplists})); | |
77 else | |
78 plh = plConfig; | |
79 end | |
80 | |
81 % Set some properties | |
82 warning('off', utils.const.warnings.METHOD_NOT_FOUND); | |
83 cols(j).setProperties(plConfig); | |
84 warning('on', utils.const.warnings.METHOD_NOT_FOUND); | |
85 | |
86 % Add history from the collection and all the input variables | |
87 cols(j).addHistory(getInfo('None'), plh, cols_invars(j), [cols(j).hist histories]); | |
88 end | |
89 | |
90 | |
91 % Set output | |
92 if nargout == numel(cols) | |
93 % List of outputs | |
94 for ii = 1:numel(cols) | |
95 varargout{ii} = cols(ii); | |
96 end | |
97 else | |
98 % Single output | |
99 varargout{1} = cols; | |
100 end | |
101 end | |
102 | |
103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
104 % Local Functions % | |
105 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
106 %-------------------------------------------------------------------------- | |
107 % Get Info Object | |
108 %-------------------------------------------------------------------------- | |
109 function ii = getInfo(varargin) | |
110 | |
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, 'collection', 'ltpda', utils.const.categories.helper, '$Id: addObjects.m,v 1.16 2011/04/08 08:56:21 hewitson Exp $', sets, pl); | |
120 end | |
121 | |
122 %-------------------------------------------------------------------------- | |
123 % Get Default Plist | |
124 %-------------------------------------------------------------------------- | |
125 function plout = getDefaultPlist() | |
126 persistent pl; | |
127 if exist('pl', 'var')==0 || isempty(pl) | |
128 pl = buildplist(); | |
129 end | |
130 plout = pl; | |
131 end | |
132 | |
133 function pl = buildplist() | |
134 pl = plist({'objs', 'The inside objects to set.<br>Please use a cell array if the objects are not from the same type.'}, paramValue.EMPTY_DOUBLE); | |
135 end | |
136 |