Skip to content

Commit 49acf87

Browse files
jacobrkerstetterb-matteopyansys-ci-botpre-commit-ci[bot]
authored
chore: v1 implementation of file/designs stub (#2443)
Co-authored-by: Matteo Bini <[email protected]> Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent faf079a commit 49acf87

File tree

15 files changed

+712
-141
lines changed

15 files changed

+712
-141
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Chore: v1 implementation of file/designs stub

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
from .conversions import (
3232
build_grpc_id,
3333
from_frame_to_grpc_frame,
34+
from_grpc_edge_tess_to_pd,
35+
from_grpc_edge_tess_to_raw_data,
3436
from_grpc_point_to_point3d,
3537
from_grpc_tess_to_pd,
3638
from_grpc_tess_to_raw_data,
@@ -1359,4 +1361,19 @@ def get_full_tessellation(self, **kwargs): # noqa: D102
13591361
resp = self.stub.GetTessellationStream(request=request)
13601362

13611363
# Return the response - formatted as a dictionary
1362-
return {"tessellation": from_grpc_tess_to_pd(resp)}
1364+
tess_map = {}
1365+
for elem in resp:
1366+
for face_id, face_tess in elem.response_data[0].face_tessellation.items():
1367+
tess_map[face_id] = (
1368+
from_grpc_tess_to_raw_data(face_tess)
1369+
if kwargs["raw_data"]
1370+
else from_grpc_tess_to_pd(face_tess)
1371+
)
1372+
for edge_id, edge_tess in elem.response_data[0].edge_tessellation.items():
1373+
tess_map[edge_id] = (
1374+
from_grpc_edge_tess_to_raw_data(edge_tess)
1375+
if kwargs["raw_data"]
1376+
else from_grpc_edge_tess_to_pd(edge_tess)
1377+
)
1378+
1379+
return {"tessellation": tess_map}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ class GRPCCommandsScriptServiceV1(GRPCCommandsScriptService): # pragma: no cove
4343

4444
@protect_grpc
4545
def __init__(self, channel: grpc.Channel): # noqa: D102
46-
from ansys.api.discovery.v1.commands.script_pb2 import ScriptStub
46+
from ansys.api.discovery.v1.commands.script_pb2_grpc import ScriptStub
4747

4848
self.stub = ScriptStub(channel)
4949

5050
@protect_grpc
5151
def run_script_file(self, **kwargs) -> dict: # noqa: D102
52-
from aansys.api.discovery.v1.commands.script_pb2 import RunScriptFileRequest
52+
from ansys.api.discovery.v1.commands.script_pb2 import RunScriptFileRequest
5353

5454
# Create the request - assumes all inputs are valid and of the proper type
5555
request = RunScriptFileRequest(
@@ -63,7 +63,7 @@ def run_script_file(self, **kwargs) -> dict: # noqa: D102
6363

6464
# Return the response - formatted as a dictionary
6565
return {
66-
"success": response.success,
67-
"message": response.message,
66+
"success": response.command_response.success,
67+
"message": response.command_response.message,
6868
"values": None if not response.values else dict(response.values),
6969
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
from ansys.geometry.core.errors import protect_grpc
2727

2828
from ..base.components import GRPCComponentsService
29-
from ..base.conversions import from_measurement_to_server_angle
3029
from .conversions import (
3130
build_grpc_id,
31+
from_angle_to_grpc_quantity,
3232
from_grpc_matrix_to_matrix,
3333
from_point3d_to_grpc_point,
3434
from_unit_vector_to_grpc_direction,
@@ -80,7 +80,7 @@ def create(self, **kwargs) -> dict: # noqa: D102
8080
# Note: response.components is a repeated field, we return the first one
8181
component = response.components[0]
8282
return {
83-
"id": component.id,
83+
"id": component.id.id,
8484
"name": component.name,
8585
"instance_name": component.instance_name,
8686
"template": kwargs["template_id"], # template_id from input
@@ -132,7 +132,7 @@ def set_placement(self, **kwargs) -> dict: # noqa: D102
132132
translation=translation,
133133
rotation_axis_origin=origin,
134134
rotation_axis_direction=direction,
135-
rotation_angle=from_measurement_to_server_angle(kwargs["rotation_angle"]),
135+
rotation_angle=from_angle_to_grpc_quantity(kwargs["rotation_angle"]),
136136
)
137137
],
138138
)
@@ -143,7 +143,7 @@ def set_placement(self, **kwargs) -> dict: # noqa: D102
143143
# Return the response - formatted as a dictionary
144144
# Note: response.matrices is a map<string, Matrix>
145145
# Get the matrix for our component ID
146-
matrix_value = response.matrices.get(kwargs["id"].id)
146+
matrix_value = response.matrices.get(kwargs["id"])
147147
return {"matrix": from_grpc_matrix_to_matrix(matrix_value) if matrix_value else None}
148148

149149
@protect_grpc

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

Lines changed: 87 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323

2424
from typing import TYPE_CHECKING
2525

26+
from ansys.api.discovery.v1.commands.file_pb2 import (
27+
ImportOptionDefinition as GRPCImportOptionDefinition,
28+
)
2629
from ansys.api.discovery.v1.commonenums_pb2 import (
2730
BackendType as GRPCBackendType,
2831
FileFormat as GRPCFileFormat,
@@ -42,6 +45,7 @@
4245
)
4346
from ansys.api.discovery.v1.design.designmessages_pb2 import (
4447
CurveGeometry as GRPCCurveGeometry,
48+
DatumPointEntity as GRPCDesignPoint,
4549
DrivingDimensionEntity as GRPCDrivingDimension,
4650
EdgeTessellation as GRPCEdgeTessellation,
4751
EnhancedRepairToolMessage as GRPCEnhancedRepairToolResponse,
@@ -90,7 +94,7 @@
9094
from ansys.geometry.core.math.point import Point2D, Point3D
9195
from ansys.geometry.core.math.vector import UnitVector3D
9296
from ansys.geometry.core.misc.measurements import Measurement
93-
from ansys.geometry.core.misc.options import TessellationOptions
97+
from ansys.geometry.core.misc.options import ImportOptionsDefinitions, TessellationOptions
9498
from ansys.geometry.core.parameters.parameter import (
9599
Parameter,
96100
ParameterUpdateStatus,
@@ -237,6 +241,24 @@ def from_point2d_to_grpc_point(plane: "Plane", point2d: "Point2D") -> GRPCPoint:
237241
)
238242

239243

244+
def from_point3d_to_grpc_design_point(point: "Point3D") -> GRPCDesignPoint:
245+
"""Convert a ``Point3D`` class to a design point gRPC message.
246+
247+
Parameters
248+
----------
249+
point : Point3D
250+
Source point data.
251+
252+
Returns
253+
-------
254+
GRPCDesignPoint
255+
Geometry service gRPC design point message. The unit is meters.
256+
"""
257+
return GRPCDesignPoint(
258+
position=from_point3d_to_grpc_point(point),
259+
)
260+
261+
240262
def from_unit_vector_to_grpc_direction(unit_vector: "UnitVector3D") -> GRPCDirection:
241263
"""Convert a ``UnitVector3D`` class to a unit vector gRPC message.
242264
@@ -376,9 +398,9 @@ def from_grpc_frame_to_frame(frame: GRPCFrame) -> "Frame":
376398
return Frame(
377399
Point3D(
378400
input=[
379-
frame.origin.x,
380-
frame.origin.y,
381-
frame.origin.z,
401+
frame.origin.x.value_in_geometry_units,
402+
frame.origin.y.value_in_geometry_units,
403+
frame.origin.z.value_in_geometry_units,
382404
],
383405
unit=DEFAULT_UNITS.SERVER_LENGTH,
384406
),
@@ -1271,6 +1293,45 @@ def from_grpc_update_status_to_parameter_update_status(
12711293
return status_mapping.get(update_status, ParameterUpdateStatus.UNKNOWN)
12721294

12731295

1296+
def from_design_file_format_to_grpc_file_export_format(
1297+
design_file_format: "DesignFileFormat",
1298+
) -> GRPCFileFormat:
1299+
"""Convert from a DesignFileFormat object to a gRPC FileExportFormat one.
1300+
1301+
Parameters
1302+
----------
1303+
design_file_format : DesignFileFormat
1304+
The file format desired
1305+
1306+
Returns
1307+
-------
1308+
GRPCFileExportFormat
1309+
Converted gRPC File format
1310+
"""
1311+
from ansys.geometry.core.designer.design import DesignFileFormat
1312+
1313+
if design_file_format == DesignFileFormat.SCDOCX:
1314+
return GRPCFileFormat.FILEFORMAT_SCDOCX
1315+
elif design_file_format == DesignFileFormat.PARASOLID_TEXT:
1316+
return GRPCFileFormat.FILEFORMAT_PARASOLID_TEXT
1317+
elif design_file_format == DesignFileFormat.PARASOLID_BIN:
1318+
return GRPCFileFormat.FILEFORMAT_PARASOLID_BINARY
1319+
elif design_file_format == DesignFileFormat.FMD:
1320+
return GRPCFileFormat.FILEFORMAT_FMD
1321+
elif design_file_format == DesignFileFormat.STEP:
1322+
return GRPCFileFormat.FILEFORMAT_STEP
1323+
elif design_file_format == DesignFileFormat.IGES:
1324+
return GRPCFileFormat.FILEFORMAT_IGES
1325+
elif design_file_format == DesignFileFormat.PMDB:
1326+
return GRPCFileFormat.FILEFORMAT_PMDB
1327+
elif design_file_format == DesignFileFormat.STRIDE:
1328+
return GRPCFileFormat.FILEFORMAT_STRIDE
1329+
elif design_file_format == DesignFileFormat.DISCO:
1330+
return GRPCFileFormat.FILEFORMAT_DISCO
1331+
else:
1332+
return None
1333+
1334+
12741335
def from_material_to_grpc_material(
12751336
material: "Material",
12761337
) -> GRPCMaterial:
@@ -1447,6 +1508,28 @@ def from_parameter_to_grpc_quantity(value: float) -> GRPCQuantity:
14471508
return GRPCQuantity(value_in_geometry_units=value)
14481509

14491510

1511+
def from_import_options_definitions_to_grpc_import_options_definition(
1512+
import_options_definitions: "ImportOptionsDefinitions",
1513+
) -> GRPCImportOptionDefinition:
1514+
"""Convert an ``ImportOptionsDefinitions`` to import options definition gRPC message.
1515+
1516+
Parameters
1517+
----------
1518+
import_options_definitions : ImportOptionsDefinitions
1519+
Definition of the import options.
1520+
1521+
Returns
1522+
-------
1523+
GRPCImportOptionDefinition
1524+
Geometry service gRPC import options definition message.
1525+
"""
1526+
definitions = {}
1527+
for key, definition in import_options_definitions.to_dict().items():
1528+
definitions[key] = GRPCImportOptionDefinition(string_option=str(definition))
1529+
1530+
return definitions
1531+
1532+
14501533
def _nurbs_curves_compatibility(backend_version: "semver.Version", grpc_geometries: GRPCGeometries):
14511534
"""Check if the backend version is compatible with NURBS curves in sketches.
14521535
@@ -1514,45 +1597,6 @@ def from_enclosure_options_to_grpc_enclosure_options(
15141597
)
15151598

15161599

1517-
def from_design_file_format_to_grpc_file_format(
1518-
design_file_format: "DesignFileFormat",
1519-
) -> GRPCFileFormat:
1520-
"""Convert from a ``DesignFileFormat`` object to a gRPC file format.
1521-
1522-
Parameters
1523-
----------
1524-
design_file_format : DesignFileFormat
1525-
The file format desired
1526-
1527-
Returns
1528-
-------
1529-
GRPCFileFormat
1530-
Converted gRPC FileFormat.
1531-
"""
1532-
from ansys.geometry.core.designer.design import DesignFileFormat
1533-
1534-
if design_file_format == DesignFileFormat.SCDOCX:
1535-
return GRPCFileFormat.FILEFORMAT_SCDOCX
1536-
elif design_file_format == DesignFileFormat.PARASOLID_TEXT:
1537-
return GRPCFileFormat.FILEFORMAT_PARASOLID_TEXT
1538-
elif design_file_format == DesignFileFormat.PARASOLID_BIN:
1539-
return GRPCFileFormat.FILEFORMAT_PARASOLID_BINARY
1540-
elif design_file_format == DesignFileFormat.FMD:
1541-
return GRPCFileFormat.FILEFORMAT_FMD
1542-
elif design_file_format == DesignFileFormat.STEP:
1543-
return GRPCFileFormat.FILEFORMAT_STEP
1544-
elif design_file_format == DesignFileFormat.IGES:
1545-
return GRPCFileFormat.FILEFORMAT_IGES
1546-
elif design_file_format == DesignFileFormat.PMDB:
1547-
return GRPCFileFormat.FILEFORMAT_PMDB
1548-
elif design_file_format == DesignFileFormat.STRIDE:
1549-
return GRPCFileFormat.FILEFORMAT_STRIDE
1550-
elif design_file_format == DesignFileFormat.DISCO:
1551-
return GRPCFileFormat.FILEFORMAT_DISCO
1552-
else:
1553-
return None
1554-
1555-
15561600
def serialize_tracked_command_response(response: GRPCTrackedCommandResponse) -> dict:
15571601
"""Serialize a TrackedCommandResponse object into a dictionary.
15581602

0 commit comments

Comments
 (0)