Skip to content

Commit b0a660e

Browse files
committed
Move process of get assembly response to version specific
The information from get assembly is specific to the grpc response being processed and needed to be move the grpc version of the file. All conversion method are also moved to the version specific counterpart
1 parent 3611a99 commit b0a660e

File tree

5 files changed

+277
-69
lines changed

5 files changed

+277
-69
lines changed

src/ansys/geometry/core/_grpc/_services/base/designs.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ def new(self, **kwargs) -> dict:
4949
"""Create a new design."""
5050
pass
5151

52+
@abstractmethod
53+
def get_assembly(self, **kwargs) -> dict:
54+
"""Create a new design."""
55+
pass
56+
5257
@abstractmethod
5358
def close(self, **kwargs) -> dict:
5459
"""Close the currently open design."""

src/ansys/geometry/core/_grpc/_services/v0/designs.py

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# SOFTWARE.
2222
"""Module containing the designs service implementation for v0."""
2323

24+
from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier
2425
import grpc
2526

2627
from ansys.geometry.core.errors import protect_grpc
@@ -30,6 +31,11 @@
3031
_check_write_body_facets_input,
3132
build_grpc_id,
3233
from_design_file_format_to_grpc_part_export_format,
34+
from_grpc_curve_to_curve,
35+
from_grpc_frame_to_frame,
36+
from_grpc_material_to_material,
37+
from_grpc_matrix_to_matrix,
38+
from_grpc_point_to_point3d,
3339
)
3440

3541

@@ -86,6 +92,14 @@ def new(self, **kwargs) -> dict: # noqa: D102
8692
"main_part_id": response.main_part.id,
8793
}
8894

