|
30 | 30 | _check_write_body_facets_input, |
31 | 31 | build_grpc_id, |
32 | 32 | from_design_file_format_to_grpc_part_export_format, |
| 33 | + from_grpc_curve_to_curve, |
| 34 | + from_grpc_frame_to_frame, |
| 35 | + from_grpc_material_to_material, |
| 36 | + from_grpc_matrix_to_matrix, |
| 37 | + from_grpc_point_to_point3d, |
33 | 38 | from_grpc_tess_to_raw_data, |
34 | 39 | from_tess_options_to_grpc_tess_options, |
35 | 40 | ) |
@@ -88,6 +93,22 @@ def new(self, **kwargs) -> dict: # noqa: D102 |
88 | 93 | "main_part_id": response.main_part.id, |
89 | 94 | } |
90 | 95 |
|
| 96 | + @protect_grpc |
| 97 | + def get_assembly(self, **kwargs) -> dict: # noqa: D102 |
| 98 | + # Return the information needed to fill a design. |
| 99 | + active_design = kwargs["active_design"] |
| 100 | + design_id = active_design.get("design_id") |
| 101 | + |
| 102 | + # Create the request - assumes all inputs are valid and of the proper type |
| 103 | + request = build_grpc_id(id=design_id) |
| 104 | + |
| 105 | + # Call the gRPC service |
| 106 | + response = self.commands_stub.GetAssembly(request) |
| 107 | + |
| 108 | + # Return the response - formatted as a dictionary |
| 109 | + serialized_response = self._serialize_assembly_response(response) |
| 110 | + return serialized_response |
| 111 | + |
91 | 112 | @protect_grpc |
92 | 113 | def close(self, **kwargs) -> dict: # noqa: D102 |
93 | 114 | # Create the request - assumes all inputs are valid and of the proper type |
@@ -259,6 +280,178 @@ def request_generator( |
259 | 280 | # Return the response - formatted as a dictionary |
260 | 281 | return {"file_path": response.file_path} |
261 | 282 |
|
| 283 | + def _serialize_assembly_response(self, response): |
| 284 | + def serialize_body(body): |
| 285 | + return { |
| 286 | + "id": body.id, |
| 287 | + "name": body.name, |
| 288 | + "master_id": body.master_id, |
| 289 | + "parent_id": body.parent_id, |
| 290 | + "is_surface": body.is_surface, |
| 291 | + } |
| 292 | + |
| 293 | + def serialize_component(component): |
| 294 | + return { |
| 295 | + "id": component.id, |
| 296 | + "parent_id": component.parent_id, |
| 297 | + "master_id": component.master_id, |
| 298 | + "name": component.name, |
| 299 | + "placement": component.placement, |
| 300 | + "part_master": serialize_part(component.part_master), |
| 301 | + } |
| 302 | + |
| 303 | + def serialize_transformed_part(transformed_part): |
| 304 | + return { |
| 305 | + "id": transformed_part.id, |
| 306 | + "name": transformed_part.name, |
| 307 | + "placement": from_grpc_matrix_to_matrix(transformed_part.placement), |
| 308 | + "part_master": serialize_part(transformed_part.part_master), |
| 309 | + } |
| 310 | + |
| 311 | + def serialize_part(part): |
| 312 | + return { |
| 313 | + "id": part.id, |
| 314 | + "name": part.name, |
| 315 | + } |
| 316 | + |
| 317 | + def serialize_material_properties(material_property): |
| 318 | + return { |
| 319 | + "id": material_property.id, |
| 320 | + "display_name": material_property.display_name, |
| 321 | + "value": material_property.value, |
| 322 | + "units": material_property.units, |
| 323 | + } |
| 324 | + |
| 325 | + def serialize_material(material): |
| 326 | + material_properties = getattr(material, "material_properties", []) |
| 327 | + return { |
| 328 | + "name": material.name, |
| 329 | + "material_properties": [ |
| 330 | + serialize_material_properties(property) for property in material_properties |
| 331 | + ], |
| 332 | + } |
| 333 | + |
| 334 | + def serialize_named_selection(named_selection): |
| 335 | + return {"id": named_selection.id, "name": named_selection.name} |
| 336 | + |
| 337 | + def serialize_coordinate_systems(coordinate_systems): |
| 338 | + serialized_cs = [] |
| 339 | + for cs in coordinate_systems.coordinate_systems: |
| 340 | + serialized_cs.append( |
| 341 | + { |
| 342 | + "id": cs.id, |
| 343 | + "name": cs.name, |
| 344 | + "frame": from_grpc_frame_to_frame(cs.frame), |
| 345 | + } |
| 346 | + ) |
| 347 | + |
| 348 | + return serialized_cs |
| 349 | + |
| 350 | + def serialize_component_coordinate_systems(component_coordinate_system): |
| 351 | + serialized_component_coordinate_systems = [] |
| 352 | + for ( |
| 353 | + component_coordinate_system_id, |
| 354 | + coordinate_systems, |
| 355 | + ) in component_coordinate_system.items(): |
| 356 | + serialized_component_coordinate_systems.append( |
| 357 | + { |
| 358 | + "component_id": component_coordinate_system_id, |
| 359 | + "coordinate_systems": serialize_coordinate_systems(coordinate_systems), |
| 360 | + } |
| 361 | + ) |
| 362 | + |
| 363 | + return serialized_component_coordinate_systems |
| 364 | + |
| 365 | + def serialize_component_shared_topologies(component_share_topology): |
| 366 | + serialized_share_topology = [] |
| 367 | + for component_shared_topology_id, shared_topology in component_share_topology.items(): |
| 368 | + serialized_share_topology.append( |
| 369 | + { |
| 370 | + "component_id": component_shared_topology_id, |
| 371 | + "shared_topology_type": shared_topology, |
| 372 | + } |
| 373 | + ) |
| 374 | + return serialized_share_topology |
| 375 | + |
| 376 | + def serialize_beam_curve(curve): |
| 377 | + return { |
| 378 | + "curve": from_grpc_curve_to_curve(curve.curve), |
| 379 | + "start": from_grpc_point_to_point3d(curve.start), |
| 380 | + "end": from_grpc_point_to_point3d(curve.end), |
| 381 | + "interval_start": curve.interval_start, |
| 382 | + "interval_end": curve.interval_end, |
| 383 | + "length": curve.length, |
| 384 | + } |
| 385 | + |
| 386 | + def serialize_beam_curve_list(curve_list): |
| 387 | + return {"curves": [serialize_beam_curve(curve) for curve in curve_list.curves]} |
| 388 | + |
| 389 | + def serialize_beam_cross_section(cross_section): |
| 390 | + return { |
| 391 | + "section_anchor": cross_section.section_anchor, |
| 392 | + "section_angle": cross_section.section_angle, |
| 393 | + "section_frame": from_grpc_frame_to_frame(cross_section.section_frame), |
| 394 | + "section_profile": [ |
| 395 | + serialize_beam_curve_list(curve_list) |
| 396 | + for curve_list in cross_section.section_profile |
| 397 | + ], |
| 398 | + } |
| 399 | + |
| 400 | + def serialize_beam_properties(properties): |
| 401 | + return { |
| 402 | + "area": properties.area, |
| 403 | + "centroid_x": properties.centroid_x, |
| 404 | + "centroid_y": properties.centroid_y, |
| 405 | + "warping_constant": properties.warping_constant, |
| 406 | + "ixx": properties.ixx, |
| 407 | + "ixy": properties.ixy, |
| 408 | + "iyy": properties.iyy, |
| 409 | + "shear_center_x": properties.shear_center_x, |
| 410 | + "shear_center_y": properties.shear_center_y, |
| 411 | + "torsional_constant": properties.torsional_constant, |
| 412 | + } |
| 413 | + |
| 414 | + def serialize_beam(beam): |
| 415 | + return { |
| 416 | + "id": beam.id.id, |
| 417 | + "parent_id": beam.parent.id, |
| 418 | + "start": from_grpc_point_to_point3d(beam.shape.start), |
| 419 | + "end": from_grpc_point_to_point3d(beam.shape.end), |
| 420 | + "name": beam.name, |
| 421 | + "is_deleted": beam.is_deleted, |
| 422 | + "is_reversed": beam.is_reversed, |
| 423 | + "is_rigid": beam.is_rigid, |
| 424 | + "material": from_grpc_material_to_material(beam.material), |
| 425 | + "type": beam.type, |
| 426 | + "properties": serialize_beam_properties(beam.properties), |
| 427 | + "cross_section": serialize_beam_cross_section(beam.cross_section), |
| 428 | + } |
| 429 | + |
| 430 | + parts = getattr(response, "parts", []) |
| 431 | + transformed_parts = getattr(response, "transformed_parts", []) |
| 432 | + bodies = getattr(response, "bodies", []) |
| 433 | + components = getattr(response, "components", []) |
| 434 | + materials = getattr(response, "materials", []) |
| 435 | + named_selections = getattr(response, "named_selections", []) |
| 436 | + component_coordinate_systems = getattr(response, "component_coord_systems", []) |
| 437 | + component_shared_topologies = getattr(response, "component_shared_topologies", []) |
| 438 | + beams = getattr(response, "beams", []) |
| 439 | + return { |
| 440 | + "parts": [serialize_part(part) for part in parts] if len(parts) > 0 else [], |
| 441 | + "transformed_parts": [serialize_transformed_part(tp) for tp in transformed_parts], |
| 442 | + "bodies": [serialize_body(body) for body in bodies] if len(bodies) > 0 else [], |
| 443 | + "components": [serialize_component(component) for component in components], |
| 444 | + "materials": [serialize_material(material) for material in materials], |
| 445 | + "named_selections": [serialize_named_selection(ns) for ns in named_selections], |
| 446 | + "component_coordinate_systems": serialize_component_coordinate_systems( |
| 447 | + component_coordinate_systems |
| 448 | + ), |
| 449 | + "component_shared_topologies": serialize_component_shared_topologies( |
| 450 | + component_shared_topologies |
| 451 | + ), |
| 452 | + "beams": [serialize_beam(beam) for beam in beams], |
| 453 | + } |
| 454 | + |
262 | 455 | @protect_grpc |
263 | 456 | def stream_design_tessellation(self, **kwargs) -> dict: # noqa: D102 |
264 | 457 | from ansys.api.dbu.v0.designs_pb2 import DesignTessellationRequest |
|
0 commit comments