%% clone
%   creates copy of a data object, which involves copying
%   properties and calling individual clone functions on objects if
%   necessary.
% inputs:
%   object:Data - current object
%   handle:Data - the handle to the block
% outputs:
%   copy:Data - copy of the current block, perhaps with a new name
% Author: Colin Eles elesc@mcmaster.ca
% Organization: McMaster Centre for Software Certification
function copy = clone(object,handle)
% assume that dialog is closed
if ~object.valid
    copy = [];
    return;
end
copy = Data();
if ~isempty(handle)
    copy.function_name =   get(handle,'Name');
else
    copy.function_name = '';
end
copy.function_inputs = object.function_inputs;
copy.checked = object.checked;
copy.settings = object.settings;
copy.multi_mode = object.multi_mode;

copy.Grid2 = Grid(2,[]);
copy.Grid1 = Grid(1,[]);
copy.Grid0 = RGrid(copy.Grid1,copy.Grid2);
copy.Grid1.set_rGrid(copy.Grid0);
copy.Grid2.set_rGrid(copy.Grid0);


object.Grid2.clone(copy.Grid2,object.Grid2.grid_index,[]);
object.Grid1.clone(copy.Grid1,object.Grid1.grid_index,[]);

object.copy_results(copy);

end

