view aim-mat/tools/@parameter/set.m @ 0:74dedb26614d

Initial checkin of AIM-MAT version 1.5 (6.4.2011).
author tomwalters
date Fri, 20 May 2011 12:32:31 +0100
parents
children 20ada0af3d7d
line wrap: on
line source
% method of class @parameter
% 
% (c) 2003-2008, University of Cambridge
% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
% http://www.pdn.cam.ac.uk/cnbh/aim2006/tools/parameter
% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
function param=set(param,text,newvalue,inbox)
%% sets the parameter value in the parameter "text" in the panel "inbox" to
%% the value "value".
% if its a float then the unit is assumed to be the one with wich the
% parameter was first defined

if nargin<4
    inbox='all';
end

cont=param.entries;
nr=getentrynumberbytext(param,text,inbox);
if nr>0
    type=cont{nr}.type;
    if strcmp(type,'float') ||  strcmp(type,'slider')
        unit=cont{nr}.orgunit;
        param=setas(param,text,newvalue,unit,inbox);  %call new with unit
        return
    else
        param.entries{nr}.value=newvalue;    % set the value in the class structure
    end
    if isfield(cont{nr},'handle') && ishandle(cont{nr}.handle{1}) % and set in the gui as well
        hand=cont{nr}.handle{1};
        if strcmp(type,'float') || strcmp(type,'string') || strcmp(type,'filename') || strcmp(type,'directoryname')
            set(hand,'String',newvalue);
        elseif strcmp(type,'int')   % ints are capped
            if isnumeric(newvalue)
                intnewvalue=round(newvalue);
                if length(intnewvalue)==1
                    set(hand,'String',intnewvalue);
                else
                    set(hand,'String',num2str(intnewvalue));
                end
                param.entries{nr}.value=intnewvalue;    % set the value in the class structure
            else
                set(hand,'String',newvalue);
            end
        else
            if strcmp(type,'pop-up menu')
                cont=param.entries{nr}.possible_values;
                for i=1:length(cont)
                    if strcmp(cont{i},newvalue)
                        set(hand,'value',i);
                    end
                end
            else
                set(hand,'value',newvalue); % could be bool
            end
        end
    end
    return
else
    error('setvalue::error, the entry does not exist');
end