Skip to content
Commits on Source (30)
function update_cell( src, event, cell )
%UPDATE_CELL Updates the cell with the control's string
% A helper callback for updating the cell given to the controls text.
cell.set_string(get(src, 'String'));
end
......@@ -12,27 +12,30 @@
% Author: Colin Eles elesc@mcmaster.ca
% Organization: McMaster Centre for Software Certification
function [ code , query] = generate_cvc_grid( grid , level)
function [ code , query] = generate_cvc_grid( container , level, parent_cell, parent_cond)
if nargin == 2
parent_cell = []
parent_cond = ''
end
% generate the formulas for the main grid
parents = CVC_checker.find_parents(grid.cells(1));
if isempty(parents);
if isempty(parent_cond);
disjoint = 'QUERY (';
complete = 'QUERY (';
else
disjoint = ['QUERY ' CVC_checker.matlab_to_cvc_syntax_translation(parents) ' => ('];
complete = ['QUERY ' CVC_checker.matlab_to_cvc_syntax_translation(parents) ' => ('];
disjoint = ['QUERY ' CVC_checker.matlab_to_cvc_syntax_translation(parent_cond) ' => ('];
complete = ['QUERY ' CVC_checker.matlab_to_cvc_syntax_translation(parent_cond) ' => ('];
end
for i=1:size(grid.cells,2)
for i=1:container.get_children_count(parent_cell)
ith_cond = container.get_child_cell(parent_cell, i).get_matlab_string
for j = i+1:size(grid.cells,2)
for j = i+1:container.get_children_count(parent_cell)
% compare i to j
disjoint = [disjoint 'NOT ( (' CVC_checker.matlab_to_cvc_syntax_translation(char(grid.cells(i).cond_text)) ') AND (' CVC_checker.matlab_to_cvc_syntax_translation(char(grid.cells(j).cond_text)) ') )'];
disjoint = [disjoint 'NOT ( (' CVC_checker.matlab_to_cvc_syntax_translation(ith_cond) ') AND (' CVC_checker.matlab_to_cvc_syntax_translation(char(container.get_child_cell(parent_cell, j).get_matlab_string)) ') )'];
if j~= size(grid.cells,2)
if j~= container.get_children_count(parent_cell)
disjoint = [disjoint ' AND ' char(10)];
end
......@@ -43,13 +46,13 @@ for i=1:size(grid.cells,2)
complete = [complete '(' CVC_checker.matlab_to_cvc_syntax_translation(char(grid.cells(i).cond_text)) ')'];
complete = [complete '(' CVC_checker.matlab_to_cvc_syntax_translation(ith_cond) ')'];
if i < size(grid.cells,2) - 1
if i < container.get_children_count(parent_cell)
disjoint = [disjoint ' AND ' char(10)];
end
if i < size(grid.cells,2)
if i < container.get_children_count(parent_cell)
complete = [complete ' OR '];
end
end
......@@ -63,9 +66,10 @@ code = [code 'ECHO "begin' num2str(level+2) '";' char(10) 'PUSH;' char(10) compl
for i=1:size(grid.cells,2)
if ~isempty(grid.cells(i).subgrid)
[new_code,new_queries] = CVC_checker.generate_cvc_grid(grid.cells(i).subgrid,level+2);
for i=1:container.get_children_count(parent_cell)
child_cell = container.get_child_cell(parent_cell, i);
if container.get_children_count(child_cell) ~= 0
[new_code,new_queries] = CVC_checker.generate_cvc_grid(grid.cells(i).subgrid,level+2, child_cell);
code = [code new_code];
query = [query new_queries];
level = size(query,2) - 2;
......
......@@ -34,12 +34,12 @@ end
new_code = '';
queries = [];
%generate grid 2
if size(object.data.Grid2.cells,2) > 1
[new_code,queries] = CVC_checker.generate_cvc_grid(object.data.Grid2,0);
if object.data.left_cond.length > 1
[new_code,queries] = CVC_checker.generate_cvc_grid(object.data.left_cond,0);
end
code = [code new_code];
if size(object.data.Grid1.cells,2) > 1
if object.data.multi_mode == 0 && object.data.top_cond.length > 1
[new_code,new_queries] = CVC_checker.generate_cvc_grid(object.data.Grid1,size(queries,2));
queries = [queries new_queries];
code = [code new_code];
......
classdef Cell < handle
%CELL Base cell class that stores text.
% Base cell that handles the text. All other cell uses this to
% implement their data specific representations.
properties
subgrid = [];
cond = [];
cond_text = [];
cell_index = 0;
parent_grid = [];
width = 0;
height = 0;
grid_pb = [];
pb_flag = 0;
color = [];
condition_text_width = 200;
condition_text_height = 60;
condition_text_x = 10;
condition_text_y = 10;
condition_text_offset = 20;
grid_push_width = 30;
text = ''
end
methods
%% Cell
%
% inputs:
% index:integer - cells index
% p_grid:Grid - Parent grid of cell
% outputs;
% object:Cell - created cell
function object = Cell(index, p_grid)
object.cell_index = index;
object.parent_grid = p_grid;
object.pb_flag = 1;
function str = get_matlab_string(object)
str = object.text;
if size(str) > 0
s = [str(1,:)];
for j = 2:size(str,1)
s = [s ' ' str(j,:)];
end
str = s;
end
end
end
function str = get_user_string(object)
str = object.text;
end
function set_string(object, string)
%TODO: Verify string is a string ...
object.text = string;
end
end
end
%% cal_height
% calculates the height in number of cells of the current cell.
% if the cell does not have a subgrid the height will be 1, else
% it will be the height of the subgrid.
% inputs:
% object:Cell - Current Cell Object
% edit:boolean - 0 when not in edit mode, 1 in edit mode
% outputs;
% h:double - height in number of cells
% Author: Colin Eles elesc@mcmaster.ca
% Organization: McMaster Centre for Software Certification
function h = cal_height(object,edit)
h = 0;
if (isempty(object.subgrid))
h = 1;
else
for i=1:size(object.subgrid.cells,2)
h = h + cal_height(object.subgrid.cells(i),edit);
end
% edit button is half a cell high, if in edit mode increase
% by 0.5
if (edit == 1)
h = h + 0.5;
end
end
end
%% delete_Cell
% deletes the current cell, will recursively delete any subgrids
% if they exist.
% inputs:
% object:Cell - Current Cell Object
% outputs;
% none
% Author: Colin Eles elesc@mcmaster.ca
% Organization: McMaster Centre for Software Certification
function [] = delete_Cell(object)
if(isempty(object.subgrid))
delete(object.grid_pb);
delete(object.cond);
object.cond = [];
object.grid_pb = [];
%delete(object);
else
% delete the subgrid
object.subgrid.deep_delete;
if(ishghandle(object.grid_pb))
delete(object.grid_pb);
end
delete(object.cond);
object.cond = [];
object.grid_pb = [];
%delete(object);
end
end
%% flag_cell
% mode
% 0 - normal
% 1 - red (error/false)
% 2 - green (ok/true)
% 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.cond,'BackgroundColor');
end
if (mode == 0)
set(object.cond,'BackgroundColor',object.color);
elseif (mode == 1)
set(object.cond,'BackgroundColor',[0.92 0.65 0.65]);
elseif (mode == 2)
set(object.cond,'BackgroundColor',[0.03 1.0 0.32]);
end
end
%% get_pos
% Returns the position of the edit box for the cell
% inputs:
% object:Cell - Current Cell Object
% outputs;
% pos:[double double double double] - position of the cell
% Author: Colin Eles elesc@mcmaster.ca
% Organization: McMaster Centre for Software Certification
function pos = get_pos(object)
if (~isempty(object.cond))
pos = get(object.cond,'position');
end
end
%% new_Grid
%
% inputs:
% object:Cell - Current Cell Object
% outputs;
% Author: Colin Eles elesc@mcmaster.ca
% Organization: McMaster Centre for Software Certification
function [] = new_Grid(object)
object.subgrid = Grid(object.cell_index,object);
object.subgrid.new_Cell;
object.subgrid.new_Cell;
object.subgrid.set_rGrid(object.parent_grid.rGrid);
object.pb_flag = 0;
delete(object.grid_pb);
if(~isempty(object.parent_grid.rGrid))
object.parent_grid.rGrid.delete_g2s(object);
end
end
%% pb_call
% callback function for the new subgrid button
% inputs:
% object:Cell - Current Cell Object
% src:double - Source of the callback
% event:eventdata - Data of the eventcall
% outputs;
% none
% Author: Colin Eles elesc@mcmaster.ca
% Organization: McMaster Centre for Software Certification
function [] = pb_call(object,src,event)
gui = get(src,'userdata');
object.new_Grid;
gui.reset_wh();
%gui.draw_grid2(gui.Grid2);
gui.draw_allgrids(0);
if isempty(event) || event ~= 1
undo_data.action = 4;
undo_data.grid = object.subgrid;
undo_data.cell = object;
undo_data.text = [];
undo_data.subgrid = [];
gui.undo_man.new_state(undo_data);
end
gui.update_undoredo;
end
%% set_pb
% create the new subgrid push button handle
% inputs:
% object:Cell - Current Cell Object
% outputs;
% none
% Author: Colin Eles elesc@mcmaster.ca
% Organization: McMaster Centre for Software Certification
function [] = set_pb(object,fig,pos)
if(object.pb_flag == 1 && (isempty(object.grid_pb) || ~ishghandle(object.grid_pb)))
object.grid_pb = uicontrol('style','push',...
'units','pix',...
'string','+',...
'HorizontalAlign','left',...
'Parent',fig,...
'position',pos,...
'callback',@(src,event)pb_call(object,src,event));
elseif (object.pb_flag == 1 && ~isempty(object.grid_pb))
set(object.grid_pb,'Position',pos);
else
end
end
%% set_pos
% allows accessor to set the position of the edit box for the
% cell.
% inputs:
% object:Cell - Current Cell Object
% pos:[double double double double] - the new position of the
% cell
% outputs;
% none
% Author: Colin Eles elesc@mcmaster.ca
% Organization: McMaster Centre for Software Certification
function [] = set_pos(object,pos)
if (~isempty(object.cond))
set(object.cond,'position',pos);
end
end
% Author: Colin Eles elesc@mcmaster.ca
% Author: Matthew Dawson matthew@mjdsystems.ca
% Organization: McMaster Centre for Software Certification
classdef Data < handle
% This class will store the data for each table, ideally to seperate
% out the data from the gui and logic.
properties
Grid0 = [];
Grid1 = [];
Grid2 = [];
left_cond = [];
top_cond = [];
outputs_grid = [];
let_statements = [];
function_name = [];
function_inputs = [];
settings = [];
......@@ -27,12 +28,20 @@ classdef Data < handle
% none
% outputs:
% object:Data - created object
function object = Data()
function object = Data()
object.left_cond = HierarchicalGrid();
object.top_cond = HierarchicalGrid();
object.outputs_grid = TableGrid();
object.let_statements = LetStatments();
object.left_cond.addlistener('AddedOuterCell', @(src, event) left_grid_added_cell(object, src, event));
object.left_cond.addlistener('RemovedOuterCell', @(src, event) object.outputs_grid.delete_row(event.changed_cell));
object.top_cond.addlistener('AddedOuterCell', @(src, event) top_grid_added_cell(object, src, event));
object.top_cond.addlistener('RemovedOuterCell', @(src, event) object.outputs_grid.delete_column(event.changed_cell));
end
end
end
%% 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
%% copy_results
% copy the results text of the current grid0 to a destination
% Data's grid0 object.
% inputs:
% object:Data - current object
% dest:Data - destination object to save results text to, results
% grid is assumed to already be set up.
% outputs:
% none
% Author: Colin Eles elesc@mcmaster.ca
% Organization: McMaster Centre for Software Certification
function [] = copy_results(object,dest)
for i=1:size(dest.Grid0.Cells,2)
for j=1:size(object.Grid0.Cells,2)
if (strcmp(object.Grid0.Cells(j).Cell1.cond_text,dest.Grid0.Cells(i).Cell1.cond_text) && strcmp(object.Grid0.Cells(j).Cell2.cond_text,dest.Grid0.Cells(i).Cell2.cond_text))
dest.Grid0.Cells(i).result_text = object.Grid0.Cells(j).result_text;
end
end
end
end
%% getData
% resturn individual properties to calling function
% inputs:
% object:Data - current object
% outputs:
% grid0:Grid - Results Grid
% grid1:Grid - Left Grid
% grid2:Grid - Top Grid
% name:string - Function name
% inputs:string - input string
% checked:boolean - typecheck status
% Author: Colin Eles elesc@mcmaster.ca
% Organization: McMaster Centre for Software Certification
function [grid0, grid1, grid2, name, inputs, checked, multi] = getData(object)
grid0 = object.Grid0;
grid1 = object.Grid1;
grid2 = object.Grid2;
name = object.function_name;
inputs = object.function_inputs;
checked = object.checked;
multi = object.multi_mode;
end
%% init
% initialize the data to some default values and objects
% inputs:
% object:Data - current object
% outputs:
% none
% Author: Colin Eles elesc@mcmaster.ca
% Organization: McMaster Centre for Software Certification
function [] = init(object)
object.Grid2 = Grid(2,[]);
object.Grid1 = Grid(1,[]);
object.Grid0 = RGrid(object.Grid1,object.Grid2);
object.Grid1.set_rGrid(object.Grid0);
object.Grid2.set_rGrid(object.Grid0);
object.Grid2.new_Cell;
object.Grid1.new_Cell;
object.checked = 0;
object.multi_mode = 0;
function init( object )
%INIT Summary of this function goes here
% Detailed explanation goes here
object.left_cond.add_cell([], []);
object.left_cond.add_cell([], []);
object.top_cond.add_cell([], []);
end
function left_grid_added_cell( object, src, event )
%LEFT_GRID_ADDED_CELL Handler for when a new left condition is added.
object.outputs_grid.add_row(event.changed_cell);
end
%% save
% saves the current data object to an external file
% inputs:
% object:Data - current Data object
% outputs:
% none
% Author: Colin Eles elesc@mcmaster.ca
% Organization: McMaster Centre for Software Certification
function [] = save(object)
filename = [ object.function_name '.table'];
save(filename,'object');
end
%% setData
% set the object properties, used when copying and other places
% inputs:
% object:Data - current object
% grid0:Grid - Results Grid
% grid1:Grid - Left Grid
% grid2:Grid - Top Grid
% name:string - Function name
% inputs:string - input string
% checked:boolean - typecheck status
% outputs:
% none
% Author: Colin Eles elesc@mcmaster.ca
% Organization: McMaster Centre for Software Certification
function [] = setData(object, grid0, grid1, grid2, name, inputs, checked, multi)
object.Grid0 = grid0;
object.Grid1 = grid1;
object.Grid2 = grid2;
object.function_name = name;
object.function_inputs = inputs;
object.checked = checked;
object.multi_mode = multi;
end