Skip to content

Commit 74eb796

Browse files
finished implementing prepare tools v0
1 parent 6feed75 commit 74eb796

File tree

4 files changed

+298
-81
lines changed

4 files changed

+298
-81
lines changed

src/ansys/geometry/core/_grpc/_services/_service.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def __init__(self, channel: grpc.Channel, version: GeometryApiProtos | str | Non
7474
self._dbu_application = None
7575
self._named_selection = None
7676
self._measurement_tools = None
77-
self._prepare_tools = None
77+
self._prepare_tools = None
7878

7979
@property
8080
def bodies(self) -> GRPCBodyService:
@@ -180,7 +180,7 @@ def named_selection(self) -> GRPCNamedSelectionService:
180180

181181
return self._named_selection
182182

183-
@property
183+
@property
184184
def measurement_tools(self) -> GRPCMeasurementToolsService:
185185
"""
186186
Get the measurement tools service for the specified version.
@@ -206,7 +206,7 @@ def measurement_tools(self) -> GRPCMeasurementToolsService:
206206

207207
return self._measurement_tools
208208

209-
@property
209+
@property
210210
def prepare_tools(self) -> GRPCPrepareToolsService:
211211
"""
212212
Get the prepare tools service for the specified version.

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

Lines changed: 178 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,183 @@
2525

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

28-
from ..base.named_selection import GRPCPrepareToolsService
28+
from ..base.prepare_tools import GRPCPrepareToolsService
2929

3030

31-
class GRPCPrepareToolsServiceV0(GRPCPrepareToolsService):
31+
class GRPCPrepareToolsServiceV0(GRPCPrepareToolsService):
32+
"""Prepare tools service for gRPC communication with the Geometry server.
33+
34+
This class provides methods to interact with the Geometry server's
35+
Prepare Tools service. It is specifically designed for the v0 version
36+
of the Geometry API.
37+
38+
Parameters
39+
----------
40+
channel : grpc.Channel
41+
The gRPC channel to the server.
42+
"""
43+
44+
@protect_grpc
45+
def __init__(self, channel: grpc.Channel): # noqa: D102
46+
from ansys.api.geometry.v0.preparetools_pb2_grpc import PrepareToolsStub
47+
48+
self.stub = PrepareToolsStub(channel)
49+
50+
@protect_grpc
51+
def extract_volume_from_faces(self, **kwargs) -> dict: # noqa: D102
52+
from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier
53+
from ansys.api.geometry.v0.preparetools_pb2 import ExtractVolumeFromFacesRequest
54+
55+
# Create the request - assumes all inputs are valid and of the proper type
56+
request = ExtractVolumeFromFacesRequest(
57+
sealing_faces=[EntityIdentifier(id=face.id) for face in kwargs["sealing_faces"]],
58+
inside_faces=[EntityIdentifier(id=face.id) for face in kwargs["inside_faces"]],
59+
)
60+
61+
# Call the gRPC service
62+
response = self.stub.ExtractVolumeFromFaces(request)
63+
64+
# Return the response - formatted as a dictionary
65+
return {
66+
"success": response.success,
67+
"created_bodies": [body.id for body in response.created_bodies],
68+
}
69+
70+
71+
@protect_grpc
72+
def extract_volume_from_edge_loops(self, **kwargs) -> dict: # noqa: D102
73+
from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier
74+
from ansys.api.geometry.v0.preparetools_pb2 import ExtractVolumeFromEdgeLoopsRequest
75+
76+
# Create the request - assumes all inputs are valid and of the proper type
77+
request = ExtractVolumeFromEdgeLoopsRequest(
78+
sealing_edges=[EntityIdentifier(id=face.id) for face in kwargs["sealing_edges"]],
79+
inside_faces=[EntityIdentifier(id=face.id) for face in kwargs["inside_faces"]],
80+
)
81+
82+
# Call the gRPC service
83+
response = self.stub.ExtractVolumeFromEdgeLoops(request)
84+
85+
# Return the response - formatted as a dictionary
86+
return {
87+
"success": response.success,
88+
"created_bodies": [body.id for body in response.created_bodies],
89+
}
90+
91+
92+
@protect_grpc
93+
def remove_rounds(self, **kwargs) -> dict: # noqa: D102
94+
from ansys.api.geometry.v0.models_pb2 import Face
95+
from ansys.api.geometry.v0.preparetools_pb2 import RemoveRoundsRequest
96+
97+
# Create the request - assumes all inputs are valid and of the proper type
98+
request = RemoveRoundsRequest(
99+
selection=[Face(id=round.id) for round in kwargs["rounds"]],
100+
auto_shrink=kwargs["auto_shrink"],
101+
)
102+
103+
# Call the gRPC service
104+
response = self.stub.RemoveRounds(request)
105+
106+
# Return the response - formatted as a dictionary
107+
return {
108+
"success": response.result,
109+
}
110+
111+
@protect_grpc
112+
def share_topology(self, **kwargs) -> dict: # noqa: D102
113+
from ansys.api.geometry.v0.models_pb2 import Body
114+
from ansys.api.geometry.v0.preparetools_pb2 import ShareTopologyRequest
115+
116+
# Create the request - assumes all inputs are valid and of the proper type
117+
request = ShareTopologyRequest(
118+
selection=[Body(id=body.id) for body in kwargs["bodies"]],
119+
tolerance=kwargs["tolerance"],
120+
preserve_instances=kwargs["preserve_instances"],
121+
)
122+
123+
# Call the gRPC service
124+
response = self.stub.ShareTopology(request)
125+
126+
# Return the response - formatted as a dictionary
127+
return {
128+
"success": response.result,
129+
}
130+
131+
@protect_grpc
132+
def enhanced_share_topology(self, **kwargs) -> dict: # noqa: D102
133+
from ansys.api.geometry.v0.models_pb2 import Body
134+
from ansys.api.geometry.v0.preparetools_pb2 import ShareTopologyRequest
135+
136+
# Create the request - assumes all inputs are valid and of the proper type
137+
request = ShareTopologyRequest(
138+
selection=[Body(id=body.id) for body in kwargs["bodies"]],
139+
tolerance=kwargs["tolerance"],
140+
preserve_instances=kwargs["preserve_instances"],
141+
)
142+
143+
# Call the gRPC service
144+
response = self.stub.EnhancedShareTopology(request)
145+
146+
# Return the response - formatted as a dictionary
147+
return {
148+
"success": response.success,
149+
"found": response.found,
150+
"repaired": response.repaired,
151+
"created_bodies_monikers": response.created_bodies_monikers,
152+
"modified_bodies_monikers": response.modified_bodies_monikers,
153+
"deleted_bodies_monikers": response.deleted_bodies_monikers,
154+
}
155+
156+
@protect_grpc
157+
def find_logos(self, **kwargs) -> dict: # noqa: D102
158+
from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier
159+
from ansys.api.geometry.v0.models_pb2 import FindLogoOptions
160+
from ansys.api.geometry.v0.preparetools_pb2 import FindLogosRequest
161+
162+
# Create the gRPC options object
163+
options = FindLogoOptions(
164+
min_height=kwargs["min_height"],
165+
max_height=kwargs["max_height"],
166+
)
167+
168+
# Create the request - assumes all inputs are valid and of the proper type
169+
request = FindLogosRequest(
170+
bodies=[EntityIdentifier(id=body.id) for body in kwargs["bodies"]],
171+
options=options,
172+
)
173+
174+
# Call the gRPC service
175+
response = self.stub.FindLogos(request)
176+
177+
# Return the response - formatted as a dictionary
178+
return {
179+
"id": response.id,
180+
"face_ids": [face.id for face in response.logo_faces],
181+
}
182+
183+
@protect_grpc
184+
def find_and_remove_logos(self, **kwargs) -> dict: # noqa: D102
185+
from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier
186+
from ansys.api.geometry.v0.models_pb2 import FindLogoOptions
187+
from ansys.api.geometry.v0.preparetools_pb2 import FindLogosRequest
188+
189+
# Create the gRPC options object
190+
options = FindLogoOptions(
191+
min_height=kwargs["min_height"],
192+
max_height=kwargs["max_height"],
193+
)
194+
195+
# Create the request - assumes all inputs are valid and of the proper type
196+
request = FindLogosRequest(
197+
bodies=[EntityIdentifier(id=body.id) for body in kwargs["bodies"]],
198+
options=options,
199+
)
200+
201+
# Call the gRPC service
202+
response = self.stub.FindAndRemoveLogos(request)
203+
204+
# Return the response - formatted as a dictionary
205+
return {
206+
"success": response.success
207+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Copyright (C) 2023 - 2025 ANSYS, Inc. and/or its affiliates.
2+
# SPDX-License-Identifier: MIT
3+
#
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in all
13+
# copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
# SOFTWARE.
22+
"""Module containing the Named Selection service implementation for v0."""
23+
24+
import grpc
25+
26+
from ansys.geometry.core.errors import protect_grpc
27+
28+
from ..base.prepare_tools import GRPCPrepareToolsService
29+
30+
31+
class GRPCPrepareToolsServiceV1(GRPCPrepareToolsService):
32+
"""Prepare tools service for gRPC communication with the Geometry server.
33+
34+
This class provides methods to interact with the Geometry server's
35+
Prepare Tools service. It is specifically designed for the v1 version
36+
of the Geometry API.
37+
38+
Parameters
39+
----------
40+
channel : grpc.Channel
41+
The gRPC channel to the server.
42+
"""
43+
44+
@protect_grpc
45+
def __init__(self, channel: grpc.Channel): # noqa: D102
46+
from ansys.api.geometry.v1.preparetools_pb2_grpc import PrepareToolsStub
47+
48+
self.stub = PrepareToolsStub(channel)
49+
50+
def extract_volume_from_faces(self, **kwargs) -> dict: # noqa: D102
51+
"""Extract a volume from input faces."""
52+
raise NotImplementedError
53+
54+
def extract_volume_from_edge_loops(self, **kwargs) -> dict: # noqa: D102
55+
"""Extract a volume from input edge loop."""
56+
raise NotImplementedError
57+
58+
def remove_rounds(self, **kwargs) -> dict: # noqa: D102
59+
"""Remove rounds from geometry."""
60+
raise NotImplementedError
61+
62+
def share_topology(self, **kwargs) -> dict: # noqa: D102
63+
"""Share topology between the given bodies."""
64+
raise NotImplementedError
65+
66+
def enhanced_share_topology(self, **kwargs) -> dict: # noqa: D102
67+
"""Share topology between the given bodies."""
68+
raise NotImplementedError
69+
70+
def find_logos(self, **kwargs) -> dict: # noqa: D102
71+
"""Detect logos in geometry."""
72+
raise NotImplementedError
73+
74+
def find_and_remove_logos(self, **kwargs) -> dict: # noqa: D102
75+
"""Detect and remove logos in geometry."""
76+
raise NotImplementedError

0 commit comments

Comments
 (0)