Commit 7f4e3b1c authored by Colin Eles's avatar Colin Eles
Browse files

latest

git-svn-id: https://groke.mcmaster.ca/svn/grad/colin/trunk/TableTool@5983 57e6efec-57d4-0310-aeb1-a6c144bb1a8b
parent 28c0f1a5
Loading
Loading
Loading
Loading

#my_func.pvs#

0 → 100644
+9 −0
Original line number Diff line number Diff line
my_func:THEORY
BEGIN
IMPORTING ENUM_TYPES
my_func(x:real,y:real,z:real):real = 
COND
x>1->y+z,
x<1->y-z
ENDCOND
END my_func
 No newline at end of file

Cell.m~

0 → 100644
+202 −0
Original line number Diff line number Diff line
classdef Cell < handle
    
    
    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;
    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;
            
        end
        
        %% new_Grid
        %    
        % inputs:
        %   object:Cell - Current Cell Object
        % outputs;
        %   
        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
        
        %% delete_Cell
        %    deletes the current cell, will recursively delete any subgrids
        %    if they exist.
        % inputs:
        %   object:Cell - Current Cell Object         
        % outputs;
        %   none
        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
        
        %% set_pb
        %    create the new subgrid push button handle
        % inputs:
        %   object:Cell - Current Cell Object  
        % outputs;
        %   none
        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
        
        %% 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
        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);
        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
        function h = cal_height(obj,edit)
            h = 0;
            if (isempty(obj.subgrid))
                h = 1;
            else
                for i=1:size(obj.subgrid.cells,2)
                    h = h + cal_height(obj.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
        
        %% get_pos
        %    Returns the position of the edit box for the cell
        % inputs:
        %   obj: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');
            end
        end
        
        %% set_pos
        %    allows accessor to set the position of the edit box for the
        %    cell.
        % inputs:
        %   obj: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);
            end
        end
        
        %% flag_cell
        % mode
        %   0 - normal
        %   1 - red (error/false)
        %   2 - green (ok/true)
        function [] = flag_cell(obj,mode)
        
            if (isempty(obj.color))
                obj.color = get(obj.cond,'BackgroundColor');
            end
            
            if (mode == 0)
                set(obj.cond,'BackgroundColor',obj.color);
            elseif (mode == 1)
                set(obj.cond,'BackgroundColor',[0.92 0.65 0.65])
            elseif (mode == 2)
                set(obj.cond,'BackgroundColor',[0.03 1.0 0.32]);
            end
        
        end
        
        function new_cell = clone()
            
        end
    end
    
end

Data.m~

0 → 100644
+195 −0
Original line number Diff line number Diff line
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 = [];
        function_name = [];
        function_inputs = [];
        settings = [];
        checked = [];
        open = [];
        fig = [];
    end
    
    
    
    methods
        
        %% Data
        %   constructor
        % inputs:
        %   none
        % outputs:
        %   none
        function obj = 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;
            object.Grid2 = grid2;
            object.function_name = name;
            object.function_inputs = inputs;
            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,[]);
            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;
        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;
            grid2 = object.Grid2;
            name = object.function_name;
            inputs = object.function_inputs;
            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;
                return
            end
            if isempty(object.Grid1)
                valid = 0;
                return
            end
            if isempty(object.Grid2)
                valid = 0;
                return
            end
            valid = 1;
        
        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
        function copy = clone(obj,handle)
            % assume that dialog is closed
            if ~obj.valid
                copy = [];
                return;
            end
            copy = Data();
            if ~isempty(handle)
            copy.function_name =   get(handle,'Name');
            else
                copy.function_name = '';
            end
            copy.function_inputs = obj.function_inputs;
            copy.checked = obj.checked;
            copy.settings = obj.settings;
            
            
            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);
            

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

        end
        
        %% setvalues
        %   set the settings property to a settings object
        % inputs:
        %   object:Data - current object
        %   settings:Settings - settings object to save
        % outputs:
        %   none
        function [] = setvalues(obj,settings)
            obj.settings = settings;
        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 - 
        % outputs:
        %   none
        function [] = copy_results(obj,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;
                    end
                end
            end
        end
        
        %% save
        %   constructor
        % inputs:
        %   none
        % outputs:
        %   none
        function [] = save(obj)
            filename = [ obj.function_name '.table'];
            save(filename,'obj');
        end
    end
    
end
+27 −5
Original line number Diff line number Diff line
@@ -56,6 +56,26 @@ classdef EMLGenerator < handle
               revised_input = new_inputs;
           end
        end
        
        
        %% type_convert
        %    generate a type conversion string based on an inputed type and
        %    an expression to convert.
        % inputs:
        %   type:string - datatype string
        %   expression:string - string of the expression
        % outputs:
        %   converted:string - type conversion string
        function converted = type_convert(type,expression)
            if strncmp(type,'fixdt',5)
                params = type(7:end-1)
                converted = ['fi(' expression ',' params ')'];
            else
                converted = [type '(' expression ')']
            end
        end

        
    end
    
    methods
@@ -110,7 +130,7 @@ 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',object.datatype,char(object.data.Grid0.Cells(1).result_text))];
                code = [code sprintf('output=%s;\n',EMLGenerator.type_convert(object.datatype,char(object.data.Grid0.Cells(1).result_text)))];
        
        end
        
@@ -168,14 +188,14 @@ classdef EMLGenerator < handle
                end
                resultcell = object.data.Grid0.search_return(g1.cells(i),g2_cell);
                if(~isempty(resultcell))
                     code = [code sprintf('%soutput = %s(%s);\n',[space '  '],object.datatype,strtrim(char(resultcell.result_text)))];
                     code = [code sprintf('%soutput = %s;\n',[space '  '],EMLGenerator.type_convert(object.datatype,strtrim(char(resultcell.result_text))))];
                                      
                else
                end
            end
            if(~isempty(elsecell))
                 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)))];
                code = [code sprintf('%selse\n%soutput = %s;\n',space,[space '  '],EMLGenerator.type_convert(object.datatype,strtrim(char(resultcell.result_text))))];

            end
            code = [code sprintf('%send\n',space)];
@@ -235,7 +255,7 @@ classdef EMLGenerator < handle
                
                        resultcell = object.data.Grid0.search_return(g1.cells(1),g2.cells(i));
                        if(~isempty(resultcell))
                                code = [code sprintf('%soutput = %s(%s);\n',[space '  '],object.datatype,strtrim(char(resultcell.result_text)))];
                                code = [code sprintf('%soutput = %s;\n',[space '  '],EMLGenerator.type_convert(object.datatype,strtrim(char(resultcell.result_text))))];

                        else
                        end
@@ -256,7 +276,7 @@ classdef EMLGenerator < handle
                
                        resultcell = object.data.Grid0.search_return(g1.cells(1),elsecell);
                        if(~isempty(resultcell))
                             code = [code sprintf('%soutput = %s(%s);\n',[space '  '],object.datatype,strtrim(char(resultcell.result_text)))];
                             code = [code sprintf('%soutput = %s;\n',[space '  '],EMLGenerator.type_convert(object.datatype,strtrim(char(resultcell.result_text))))];
                                
                        end
                    end
@@ -269,6 +289,8 @@ classdef EMLGenerator < handle
          end
        end
        
        
        
    end
    
end

EMLGenerator.m~

0 → 100644
+297 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading