Commit 4b41f128 authored by Colin Eles's avatar Colin Eles
Browse files

latest update

git-svn-id: https://groke.mcmaster.ca/svn/grad/colin/trunk/TableTool@5967 57e6efec-57d4-0310-aeb1-a6c144bb1a8b
parent c190495e
Loading
Loading
Loading
Loading
+56 −56
Original line number Diff line number Diff line
@@ -29,29 +29,29 @@ classdef Cell < handle
        %   index:integer - cells index
        %   p_grid:Grid - Parent grid of cell
        % outputs;
        %   obj:Cell - created cell
        function obj = Cell(index, p_grid)
            obj.cell_index = index;
            obj.parent_grid = p_grid;
            obj.pb_flag = 1;
        %   object:Cell - created cell
        function object = Cell(index, p_grid)
            object.cell_index = index;
            object.parent_grid = p_grid;
            object.pb_flag = 1;
            
        end
        
        %% new_Grid
        %    
        % inputs:
        %   obj:Cell - Current Cell Object
        %   object:Cell - Current Cell Object
        % outputs;
        %   
        function [] = new_Grid(obj)
            obj.subgrid = Grid(obj.cell_index,obj);
            obj.subgrid.new_Cell;
            obj.subgrid.new_Cell;
            obj.subgrid.set_rGrid(obj.parent_grid.rGrid);
            obj.pb_flag = 0;
            delete(obj.grid_pb);
            if(~isempty(obj.parent_grid.rGrid))
                obj.parent_grid.rGrid.delete_g2s(obj);
        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
        
