Mercurial > hg > ltpda
comparison m-toolbox/classes/@plist/setSelectionForParam.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 % SETSELECTIONFORPARAM Sets the selection mode of the param object in dependencies of the 'key' | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: Sets the selection mode of the param object in dependencies | |
5 % of the 'key' | |
6 % | |
7 % CALL: obj = obj.setSelectionForParam('key', selection); | |
8 % obj = obj.setSelectionForParam(plist('KEY', 'key', 'SELECTION', selection)); | |
9 % obj = setSelectionForParam(obj, 'key', selection); | |
10 % | |
11 % INPUTS: obj - can be a vector, matrix, list, or a mix of them. | |
12 % key - The key which should be changed | |
13 % selection - Selection mode of the parameter | |
14 % pl - to set the default value of a key with a plist, | |
15 % please specify only one plist with the key-words | |
16 % 'key' and 'selection' | |
17 % | |
18 % POSSIBLE VALUES FOR 'selection' | |
19 % | |
20 % selection: 1 == paramValue.OPTIONAL | |
21 % 2 == paramValue.SINGLE | |
22 % 3 == paramValue.MULTI | |
23 % | |
24 % <a href="matlab:utils.helper.displayMethodInfo('plist', 'setSelectionForParam')">Parameters Description</a> | |
25 % | |
26 % VERSION: $Id: setSelectionForParam.m,v 1.6 2011/04/08 08:56:21 hewitson Exp $ | |
27 % | |
28 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
29 | |
30 function varargout = setSelectionForParam(varargin) | |
31 | |
32 %%% Check if this is a call for parameters | |
33 if utils.helper.isinfocall(varargin{:}) | |
34 varargout{1} = getInfo(varargin{3}); | |
35 return | |
36 end | |
37 | |
38 [objs, obj_invars, rest] = utils.helper.collect_objects(varargin(:), 'plist'); | |
39 | |
40 for kk = 1:numel(objs) | |
41 pls = objs(kk); | |
42 %%% If the plist contains only two key/value pairs with the keys 'key' | |
43 %%% and 'selection' then set the slection mode with this plist. | |
44 if pls.nparams == 2 && pls.isparam('key') && pls.isparam('selection') | |
45 rest{1} = pls.find('key'); | |
46 rest{2} = pls.find('selection'); | |
47 objs(kk) = []; | |
48 break; | |
49 end | |
50 end | |
51 | |
52 if numel(rest) ~= 2 | |
53 error('### Please specify a selection mode AND a key, either in a plist or directly.'); | |
54 end | |
55 | |
56 key = rest{1}; | |
57 selection = rest{2}; | |
58 | |
59 %%% Set the Name | |
60 for ii = 1:numel(objs) | |
61 | |
62 %%% decide whether we modify the first plist, or create a new one. | |
63 objs(ii) = copy(objs(ii), nargout); | |
64 | |
65 for kk = 1:objs(ii).nparams | |
66 if strcmpi(key, objs(ii).params(kk).key) | |
67 objs(ii).params(kk).val.setSelection(selection); | |
68 end | |
69 end | |
70 end | |
71 | |
72 %%% Set output | |
73 if nargout == numel(objs) | |
74 % List of outputs | |
75 for ii = 1:numel(objs) | |
76 varargout{ii} = objs(ii); | |
77 end | |
78 else | |
79 % Single output | |
80 varargout{1} = objs; | |
81 end | |
82 end | |
83 | |
84 | |
85 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
86 % Local Functions % | |
87 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
88 | |
89 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
90 % | |
91 % FUNCTION: getInfo | |
92 % | |
93 % DESCRIPTION: Get Info Object | |
94 % | |
95 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
96 | |
97 function ii = getInfo(varargin) | |
98 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
99 sets = {}; | |
100 pl = []; | |
101 else | |
102 sets = {'Default'}; | |
103 pl = getDefaultPlist; | |
104 end | |
105 % Build info object | |
106 ii = minfo(mfilename, 'plist', 'ltpda', utils.const.categories.helper, '$Id: setSelectionForParam.m,v 1.6 2011/04/08 08:56:21 hewitson Exp $', sets, pl); | |
107 end | |
108 | |
109 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
110 % | |
111 % FUNCTION: getDefaultPlist | |
112 % | |
113 % DESCRIPTION: Get Default Plist | |
114 % | |
115 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
116 | |
117 function pl = getDefaultPlist() | |
118 | |
119 pl = plist(); | |
120 | |
121 % Key | |
122 p = param({'key', 'The key of the parameter to set the selection mode for.'}, paramValue.EMPTY_STRING); | |
123 pl.append(p); | |
124 | |
125 % Index | |
126 p = param({'selection', 'The selection mode to set.'}, {1, {1,2,3}, paramValue.OPTIONAL}); | |
127 pl.append(p); | |
128 | |
129 end | |
130 |