% Construct a matrix object from ltpda_uoh objects.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% FUNCTION:    fromInput
%
% DESCRIPTION: Construct a matrix object from ltpda_uoh objects.
%
% CALL:        matrix = matrix.fromInput(inobjs)
%
% VERSION:     $Id: fromInput.m,v 1.9 2011/02/14 13:20:24 ingo Exp $
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function obj = fromInput(obj, pli, callerIsMethod)
  
  import utils.const.*
  
  if callerIsMethod
    % do nothing
    pl = pli;
  else
    utils.helper.msg(msg.OPROC1, 'Construct from inputs');
    pl = combine(pli, matrix.getDefaultPlist('From Input'));
  end
  shape = pl.find('shape');
  objs  = pl.find('objs');
  
  if iscell(objs)
    [inobjs, ao_invars, rest] = utils.helper.collect_objects(objs(:), '');
    if ~isempty(rest)
      warning('LTPDA:MATRIX', '### The matrix constructor collects only all %s-objects but there are some %s-objects left.', class(inobjs), class(rest{1}));
    end
  else
    inobjs = objs;
  end
  
  if ~isempty(shape)
    obj.objs = reshape(inobjs, shape);
  else
    obj.objs = inobjs;
  end
  
  
  if callerIsMethod
    % do less
  else
    pl.pset('shape', size(obj.objs));
    % Remove the input objects from the plist because we add the histories of
    % the input objects to the matrix object.
    pl.remove('objs');
    
    inhists = [];
    if ~isempty(inobjs)
      inhists = [inobjs(:).hist];
    end
    obj.addHistory(matrix.getInfo('matrix', 'None'), pl, [], inhists);
    warning('off', utils.const.warnings.METHOD_NOT_FOUND);
    % remove parameters we already used
    pl_set = copy(pl,1);
    if pl_set.isparam('objs')
      pl_set.remove('objs');
    end
    if pl_set.isparam('shape')
      pl_set.remove('shape');
    end
    obj.setProperties(pl_set);
    warning('on', utils.const.warnings.METHOD_NOT_FOUND);
  end
  
end
