1 # Copyright (C) 2012-2013 EDF
3 # This file is part of SALOME HYDRO module.
5 # SALOME HYDRO module is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # SALOME HYDRO module is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with SALOME HYDRO module. If not, see <http://www.gnu.org/licenses/>.
20 from generator.generator_file_from_template import FileFromTemplateGenerator
23 return {'name': 'coupling1d2d',
24 'factory' : Coupling1D2DGenerator}
26 class Coupling1D2DGenerator(FileFromTemplateGenerator):
28 This generator is mostly identical to FileFromTemplateGenerator, but it
29 can also perform replacements using functions. The syntax for this kind
30 of replacement is %func(KEYWORD)%. The replacement method will call
31 the function "func" that must be defined in this class with the parameter
32 KEYWORD. The available function is parse_entry.
35 def generate_output_from_template(self):
37 Generate the output by replacing the keywords and the functions in the
40 FileFromTemplateGenerator.generate_output_from_template(self)
41 self.output_text = self.replace_functions(self.output_text)
43 def replace_functions(self, template_string):
45 Replace the functions in the template string.
47 result = template_string
48 pattern = "%(.*)\((.*)\)%"
49 matchObj = re.search(pattern, result)
51 (whole_string, func_name, param_keyword) = matchObj.group(0, 1, 2)
52 param_value = self.kw_dict[param_keyword]
53 func = eval(func_name)
54 value = func(param_value)
55 result = result.replace(whole_string, value)
56 matchObj = re.search(pattern, result)
59 def parse_entry(selected_value):
61 Find entry if selected_value is something like "name (entry)"
63 entry = selected_value
64 match = re.search("\((.*)\)$", entry)
66 entry = match.group(1)