Skip to content

Commit 38ad139

Browse files
umutsoysalansysRobPasMue
authored andcommitted
Refactoring repair tools (#862)
1 parent 19b7b16 commit 38ad139

File tree

2 files changed

+126
-146
lines changed

2 files changed

+126
-146
lines changed

src/ansys/geometry/core/tools/repair_tools.py

Lines changed: 71 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@
3131
FindStitchFacesRequest,
3232
)
3333
from ansys.api.geometry.v0.repairtools_pb2_grpc import RepairToolsStub
34-
from beartype.typing import List
34+
from beartype.typing import TYPE_CHECKING, List
35+
36+
if TYPE_CHECKING: # pragma: no cover
37+
from ansys.geometry.core.designer.body import Body
38+
3539
from google.protobuf.wrappers_pb2 import DoubleValue
3640

3741
from ansys.geometry.core.connection import GrpcClient
@@ -56,7 +60,7 @@ def __init__(self, grpc_client: GrpcClient):
5660
self._repair_stub = RepairToolsStub(self._grpc_client.channel)
5761

5862
def find_split_edges(
59-
self, ids: List[str], angle: Real = 0.0, length: Real = 0.0
63+
self, bodies: List["Body"], angle: Real = 0.0, length: Real = 0.0
6064
) -> List[SplitEdgeProblemAreas]:
6165
"""
6266
Find split edges in the given list of bodies.
@@ -66,8 +70,8 @@ def find_split_edges(
6670
6771
Parameters
6872
----------
69-
ids : List[str]
70-
Server-defined ID for the bodies.
73+
bodies : List[Body]
74+
List of bodies that split edges are investigated on.
7175
angle : Real
7276
The maximum angle between edges.
7377
length : Real
@@ -80,21 +84,21 @@ def find_split_edges(
8084
"""
8185
angle_value = DoubleValue(value=float(angle))
8286
length_value = DoubleValue(value=float(length))
87+
body_ids = [body.id for body in bodies]
88+
8389
problem_areas_response = self._repair_stub.FindSplitEdges(
84-
FindSplitEdgesRequest(bodies_or_faces=ids, angle=angle_value, distance=length_value)
90+
FindSplitEdgesRequest(
91+
bodies_or_faces=body_ids, angle=angle_value, distance=length_value
92+
)
8593
)
8694

87-
problem_areas = []
88-
for res in problem_areas_response.result:
89-
connected_edges = []
90-
for edge_moniker in res.edge_monikers:
91-
connected_edges.append(edge_moniker)
92-
problem_area = SplitEdgeProblemAreas(res.id, connected_edges, self._grpc_client)
93-
problem_areas.append(problem_area)
94-
95+
problem_areas = [
96+
SplitEdgeProblemAreas(res.id, list(res.edge_monikers), self._grpc_client)
97+
for res in problem_areas_response.result
98+
]
9599
return problem_areas
96100

97-
def find_extra_edges(self, ids: List[str]) -> List[ExtraEdgeProblemAreas]:
101+
def find_extra_edges(self, bodies: List["Body"]) -> List[ExtraEdgeProblemAreas]:
98102
"""
99103
Find the extra edges in the given list of bodies.
100104
@@ -103,28 +107,25 @@ def find_extra_edges(self, ids: List[str]) -> List[ExtraEdgeProblemAreas]:
103107
104108
Parameters
105109
----------
106-
ids : List[str]
107-
Server-defined ID for the bodies.
110+
bodies : List[Body]
111+
List of bodies that extra edges are investigated on.
108112
109113
Returns
110114
----------
111115
List[ExtraEdgeProblemArea]
112116
List of objects representing extra edge problem areas.
113117
"""
118+
body_ids = [body.id for body in bodies]
114119
problem_areas_response = self._repair_stub.FindExtraEdges(
115-
FindExtraEdgesRequest(selection=ids)
120+
FindExtraEdgesRequest(selection=body_ids)
116121
)
117-
problem_areas = []
118-
for res in problem_areas_response.result:
119-
connected_edges = []
120-
for edge_moniker in res.edge_monikers:
121-
connected_edges.append(edge_moniker)
122-
problem_area = ExtraEdgeProblemAreas(res.id, connected_edges, self._grpc_client)
123-
problem_areas.append(problem_area)
124-
122+
problem_areas = [
123+
ExtraEdgeProblemAreas(res.id, list(res.edge_monikers), self._grpc_client)
124+
for res in problem_areas_response.result
125+
]
125126
return problem_areas
126127

