Skip to content

Commit 34e7358

Browse files
smereupyansys-ci-botpre-commit-ci[bot]RobPasMuejacobrkerstetter
authored
feat: implement version based import (#2307)
Co-authored-by: PyAnsys CI Bot <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Roberto Pastor Muela <[email protected]> Co-authored-by: Jacob Kerstetter <[email protected]>
1 parent 0bdbc5c commit 34e7358

File tree

6 files changed

+285
-70
lines changed

6 files changed

+285
-70
lines changed

doc/changelog.d/2307.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Implement version based import

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: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@
3030
_check_write_body_facets_input,
3131
build_grpc_id,
3232
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,
3338
from_grpc_tess_to_raw_data,
3439
from_tess_options_to_grpc_tess_options,
3540
)
@@ -88,6 +93,22 @@ def new(self, **kwargs) -> dict: # noqa: D102
8893
"main_part_id": response.main_part.id,
8994
}
9095

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+
91112
@protect_grpc
92113
def close(self, **kwargs) -> dict: # noqa: D102
93114
# Create the request - assumes all inputs are valid and of the proper type
@@ -259,6 +280,178 @@ def request_generator(
259280
# Return the response - formatted as a dictionary
260281
return {"file_path": response.file_path}
261282

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+
262455
@protect_grpc
263456
def stream_design_tessellation(self, **kwargs) -> dict: # noqa: D102
264457
from ansys.api.dbu.v0.designs_pb2 import DesignTessellationRequest

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: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,6 @@ def __init__(
390390
self._material = material
391391
self._cross_section = cross_section
392392
self._properties = properties
393-
self._shape = shape
394393
self._type = beam_type
395394

396395
@property

0 commit comments

Comments
 (0)