95+
@protect_grpc
96+
def get_assembly(self, **kwargs) -> dict: # noqa: D102
97+
active_design = kwargs["active_design"]
98+
design_id = active_design.get("design_id")
99+
response = self.commands_stub.GetAssembly(EntityIdentifier(id=design_id))
100+
serialized_response = self._serialize_assembly_response(response)
101+
return serialized_response
102+
89103
@protect_grpc
90104
def close(self, **kwargs) -> dict: # noqa: D102
91105
# Create the request - assumes all inputs are valid and of the proper type
@@ -256,3 +270,173 @@ def request_generator(
256270

257271
# Return the response - formatted as a dictionary
258272
return {"file_path": response.file_path}
273+
274+
def _serialize_assembly_response(self, response):
275+
def serialize_body(body):
276+
return {
277+
"id": body.id,
278+
"name": body.name,
279+
"master_id": body.master_id,
280+
"parent_id": body.parent_id,
281+
"is_surface": body.is_surface,
282+
}
283+
284+
def serialize_component(component):
285+
return {
286+
"id": component.id,
287+
"parent_id": component.parent_id,
288+
"master_id": component.master_id,
289+
"name": component.name,
290+
"placement": component.placement,
291+
"part_master": serialize_part(component.part_master),
292+
}
293+
294+
def serialize_transformed_part(transformed_part):
295+
return {
296+
"id": transformed_part.id,
297+
"name": transformed_part.name,
298+
"placement": from_grpc_matrix_to_matrix(transformed_part.placement),
299+
"part_master": serialize_part(transformed_part.part_master),
300+
}
301+
302+
def serialize_part(part):
303+
return {
304+
"id": part.id,
305+
"name": part.name,
306+
}
307+
308+
def serialize_material_properties(material_property):
309+
return {
310+
"id": material_property.id,
311+
"display_name": material_property.display_name,
312+
"value": material_property.value,
313+
"units": material_property.units,
314+
}
315+
316+
def serialize_material(material):
317+
material_properties = getattr(material, "material_properties", [])
318+
return {
319+
"name": material.name,
320+
"material_properties": [
321+
serialize_material_properties(property) for property in material_properties
322+
]
323+
}
324+
325+
def serialize_named_selection(named_selection):
326+
return {"id": named_selection.id, "name": named_selection.name}
327+
328+
def serialize_coordinate_systems(coordinate_systems):
329+
serialized_cs = []
330+
for cs in coordinate_systems.coordinate_systems:
331+
serialized_cs.append(
332+
{
333+
"id": cs.id,
334+
"name": cs.name,
335+
"frame": from_grpc_frame_to_frame(cs.frame),
336+
}
337+
)
338+
339+
return serialized_cs
340+
341+
def serialize_component_coordinate_systems(component_coordinate_system):
342+
serialized_component_coordinate_systems = []
343+
for (
344+
component_coordinate_system_id,
345+
coordinate_systems,
346+
) in component_coordinate_system.items():
347+
serialized_component_coordinate_systems.append(
348+
{
349+
"component_id": component_coordinate_system_id,
350+
"coordinate_systems": serialize_coordinate_systems(coordinate_systems),
351+
}
352+
)
353+
354+
return serialized_component_coordinate_systems
355+
356+
def serialize_component_shared_topologies(component_share_topology):
357+
serialized_share_topology = []
358+
for component_shared_topology_id, shared_topology in component_share_topology.items():
359+
serialized_share_topology.append(
360+
{
361+
"component_id": component_shared_topology_id,
362+
"shared_topology_type": shared_topology,
363+
}
364+
)
365+
return serialized_share_topology
366+
367+
def serialize_beam_curve(curve):
368+
return {
369+
"curve": from_grpc_curve_to_curve(curve.curve),
370+
"start": from_grpc_point_to_point3d(curve.start),
371+
"end": from_grpc_point_to_point3d(curve.end),
372+
"interval_start": curve.interval_start,
373+
"interval_end": curve.interval_end,
374+
"length": curve.length,
375+
}
376+
377+
def serialize_beam_curve_list(curve_list):
378+
return {"curves": [serialize_beam_curve(curve) for curve in curve_list.curves]}
379+
380+
def serialize_beam_cross_section(cross_section):
381+
return {
382+
"section_anchor": cross_section.section_anchor,
383+
"section_angle": cross_section.section_angle,
384+
"section_frame": from_grpc_frame_to_frame(cross_section.section_frame),
385+
"section_profile": [
386+
serialize_beam_curve_list(curve_list)
387+
for curve_list in cross_section.section_profile
388+
],
389+
}
390+
391+
def serialize_beam_properties(properties):
392+
return {
393+
"area": properties.area,
394+
"centroid_x": properties.centroid_x,
395+
"centroid_y": properties.centroid_y,
396+
"warping_constant": properties.warping_constant,
397+
"ixx": properties.ixx,
398+
"ixy": properties.ixy,
399+
"iyy": properties.iyy,
400+
"shear_center_x": properties.shear_center_x,
401+
"shear_center_y": properties.shear_center_y,
402+
"torsional_constant": properties.torsional_constant,
403+
}
404+
405+
def serialize_beam(beam):
406+
return {
407+
"id": beam.id.id,
408+
"parent_id": beam.parent.id,
409+
"start": from_grpc_point_to_point3d(beam.shape.start),
410+
"end": from_grpc_point_to_point3d(beam.shape.end),
411+
"name": beam.name,
412+
"is_deleted": beam.is_deleted,
413+
"is_reversed": beam.is_reversed,
414+
"is_rigid": beam.is_rigid,
415+
"material": from_grpc_material_to_material(beam.material),
416+
"type": beam.type,
417+
"properties": serialize_beam_properties(beam.properties),
418+
"cross_section": serialize_beam_cross_section(beam.cross_section),
419+
}
420+
421+
parts = getattr(response, "parts", [])
422+
transformed_parts = getattr(response, "transformed_parts", [])
423+
bodies = getattr(response, "bodies", [])
424+
components = getattr(response, "components", [])
425+
materials = getattr(response, "materials", [])
426+
named_selections = getattr(response, "named_selections", [])
427+
component_coordinate_systems = getattr(response, "component_coord_systems", [])
428+
component_shared_topologies = getattr(response, "component_shared_topologies", [])
429+
beams = getattr(response, "beams", [])
430+
return {
431+
"parts": [serialize_part(part) for part in parts] if len(parts) > 0 else [],
432+
"transformed_parts": [serialize_transformed_part(tp) for tp in transformed_parts],
433+
"bodies": [serialize_body(body) for body in bodies] if len(bodies) > 0 else [],
434+
"components": [serialize_component(component) for component in components],
435+
"materials": [serialize_material(material) for material in materials],
436+
"named_selections": [serialize_named_selection(ns) for ns in named_selections],
437+
"component_coordinate_systems": serialize_component_coordinate_systems(
438+
component_coordinate_systems),
439+
"component_shared_topologies": serialize_component_shared_topologies(
440+
component_shared_topologies),
441+
"beams": [serialize_beam(beam) for beam in beams],
442+
}

src/ansys/geometry/core/_grpc/_services/v1/designs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ def open(self, **kwargs) -> dict: # noqa: D102
5555
def new(self, **kwargs) -> dict: # noqa: D102
5656
raise NotImplementedError
5757

58+
@protect_grpc
59+
def get_assembly(self, **kwargs) -> dict: # noqa: D102
60+
raise NotImplementedError
61+
5862
@protect_grpc
5963
def close(self, **kwargs) -> dict: # noqa: D102
6064
raise NotImplementedError

src/ansys/geometry/core/designer/beam.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ def __init__(
390390
self._material = material
391391
self._cross_section = cross_section
392392
self._properties = properties
393-
self._shape = shape
393+
# self._shape = shape
394394
self._type = beam_type
395395

396396
@property

0 commit comments

Comments
 (0)