% SETPLOTINFO sets the 'plotinfo' property of a ltpda_uoh object.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% DESCRIPTION: SETPLOTINFO sets the 'plotinfo' property of a ltpda_uoh object.
%
% CALL:        objs.setPlotinfo(val);
%              objs.setPlotinfo(val1, val2);
%              objs.setPlotinfo(plist('plotinfo', val));
%              objs = objs.setPlotinfo(val);
%
% INPUTS:      objs: Any shape of ltpda_uoh objects
%              val:
%                 1. Single PLIST e.g.
%                      Each object in objs get this value.
%                 2. Single PLIST in a cell-array
%                      Each objects in objs get this value.
%                 3. cell-array with the same number of PLISTSs as in objs
%                    e.g. {pl1, pl2, pl3} and 3 objects in objs
%                      Each object in objs get its corresponding value from the
%                      cell-array
%
% <a href="matlab:utils.helper.displayMethodInfo('ltpda_uoh', 'setPlotinfo')">Parameter Sets</a>
%
% VERSION:     $Id: setPlotinfo.m,v 1.15 2011/09/16 05:02:22 hewitson Exp $
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function varargout = setPlotinfo(varargin)
  
  % Check if this is a call from a class method
  callerIsMethod = utils.helper.callerIsMethod;
    
  if callerIsMethod
    in_names = {};
  else
    % Collect input variable names
    in_names = cell(size(varargin));
    for ii = 1:nargin,in_names{ii} = inputname(ii);end
  end
  
  objects = setPropertyValue(...
    varargin{:}, ...
    in_names, ...
    callerIsMethod, ...
    'plotinfo', ...
    @setterFcn, ...
    nargout, ...
    @getInfo);
  
  % set outputs
  varargout = utils.helper.setoutputs(nargout, objects);
  
end

% Setter function to set the plotinfo
function value = setterFcn(varargin)
  
  obj = varargin{1};
  pls = varargin{2};
  if nargin == 2
    % copy this before we remove the supported keys. We want to remove the
    % keys otherwise applyDefaults complains because these are not
    % supported keys of the plist.
    value = copy(pls,1);
    % remove supported keys: 'linestyle', 'linewidth', 'color', 'marker', 'legend_on'
    if pls.isparam('linestyle')
      pls.removeKeys('linestyle');
    end
    if pls.isparam('linewidth')
      pls.removeKeys('linewidth');
    end
    if pls.isparam('color')
      pls.removeKeys('color');
    end
    if pls.isparam('marker')
      pls.removeKeys('marker');
    end
    if pls.isparam('legend_on')
      pls.removeKeys('legend_on');
    end
  end
  if nargin == 3
    value = varargin{3};
  end
  
  obj.plotinfo = value;
  
end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                               Local Functions                               %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%--------------------------------------------------------------------------
% 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, mfilename('class'), 'ltpda', utils.const.categories.helper, '$Id: setPlotinfo.m,v 1.15 2011/09/16 05:02:22 hewitson Exp $', sets, pl);
end

%--------------------------------------------------------------------------
% Get Default Plist
%--------------------------------------------------------------------------
function plout = getDefaultPlist()
  persistent pl;
  if ~exist('pl', 'var') || isempty(pl)
    pl = buildplist();
  end
  plout = pl;
end

function pl = buildplist()
  pl = plist({'plotinfo', 'A plist to set to the plot info.'}, {1, {plist}, paramValue.OPTIONAL});
end
