% SETGD Set the property 'gd'
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% DESCRIPTION: SETGD Set the property 'gd'
%
% CALL:        obj = obj.setGd(12);
%              obj = setGd(obj, 12);
%
% INPUTS:      obj - is a mfir object
%
% <a href="matlab:utils.helper.displayMethodInfo('mfir', 'setGd')">Parameters Description</a>
%
% VERSION:     $Id: setGd.m,v 1.6 2011/04/08 08:56:20 hewitson Exp $
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function varargout = setGd(varargin)

  %%% Check if this is a call for parameters
  if utils.helper.isinfocall(varargin{:})
    varargout{1} = getInfo(varargin{3});
    return
  end

  % Check if this is a call from a class method
  callerIsMethod = utils.helper.callerIsMethod;
  
  obj = varargin{1};
  val = varargin{2};

  %%% If val is a plist-object then get the value out of the plist
  if isa(val, 'plist')
    val = find(val, 'gd');
  end

  %%% decide whether we modify the mfir-object, or create a new one.
  obj = copy(obj, nargout);

  %%% set 'gd'
  obj.gd = val;

  if ~callerIsMethod
  obj.addHistory(getInfo('None'), plist('gd', val), '', obj.hist);
  end

  varargout{1} = obj;
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                               Local Functions                               %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% FUNCTION:    getInfo
%
% DESCRIPTION: Get Info Object
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function ii = getInfo(varargin)
  if nargin == 1 && strcmpi(varargin{1}, 'None')
    sets = {};
    pl   = [];
  else
    sets = {'Default'};
    pl   = getDefaultPlist;
  end
  % Build info object
  ii = minfo(mfilename, 'mfir', 'ltpda', utils.const.categories.helper, '$Id: setGd.m,v 1.6 2011/04/08 08:56:20 hewitson Exp $', sets, pl);
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% FUNCTION:    getDefaultPlist
%
% DESCRIPTION: Get Default Plist
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function plout = getDefaultPlist()
  persistent pl;  
  if exist('pl', 'var')==0 || isempty(pl)
    pl = buildplist();
  end
  plout = pl;  
end

function pl = buildplist()
  pl = plist({'gd', ''}, paramValue.EMPTY_DOUBLE);
end

