Skip to content

Commit 5bde7de

Browse files
jacobrkerstetterpre-commit-ci[bot]pyansys-ci-bot
authored
chore: v1 implementation of measurement tools and model tools stubs (#2413)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 456480d commit 5bde7de

File tree

4 files changed

+186
-11
lines changed

4 files changed

+186
-11
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
V1 implementation of measurement tools and model tools stubs

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,4 +1461,28 @@ def serialize_entity_identifier(entity):
14611461
serialize_entity_identifier(entity)
14621462
for entity in getattr(response.tracked_changes, "deleted_bodies", [])
14631463
],
1464+
"created_faces": [
1465+
serialize_entity_identifier(entity)
1466+
for entity in getattr(response.tracked_changes, "created_face_ids", [])
1467+
],
1468+
"modified_faces": [
1469+
serialize_entity_identifier(entity)
1470+
for entity in getattr(response.tracked_changes, "modified_face_ids", [])
1471+
],
1472+
"deleted_faces": [
1473+
serialize_entity_identifier(entity)
1474+
for entity in getattr(response.tracked_changes, "deleted_face_ids", [])
1475+
],
1476+
"created_edges": [
1477+
serialize_entity_identifier(entity)
1478+
for entity in getattr(response.tracked_changes, "created_edge_ids", [])
1479+
],
1480+
"modified_edges": [
1481+
serialize_entity_identifier(entity)
1482+
for entity in getattr(response.tracked_changes, "modified_edge_ids", [])
1483+
],
1484+
"deleted_edges": [
1485+
serialize_entity_identifier(entity)
1486+
for entity in getattr(response.tracked_changes, "deleted_edge_ids", [])
1487+
],
14641488
}

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525

2626
from ansys.geometry.core.errors import protect_grpc
2727

28+
from ..base.conversions import to_distance
2829
from ..base.measurement_tools import GRPCMeasurementToolsService
30+
from .conversions import build_grpc_id
2931

3032

3133
class GRPCMeasurementToolsServiceV1(GRPCMeasurementToolsService): # pragma: no cover
@@ -43,10 +45,21 @@ class GRPCMeasurementToolsServiceV1(GRPCMeasurementToolsService): # pragma: no
4345

4446
@protect_grpc
4547
def __init__(self, channel: grpc.Channel): # noqa: D102
46-
from ansys.api.geometry.v1.measuretools_pb2_grpc import MeasureToolsStub
48+
from ansys.api.discovery.v1.operations.measure_pb2_grpc import MeasureStub
4749

48-
self.stub = MeasureToolsStub(channel)
50+
self.stub = MeasureStub(channel)
4951

5052
@protect_grpc
5153
def min_distance_between_objects(self, **kwargs) -> dict: # noqa: D102
52-
raise NotImplementedError
54+
from ansys.api.discovery.v1.operations.measure_pb2 import MinDistanceBetweenObjectsRequest
55+
56+
# Create the request - assumes all inputs are valid and of the proper type
57+
request = MinDistanceBetweenObjectsRequest(
58+
selection=[build_grpc_id(item) for item in kwargs["selection"]]
59+
)
60+
61+
# Call the gRPC service
62+
response = self.stub.MinDistanceBetweenSelectionObjects(request)
63+
64+
# Return the response - formatted as a dictionary
65+
return {"distance": to_distance(response.gap.distance.value_in_geometry_units)}

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

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

2828
from ..base.model_tools import GRPCModelToolsService
29+
from .conversions import (
30+
build_grpc_id,
31+
from_length_to_grpc_quantity,
32+
serialize_tracked_command_response,
33+
)
2934

3035

3136
class GRPCModelToolsServiceV1(GRPCModelToolsService):
@@ -43,30 +48,162 @@ class GRPCModelToolsServiceV1(GRPCModelToolsService):
4348

4449
@protect_grpc
4550
def __init__(self, channel: grpc.Channel): # noqa: D102
46-
from ansys.api.geometry.v1.model_tools_pb2_grpc import ModelToolsStub
51+
from ansys.api.discovery.v1.operations.edit_pb2_grpc import EditStub
52+
from ansys.api.discovery.v1.operations.sketch_pb2_grpc import SketchStub
4753

48-
self._stub = ModelToolsStub(channel)
54+
self.stub = EditStub(channel)
55+
self.sketch_stub = SketchStub(channel)
4956

5057
@protect_grpc
5158
def chamfer(self, **kwargs) -> dict: # noqa: D102
52-
raise NotImplementedError
59+
from ansys.api.discovery.v1.operations.edit_pb2 import ChamferRequest, ChamferRequestData
60+
61+
# Create the request - assumes all inputs are valid and of the proper type
62+
request = ChamferRequest(
63+
request_data=[
64+
ChamferRequestData(
65+
ids=[build_grpc_id(id) for id in kwargs["selection_ids"]],
66+
distance=from_length_to_grpc_quantity(kwargs["distance"]),
67+
)
68+
]
69+
)
70+
71+
# Call the gRPC service
72+
response = self.stub.Chamfer(request).response_data[0]
73+
74+
# Return the response as a dictionary
75+
return {
76+
"success": response.success,
77+
}
5378

