Skip to content

Commit 6ee5a1d

Browse files
wip
1 parent 2a3fe73 commit 6ee5a1d

File tree

1 file changed

+144
-11
lines changed
  • src/ansys/geometry/core/_grpc/_services/v1

1 file changed

+144
-11
lines changed

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

Lines changed: 144 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,21 @@
2121
# SOFTWARE.
2222
"""Module containing the edges service implementation for v1."""
2323

24+
from ansys.api.discovery.v1.commonmessages_pb2 import MultipleEntitiesRequest
2425
import grpc
2526

2627
from ansys.geometry.core.errors import protect_grpc
2728

29+
from ..base.conversions import to_distance
2830
from ..base.edges import GRPCEdgesService
31+
from .conversions import (
32+
build_grpc_id,
33+
from_grpc_curve_to_curve,
34+
from_grpc_point_to_point3d,
35+
from_length_to_grpc_quantity,
36+
from_point3d_to_grpc_point,
37+
from_unit_vector_to_grpc_direction,
38+
)
2939

3040

3141
class GRPCEdgesServiceV1(GRPCEdgesService): # pragma: no cover
@@ -43,45 +53,168 @@ class GRPCEdgesServiceV1(GRPCEdgesService): # pragma: no cover
4353

4454
@protect_grpc
4555
def __init__(self, channel: grpc.Channel): # noqa: D102
46-
from ansys.api.geometry.v1.edges_pb2_grpc import EdgesStub
56+
from ansys.api.discovery.v1.design.geometry.edge_pb2_grpc import EdgeStub
57+
from ansys.api.discovery.v1.operations.edit_pb2_grpc import EditStub
4758

48-
self.stub = EdgesStub(channel)
59+
self.stub = EdgeStub(channel)
60+
self.EditStub = EditStub(channel)
4961

5062
@protect_grpc
5163
def get_edge(self, **kwargs) -> dict: # noqa: D102
52-
return NotImplementedError
64+
from ansys.api.discovery.v1.commonmessages_pb2 import EntityRequest
65+
66+
# Create the request - assumes all inputs are valid and of the proper type
67+
request = EntityRequest(id=build_grpc_id(kwargs["id"]))
68+
69+
# Call the gRPC service
70+
response = self.stub.Get(request=request)
71+
72+
# Return the response - formatted as a dictionary
73+
return {
74+
"id": response.edge.id,
75+
"curve_type": response.edge.curve_type,
76+
"is_reversed": response.edge.is_reversed,
77+
}
5378

5479
@protect_grpc
5580
def get_curve(self, **kwargs) -> dict: # noqa: D102
56-
return NotImplementedError
81+
# Create the request - assumes all inputs are valid and of the proper type
82+
request = MultipleEntitiesRequest(ids=[build_grpc_id(kwargs["id"])])
83+
84+
# Call the gRPC service
85+
response = self.stub.GetCurve(request=request).response_data[0]
86+
87+
# Return the response - formatted as a dictionary
88+
return {
89+
"curve": from_grpc_curve_to_curve(response.curve),
90+
}
5791

5892
@protect_grpc
5993
def get_start_and_end_points(self, **kwargs) -> dict: # noqa: D102
60-
return NotImplementedError
94+
# Create the request - assumes all inputs are valid and of the proper type
95+
request = MultipleEntitiesRequest(ids=[build_grpc_id(kwargs["id"])])
96+
97+
# Call the gRPC service
98+
response = self.stub.GetStartAndEndPoints(request=request).response_data[0]
99+
100+
# Return the response - formatted as a dictionary
101+
return {
102+
"start": from_grpc_point_to_point3d(response.start),
103+
"end": from_grpc_point_to_point3d(response.end),
104+
}
61105

62106
@protect_grpc
63107
def get_length(self, **kwargs) -> dict: # noqa: D102
64-
return NotImplementedError
108+
# Create the request - assumes all inputs are valid and of the proper type
109+
request = MultipleEntitiesRequest(ids=[build_grpc_id(kwargs["id"])])
110+
111+
# Call the gRPC service
112+
response = self.stub.GetLength(request=request).response_data[0]
113+
114+
# Return the response - formatted as a dictionary
115+
return {
116+
"length": to_distance(response.length.value_in_geometry_units),
117+
}
65118