127-
def find_inexact_edges(self, ids) -> List[InexactEdgeProblemAreas]:
128+
def find_inexact_edges(self, bodies: List["Body"]) -> List[InexactEdgeProblemAreas]:
128129
"""
129130
Find inexact edges in the given list of bodies.
130131
@@ -133,28 +134,25 @@ def find_inexact_edges(self, ids) -> List[InexactEdgeProblemAreas]:
133134
134135
Parameters
135136
----------
136-
ids : List[str]
137-
Server-defined ID for the bodies.
137+
bodies : List[Body]
138+
List of bodies that inexact edges are investigated on.
138139
139140
Returns
140141
-------
141142
List[InExactEdgeProblemArea]
142143
List of objects representing inexact edge problem areas.
143144
"""
145+
body_ids = [body.id for body in bodies]
144146
problem_areas_response = self._repair_stub.FindInexactEdges(
145-
FindInexactEdgesRequest(selection=ids)
147+
FindInexactEdgesRequest(selection=body_ids)
146148
)
147-
problem_areas = []
148-
for res in problem_areas_response.result:
149-
connected_edges = []
150-
for edge_moniker in res.edge_monikers:
151-
connected_edges.append(edge_moniker)
152-
problem_area = InexactEdgeProblemAreas(res.id, connected_edges, self._grpc_client)
153-
problem_areas.append(problem_area)
154-
149+
problem_areas = [
150+
InexactEdgeProblemAreas(res.id, list(res.edge_monikers), self._grpc_client)
151+
for res in problem_areas_response.result
152+
]
155153
return problem_areas
156154

157-
def find_duplicate_faces(self, ids) -> List[DuplicateFaceProblemAreas]:
155+
def find_duplicate_faces(self, bodies: List["Body"]) -> List[DuplicateFaceProblemAreas]:
158156
"""
159157
Find the duplicate face problem areas.
160158
@@ -163,28 +161,25 @@ def find_duplicate_faces(self, ids) -> List[DuplicateFaceProblemAreas]:
163161
164162
Parameters
165163
----------
166-
ids : List[str]
167-
Server-defined ID for the bodies.
164+
bodies : List[Body]
165+
List of bodies that duplicate faces are investigated on.
168166
169167
Returns
170168
-------
171169
List[DuplicateFaceProblemAreas]
172170
List of objects representing duplicate face problem areas.
173171
"""
172+
body_ids = [body.id for body in bodies]
174173
problem_areas_response = self._repair_stub.FindDuplicateFaces(
175-
FindDuplicateFacesRequest(faces=ids)
174+
FindDuplicateFacesRequest(faces=body_ids)
176175
)
177-
problem_areas = []
178-
for res in problem_areas_response.result:
179-
connected_edges = []
180-
for face_moniker in res.face_monikers:
181-
connected_edges.append(face_moniker)
182-
problem_area = DuplicateFaceProblemAreas(res.id, connected_edges, self._grpc_client)
183-
problem_areas.append(problem_area)
184-
176+
problem_areas = [
177+
DuplicateFaceProblemAreas(res.id, list(res.face_monikers), self._grpc_client)
178+
for res in problem_areas_response.result
179+
]
185180
return problem_areas
186181

