|
19 | 19 | from catkin_pkg.package import package_exists_at
|
20 | 20 | from catkin_pkg.package import parse_package
|
21 | 21 |
|
| 22 | +from rosidl_adapter.action import convert_action_to_idl |
| 23 | +from rosidl_adapter.msg import convert_msg_to_idl |
| 24 | +from rosidl_adapter.srv import convert_srv_to_idl |
| 25 | + |
| 26 | +from rosidl_cli.command.helpers import interface_path_as_tuple |
| 27 | +from rosidl_cli.command.translate.extensions import TranslateCommandExtension |
| 28 | + |
22 | 29 |
|
23 | 30 | def convert_files_to_idl(extension, conversion_function, argv=sys.argv[1:]):
|
24 | 31 | parser = argparse.ArgumentParser(
|
@@ -48,3 +55,54 @@ def convert_files_to_idl(extension, conversion_function, argv=sys.argv[1:]):
|
48 | 55 | package_dir, pkg.name,
|
49 | 56 | interface_file.absolute().relative_to(package_dir),
|
50 | 57 | interface_file.parent)
|
| 58 | + |
| 59 | + |
| 60 | +class TranslateToIDL(TranslateCommandExtension): |
| 61 | + |
| 62 | + output_format = 'idl' |
| 63 | + |
| 64 | + def translate( |
| 65 | + self, |
| 66 | + package_name, |
| 67 | + interface_files, |
| 68 | + include_paths, |
| 69 | + output_path |
| 70 | + ): |
| 71 | + translated_interface_files = [] |
| 72 | + for interface_file in interface_files: |
| 73 | + prefix, interface_file = interface_path_as_tuple(interface_file) |
| 74 | + output_dir = output_path / interface_file.parent |
| 75 | + translated_interface_file = self.conversion_function( |
| 76 | + prefix, package_name, interface_file, output_dir) |
| 77 | + translated_interface_file = \ |
| 78 | + translated_interface_file.relative_to(output_path) |
| 79 | + translated_interface_files.append( |
| 80 | + f'{output_path}:{translated_interface_file.as_posix()}' |
| 81 | + ) |
| 82 | + return translated_interface_files |
| 83 | + |
| 84 | + |
| 85 | +class TranslateMsgToIDL(TranslateToIDL): |
| 86 | + |
| 87 | + input_format = 'msg' |
| 88 | + |
| 89 | + @property |
| 90 | + def conversion_function(self): |
| 91 | + return convert_msg_to_idl |
| 92 | + |
| 93 | + |
| 94 | +class TranslateSrvToIDL(TranslateToIDL): |
| 95 | + |
| 96 | + input_format = 'srv' |
| 97 | + |
| 98 | + @property |
| 99 | + def conversion_function(self): |
| 100 | + return convert_srv_to_idl |
| 101 | + |
| 102 | + |
| 103 | +class TranslateActionToIDL(TranslateToIDL): |
| 104 | + input_format = 'action' |
| 105 | + |
| 106 | + @property |
| 107 | + def conversion_function(self): |
| 108 | + return convert_action_to_idl |
0 commit comments