Skip to content

Commit f1418d7

Browse files
more face/edge commands
1 parent b050f16 commit f1418d7

File tree

7 files changed

+107
-34
lines changed

7 files changed

+107
-34
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,14 @@ def extrude_edges(self, **kwargs) -> dict:
8787
@abstractmethod
8888
def extrude_edges_up_to(self, **kwargs) -> dict:
8989
"""Extrude edges up to a face."""
90+
pass
91+
92+
@abstractmethod
93+
def move_imprint_edges(self, **kwargs) -> dict:
94+
"""Move imprint edges."""
95+
pass
96+
97+
@abstractmethod
98+
def offset_edges(self, **kwargs) -> dict:
99+
"""Offset edges."""
90100
pass

src/ansys/geometry/core/_grpc/_services/base/faces.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,9 @@ def thicken_faces(self, **kwargs) -> dict:
142142
@abstractmethod
143143
def draft_faces(self, **kwargs) -> dict:
144144
"""Draft a selection of faces."""
145+
pass
146+
147+
@abstractmethod
148+
def get_round_info(self, **kwargs) -> dict:
149+
"""Get round information for a selection of faces."""
145150
pass

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,4 +235,41 @@ def extrude_edges_up_to(self, **kwargs): # noqa: D102
235235
return {
236236
"created_bodies": [body.id for body in resp.created_bodies],
237237
"success": resp.success,
238+
}
239+
240+
@protect_grpc
241+
def move_imprint_edges(self, **kwargs) -> dict: # noqa: D102
242+
from ansys.api.geometry.v0.commands_pb2 import MoveImprintEdgesRequest
243+
244+
# Create the request - assumes all inputs are valid and of the proper type
245+
request = MoveImprintEdgesRequest(
246+
edges=[build_grpc_id(edge_id) for edge_id in kwargs["edge_ids"]],
247+
direction=from_unit_vector_to_grpc_direction(kwargs["direction"]),
248+
distance=from_measurement_to_server_length(kwargs["distance"]),
249+
)
250+
251+
# Call the gRPC service
252+
resp = self.commands_stub.MoveImprintEdges(request)
253+
254+
# Return the response - formatted as a dictionary
255+
return {
256+
"success": resp.result.success,
257+
}
258+
259+
@protect_grpc
260+
def offset_edges(self, **kwargs) -> dict: # noqa: D102
261+
from ansys.api.geometry.v0.commands_pb2 import OffsetEdgesRequest
262+
263+
# Create the request - assumes all inputs are valid and of the proper type
264+
request = OffsetEdgesRequest(
265+
edges=[build_grpc_id(edge_id) for edge_id in kwargs["edge_ids"]],
266+
value=from_measurement_to_server_length(kwargs["offset"]),
267+
)
268+
269+
# Call the gRPC service
270+
resp = self.commands_stub.OffsetEdges(request)
271+
272+
# Return the response - formatted as a dictionary
273+
return {
274+
"success": resp.success,
238275
}