187-
def find_missing_faces(self, ids) -> List[MissingFaceProblemAreas]:
182+
def find_missing_faces(self, bodies: List["Body"]) -> List[MissingFaceProblemAreas]:
188183
"""
189184
Find the missing faces.
190185
@@ -193,28 +188,25 @@ def find_missing_faces(self, ids) -> List[MissingFaceProblemAreas]:
193188
194189
Parameters
195190
----------
196-
ids : List[str]
197-
Server-defined ID for the bodies.
191+
bodies : List[Body]
192+
List of bodies that missing faces are investigated on.
198193
199194
Returns
200195
-------
201196
List[MissingFaceProblemAreas]
202197
List of objects representing missing face problem areas.
203198
"""
199+
body_ids = [body.id for body in bodies]
204200
problem_areas_response = self._repair_stub.FindMissingFaces(
205-
FindMissingFacesRequest(faces=ids)
201+
FindMissingFacesRequest(faces=body_ids)
206202
)
207-
problem_areas = []
208-
for res in problem_areas_response.result:
209-
connected_edges = []
210-
for edge_moniker in res.edge_monikers:
211-
connected_edges.append(edge_moniker)
212-
problem_area = MissingFaceProblemAreas(res.id, connected_edges, self._grpc_client)
213-
problem_areas.append(problem_area)
214-
203+
problem_areas = [
204+
MissingFaceProblemAreas(res.id, list(res.edge_monikers), self._grpc_client)
205+
for res in problem_areas_response.result
206+
]
215207
return problem_areas
216208

217-
def find_small_faces(self, ids) -> List[SmallFaceProblemAreas]:
209+
def find_small_faces(self, bodies: List["Body"]) -> List[SmallFaceProblemAreas]:
218210
"""
219211
Find the small face problem areas.
220212
@@ -223,28 +215,25 @@ def find_small_faces(self, ids) -> List[SmallFaceProblemAreas]:
223215
224216
Parameters
225217
----------
226-
ids : List[str]
227-
Server-defined ID for the bodies.
218+
bodies : List[Body]
219+
List of bodies that small faces are investigated on.
228220
229221
Returns
230222
-------
231223
List[SmallFaceProblemAreas]
232224
List of objects representing small face problem areas.
233225
"""
226+
body_ids = [body.id for body in bodies]
234227
problem_areas_response = self._repair_stub.FindSmallFaces(
235-
FindSmallFacesRequest(selection=ids)
228+
FindSmallFacesRequest(selection=body_ids)
236229
)
237-
problem_areas = []
238-
for res in problem_areas_response.result:
239-
connected_edges = []
240-
for face_moniker in res.face_monikers:
241-
connected_edges.append(face_moniker)
242-
problem_area = SmallFaceProblemAreas(res.id, connected_edges, self._grpc_client)
243-
problem_areas.append(problem_area)
244-
230+
problem_areas = [
231+
SmallFaceProblemAreas(res.id, list(res.face_monikers), self._grpc_client)
232+
for res in problem_areas_response.result
233+
]
245234
return problem_areas
246235

247-
def find_stitch_faces(self, ids) -> List[StitchFaceProblemAreas]:
236+
def find_stitch_faces(self, bodies: List["Body"]) -> List[StitchFaceProblemAreas]:
248237
"""
249238
Return the list of stitch face problem areas.
250239
@@ -253,23 +242,20 @@ def find_stitch_faces(self, ids) -> List[StitchFaceProblemAreas]:
253242
254243
Parameters
255244
----------
256-
ids : List[str]
257-
Server-defined ID for the bodies.
245+
bodies : List[Body]
246+
List of bodies that stitchable faces are investigated on.
258247
259248
Returns
260249
-------
261250
List[StitchFaceProblemAreas]
262251
List of objects representing stitch face problem areas.
263252
"""
253+
body_ids = [body.id for body in bodies]
264254
problem_areas_response = self._repair_stub.FindStitchFaces(
265-
FindStitchFacesRequest(faces=ids)
255+
FindStitchFacesRequest(faces=body_ids)
266256
)
267-
problem_areas = []
268-
for res in problem_areas_response.result:
269-
connected_edges = []
270-
for face_moniker in res.body_monikers:
271-
connected_edges.append(face_moniker)
272-
problem_area = StitchFaceProblemAreas(res.id, connected_edges, self._grpc_client)
273-
problem_areas.append(problem_area)
274-
257+
problem_areas = [
258+
StitchFaceProblemAreas(res.id, list(res.body_monikers), self._grpc_client)
259+
for res in problem_areas_response.result
260+
]
275261
return problem_areas

0 commit comments

Comments
 (0)