%% draw_grid0
%   function will draw the output grid onto the figure
% inputs:
%   obj:GUI - current GUI object
%   grid:Grid - grid to be drawn, should be grid on left.
%   load:tristate - 0 if grid is being refreshed, 1 if grid should reload
%                   data, 2 if the grid is being initialized.
% outputs:
%   none
% Author: Colin Eles elesc@mcmaster.ca
% Organization: McMaster Centre for Software Certification
function [] = draw_grid0(object,grid,load, init)
% ensure that the results grid is up to date.
grid.refresh();
for i=1:size(grid.Cells,2)
    % get the x coordinate from the associated top grid cell,
    % get the y coordinate from the associated right grid cell.
    pos1 = grid.Cells(i).Cell1.get_pos;
    pos2 = grid.Cells(i).Cell2.get_pos;
    pos = [0 0 0 0];
    pos(1) = pos1(1);
    pos(2) = pos2(2);
    pos(3) = pos1(3);
    pos(4) = pos2(4);
    if load == 2 || isempty(grid.Cells(i).result) || ~ishandle(grid.Cells(i).result)
        
        grid.Cells(i).result = object.create_std_text(object.fig,pos);
        % if we are loading the cell, try to restore the text
        % that was saved using save_results.
        if load ~= 0
            set(grid.Cells(i).result,'String',grid.Cells(i).result_text);
        end
    else
        set(grid.Cells(i).result,'position',pos);
    end
end
end

