Mercurial > hg > ltpda
diff m-toolbox/classes/@LTPDAworkbench/executeConstants.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/m-toolbox/classes/@LTPDAworkbench/executeConstants.m Wed Nov 23 19:22:13 2011 +0100 @@ -0,0 +1,43 @@ +function executeConstants(varargin) + + wb = varargin{1}; + + if isa(wb, 'LTPDAworkbench') + consts = awtinvoke(wb.mp, 'getAllConstants'); + elseif isa(wb, 'mpipeline.canvas.MCanvas') + consts = wb.getAllConstants; + else + error('Unknown input object'); + end + + % Then execute all constants + for kk=1:consts.size() + + c = consts.get(kk-1); + if ~c.isCommentedOut + varname = char(c.getName()); + expr = char(c.getExpression()); + + if exist(varname) > 1 || ~isvarname(varname) + error('The constant block named "%s" is not a valid variable name. \nPlease rename it.', varname); + end + + % can the expression be evaluated, or is it a string? + try + eval([expr ';']); + cmd = [varname ' = ' expr ';']; + catch + cmd = [varname ' = ''' expr ''';']; + end + + % evaluate + disp(sprintf('++ preparing variable: %s', cmd)); + evalin('base', cmd); + else + varname = char(c.getName()); + cmd = ['clear ', varname]; + evalin('base', cmd); + end + end + +end