5479
@protect_grpc
5580
def fillet(self, **kwargs) -> dict: # noqa: D102
56-
raise NotImplementedError
81+
from ansys.api.discovery.v1.operations.edit_pb2 import FilletRequest, FilletRequestData
82+
83+
# Create the request - assumes all inputs are valid and of the proper type
84+
request = FilletRequest(
85+
request_data=[
86+
FilletRequestData(
87+
ids=[build_grpc_id(id) for id in kwargs["selection_ids"]],
88+
radius=from_length_to_grpc_quantity(kwargs["radius"]),
89+
)
90+
]
91+
)
92+
93+
# Call the gRPC service and serialize the response
94+
response = self.stub.Fillet(request)
95+
tracked_response = serialize_tracked_command_response(response.tracked_command_response)
96+
97+
# Return the response as a dictionary
98+
return {
99+
"success": tracked_response.get("success"),
100+
}
57101

58102
@protect_grpc
59103
def full_fillet(self, **kwargs) -> dict: # noqa: D102
60-
raise NotImplementedError
104+
from ansys.api.discovery.v1.operations.edit_pb2 import FullFilletRequest
105+
106+
# Create the request - assumes all inputs are valid and of the proper type
107+
request = FullFilletRequest(
108+
face_ids=[build_grpc_id(id) for id in kwargs["selection_ids"]],
109+
)
110+
111+
# Call the gRPC service and serialize the response
112+
response = self.stub.FullFillet(request)
113+
tracked_response = serialize_tracked_command_response(response.tracked_command_response)
114+
115+
# Return the response as a dictionary
116+
return {
117+
"success": tracked_response.get("success"),
118+
}
61119

62120
@protect_grpc
63121
def move_rotate(self, **kwargs) -> dict: # noqa: D102
64-
raise NotImplementedError
122+
from ansys.api.discovery.v1.operations.edit_pb2 import (
123+
MoveRotateRequest,
124+
MoveRotateRequestData,
125+
)
126+
127+
from .conversions import from_angle_to_grpc_quantity, from_line_to_grpc_line
128+
129+
# Create the request - assumes all inputs are valid and of the proper type
130+
request = MoveRotateRequest(
131+
request_data=[
132+
MoveRotateRequestData(
133+
selection_ids=[build_grpc_id(kwargs["selection_id"])],
134+
axis=from_line_to_grpc_line(kwargs["axis"]),
135+
angle=from_angle_to_grpc_quantity(kwargs["angle"]),
136+
)
137+
]
138+
)
139+
140+
# Call the gRPC service and serialize the response
141+
response = self.stub.MoveRotate(request)
142+
tracked_response = serialize_tracked_command_response(response.tracked_command_response)
143+
144+
# Return the response as a dictionary
145+
return {
146+
"success": tracked_response.get("success"),
147+
"modified_bodies": [
148+
body.get("id").id for body in tracked_response.get("modified_bodies")
149+
],
150+
"modified_faces": [
151+
face.get("id").id for face in tracked_response.get("modified_faces")
152+
],
153+
"modified_edges": [
154+
edge.get("id").id for edge in tracked_response.get("modified_edges")
155+
],
156+
}
65157

66158
@protect_grpc
67159
def move_translate(self, **kwargs) -> dict: # noqa: D102
68-
raise NotImplementedError
160+
from ansys.api.discovery.v1.operations.edit_pb2 import (
161+
MoveTranslateRequest,
162+
MoveTranslateRequestData,
163+
)
164+
165+
from .conversions import from_unit_vector_to_grpc_direction
166+
167+
# Create the request - assumes all inputs are valid and of the proper type
168+
request = MoveTranslateRequest(
169+
request_data=[
170+
MoveTranslateRequestData(
171+
selection_ids=[build_grpc_id(kwargs["selection_id"])],
172+
direction=from_unit_vector_to_grpc_direction(kwargs["direction"]),
173+
distance=from_length_to_grpc_quantity(kwargs["distance"]),
174+
)
175+
]
176+
)
177+
# Call the gRPC service and serialize the response
178+
response = self.stub.MoveTranslate(request)
179+
tracked_response = serialize_tracked_command_response(response.tracked_command_response)
180+
181+
# Return the response as a dictionary
182+
return {
183+
"success": tracked_response.get("success"),
184+
}
69185

70186
@protect_grpc
71187
def create_sketch_line(self, **kwargs) -> dict: # noqa: D102
72-
raise NotImplementedError
188+
from ansys.api.discovery.v1.operations.sketch_pb2 import (
189+
CreateSketchLineRequest,
190+
CreateSketchLineRequestData,
191+
)
192+
193+
from .conversions import from_point3d_to_grpc_point
194+
195+
# Create the request - assumes all inputs are valid and of the proper type
196+
request = CreateSketchLineRequest(
197+
request_data=[
198+
CreateSketchLineRequestData(
199+
point1=from_point3d_to_grpc_point(kwargs["start"]),
200+
point2=from_point3d_to_grpc_point(kwargs["end"]),
201+
)
202+
]
203+
)
204+
205+
# Call the gRPC service
206+
_ = self.sketch_stub.CreateSketchLine(request)
207+
208+
# Return the response - formatted as a dictionary
209+
return {}

0 commit comments

Comments
 (0)