11import datetime
22from string import Template
3+ import re
34
45from robocompdsl .dsl_parsers .parsing_utils import communication_is_ice , get_name_number
56from robocompdsl .templates .templatePython .plugins .base .functions import function_utils as utils
@@ -78,11 +79,30 @@ def replace_type_cpp_to_python(t):
7879 def compute_creation (self ):
7980 result = COMPUTE_METHOD_STR
8081 return result
82+
83+ def is_ifaces (self , type_data , module , import_modules ):
84+ if type_data in [struct ['name' ].split ('/' )[1 ] for struct in module ['structs' ]+ module ['sequences' ]] or \
85+ type_data in [struct ['strName' ] for struct in module ['simpleSequences' ]]:
86+ return True
87+
88+ for mod in import_modules :
89+ patron = fr'RoboComp{ mod } ::(\w+)'
90+ match = re .fullmatch (patron , type_data )
91+ if match :
92+ return True
93+ return False
94+
8195
8296 def methods (self , interfaces , subscribe = False ):
8397 result = ""
8498 for interface , num in get_name_number (interfaces ):
8599 module = self .component .idsl_pool .module_providing_interface (interface .name )
100+ if module .get ("imports" ) is not None :
101+ import_modules = [mod .split ('.' )[0 ] for mod in module ['imports' ]]
102+ else :
103+ import_modules = []
104+
105+
86106 for module_interface in module ['interfaces' ]:
87107 if module_interface ['name' ] == interface .name :
88108 for mname in module_interface ['methods' ]:
@@ -100,27 +120,23 @@ def methods(self, interfaces, subscribe=False):
100120 param_str_a += ', ' + p ['name' ]
101121
102122 return_creation = ''
103- for out in out_values :
104- returned_type = ""
105- simple_type = out [0 ]
106- if simple_type in [struct ['name' ].split ('/' )[1 ] for struct in module ['structs' ]+ module ['sequences' ]] or \
107- simple_type in [struct ['strName' ] for struct in module ['simpleSequences' ]]:
108- returned_type = "ifaces."
109- returned_type += utils .get_type_string (simple_type , module ['name' ])
110- return_creation += f' { out [1 ]} = { returned_type } ()\n '
111-
112-
113123 return_str = "pass\n \n "
114124 if len (out_values ) == 1 :
115125 if method ['return' ] != 'void' :
116126 return_str = "return ret"
117127 else :
118- return_str = out_values [0 ][1 ] + " = " + self .replace_type_cpp_to_python (out_values [0 ][0 ]) + "()\n "
119- return_str += " return " + out_values [0 ][1 ]
128+ ifaces = ""
129+ if self .is_ifaces (type_data = out_values [0 ][0 ], module = module , import_modules = import_modules ):
130+ ifaces = "ifaces."
131+ return_creation = " " + out_values [0 ][1 ] + " = " + ifaces + self .replace_type_cpp_to_python (out_values [0 ][0 ]) + "()\n "
132+ return_str = "return " + out_values [0 ][1 ]
120133 elif len (out_values ) > 1 :
121134 for v in out_values :
135+ ifaces = ""
136+ if self .is_ifaces (type_data = v [0 ], module = module , import_modules = import_modules ):
137+ ifaces = "ifaces."
122138 if v [1 ] != 'ret' :
123- return_str += " " + v [1 ] + " = " + self .replace_type_cpp_to_python (v [0 ]) + "()\n "
139+ return_creation += " " + v [1 ] + " = " + ifaces + self .replace_type_cpp_to_python (v [0 ]) + "()\n "
124140 vector_str = ", " .join ([v [1 ] for v in out_values ])
125141 return_str = f"return [{ vector_str } ]"
126142 if subscribe :
@@ -198,7 +214,7 @@ def interface_specific_comment(self):
198214 action = action )
199215 structs_str = ""
200216 for struct in module ['structs' ]:
201- structs_str += f"# { struct ['name' ].replace ('/' , '.' )} \n "
217+ structs_str += f"# ifaces. { struct ['name' ].replace ('/' , '.' )} \n "
202218 if structs_str :
203219 result += Template (INTERFACE_TYPES_COMMENT_STR ).substitute (module_name = module ['name' ],
204220 types = structs_str )
0 commit comments