From a8cb82c2d2ef5001ea24391d812faa132e81da00 Mon Sep 17 00:00:00 2001 From: Colin Eles Date: Thu, 12 Aug 2010 18:36:42 +0000 Subject: [PATCH] support for multiple outputs in simulink, toggle currently hardcoded need some sort of gui element for this, does not work with pvs yet git-svn-id: https://groke.mcmaster.ca/svn/grad/colin/trunk/TableTool@6064 57e6efec-57d4-0310-aeb1-a6c144bb1a8b --- @EMLGenerator/EMLGenerator.m | 1 + @EMLGenerator/generate_eml_cond.m | 17 +++++++++++++-- @EMLGenerator/generate_preamble.m | 35 +++++++++++++++++++++++++++++-- @GUI/GUI.m | 4 +++- @GUI/check_call.m | 6 ++++-- @GUI/save_call.m | 3 +++ @GUI/set_command_pos.m | 8 +++---- 7 files changed, 63 insertions(+), 11 deletions(-) diff --git a/@EMLGenerator/EMLGenerator.m b/@EMLGenerator/EMLGenerator.m index b8feb79..c76e5c0 100644 --- a/@EMLGenerator/EMLGenerator.m +++ b/@EMLGenerator/EMLGenerator.m @@ -5,6 +5,7 @@ classdef EMLGenerator < handle properties data = []; datatype = []; + multi_output = 1; end methods(Static) diff --git a/@EMLGenerator/generate_eml_cond.m b/@EMLGenerator/generate_eml_cond.m index f9f629a..5de8bdf 100644 --- a/@EMLGenerator/generate_eml_cond.m +++ b/@EMLGenerator/generate_eml_cond.m @@ -11,6 +11,10 @@ % outputs: % code:string - string of eml code function code = generate_eml_cond(object,g1,g2,depth) + + + multi_output = 0; + space = ''; for i=1:depth space = [space sprintf(' ')]; @@ -20,7 +24,11 @@ code = []; %1D horizontal if(~isempty(g1cond1) && isempty(g2cond1)) + if object.multi_output == 0 code = [code object.generate_eml_horizontal(g1,g2.cells(1),depth)]; + else + code = [code object.generate_eml_multi(g1,g2.cells(1),depth)]; + end % something in vertical column else @@ -46,9 +54,14 @@ code = [code object.generate_eml_cond(g1,g2.cells(i).subgrid,depth+1)]; else if (~isempty(g1cond1)) - code = [code object.generate_eml_horizontal(g1,g2.cells(i),depth+1)]; + if object.multi_output == 0 + code = [code object.generate_eml_horizontal(g1,g2.cells(1),depth+1)]; + else + code = [code object.generate_eml_multi(g1,g2.cells(1),depth+1)]; + end + %code = [code object.generate_eml_horizontal(g1,g2.cells(i),depth+1)]; else - + resultcell = object.data.Grid0.search_return(g1.cells(1),g2.cells(i)); if(~isempty(resultcell)) code = [code sprintf('%soutput = %s;\n',[space ' '],EMLGenerator.type_convert(object.datatype,strtrim(char(resultcell.result_text))))]; diff --git a/@EMLGenerator/generate_preamble.m b/@EMLGenerator/generate_preamble.m index d7768cf..e5c1dea 100644 --- a/@EMLGenerator/generate_preamble.m +++ b/@EMLGenerator/generate_preamble.m @@ -7,6 +7,7 @@ % outputs: % code:string - string of eml code function code = generate_preamble(object) + code = []; function_name = EMLGenerator.parse_inputs(object.data.function_name); %generate input list @@ -18,7 +19,23 @@ input = [input ','] end end - code = sprintf('function output = %s(%s)\n%s\n',char(function_name{1}(1)),input,'%%#eml'); + + output = []; + if (object.multi_output == 1) + for i=1:size(object.data.Grid1.cells,2) + parsed_output = EMLGenerator.parse_inputs(strtrim(char(object.data.Grid1.cells(i).cond_text))); + + output = [output char(parsed_output{1}(1))]; + + if i ~= size(object.data.Grid1.cells,2) + output = [output ','] + end + end + else + output = 'output'; + end + + code = sprintf('function [%s] = %s(%s)\n%s\n',output,char(function_name{1}(1)),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 @@ -28,7 +45,21 @@ % 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;\n',EMLGenerator.type_convert(object.datatype,char(object.data.Grid0.Cells(1).result_text)))]; + + if (object.multi_output == 1) + for i=1:size(object.data.Grid1.cells,2) + parsed_output = EMLGenerator.parse_inputs(strtrim(char(object.data.Grid1.cells(i).cond_text))); + + output_str = char(parsed_output{1}(1)); + + code = [code sprintf('%s=%s;\n',output_str,char(object.data.Grid0.Cells(i).result_text))]; + + end + + else + code = [code sprintf('output=%s;\n',EMLGenerator.type_convert(object.datatype,char(object.data.Grid0.Cells(1).result_text)))]; + + end end diff --git a/@GUI/GUI.m b/@GUI/GUI.m index b4d00eb..b3cd76b 100644 --- a/@GUI/GUI.m +++ b/@GUI/GUI.m @@ -30,7 +30,7 @@ classdef GUI < handle block_handle = []; settings = []; % height of header where buttons and text is - header_height = 100; + header_height = 120; % window size fig_height = 600; fig_width = 800; @@ -40,6 +40,8 @@ classdef GUI < handle pb_width = 80; % height of push buttons in header pb_height = 40; + % height of header text boxes + htx_height = 60; % width of text boxes text_width = 250; name_label = []; diff --git a/@GUI/check_call.m b/@GUI/check_call.m index 5869432..e448b06 100644 --- a/@GUI/check_call.m +++ b/@GUI/check_call.m @@ -10,12 +10,14 @@ % none function error = check_call(object,src,event) error = 0; - + multi_mode = 1; msg = object.check_inputs; if (isempty(msg)) set(object.function_inputs_control,'BackgroundColor',[1 1 1]) msg = object.check_grid_condition(object.Grid2); - msg = [msg object.check_grid_condition(object.Grid1)]; + if multi_mode == 0 + msg = [msg object.check_grid_condition(object.Grid1)]; + end msg = [msg object.check_grid_result(object.Grid0)]; else set(object.function_inputs_control,'BackgroundColor',[0.92 0.65 0.65]) diff --git a/@GUI/save_call.m b/@GUI/save_call.m index 52cfc6c..5da4023 100644 --- a/@GUI/save_call.m +++ b/@GUI/save_call.m @@ -11,6 +11,7 @@ % outputs: % none function eml_handle = save_call(object,src,event) + multi_type = 1; if(object.check_call([],[]) == 1) return; end @@ -44,7 +45,9 @@ load_system('simulink') % generate the code + if multi_type == 0 object.EMLGen.set_datatype(object.output_data_type); + end code = object.EMLGen.generate_eml_code; %code = [code object.generate_code(object.Grid1,object.Grid2,0)]; diff --git a/@GUI/set_command_pos.m b/@GUI/set_command_pos.m index c03498a..f4fb90b 100644 --- a/@GUI/set_command_pos.m +++ b/@GUI/set_command_pos.m @@ -19,10 +19,10 @@ set(object.input_pb,'Position',[object.pb_offset*7+object.pb_width*6,l_fig_height-object.pb_offset-object.pb_height,object.pb_width,object.pb_height]) set(object.settings_pb,'Position',[object.pb_offset*8+object.pb_width*7,l_fig_height-object.pb_offset-object.pb_height,object.pb_width,object.pb_height]) - set(object.name_label,'Position',[object.pb_offset l_fig_height-object.pb_offset*3-object.pb_height-object.pb_height object.pb_width object.pb_height]); - set(object.function_name_control,'Position',[object.pb_offset*2+object.pb_width l_fig_height-object.pb_offset*3-object.pb_height-object.pb_height object.text_width object.pb_height]); - set(object.input_label,'Position',[object.pb_offset*2+object.pb_width+object.text_width l_fig_height-object.pb_offset*3-object.pb_height-object.pb_height object.pb_width object.pb_height]); - set(object.function_inputs_control,'Position',[object.pb_offset*3+object.pb_width*2+object.text_width l_fig_height-object.pb_offset*3-object.pb_height-object.pb_height object.text_width object.pb_height]); + set(object.input_label,'Position',[object.pb_offset l_fig_height-object.pb_offset*3-object.pb_height-object.htx_height object.pb_width object.htx_height]); + set(object.function_inputs_control,'Position',[object.pb_offset*2+object.pb_width l_fig_height-object.pb_offset*3-object.htx_height-object.pb_height object.text_width object.htx_height]); + set(object.name_label,'Position',[object.pb_offset*2+object.pb_width+object.text_width l_fig_height-object.pb_offset*3-object.pb_height-object.htx_height object.pb_width object.htx_height]); + set(object.function_name_control,'Position',[object.pb_offset*3+object.pb_width*2+object.text_width l_fig_height-object.pb_offset*3-object.pb_height-object.htx_height object.text_width object.htx_height]); end \ No newline at end of file -- GitLab