@@ -59,46 +59,46 @@ classdef Cell < handle
        %    deletes the current cell, will recursively delete any subgrids
        %    if they exist.
        % inputs:
        %   obj:Cell - Current Cell Object         
        %   object:Cell - Current Cell Object         
        % outputs;
        %   none
        function [] = delete_Cell(obj)
            if(isempty(obj.subgrid))
                delete(obj.grid_pb);
                delete(obj.cond);
                obj.cond = [];
                obj.grid_pb = [];
                delete(obj);
        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
                obj.subgrid.deep_delete
                if(ishghandle(obj.grid_pb))
                    delete(obj.grid_pb);
                object.subgrid.deep_delete
                if(ishghandle(object.grid_pb))
                    delete(object.grid_pb);
                end
                delete(obj.cond);
                obj.cond = [];
                obj.grid_pb = [];
                delete(obj);
                delete(object.cond);
                object.cond = [];
                object.grid_pb = [];
                delete(object);
            end
        end
        
        %% set_pb
        %    create the new subgrid push button handle
        % inputs:
        %   obj:Cell - Current Cell Object  
        %   object:Cell - Current Cell Object  
        % outputs;
        %   none
        function [] = set_pb(obj,fig,pos)
            if(obj.pb_flag == 1 && (isempty(obj.grid_pb) || ~ishghandle(obj.grid_pb)))
            obj.grid_pb = uicontrol('style','push',...
        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(obj,src,event));
            elseif (obj.pb_flag == 1 && ~isempty(obj.grid_pb))
                    set(obj.grid_pb,'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
@@ -124,17 +124,17 @@ classdef Cell < handle
        %    if the cell does not have a subgrid the height will be 1, else
        %    it will be the height of the subgrid.
        % inputs:
        %   obj:Cell - Current Cell Object 
        %   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
        function h = cal_height(obj,edit)
        function h = cal_height(object,edit)
            h = 0;
            if (isempty(obj.subgrid))
            if (isempty(object.subgrid))
                h = 1;
            else
                for i=1:size(obj.subgrid.cells,2)
                    h = h + cal_height(obj.subgrid.cells(i),edit);
                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
@@ -148,12 +148,12 @@ classdef Cell < handle
        %% get_pos
        %    Returns the position of the edit box for the cell
        % inputs:
        %   obj:Cell - Current Cell Object  
        %   object:Cell - Current Cell Object  
        % outputs;
        %   pos:[double double double double] - position of the cell
        function pos = get_pos(obj)
            if (~isempty(obj.cond))
                pos = get(obj.cond,'position');
        function pos = get_pos(object)
            if (~isempty(object.cond))
                pos = get(object.cond,'position');
            end
        end
        
@@ -161,14 +161,14 @@ classdef Cell < handle
        %    allows accessor to set the position of the edit box for the
        %    cell.
        % inputs:
        %   obj:Cell - Current Cell Object 
        %   object:Cell - Current Cell Object 
        %   pos:[double double double double] - the new position of the
        %   cell
        % outputs;
        %   none
        function [] = set_pos(obj,pos)
            if (~isempty(obj.cond))
                set(obj.cond,'position',pos);
        function [] = set_pos(object,pos)
            if (~isempty(object.cond))
                set(object.cond,'position',pos);
            end
        end
        
@@ -177,18 +177,18 @@ classdef Cell < handle
        %   0 - normal
        %   1 - red (error/false)
        %   2 - green (ok/true)
        function [] = flag_cell(obj,mode)
        function [] = flag_cell(object,mode)
        
            if (isempty(obj.color))
                obj.color = get(obj.cond,'BackgroundColor');
            if (isempty(object.color))
                object.color = get(object.cond,'BackgroundColor');
            end
            
            if (mode == 0)
                set(obj.cond,'BackgroundColor',obj.color);
                set(object.cond,'BackgroundColor',object.color);
            elseif (mode == 1)
                set(obj.cond,'BackgroundColor',[0.92 0.65 0.65])
                set(object.cond,'BackgroundColor',[0.92 0.65 0.65])
            elseif (mode == 2)
                set(obj.cond,'BackgroundColor',[0.03 1.0 0.32]);
                set(object.cond,'BackgroundColor',[0.03 1.0 0.32]);
            end
        
        end
+91 −22
Original line number Diff line number Diff line
@@ -18,10 +18,29 @@ classdef Data < handle
    
    methods
        
        function obj = Data()
            
        end
        
        %% Data
        %   constructor
        % inputs:
        %   none
        % outputs:
        %   object:Data - created object
        function object = Data()
            
        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
        function [] = setData(object, grid0, grid1, grid2, name, inputs, checked)
            object.Grid0 = grid0;
            object.Grid1 = grid1;
@@ -31,6 +50,12 @@ classdef Data < handle
            object.checked = checked;
        end
        
        %% init
        %   initialize the data to some default values and objects
        % inputs:
        %   object:Data - current object
        % outputs:
        %   none
        function [] = init(object)
            object.Grid2 = Grid(2,[]);
            object.Grid1 = Grid(1,[]);
@@ -40,10 +65,19 @@ classdef Data < handle
            object.Grid2.new_Cell;
            object.Grid1.new_Cell;
            object.checked = 0;
            
            
        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
        function [grid0, grid1, grid2, name, inputs, checked] = getData(object)
            grid0 = object.Grid0;
            grid1 = object.Grid1;
@@ -53,6 +87,12 @@ classdef Data < handle
            checked = object.checked;
        end
    
        %% valid
        %   determine if a given data object is valid for use or not
        % inputs:
        %   object:Data - current object
        % outputs:
        %   valid:boolean - 0 if not valid, 1 if valid
        function valid = valid(object)
            if isempty(object.Grid0)
                valid = 0;
@@ -71,10 +111,17 @@ classdef Data < handle
        end
        
        %% clone
        % creates copy of object
        function copy = clone(obj,handle)
        %   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
        function copy = clone(object,handle)
            % assume that dialog is closed
            if ~obj.valid
            if ~object.valid
                copy = [];
                return;
            end
@@ -84,9 +131,9 @@ classdef Data < handle
            else
                copy.function_name = '';
            end
            copy.function_inputs = obj.function_inputs;
            copy.checked = obj.checked;
            copy.settings = obj.settings;
            copy.function_inputs = object.function_inputs;
            copy.checked = object.checked;
            copy.settings = object.settings;
            
            
            copy.Grid2 = Grid(2,[]);
@@ -96,30 +143,52 @@ classdef Data < handle
            copy.Grid2.set_rGrid(copy.Grid0);
            

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

        end
        
        function [] = setvalues(obj,settings)
            obj.settings = settings;
        %% setvalues
        %   set the settings property to a settings object
        % inputs:
        %   object:Data - current object
        %   settings:Settings - settings object to save
        % outputs:
        %   none
        function [] = setvalues(object,settings)
            object.settings = settings;
        end
        
        function [] = copy_results(obj,dest)
        %% 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
        function [] = copy_results(object,dest)
            for i=1:size(dest.Grid0.Cells,2)
                for j=1:size(obj.Grid0.Cells,2)
                    if (strcmp(obj.Grid0.Cells(j).Cell1.cond_text,dest.Grid0.Cells(i).Cell1.cond_text) && strcmp(obj.Grid0.Cells(j).Cell2.cond_text,dest.Grid0.Cells(i).Cell2.cond_text))
                        dest.Grid0.Cells(i).result_text = obj.Grid0.Cells(j).result_text;
                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
        
        function [] = save(obj)
            filename = [ obj.function_name '.table'];
            save(filename,'obj');
        %% save
        %   saves the current data object to an external file
        % inputs:
        %   object:Data - current Data object
        % outputs:
        %   none
        function [] = save(object)
            filename = [ object.function_name '.table'];
            save(filename,'object');
        end
    end
    
+88 −32
Original line number Diff line number Diff line
@@ -8,7 +8,16 @@ classdef EMLGenerator < handle
    end
    
    methods(Static)
        %%
        %% parse_inputs
        %    parse an input string and return the list of inputs as a
        %    matrix with accompaning type or indicating an error
        % inputs:
        %   input_string:string - string containing input string, comma
        %   delimited list of variables, each variable may or may not be
        %   followed by a colon then a type string.
        % outputs:
        %   revised_input:matrix - matrix containing parsed list, ex.
        %   [{'x' 'int'};{'y'};{ 'z:{x:real|x>1}' }]
        function revised_input = parse_inputs(input_string)
            revised_input = [];
            input_string2 = reshape(input_string',1,size(input_string,1)*size(input_string,2));
@@ -50,20 +59,40 @@ classdef EMLGenerator < handle
    end
    
    methods
        
        function obj = EMLGenerator(data)
            obj.data = data;
        end
        
        function [] = set_datatype(obj,type)
            obj.datatype = type;
        end
        
        function code = generate_preamble(obj)
        %% EMLGenerator
        %    constructor
        % inputs:
        %   data:Data - data object to use as data
        % outputs:
        %   object:EMLGenerator - created object
        function object = EMLGenerator(data)
            object.data = data;
        end
        
        %% set_datatype
        %    set the datatype property based inputed string based on the simulink settings
        % inputs:
        %   object:EMLGenerator - current object
        %   type:string - string of datatype conversion
        % outputs:
        %   none 
        function [] = set_datatype(object,type)
            object.datatype = type;
        end
        
        %% generate_preamble
        %    generates the preamble for the eml code, the preamble is
        %    everything before the first if statement, this is seperated
        %    out to make the code simpler. 
        % inputs:
        %   object:EMLGenerator - current object
        % outputs:
        %   code:string - string of eml code
        function code = generate_preamble(object)
                code = [];

                %generate input list
                parsed_input = EMLGenerator.parse_inputs(obj.data.function_inputs);
                parsed_input = EMLGenerator.parse_inputs(object.data.function_inputs);
                input = [];
                for i= 1:size(parsed_input,2)
                    input = [input char(parsed_input{i}(1))];
@@ -71,7 +100,7 @@ classdef EMLGenerator < handle
                        input = [input ',']
                    end
                end
                code = sprintf('function output = %s(%s)\n%s\n',obj.data.function_name,input,'%%#eml');
                code = sprintf('function output = %s(%s)\n%s\n',object.data.function_name,input,'%%#eml');
                % simulink forces you to have an output for all execution paths
                % since it can't compute completness and disjointness we need
                % to have a default value, if the user builds the table
@@ -81,23 +110,39 @@ classdef EMLGenerator < handle
                % table, we will use the first cell because it is
                % guaranteed to
                % be filled in, regardless of the dimensionality of the table.
                code = [code sprintf('output=%s(%s);\n',obj.datatype,char(obj.data.Grid0.Cells(1).result_text))];
                code = [code sprintf('output=%s(%s);\n',object.datatype,char(object.data.Grid0.Cells(1).result_text))];
        
        end
        
        
        function code = generate_eml_code(obj)
        %% generate_eml_code
        %    generates the embedded matlab code by calling other methods in
        %    this class
        % inputs:
        %   object:EMLGenerator - current object
        % outputs:
        %   code:string - string of eml code
        function code = generate_eml_code(object)
            code = [];
            code = [code obj.generate_preamble];
            code = [code obj.generate_eml_cond(obj.data.Grid1,obj.data.Grid2,0)];
            %code = [code obj.generate_conditional(obj.data.Grid1,obj.data.Grid2,0)];
            code = [code object.generate_preamble];
            code = [code object.generate_eml_cond(object.data.Grid1,object.data.Grid2,0)];
            
        end
        
          
        
        %% generate_eml_horizontal
        function code = generate_eml_horizontal(obj,g1,g2_cell,depth)
        %    generate the embedded matlab code for grid1, seperated from
        %    the code for grid2 since for a 2d table grid1 conditions will
        %    be sub conditions of grid2 conditions
        % inputs:
        %   object:EMLGenerator - current object
        %   g1:Grid - Grid 1
        %   g2_cell:Cell - Cell for which grid1 is sub conditon of
        %   depth:int - integer representing recursion dept for formating
        %   use
        % outputs:
        %   code:string - string of eml code
        function code = generate_eml_horizontal(object,g1,g2_cell,depth)
            space = '';
            for i=1:depth
                space = [space sprintf('  ')];
@@ -121,24 +166,35 @@ classdef EMLGenerator < handle
                else
                    code = [code sprintf('%selseif(%s)\n',space,strtrim(char(g1.cells(i).cond_text)))];
                end
                resultcell = obj.data.Grid0.search_return(g1.cells(i),g2_cell);
                resultcell = object.data.Grid0.search_return(g1.cells(i),g2_cell);
                if(~isempty(resultcell))
                     code = [code sprintf('%soutput = %s(%s);\n',[space '  '],obj.datatype,strtrim(char(resultcell.result_text)))];
                     code = [code sprintf('%soutput = %s(%s);\n',[space '  '],object.datatype,strtrim(char(resultcell.result_text)))];
                                      
                else
                end
            end
            if(~isempty(elsecell))
                 resultcell = obj.data.Grid0.search_return(elsecell,g2_cell);
                code = [code sprintf('%selse\n%soutput = %s(%s);\n',space,[space '  '],obj.datatype,strtrim(char(resultcell.result_text)))];
                 resultcell = object.data.Grid0.search_return(elsecell,g2_cell);
                code = [code sprintf('%selse\n%soutput = %s(%s);\n',space,[space '  '],object.datatype,strtrim(char(resultcell.result_text)))];

            end
            code = [code sprintf('%send\n',space)];

        end
        
        %% genereate_pvs
        function code = generate_eml_cond(obj,g1,g2,depth)
        %% generate_eml_cond
        %    generate the embedded matlab for a conditon grid, recursive
        %    function, will call horizontal generator if finds conditions
        %    in that grid.
        % inputs:
        %   object:EMLGenerator - current object
        %   g1:Grid - Grid 1
        %   g2:Grid - Grid 2
        %   depth:int - integer representing recursion dept for formating
        %   use
        % outputs:
        %   code:string - string of eml code
        function code = generate_eml_cond(object,g1,g2,depth)
             space = '';
            for i=1:depth
                space = [space sprintf('  ')];
@@ -148,7 +204,7 @@ classdef EMLGenerator < handle
          code = [];
          %1D horizontal
          if(~isempty(g1cond1) && isempty(g2cond1))
            code = [code obj.generate_eml_horizontal(g1,g2.cells(1),depth)];
            code = [code object.generate_eml_horizontal(g1,g2.cells(1),depth)];
          % something in vertical column
          else

@@ -171,15 +227,15 @@ classdef EMLGenerator < handle
                end

                if(~isempty(g2.cells(i).subgrid))
                    code = [code obj.generate_eml_cond(g1,g2.cells(i).subgrid,depth+1)];
                    code = [code object.generate_eml_cond(g1,g2.cells(i).subgrid,depth+1)];
                else
                    if (~isempty(g1cond1))
                         code = [code obj.generate_eml_horizontal(g1,g2.cells(i),depth+1)];
                         code = [code object.generate_eml_horizontal(g1,g2.cells(i),depth+1)];
                    else    
                
                        resultcell = obj.data.Grid0.search_return(g1.cells(1),g2.cells(i));
                        resultcell = object.data.Grid0.search_return(g1.cells(1),g2.cells(i));
                        if(~isempty(resultcell))
                                code = [code sprintf('%soutput = %s(%s);\n',[space '  '],obj.datatype,strtrim(char(resultcell.result_text)))];
                                code = [code sprintf('%soutput = %s(%s);\n',[space '  '],object.datatype,strtrim(char(resultcell.result_text)))];

                        else
                        end
@@ -188,19 +244,19 @@ classdef EMLGenerator < handle
              
            end
           if(~isempty(elsecell))
                 %resultcell = obj.Grid0.search_return(elsecell,elsecell);
                 %resultcell = object.Grid0.search_return(elsecell,elsecell);
                code = [code sprintf('%selse\n',space)];

                if(~isempty(elsecell.subgrid))
                    code = [code obj.generate_eml_cond(g1,elsecell.subgrid,depth) sprintf('\n')];
                    code = [code object.generate_eml_cond(g1,elsecell.subgrid,depth) sprintf('\n')];
                else
                    if (~isempty(g1cond1))
                         code = [code obj.generate_eml_horizontal(g1,elsecell,depth) sprintf('\n')];
                         code = [code object.generate_eml_horizontal(g1,elsecell,depth) sprintf('\n')];
                    else    
                
                        resultcell = obj.data.Grid0.search_return(g1.cells(1),elsecell);
                        resultcell = object.data.Grid0.search_return(g1.cells(1),elsecell);
                        if(~isempty(resultcell))
                             code = [code sprintf('%soutput = %s(%s);\n',[space '  '],obj.datatype,strtrim(char(resultcell.result_text)))];
                             code = [code sprintf('%soutput = %s(%s);\n',[space '  '],object.datatype,strtrim(char(resultcell.result_text)))];
                                
                        end
                    end
+39 −39

File changed.

Preview size limit exceeded, changes collapsed.

+99 −89

File changed.

Preview size limit exceeded, changes collapsed.

Loading