|
11 | 11 | from enum import Enum |
12 | 12 | from ansys import dpf |
13 | 13 | from ansys.dpf.core import dpf_operator, inputs, outputs |
14 | | -from ansys.dpf.core.check_version import server_meet_version, version_requires |
| 14 | +from ansys.dpf.core.check_version import server_meet_version, version_requires, server_meet_version_and_raise |
15 | 15 | from ansys.dpf.core import server as server_module |
16 | 16 | from ansys.dpf.gate import ( |
17 | 17 | workflow_abstract_api, |
|
20 | 20 | data_processing_capi, |
21 | 21 | data_processing_grpcapi, |
22 | 22 | dpf_vector, |
23 | | - object_handler, |
| 23 | + object_handler, integral_types, |
24 | 24 | ) |
25 | 25 |
|
26 | 26 | LOG = logging.getLogger(__name__) |
@@ -106,6 +106,42 @@ def progress_bar(self) -> bool: |
106 | 106 | def progress_bar(self, value: bool) -> None: |
107 | 107 | self._progress_bar = value |
108 | 108 |
|
| 109 | + @staticmethod |
| 110 | + def _getoutput_string(self, pin): |
| 111 | + out = Workflow._getoutput_string_as_bytes(self, pin) |
| 112 | + if out is not None and not isinstance(out, str): |
| 113 | + return out.decode('utf-8') |
| 114 | + return out |
| 115 | + |
| 116 | + @staticmethod |
| 117 | + def _connect_string(self, pin, str): |
| 118 | + return Workflow._connect_string_as_bytes(self, pin, str.encode('utf-8')) |
| 119 | + |
| 120 | + @staticmethod |
| 121 | + def _getoutput_string_as_bytes(self, pin): |
| 122 | + if server_meet_version("8.0", self._server): |
| 123 | + size = integral_types.MutableUInt64(0) |
| 124 | + return self._api.work_flow_getoutput_string_with_size(self, pin, size) |
| 125 | + else: |
| 126 | + return self._api.work_flow_getoutput_string(self, pin) |
| 127 | + |
| 128 | + @staticmethod |
| 129 | + def _getoutput_bytes(self, pin): |
| 130 | + server_meet_version_and_raise( |
| 131 | + "8.0", |
| 132 | + self._server, |
| 133 | + "output of type bytes available with server's version starting at 8.0 (Ansys 2024R2)." |
| 134 | + ) |
| 135 | + return Workflow._getoutput_string_as_bytes(self, pin) |
| 136 | + |
| 137 | + @staticmethod |
| 138 | + def _connect_string_as_bytes(self, pin, str): |
| 139 | + if server_meet_version("8.0", self._server): |
| 140 | + size = integral_types.MutableUInt64(len(str)) |
| 141 | + return self._api.work_flow_connect_string_with_size(self, pin, str, size) |
| 142 | + else: |
| 143 | + return self._api.work_flow_connect_string(self, pin, str) |
| 144 | + |
109 | 145 | def connect(self, pin_name, inpt, pin_out=0): |
110 | 146 | """Connect an input on the workflow using a pin name. |
111 | 147 |
|
@@ -199,7 +235,8 @@ def _type_to_input_method(self): |
199 | 235 | out = [ |
200 | 236 | (bool, self._api.work_flow_connect_bool), |
201 | 237 | ((int, Enum), self._api.work_flow_connect_int), |
202 | | - (str, self._api.work_flow_connect_string), |
| 238 | + (str, self._connect_string), |
| 239 | + (bytes, self._connect_string_as_bytes), |
203 | 240 | (float, self._api.work_flow_connect_double), |
204 | 241 | (field.Field, self._api.work_flow_connect_field), |
205 | 242 | (property_field.PropertyField, self._api.work_flow_connect_property_field), |
@@ -260,7 +297,8 @@ def _type_to_output_method(self): |
260 | 297 | out = [ |
261 | 298 | (bool, self._api.work_flow_getoutput_bool), |
262 | 299 | (int, self._api.work_flow_getoutput_int), |
263 | | - (str, self._api.work_flow_getoutput_string), |
| 300 | + (str, self._getoutput_string), |
| 301 | + (bytes, self._getoutput_bytes), |
264 | 302 | (float, self._api.work_flow_getoutput_double), |
265 | 303 | (field.Field, self._api.work_flow_getoutput_field, "field"), |
266 | 304 | ( |
|
0 commit comments