src/ansys/geometry/core/_grpc/_services/v0/faces.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,4 +498,23 @@ def draft_faces(self, **kwargs) -> dict: # noqa: D102
498498
# Return the drafted faces
499499
return {
500500
"created_faces": [face.id for face in response.created_faces],
501+
}
502+
503+
@protect_grpc
504+
def get_round_info(self, **kwargs): # noqa: D102
505+
from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier
506+
from ansys.api.geometry.v0.commands_pb2 import RoundInfoRequest
507+
508+
# Create the request - assumes all inputs are valid and of the proper type
509+
request = RoundInfoRequest(
510+
face_id=[EntityIdentifier(id=kwargs["face_id"])],
511+
)
512+
513+
# Call the gRPC service
514+
response = self.commands_stub.GetRoundInfo(request=request)
515+
516+
# Return the response - formatted as a dictionary
517+
return {
518+
"along_u": response.along_u,
519+
"radius": response.radius,
501520
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,12 @@ def extrude_edges(self, **kwargs) -> dict: # noqa: D102
8585

8686
@protect_grpc
8787
def extrude_edges_up_to(self, **kwargs) -> dict: # noqa: D102
88+
return NotImplementedError
89+
90+
@protect_grpc
91+
def move_imprint_edges(self, **kwargs) -> dict: # noqa: D102
92+
return NotImplementedError
93+
94+
@protect_grpc
95+
def offset_edges(self, **kwargs) -> dict: # noqa: D102
8896
return NotImplementedError

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,8 @@ def thicken_faces(self, **kwargs) -> dict: # noqa: D102
129129

130130
@protect_grpc
131131
def draft_faces(self, **kwargs) -> dict: # noqa: D102
132+
raise NotImplementedError
133+
134+
@protect_grpc
135+
def get_round_info(self, **kwargs): # noqa: D102
132136
raise NotImplementedError

src/ansys/geometry/core/designer/geometry_commands.py

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@
2626

2727
from ansys.api.geometry.v0.commands_pb2 import (
2828
CreateAlignTangentOrientGearConditionRequest,
29-
MoveImprintEdgesRequest,
30-
OffsetEdgesRequest,
3129
RenameObjectRequest,
32-
RoundInfoRequest,
3330
SplitBodyRequest,
3431
)
3532
from ansys.api.geometry.v0.commands_pb2_grpc import CommandsStub
@@ -39,7 +36,6 @@
3936
from ansys.geometry.core.connection.client import GrpcClient
4037
from ansys.geometry.core.connection.conversions import (
4138
plane_to_grpc_plane,
42-
unit_vector_to_grpc_direction,
4339
)
4440
from ansys.geometry.core.designer.component import Component
4541
from ansys.geometry.core.designer.mating_conditions import (
@@ -65,7 +61,7 @@
6561
check_type_all_elements_in_iterable,
6662
min_backend_version,
6763
)
68-
from ansys.geometry.core.misc.measurements import DEFAULT_UNITS, Angle, Distance
64+
from ansys.geometry.core.misc.measurements import Angle, Distance
6965
from ansys.geometry.core.shapes.curves.line import Line
7066
from ansys.geometry.core.typing import Real
7167

@@ -945,8 +941,14 @@ def create_fill_pattern(
945941
margin = margin if isinstance(margin, Distance) else Distance(margin)
946942
x_spacing = x_spacing if isinstance(x_spacing, Distance) else Distance(x_spacing)
947943
y_spacing = y_spacing if isinstance(y_spacing, Distance) else Distance(y_spacing)
948-
row_x_offset = row_x_offset if isinstance(row_x_offset, Distance) else Distance(row_x_offset)
949-
row_y_offset = row_y_offset if isinstance(row_y_offset, Distance) else Distance(row_y_offset)
944+
row_x_offset = (
945+
row_x_offset if isinstance(row_x_offset, Distance)
946+
else Distance(row_x_offset)
947+
)
948+
row_y_offset = (
949+
row_y_offset if isinstance(row_y_offset, Distance)
950+
else Distance(row_y_offset)
951+
)
950952
column_x_offset = (
951953
column_x_offset if isinstance(column_x_offset, Distance)
952954
else Distance(column_x_offset)
@@ -1343,9 +1345,11 @@ def get_round_info(self, face: "Face") -> tuple[bool, Real]:
13431345
--------
13441346
This method is only available starting on Ansys release 25R2.
13451347
"""
1346-
result = self._commands_stub.GetRoundInfo(RoundInfoRequest(face=face._grpc_id))
1348+
result = self._grpc_client._services.faces.get_round_info(
1349+
face_id = face.id
1350+
)
13471351

1348-
return (result.along_u, result.radius)
1352+
return (result.get("along_u"), result.get("radius"))
13491353

13501354
@protect_grpc
13511355
@check_input_types
@@ -1677,30 +1681,23 @@ def move_imprint_edges(
16771681
The edges to move.
16781682
direction : UnitVector3D
16791683
The direction to move the edges.
1680-
distance : Distance
1684+
distance : Distance | Quantity | Real
16811685
The distance to move the edges.
16821686
16831687
Returns
16841688
-------
16851689
bool
16861690
Returns True if the edges were moved successfully, False otherwise.
16871691
"""
1688-
# Convert the distance object
16891692
distance = distance if isinstance(distance, Distance) else Distance(distance)
1690-
move_magnitude = distance.value.m_as(DEFAULT_UNITS.SERVER_LENGTH)
16911693

1692-
# Create the request object
1693-
request = MoveImprintEdgesRequest(
1694-
edges=[edge._grpc_id for edge in edges],
1695-
direction=unit_vector_to_grpc_direction(direction),
1696-
distance=move_magnitude,
1694+
response = self._grpc_client._services.edges.move_imprint_edges(
1695+
edge_ids=[edge.id for edge in edges],
1696+
direction=direction,
1697+
distance=distance,
16971698
)
16981699

1699-
# Call the gRPC service
1700-
response = self._commands_stub.MoveImprintEdges(request)
1701-
1702-
# Return success flag
1703-
return response.result.success
1700+
return response.get("success")
17041701

17051702
@protect_grpc
17061703
@min_backend_version(26, 1, 0)
@@ -1711,29 +1708,22 @@ def offset_edges(self, edges: list["Edge"], offset: Distance | Quantity | Real)
17111708
----------
17121709
edges : list[Edge]
17131710
The edges to offset.
1714-
offset : Distance
1711+
offset : Distance | Quantity | Real
17151712
The distance to offset the edges.
17161713
17171714
Returns
17181715
-------
17191716
bool
17201717
Returns True if the edges were offset successfully, False otherwise.
17211718
"""
1722-
# Convert the distance object
17231719
offset = offset if isinstance(offset, Distance) else Distance(offset)
1724-
offset_magnitude = offset.value.m_as(DEFAULT_UNITS.SERVER_LENGTH)
17251720

1726-
# Create the request object
1727-
request = OffsetEdgesRequest(
1728-
edges=[edge._grpc_id for edge in edges],
1729-
value=offset_magnitude,
1721+
response = self._grpc_client._services.edges.offset_edges(
1722+
edge_ids=[edge.id for edge in edges],
1723+
offset=offset,
17301724
)
17311725

1732-
# Call the gRPC service
1733-
response = self._commands_stub.OffsetEdges(request)
1734-
1735-
# Return success flag
1736-
return response.success
1726+
return response.get("success")
17371727

17381728
@protect_grpc
17391729
@min_backend_version(26, 1, 0)

0 commit comments

Comments
 (0)