Skip to content
%% flag_cell
% allows changing the background color of a cell based on an
% inputed mode
% inputs
% object:RCell - current object
% mode:int -
% 0 - normal
% 1 - red (error/false)
% 2 - green (ok/true)
% outputs:
% none
% Author: Colin Eles elesc@mcmaster.ca
% Organization: McMaster Centre for Software Certification
function [] = flag_cell(object,mode)
if (isempty(object.color))
object.color = get(object.result,'BackgroundColor');
end
if ishandle(object.result)
if (mode == 0)
set(object.result,'BackgroundColor',object.color);
elseif (mode == 1)
set(object.result,'BackgroundColor',[0.92 0.65 0.65]);
elseif (mode == 2)
set(object.result,'BackgroundColor',[0.03 1.0 0.32]);
end
end
end
\ No newline at end of file
% Author: Colin Eles elesc@mcmaster.ca
% Organization: McMaster Centre for Software Certification
classdef RGrid < handle
properties
Cells = [];
Grid1 = [];
Grid2 = [];
end
methods
%% RGrid
% constructor method
% inputs:
% g1:Grid - reference to top grid
% g2:Grid - reference to left grid.
% outputs;
% n:RGrid - Created RGrid
function n = RGrid(g1, g2)
n.Grid1 = g1;
n.Grid2 = g2;
end
end
end
%% delete_g1s
% Same as delete_g2s but we are now deleting RCell with a
% reference to the inputed cell in their Cell1
% inputs:
% object:RGrid - reference to current RGrid
% cell:Cell - reference to cell being deleted
% outputs;
% none
% Author: Colin Eles elesc@mcmaster.ca
% Organization: McMaster Centre for Software Certification
function [] = delete_g1s(object,cell)
deleted = [];
for i=1:size(object.Cells,2)
if (object.Cells(i).Cell1 == cell)
deleted = [deleted i];
end
end
if(~isempty(deleted))
delete(object.Cells(deleted).result);
object.Cells(deleted) = [];
end
end
%% delete_g2s
% function will delete all the cells that reference an inputed
% condition cell as their Cell2.
% inputs:
% object:RGrid - reference to current RGrid
% cell:Cell - reference to cell being deleted
% outputs;
% none
% Author: Colin Eles elesc@mcmaster.ca
% Organization: McMaster Centre for Software Certification
function [] = delete_g2s(object,cell)
deleted = [];
% loop through all the cells, if we find any Rcell with cell as
% its Cell2 then add the index to the array, if we were to
% delete the cell right away the array size would decrease and
% we would get out of bounds issues.
for i=1:size(object.Cells,2)
if (object.Cells(i).Cell2 == cell)
deleted = [deleted i];
end
end
if(~isempty(deleted))
delete(object.Cells(deleted).result);
object.Cells(deleted) = [];
end
end
%% new_RCell
% creates a new Cell in the current RGrid
% inputs:
% object:RGrid - current RGrid object
% cell1:Cell - reference to condition cell in top grid
% cell2:Cell - reference to condition cell in left grid
% outputs;
% none
% Author: Colin Eles elesc@mcmaster.ca
% Organization: McMaster Centre for Software Certification
function [] = new_RCell(object,cell1,cell2)
cell = RCell;
cell.Cell1 = cell1;
cell.Cell2 = cell2;
object.Cells = [object.Cells cell];
end
%% refresh
% calls the setup function, might add furthur functionality in
% the future to this function
% inputs:
% object:RGrid - reference to current RGrid
% outputs;
% none
% Author: Colin Eles elesc@mcmaster.ca
% Organization: McMaster Centre for Software Certification
function [] = refresh(object)
object.setup(object.Grid1,object.Grid2);
end
%% search
% determine wheter a results cell exists for a pair of condition
% cells.
% inputs:
% object:RGrid - reference to current RGrid
% cell1:Cell - reference to condition cell in top grid.
% cell2:Cell - reference to condition cell in left grid.
% outputs;
% cell:boolean - 1 if cell is found, 0 if cell is not found
% Author: Colin Eles elesc@mcmaster.ca
% Organization: McMaster Centre for Software Certification
function cell = search(object,cell1,cell2)
cell = 0;
for i=1:size(object.Cells,2)
if (object.Cells(i).Cell1 == cell1 && object.Cells(i).Cell2 == cell2);
cell = 1;
end
end
end
%% search_return
% determine where a results cell exists for a pair of condition
% cells and returns the cell itself.
% inputs:
% object:rgrid - reference to current rgrid
% cell1:cell - reference to condition cell in top grid.
% cell2:cell - reference to condition cell in left grid.
% outputs;
% cell:rcell - if found returns reference to cell, if not returns
% empty
% Author: Colin Eles elesc@mcmaster.ca
% Organization: McMaster Centre for Software Certification
function cell = search_return(object,cell1,cell2)
cell = [];
for i=1:size(object.Cells,2)
if (object.Cells(i).Cell1 == cell1 && object.Cells(i).Cell2 == cell2);
cell = object.Cells(i);
end
end
end
%% setup
% this function will loop through all the cells in both the left
% grid and the top grid, once we reach a leaf cell for both
% grids, if there does not exist an RCell in the RGrid for both
% these leaf cells then we need to create one.
% inputs:
% object:RGrid - reference to current RGrid
% g1:Grid - reference to the top grid
% g2:Grid - reference to the left grid.
% outputs;
% none
% Author: Colin Eles elesc@mcmaster.ca
% Organization: McMaster Centre for Software Certification
function [] = setup(object,g1,g2)
for i=1:size(g2.cells,2)
if (~isempty(g2.cells(i).subgrid))
object.setup(g1,g2.cells(i).subgrid);
else
for j=1:size(g1.cells,2)
if(~isempty(g1.cells(j).subgrid))
object.setup(g1.cells(j).subgrid,g2);
else
if (object.search(g1.cells(j),g2.cells(i)) == 0)
rcell = RCell(g1.cells(j),g2.cells(i));
object.Cells = [object.Cells rcell];
end
end
end
end
end
end
\ No newline at end of file
% Author: Matthew Dawson matthew@mjdsystems.ca
% Organization: McMaster Centre for Software Certification
classdef TableGrid < handle
% This class will store the data for each table, ideally to seperate
% out the data from the gui and logic.
properties
grid = TableGridCell
width = 0
height = 0
end
events
AddedColumn
AddedRow
StructureChanged
end
methods
%% Data
% constructor
% inputs:
% none
% outputs:
% object:Data - created object
function object = TableGrid()
% object.grid = TableGridCell;
object.grid(:,1) = [];
end
function cell = get_cell(object, y, x)
assert( x > 0 && x <= object.width, 'Provide a valid X cordinate!');
assert( y > 0 && y <= object.height, 'Provide a valid Y cordinate!');
cell = object.grid(y, x);
end
end
end
% Author: Matthew Dawson matthew@mjdsystems.ca
% Organization: McMaster Centre for Software Certification
function add_column( object, after_cell_index )
%ADD_COLUMN Add a column to the grid. If there are no rows, then no new
%cells will be added.
% This function adds a new cell such that after_cell_index is the next
% column index after the new cell. If no rows exist, then it only stores
% the count of columns. If after_cell_index is either [] or equal to the
% number of columns+1, append.
object.width = object.width + 1;
if object.height ~= 0
if isempty(after_cell_index)
object.grid(object.height, object.width) = TableGridCell();
after_cell_index = object.width;
else
tmp(object.height, 1) = TableGridCell();
object.grid = [ object.grid(:, 1:(after_cell_index-1)) tmp object.grid(:, after_cell_index:size(object.grid, 2)) ];
end
end
notify(object, 'AddedColumn', GridSingleColumnEventDetails(after_cell_index));
notify(object, 'StructureChanged');
end
% Author: Matthew Dawson matthew@mjdsystems.ca
% Organization: McMaster Centre for Software Certification
function add_row( object, after_cell_index )
%ADD_COLUMN Add a column to the grid. If there are no rows, then no new
%cells will be added.
% This function adds a new cell such that after_cell_index is the next
% column index after the new cell. If no rows exist, then it only stores
% the count of columns. If after_cell_index is either [] or equal to the
% number of columns+1, append.
object.height = object.height + 1;
if object.width ~= 0
if isempty(after_cell_index)
object.grid(object.height, object.width) = TableGridCell();
after_cell_index = object.width;
else
tmp(1, object.width) = TableGridCell();
object.grid = [ object.grid(1:(after_cell_index-1), :); tmp; object.grid(after_cell_index:size(object.grid, 1), :) ];
end
end
notify(object, 'AddedRow', GridSingleRowEventDetails(after_cell_index));
notify(object, 'StructureChanged');
end
function delete_column( object, index )
%DELETE_COLUMN Deletes the requested column
% Deletes the requested column from the table.
object.grid(:, index) = [];
object.width = object.width-1;
notify(object, 'StructureChanged');
end
function delete_row( object, index )
%DELETE_COLUMN Deletes the requested column
% Deletes the requested column from the table.
object.grid(index, :) = [];
object.height = object.height-1;
notify(object, 'StructureChanged');
end
% Author: Matthew Dawson matthew@mjdsystems.ca
% Organization: McMaster Centre for Software Certification
classdef TableGridCell < Cell
%TABLECELL Summary of this class goes here
% Detailed explanation goes here
properties
end
methods
function object = TableGridCell()
end
end
end
classdef TableGridDraw < GUIBase
%TABLEGRIDDRAW Draw a TableGrid into a uipanel
% Draws a 2D Grid inside a uipanel (Yay!)
properties
my_table_grid = []
controls = []
gui_params = []
end
methods
function object = TableGridDraw(my_table_grid, gui_params)
if nargin == 1
gui_params = GUIParameters();
end
object.my_table_grid = my_table_grid;
object.gui_params = gui_params;
my_table_grid.addlistener('StructureChanged', @(src, event)object.handle_table_change(src, event));
end
function handle_table_change(object, src, event)
notify(object, 'BoundingBoxChanged');
object.redraw();
end
end
end
function draw_onto( object, parent_handle )
%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.
%Need to invert y, so need total size
[~, y] = object.get_bounding_box();
% First delete an extra controls
if size(object.controls, 2) > object.my_table_grid.width
delete(object.controls(:, object.my_table_grid.width+1:size(object.controls, 2)));
object.controls(:, object.my_table_grid.width+1:size(object.controls, 2)) = [];
end
assert( ~(size(object.controls, 2) > object.my_table_grid.width), 'Implment delete when necessary.');
if size(object.controls, 1) > object.my_table_grid.height
delete(object.controls(object.my_table_grid.height+1:size(object.controls, 1), :));
object.controls(object.my_table_grid.height+1:size(object.controls, 1), :) = [];
end
assert( ~(size(object.controls, 1) > object.my_table_grid.height), 'Implment delete when necessary.');
if size(object.controls, 2) ~= object.my_table_grid.width || size(object.controls, 1) ~= object.my_table_grid.height
object.controls(object.my_table_grid.height, object.my_table_grid.width) = 0;
end
for i = 1:object.my_table_grid.width
for j = 1:object.my_table_grid.height
position = [(i-1)*object.gui_params.edit_width, y-((j)*object.gui_params.edit_height), object.gui_params.edit_width, object.gui_params.edit_height];
str = object.my_table_grid.get_cell(j, i).get_user_string();
if object.controls(j,i) ~= 0 && ishandle(object.controls(j,i))
set(object.controls(j, i), 'Parent', parent_handle);
set(object.controls(j, i), 'Position', position);
set(object.controls(j, i), 'String', str);
set(object.controls(j, i), 'Callback', @(src,event)GUIHelpers.update_cell(src, event, object.my_table_grid.get_cell(j, i)) );
else
%Standardize this
object.controls(j, i) = uicontrol(parent_handle, 'Style', 'edit', 'Position', position, 'String', str, 'Callback', @(src,event)GUIHelpers.update_cell(src, event, object.my_table_grid.get_cell(j, i)));
end
end
end
end
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_table_grid.height; %Store number of cells first
x = object.gui_params.edit_width*x; %Then calculate the pixels.
y = object.my_table_grid.height;
y = object.gui_params.edit_height*y; %Same here.
end
classdef VLayout < LinearLayoutBase
%HLAYOUT Summary of this class goes here
% Detailed explanation goes here
methods
function [x, y] = get_bounding_box(object)
x = 0;
y = 0;
for i=1:size(object.children, 2)
[xi, yi] = object.children{i}.get_bounding_box();
x = max([x, xi]);
y = y + yi;
end
end
function relayout(object)
[~, y] = get_bounding_box(object);
y_sofar = 0;
for i=1:size(object.children, 2)
[~, yi] = object.children{i}.get_bounding_box();
y_sofar = y_sofar+yi;
set(object.children_controls{i}, 'Position', [0, y-y_sofar, 1, 1]);
end
object.notify('BoundingBoxChanged');
end
end
end
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
% Author: Colin Eles elesc@mcmaster.ca % Author: Colin Eles elesc@mcmaster.ca
% Organization: McMaster Centre for Software Certification % Organization: McMaster Centre for Software Certification
function [] = close_req_call(object,src,event) function [] = close_req_call(object,src,event)
if (object.gui.Data.open) if (object.gui.data.open)
object.gui.check_call([],[]); object.gui.check_call([],[]);
end end
object.gui.validation_report_handle = 0; object.gui.validation_report_handle = 0;
......