Skip to content

Commit 46c30c0

Browse files
Merge branch 'main' into feat/sweepable_body_detection
2 parents 7564a55 + b9faa09 commit 46c30c0

File tree

10 files changed

+182
-16
lines changed

10 files changed

+182
-16
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ repos:
2121
args: [--keep-full-version]
2222

2323
- repo: https://github.com/astral-sh/ruff-pre-commit
24-
rev: v0.14.5
24+
rev: v0.14.6
2525
hooks:
2626
- id: ruff-check
2727
- id: ruff-format
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
V1 implementation of components stub
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Bump beartype from 0.22.5 to 0.22.6
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Bump ansys-api-discovery from 1.0.9 to 1.0.10
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Pre-commit automatic update
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
V1 implementation of materials stub

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ general-all = [
9999
"ansys-platform-instancemanagement==1.1.2",
100100
"ansys-tools-common==0.2.1",
101101
"ansys-tools-visualization-interface==0.12.1",
102-
"beartype==0.22.5",
102+
"beartype==0.22.6",
103103
"docker==7.1.0",
104104
"geomdl==5.4.0",
105105
"grpcio==1.75.0",

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

Lines changed: 146 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
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
30+
from .conversions import (
31+
build_grpc_id,
32+
from_grpc_matrix_to_matrix,
33+
from_point3d_to_grpc_point,
34+
from_unit_vector_to_grpc_direction,
35+
)
2936

3037

3138
class GRPCComponentsServiceV1(GRPCComponentsService):
@@ -43,34 +50,164 @@ class GRPCComponentsServiceV1(GRPCComponentsService):
4350

4451
@protect_grpc
4552
def __init__(self, channel: grpc.Channel): # noqa: D102
46-
from ansys.api.geometry.v1.components_pb2_grpc import ComponentsStub
53+
from ansys.api.discovery.v1.design.geometry.component_pb2_grpc import ComponentStub
4754

48-
self.stub = ComponentsStub(channel)
55+
self.stub = ComponentStub(channel)
4956

5057
@protect_grpc
5158
def create(self, **kwargs) -> dict: # noqa: D102
52-
raise NotImplementedError
59+
from ansys.api.discovery.v1.design.geometry.component_pb2 import (
60+
CreateComponentData,
61+
CreateRequest,
62+
)
63+
64+
# Create the request - assumes all inputs are valid and of the proper type
65+
request = CreateRequest(
66+
components=[
67+
CreateComponentData(
68+
name=kwargs["name"],
69+
parent_id=build_grpc_id(kwargs["parent_id"]),
70+
template_id=build_grpc_id(kwargs["template_id"]),
71+
instance_name=kwargs["instance_name"],
72+
)
73+
]
74+
)
75+
76+
# Call the gRPC service
77+
response = self.stub.Create(request)
78+
79+
# Return the response - formatted as a dictionary
80+
# Note: response.components is a repeated field, we return the first one
81+
component = response.components[0]
82+
return {
83+
"id": component.id,
84+
"name": component.name,
85+
"instance_name": component.instance_name,
86+
"template": kwargs["template_id"], # template_id from input
87+
"component": component,
88+
}
5389

5490
@protect_grpc
5591
def set_name(self, **kwargs) -> dict: # noqa: D102
56-
raise NotImplementedError
92+
from ansys.api.discovery.v1.design.designmessages_pb2 import SetDesignEntityNameRequest
93+
94+
# Create the request - assumes all inputs are valid and of the proper type
95+
request = SetDesignEntityNameRequest(id=build_grpc_id(kwargs["id"]), name=kwargs["name"])
96+
97+
# Call the gRPC service
98+
_ = self.stub.SetName(request)
99+
100+
# Return the response - formatted as a dictionary
101+
return {}
57102

58103
@protect_grpc
59104
def set_placement(self, **kwargs) -> dict: # noqa: D102
60-
raise NotImplementedError
105+
from ansys.api.discovery.v1.design.geometry.component_pb2 import (
106+
PlacementData,
107+
SetPlacementRequest,
108+
)
109+
110+
# Create the direction and point objects
111+
translation = (
112+
from_unit_vector_to_grpc_direction(kwargs["translation"].normalize())
113+
if kwargs["translation"] is not None
114+
else None
115+
)
116+
origin = (
117+
from_point3d_to_grpc_point(kwargs["rotation_axis_origin"])
118+
if kwargs["rotation_axis_origin"] is not None
119+
else None
120+
)
121+
direction = (
122+
from_unit_vector_to_grpc_direction(kwargs["rotation_axis_direction"])
123+
if kwargs["rotation_axis_direction"] is not None
124+
else None
125+
)
126+
127+
# Create the request with repeated ids and placements
128+
request = SetPlacementRequest(
129+
ids=[build_grpc_id(kwargs["id"])],
130+
placements=[
131+
PlacementData(
132+
translation=translation,
133+
rotation_axis_origin=origin,
134+
rotation_axis_direction=direction,
135+
rotation_angle=from_measurement_to_server_angle(kwargs["rotation_angle"]),
136+
)
137+
],
138+
)
139+
140+
# Call the gRPC service
141+
response = self.stub.SetPlacement(request)
142+
143+
# Return the response - formatted as a dictionary
144+
# Note: response.matrices is a map<string, Matrix>
145+
# Get the matrix for our component ID
146+
matrix_value = response.matrices.get(kwargs["id"].id)
147+
return {"matrix": from_grpc_matrix_to_matrix(matrix_value) if matrix_value else None}
61148

62149
@protect_grpc
63150
def set_shared_topology(self, **kwargs) -> dict: # noqa: D102
64-
raise NotImplementedError
151+
from ansys.api.discovery.v1.design.geometry.component_pb2 import (
152+
SetSharedTopologyRequest,
153+
SharedTopologyData,
154+
)
155+
156+
# Create the request - assumes all inputs are valid and of the proper type
157+
request = SetSharedTopologyRequest(
158+
shared_topologies=[
159+
SharedTopologyData(
160+
id=build_grpc_id(kwargs["id"]),
161+
share_type=kwargs["share_type"].value,
162+
)
163+
]
164+
)
165+
166+
# Call the gRPC service
167+
_ = self.stub.SetSharedTopology(request)
168+
169+
# Return the response - formatted as a dictionary
170+
return {}
65171

66172
@protect_grpc
67173
def delete(self, **kwargs) -> dict: # noqa: D102
68-
raise NotImplementedError
174+
from ansys.api.discovery.v1.commonmessages_pb2 import MultipleEntitiesRequest
175+
176+
# Create the request - assumes all inputs are valid and of the proper type
177+
request = MultipleEntitiesRequest(ids=[build_grpc_id(kwargs["id"])])
178+
179+
# Call the gRPC service
180+
_ = self.stub.Delete(request)
181+
182+
# Return the response - formatted as a dictionary
183+
return {}
69184

70185
@protect_grpc
71186
def import_groups(self, **kwargs) -> dict: # noqa: D102
72-
raise NotImplementedError
187+
from ansys.api.discovery.v1.design.geometry.component_pb2 import ImportGroupsRequest
188+
189+
# Create the request - assumes all inputs are valid and of the proper type
190+
request = ImportGroupsRequest(
191+
id=build_grpc_id(kwargs["id"]),
192+
)
193+
194+
# Call the gRPC service
195+
_ = self.stub.ImportGroups(request)
196+
197+
# Return the response - formatted as a dictionary
198+
return {}
73199

74200
@protect_grpc
75201
def make_independent(self, **kwargs) -> dict: # noqa: D102
76-
raise NotImplementedError
202+
from ansys.api.discovery.v1.design.geometry.component_pb2 import MakeIndependentRequest
203+
204+
# Create the request - assumes all inputs are valid and of the proper type
205+
request = MakeIndependentRequest(
206+
ids=[build_grpc_id(id) for id in kwargs["ids"]],
207+
)
208+
209+
# Call the gRPC service
210+
_ = self.stub.MakeIndependent(request)
211+
212+
# Return the response - formatted as a dictionary
213+
return {}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import grpc
2525

26+
from ansys.geometry.core._grpc._services.v1.conversions import build_grpc_id
2627
from ansys.geometry.core.errors import protect_grpc
2728

2829
from ..base.coordinate_systems import GRPCCoordinateSystemService
@@ -61,7 +62,7 @@ def create(self, **kwargs) -> dict: # noqa: D102
6162
request = CreateRequest(
6263
request_data=[
6364
CreateRequestData(
64-
parent_id=kwargs["parent_id"],
65+
parent_id=build_grpc_id(kwargs["parent_id"]),
6566
name=kwargs["name"],
6667
frame=from_frame_to_grpc_frame(kwargs["frame"]),
6768
)

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

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

2828
from ..base.materials import GRPCMaterialsService
29+
from .conversions import from_material_to_grpc_material
2930

3031

31-
class GRPCMaterialsServiceV1(GRPCMaterialsService): # pragma: no cover
32+
class GRPCMaterialsServiceV1(GRPCMaterialsService):
3233
"""Materials service for gRPC communication with the Geometry server.
3334
3435
This class provides methods to interact with the Geometry server's
@@ -43,14 +44,36 @@ class GRPCMaterialsServiceV1(GRPCMaterialsService): # pragma: no cover
4344

4445
@protect_grpc
4546
def __init__(self, channel: grpc.Channel): # noqa: D102
46-
from ansys.api.geometry.v1.materials_pb2_grpc import MaterialsStub
47+
from ansys.api.discovery.v1.design.data.cadmaterial_pb2_grpc import MaterialsStub
4748

4849
self.stub = MaterialsStub(channel)
4950

5051
@protect_grpc
5152
def add_material(self, **kwargs) -> dict: # noqa: D102
52-
raise NotImplementedError
53+
from ansys.api.discovery.v1.design.data.cadmaterial_pb2_grpc import CreateRequest
54+
55+
# Create the request - assumes all inputs are valid and of the proper type
56+
request = CreateRequest(
57+
request_data=from_material_to_grpc_material(kwargs["material"]),
58+
)
59+
60+
# Call the gRPC service
61+
_ = self.stub.Create(request=request)
62+
63+
# Convert the response to a dictionary
64+
return {}
5365

5466
@protect_grpc
5567
def remove_material(self, **kwargs) -> dict: # noqa: D102
56-
raise NotImplementedError
68+
from ansys.api.discovery.v1.design.data.cadmaterial_pb2_grpc import DeleteRequest
69+
70+
# Create the request - assumes all inputs are valid and of the proper type
71+
request = DeleteRequest(
72+
request_data=[from_material_to_grpc_material(mat) for mat in kwargs["materials"]]
73+
)
74+
75+
# Call the gRPC service
76+
_ = self.stub.Delete(request=request)
77+
78+
# Convert the response to a dictionary
79+
return {}

0 commit comments

Comments
 (0)