66119
@protect_grpc
67120
def get_interval(self, **kwargs) -> dict: # noqa: D102
68-
return NotImplementedError
121+
# Create the request - assumes all inputs are valid and of the proper type
122+
request = MultipleEntitiesRequest(ids=[build_grpc_id(kwargs["id"])])
123+
124+
# Call the gRPC service
125+
response = self.stub.GetInterval(request=request).response_data[0]
126+
127+
# Return the response - formatted as a dictionary
128+
return {
129+
"start": response.start,
130+
"end": response.end,
131+
}
69132

70133
@protect_grpc
71134
def get_faces(self, **kwargs) -> dict: # noqa: D102
72-
return NotImplementedError
135+
# Create the request - assumes all inputs are valid and of the proper type
136+
request = MultipleEntitiesRequest(ids=[build_grpc_id(kwargs["id"])])
137+
138+
# Call the gRPC service
139+
response = self.stub.GetFaces(request=request).response_data[0]
140+
141+
# Return the response - formatted as a dictionary
142+
return {
143+
"faces": [
144+
{
145+
"id": face.id,
146+
"surface_type": face.surface_type,
147+
"is_reversed": face.is_reversed,
148+
}
149+
for face in response.faces
150+
],
151+
}
73152

74153
@protect_grpc
75154
def get_vertices(self, **kwargs) -> dict: # noqa: D102
76-
return NotImplementedError
155+
# Create the request - assumes all inputs are valid and of proper type
156+
request = MultipleEntitiesRequest(ids=[build_grpc_id(kwargs["id"])])
157+
158+
# Call the gRPC service
159+
response = self.stub.GetVertices(request=request).response_data[0]
160+
161+
# Return the response - formatted as a dictionary
162+
return {
163+
"vertices": [
164+
{
165+
"id": vertex.id.id,
166+
"position": from_grpc_point_to_point3d(vertex.position),
167+
}
168+
for vertex in response.vertices
169+
],
170+
}
77171

78172
@protect_grpc
79173
def get_bounding_box(self, **kwargs) -> dict: # noqa: D102
80-
return NotImplementedError
174+
# Create the request - assumes all inputs are valid and of the proper type
175+
request = MultipleEntitiesRequest(ids=[build_grpc_id(kwargs["id"])])
176+
177+
# Call the gRPC service
178+
response = self.stub.GetBoundingBox(request=request).response_data[0]
179+
180+
# Return the response - formatted as a dictionary
181+
return {
182+
"min_corner": from_grpc_point_to_point3d(response.box.min),
183+
"max_corner": from_grpc_point_to_point3d(response.box.max),
184+
"center": from_grpc_point_to_point3d(response.box.center),
185+
}
81186

82187
@protect_grpc
83188
def extrude_edges(self, **kwargs) -> dict: # noqa: D102
84-
return NotImplementedError
189+
from ansys.api.geometry.v0.commands_pb2 import ExtrudeEdgesRequest
190+
191+
# Parse some optional arguments
192+
point = from_point3d_to_grpc_point(kwargs["point"]) if kwargs["point"] else None
193+
direction = (
194+
from_unit_vector_to_grpc_direction(kwargs["direction"]) if kwargs["direction"] else None
195+
)
196+
197+
# Create the request - assumes all inputs are valid and of the proper type
198+
request = ExtrudeEdgesRequest(
199+
edges=[build_grpc_id(edge_id) for edge_id in kwargs["edge_ids"]],
200+
distance=from_length_to_grpc_quantity(kwargs["distance"]),
201+
face=build_grpc_id(kwargs["face"]),
202+
point=point,
203+
direction=direction,
204+
extrude_type=kwargs["extrude_type"].value,
205+
pull_symmetric=kwargs["pull_symmetric"],
206+
copy=kwargs["copy"],
207+
natural_extension=kwargs["natural_extension"],
208+
)
209+
210+
# Call the gRPC service
211+
resp = self.EditStub.ExtrudeEdges(request)
212+
213+
# Return the response - formatted as a dictionary
214+
return {
215+
"created_bodies": [body.id for body in resp.created_bodies],
216+
"success": resp.success,
217+
}
85218

86219
@protect_grpc
87220
def extrude_edges_up_to(self, **kwargs) -> dict: # noqa: D102

0 commit comments

Comments
 (0)