33
44from pathlib import Path
55
6- def make_filter (output_dir : Path , name : str , template_dir : Path ) -> None :
7- header_template_file = f'{ template_dir } /filter.hpp.in'
6+ def make_filter (plugin_dir : Path , name : str , template_dir : Path ) -> None :
7+
8+ plugin_name = plugin_dir .name
9+ filter_name = f'{ name } Filter'
10+ header_template_file = f'{ template_dir } /simplnx_filter.hpp.in'
811 header_file_contents : str
912 with open (header_template_file , 'r' ) as header_file :
10- header_file_contents = header_file .read ().replace ('@FILTER_NAME@' , name ).replace ('@UUID@' , str (uuid .uuid4 ()))
13+ header_file_contents = header_file .read ().replace ('@FILTER_NAME@' , filter_name ).replace ('@UUID@' , str (uuid .uuid4 ()))
14+ header_file_contents = header_file_contents .replace ('@PLUGIN_NAME_UPPER@' , plugin_name .upper ())
15+ header_file_contents = header_file_contents .replace ('@PLUGIN_NAME@' , plugin_name )
16+ header_file_contents = header_file_contents .replace ('@PARAMETER_KEYS@' , " // THESE NEED TO BE GENERATED\n " )
1117
1218 # write contents out to the new target header file
13- header_target_file = f'{ output_dir } / { name } .hpp'
19+ header_target_file = f'{ plugin_dir } /src/ { plugin_name } /Filters/ { name } Filter .hpp'
1420 print (f'Writing Header file: { header_target_file } ' )
1521 with open (header_target_file , 'w' ) as header_file :
1622 header_file .write (header_file_contents )
1723
18- cpp_template_file = f'{ template_dir } /filter .cpp.in'
24+ cpp_template_file = f'{ template_dir } /simplnx_filter .cpp.in'
1925 cpp_file_contents : str
2026 with open (cpp_template_file , 'r' ) as cpp_file :
21- cpp_file_contents = cpp_file .read ().replace ('@FILTER_NAME@' , name )
27+ cpp_file_contents = cpp_file .read ().replace ('@ALGORITHM_NAME@' , name )
28+ cpp_file_contents = cpp_file_contents .replace ('@FILTER_NAME@' , filter_name )
29+ cpp_file_contents = cpp_file_contents .replace ('@PLUGIN_NAME@' , plugin_name )
30+ cpp_file_contents = cpp_file_contents .replace ('@PARAMETER_KEYS@' , " //TODO: THESE NEED TO BE GENERATED\n " )
31+ cpp_file_contents = cpp_file_contents .replace ('@PARAMETER_INCLUDES@' , "\n //TODO: PARAMETER_INCLUDES" )
32+ cpp_file_contents = cpp_file_contents .replace ('@DEFAULT_TAGS@' , "\" \" " )
33+ cpp_file_contents = cpp_file_contents .replace ('@PARAMETER_DEFS@' , "\n //TODO: PARAMETER_DEFS" )
34+ cpp_file_contents = cpp_file_contents .replace ('@PREFLIGHT_DEFS@' , "\n //TODO: PREFLIGHT_DEFS" )
35+ cpp_file_contents = cpp_file_contents .replace ('@PROPOSED_ACTIONS@' , "\n //TODO: PROPOSED_ACTIONS" )
36+ cpp_file_contents = cpp_file_contents .replace ('@PREFLIGHT_UPDATED_DEFS@' , "\n //TODO: PREFLIGHT_UPDATED_DEFS" )
37+ cpp_file_contents = cpp_file_contents .replace ('@PREFLIGHT_UPDATED_VALUES@' , "\n //TODO: PREFLIGHT_UPDATED_VALUES" )
38+ cpp_file_contents = cpp_file_contents .replace ('@PARAMETER_JSON_CONSTANTS@' , "\n //TODO: PARAMETER_JSON_CONSTANTS" )
39+ cpp_file_contents = cpp_file_contents .replace ('@INPUT_VALUES_DEF@' , "\n //TODO: INPUT_VALUES_DEF" )
40+ cpp_file_contents = cpp_file_contents .replace ('@PARAMETER_JSON_CONVERSION@' , "/* This is a NEW filter and not ported so this section does not matter */" )
41+
42+ # write contents out to the new target CPP file
43+ cpp_target_file = f'{ plugin_dir } /src/{ plugin_name } /Filters/{ name } Filter.cpp'
44+ print (f'Writing CPP file: { cpp_target_file } ' )
45+ with open (cpp_target_file , 'w' ) as cpp_file :
46+ cpp_file .write (cpp_file_contents )
47+
48+ # ***************************************************************************
49+ # Algorithm File Generation
50+ # ***************************************************************************
51+ header_template_file = f'{ template_dir } /simplnx_algorithm.hpp.in'
52+ header_file_contents : str
53+ with open (header_template_file , 'r' ) as header_file :
54+ header_file_contents = header_file .read ().replace ('@FILTER_NAME@' , name ).replace ('@UUID@' , str (uuid .uuid4 ()))
55+ header_file_contents = header_file_contents .replace ('@PLUGIN_NAME_UPPER@' , plugin_name .upper ())
56+ header_file_contents = header_file_contents .replace ('@PLUGIN_NAME@' , plugin_name )
57+ header_file_contents = header_file_contents .replace ('@PARAMETER_KEYS@' , " // THESE NEED TO BE GENERATED\n " )
58+ header_file_contents = header_file_contents .replace ('@PARAMETER_INCLUDES@' , "\n //TODO: PARAMETER_INCLUDES" )
59+ header_file_contents = header_file_contents .replace ('@INPUT_VALUE_STRUCT_DEF@' , "//TODO: INPUT_VALUE_STRUCT_DEF\n " )
2260
2361 # write contents out to the new target header file
24- cpp_target_file = f'{ output_dir } /{ name } .cpp'
62+ header_target_file = f'{ plugin_dir } /src/{ plugin_name } /Filters/Algorithms/{ name } .hpp'
63+ print (f'Writing Header file: { header_target_file } ' )
64+ with open (header_target_file , 'w' ) as header_file :
65+ header_file .write (header_file_contents )
66+
67+ cpp_template_file = f'{ template_dir } /simplnx_algorithm.cpp.in'
68+ cpp_file_contents : str
69+ with open (cpp_template_file , 'r' ) as cpp_file :
70+ cpp_file_contents = cpp_file .read ().replace ('@FILTER_NAME@' , name )
71+
72+ # write contents out to the new target CPP file
73+ cpp_target_file = f'{ plugin_dir } /src/{ plugin_name } /Filters/Algorithms/{ name } .cpp'
2574 print (f'Writing CPP file: { cpp_target_file } ' )
2675 with open (cpp_target_file , 'w' ) as cpp_file :
2776 cpp_file .write (cpp_file_contents )
2877
78+ # ***************************************************************************
79+ # Unit test File Generation
80+ # ***************************************************************************
81+ cpp_template_file = f'{ template_dir } /simplnx_unit_test.cpp.in'
82+ cpp_file_contents : str
83+ with open (cpp_template_file , 'r' ) as cpp_file :
84+ cpp_file_contents = cpp_file .read ().replace ('@FILTER_NAME@' , filter_name )
85+ cpp_file_contents = cpp_file_contents .replace ('@PARAMETER_INCLUDES@' , "\n //TODO: PARAMETER_INCLUDES" )
86+ cpp_file_contents = cpp_file_contents .replace ('@PLUGIN_NAME@' , plugin_name )
87+ cpp_file_contents = cpp_file_contents .replace ('@PARAMETER_DEFS@' , "\n //TODO: PARAMETER_DEFS" )
88+
89+ # write contents out to the new target CPP file
90+ cpp_target_file = f'{ plugin_dir } /test/{ name } Test.cpp'
91+ print (f'Writing Doc file: { cpp_target_file } ' )
92+ with open (cpp_target_file , 'w' ) as cpp_file :
93+ cpp_file .write (cpp_file_contents )
94+
95+
96+ # ***************************************************************************
97+ # Documentation File Generation
98+ # ***************************************************************************
99+ cpp_template_file = f'{ template_dir } /simplnx_docs.md.in'
100+ cpp_file_contents : str
101+ with open (cpp_template_file , 'r' ) as cpp_file :
102+ cpp_file_contents = cpp_file .read ().replace ('@FILTER_NAME@' , name )
103+
104+ # write contents out to the new target CPP file
105+ cpp_target_file = f'{ plugin_dir } /docs/{ name } Filter.md'
106+ print (f'Writing Doc file: { cpp_target_file } ' )
107+ with open (cpp_target_file , 'w' ) as cpp_file :
108+ cpp_file .write (cpp_file_contents )
109+
110+
111+
29112 print (f'===================================================================' )
30- print (f'Do NOT forget to add your filter to the appropriate CMake Files' )
113+ print (f'Do NOT forget to add your filter and algorithm to the CMakeLists.txt file at:' )
114+ print (f'{ plugin_dir } /CMakeLists.txt' )
115+ print (f'Update the unit test CMakeLists.txt file at:' )
116+ print (f'{ plugin_dir } /test/CMakeLists.txt' )
117+ print (f'Do NOT forget to update the documentation file when you are done writing the file' )
31118 print (f'===================================================================' )
32119
33120def main () -> None :
34121 parser = argparse .ArgumentParser (description = 'Creates simplnx filter header and implementation skeleton codes' )
35- parser .add_argument ('-o' , '--output_dir ' , type = Path , help = 'Input directory where files will be created ' )
122+ parser .add_argument ('-o' , '--plugin_dir ' , type = Path , help = 'Plugin Directory to create the filter ' )
36123 parser .add_argument ('-n' , '--name' , type = str , help = 'Name of filter' )
37124 parser .add_argument ('-t' , '--template_dir' , type = Path , help = 'Location of template files' )
38125
39126 args = parser .parse_args ()
40127
41128 print ('args:' )
42- print (f' output_dir = \" { args .output_dir } \" ' )
129+ print (f' plugin_dir = \" { args .plugin_dir } \" ' )
43130 print (f' name = \" { args .name } \" ' )
44131 print (f' template_dir = \" { args .template_dir } \" ' )
45132 print ('' )
@@ -48,7 +135,12 @@ def main() -> None:
48135 print (f' THIS WILL OVERWRITE ANY EXISTING FILE' )
49136 print (f'===================================================================' )
50137
51- make_filter (args .output_dir , args .name , args .template_dir )
138+ make_filter (args .plugin_dir , args .name , args .template_dir )
52139
53140if __name__ == '__main__' :
54141 main ()
142+
143+ # -----------------------------------------------------------------------------
144+ # Example invocation
145+ # python make_filter.py --plugin_dir /Users/mjackson/Workspace1/simplnx/src/Plugins/SimplnxCore --name "ReadNotesFile" --template_dir /Users/mjackson/Workspace1/simplnx/scripts
146+ # -----------------------------------------------------------------------------
0 commit comments