Commit 24d56bce authored by Matthew Dawson's avatar Matthew Dawson
Browse files

Add support for drawing the Hierarichical Grid vertically.

Almost everything is in place for the table tool to come together.


git-svn-id: https://groke.mcmaster.ca/svn/grad/colin/branches/TableTool_refactor@8680 57e6efec-57d4-0310-aeb1-a6c144bb1a8b
parent 005a8e4b
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -25,6 +25,10 @@ classdef HierarchicalGrid < handle
            
        end
        
        function width = max_width(object)
            width = object.max_width_impl(object.grid, 1);
        end
        
    end
    
    
+24 −0
Original line number Diff line number Diff line

%% max_width_impl
%    determines the maximum width from a current grid, the maximum
%    widht represents the number of levels of subgrids from a given
%    grid.
% inputs:
%   object:Grid - current Grid object
% outputs:
%   m:integer - value representing the maximum width from the
%   current grid.
% Author: Colin Eles elesc@mcmaster.ca
% Author: Matthew Dawson matthew@mjdsystems.ca
% Organization: McMaster Centre for Software Certification
function m = max_width_impl(object,grid,width)
temp = [width];
for i=1:size(grid,2)
    if (~isempty(grid{i}.grid))
        temp = [temp object.max_width_impl(grid{i}.grid, width+1)];
    end
    
end
m = max(temp);
end
+17 −0
Original line number Diff line number Diff line
classdef VerticalHierarchicalGridDraw < handle
    %TABLEGRIDDRAW Draw a TableGrid into a uipanel
    %   Draws a 2D Grid inside a uipanel (Yay!)
    
    properties
        my_grid = []
        controls = {}
    end
    
    methods
        function object = VerticalHierarchicalGridDraw(my_grid)
           object.my_grid = my_grid;
        end
    end
    
end
+40 −0
Original line number Diff line number Diff line
function [height, grid_controls] = draw_onto( object, parent_handle, grid, grid_controls, depth, start_height, x, y )
%DRAW_ONTO Draws the controls onto the parent_handle.  This function needs to be called everytime an update happens.
%   This function draws the entire handle onto the handle.  This function
%   needs to be called everytime the back table is updated.  The class will
%   notify when its necessary.

    if nargin == 2
        %Need to invert y, so need total size
        [x, y] = object.get_bounding_box();
        
        draw_onto(object, parent_handle, object.my_grid.grid, object.controls, 0, 0, x, y);
        
        return ;
    end

    % First delete an extra controls
    assert( ~(size(grid_controls, 2) > size(grid, 2)), 'Implment delete when necessary.');
    
    height = 0;
    
    for i = 1:size(grid, 2)
        if size(grid_controls, 2) >= i
            assert( false, 'Deal with existing controls' );
        else
            grid_controls{i} = struct();
            grid_controls{i}.subgrid = {};
            
            [new_height, grid_controls{i}.subgrid] = draw_onto( object, parent_handle, grid{i}.grid, grid_controls{i}.subgrid, depth+1, height, x, y)
            
            new_height = max([new_height 1])
            height = height + new_height
            
            %Standardize this
            uicontrol(parent_handle, 'Style', 'edit', 'Position', [depth*125, y-((height+start_height)*80+(height+start_height-1)*5), 120, new_height*80+(new_height-1)*5], 'String', ['' num2str(depth) ', ' num2str(i) ]);
            
        end
    end

end
+11 −0
Original line number Diff line number Diff line
function [x, y] = get_bounding_box( object )
%GET_BOUNDING_BOX Gets the size in pixels of the grid.
%Returns the size of the grid (as a box) for layout purposes.
    x = object.my_grid.max_width; %Store maximum width
    x = 120*x + 5*(x-1); %Then calculate the pixels.
    
    y = size(object.my_grid.right_most_grid_cells, 2);
    y = 80*y + 5*(y-1); %Same here.

end