Skip to content

Commit 5de7e3a

Browse files
smereupyansys-ci-botpre-commit-ci[bot]jacobrkerstetter
authored
chore: fix repair/prepare v1 issues (#2456)
Co-authored-by: PyAnsys CI Bot <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Jacob Kerstetter <[email protected]> Co-authored-by: Jacob Kerstetter <[email protected]>
1 parent 961cc4e commit 5de7e3a

File tree

5 files changed

+58
-77
lines changed

5 files changed

+58
-77
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Chore: fix repair/prepare v1 issues

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from ..base.conversions import from_measurement_to_server_angle, from_measurement_to_server_length
3030
from ..base.repair_tools import GRPCRepairToolsService
3131
from .conversions import (
32+
build_grpc_id,
3233
serialize_tracker_command_response,
3334
)
3435

@@ -517,7 +518,9 @@ def inspect_geometry(self, **kwargs) -> dict: # noqa: D102
517518
from ansys.api.geometry.v0.repairtools_pb2 import InspectGeometryRequest
518519

519520
# Create the request - assumes all inputs are valid and of the proper type
520-
request = InspectGeometryRequest(bodies=kwargs.get("bodies", []))
521+
request = InspectGeometryRequest(
522+
bodies=[build_grpc_id(id) for id in kwargs.get("body_ids", [])]
523+
)
521524

522525
# Call the gRPC service
523526
inspect_result_response = self.stub.InspectGeometry(request)
@@ -530,7 +533,9 @@ def repair_geometry(self, **kwargs) -> dict: # noqa: D102
530533
from ansys.api.geometry.v0.repairtools_pb2 import RepairGeometryRequest
531534

532535
# Create the request - assumes all inputs are valid and of the proper type
533-
request = RepairGeometryRequest(bodies=kwargs.get("bodies"))
536+
request = RepairGeometryRequest(
537+
bodies=[build_grpc_id(id) for id in kwargs.get("body_ids", [])]
538+
)
534539

535540
# Call the gRPC service
536541
response = self.stub.RepairGeometry(request)

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

Lines changed: 25 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
DatumPointEntity as GRPCDesignPoint,
4949
DrivingDimensionEntity as GRPCDrivingDimension,
5050
EdgeTessellation as GRPCEdgeTessellation,
51-
EnhancedRepairToolMessage as GRPCEnhancedRepairToolResponse,
5251
Geometries as GRPCGeometries,
5352
Knot as GRPCKnot,
5453
MaterialEntity as GRPCMaterial,
@@ -72,6 +71,9 @@
7271
from ansys.api.discovery.v1.operations.prepare_pb2 import (
7372
EnclosureOptions as GRPCEnclosureOptions,
7473
)
74+
from ansys.api.discovery.v1.operations.repair_pb2 import (
75+
RepairToolMessage as GRPCRepairToolResponse,
76+
)
7577
import pint
7678

7779
from ansys.geometry.core.errors import GeometryRuntimeError
@@ -1728,68 +1730,39 @@ def serialize_entity_identifier(entity):
17281730
}
17291731

17301732

1731-
def get_standard_tracker_response(response) -> dict:
1732-
"""Get a standard dictionary response from a TrackerCommandResponse gRPC object.
1733-
1734-
Parameters
1735-
----------
1736-
response : TrackerCommandResponse
1737-
The gRPC TrackerCommandResponse object.
1738-
1739-
Returns
1740-
-------
1741-
dict
1742-
A dictionary representing the standard tracker response
1743-
"""
1744-
return {
1745-
"success": response.command_response.success,
1746-
"tracker_response": serialize_tracked_command_response(response.tracked_changes),
1747-
}
1748-
1749-
1750-
def get_tracker_response_with_created_bodies(response) -> dict:
1751-
"""Get a dictionary response from a TrackerCommandResponse gRPC object including created bodies.
1752-
1753-
Parameters
1754-
----------
1755-
response : TrackerCommandResponse
1756-
The gRPC TrackerCommandResponse object.
1757-
1758-
Returns
1759-
-------
1760-
dict
1761-
A dictionary representing the tracker response with created bodies.
1762-
"""
1763-
serialized_response = get_standard_tracker_response(response)
1764-
serialized_response["created_bodies"] = serialized_response["tracker_response"].get(
1765-
"created_bodies", []
1766-
)
1767-
return serialized_response
1768-
1769-
1770-
def serialize_repair_command_response(response: GRPCEnhancedRepairToolResponse) -> dict:
1771-
"""Serialize a EnhancedRepairToolResponse object into a dictionary.
1733+
def serialize_repair_command_response(response: GRPCRepairToolResponse) -> dict:
1734+
"""Serialize a RepairToolResponse object into a dictionary.
17721735
17731736
Parameters
17741737
----------
1775-
response : GRPCEnhancedRepairToolResponse
1776-
The gRPC EnhancedRepairToolResponse object to serialize.
1777-
A dictionary representation of the EnhancedRepairToolResponse object.
1738+
response : GRPCRepairToolResponse
1739+
The gRPC RepairToolResponse object to serialize.
1740+
A dictionary representation of the RepairToolResponse object.
17781741
"""
17791742
return {
17801743
"success": response.tracked_command_response.command_response.success,
1781-
"found": response.found,
1782-
"repaired": response.repaired,
1783-
"complete_command_response": serialize_tracked_command_response(response.tracked_changes),
1744+
"found": getattr(response, "found", -1),
1745+
"repaired": getattr(response, "repaired", -1),
1746+
"complete_command_response": serialize_tracked_command_response(
1747+
response.tracked_command_response
1748+
),
17841749
"created_bodies_monikers": [
1785-
created_body.id for created_body in response.tracked_changes.get("created_bodies", [])
1750+
created_body.id.id
1751+
for created_body in getattr(
1752+
response.tracked_command_response.tracked_changes, "created_bodies", []
1753+
)
17861754
],
17871755
"modified_bodies_monikers": [
1788-
modified_body.id
1789-
for modified_body in response.tracked_changes.get("modified_bodies", [])
1756+
modified_body.id.id
1757+
for modified_body in getattr(
1758+
response.tracked_command_response.tracked_changes, "modified_bodies", []
1759+
)
17901760
],
17911761
"deleted_bodies_monikers": [
1792-
deleted_body.id for deleted_body in response.tracked_changes.get("deleted_bodies", [])
1762+
deleted_body.id
1763+
for deleted_body in getattr(
1764+
response.tracked_command_response.tracked_changes, "deleted_bodies", []
1765+
)
17931766
],
17941767
}
17951768

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
build_grpc_id,
3232
from_enclosure_options_to_grpc_enclosure_options,
3333
from_length_to_grpc_quantity,
34-
get_standard_tracker_response,
3534
serialize_tracked_command_response,
3635
)
3736

@@ -142,14 +141,14 @@ def enhanced_share_topology(self, **kwargs) -> dict: # noqa: D102
142141
)
143142

144143
# Call the gRPC service
145-
response = self.stub.EnhancedShareTopology(request).response_data
144+
response = self.stub.EnhancedShareTopology(request)
146145
tracked_response = serialize_tracked_command_response(response.tracked_command_response)
147146

148147
# Return the response - formatted as a dictionary
149148
return {
150149
"success": response.tracked_command_response.command_response.success,
151-
"found": response.found,
152-
"repaired": response.repaired,
150+
"found": getattr(response, "found", -1),
151+
"repaired": getattr(response, "repaired", -1),
153152
"created_bodies_monikers": [
154153
created_body.get("id").id
155154
for created_body in tracked_response.get("created_bodies", [])
@@ -190,13 +189,16 @@ def find_logos(self, **kwargs) -> dict: # noqa: D102
190189

191190
# Return the response - formatted as a dictionary
192191
return {
193-
"id": response.id,
192+
"id": getattr(response, "id", None),
194193
"face_ids": [face.id for face in response.logo_faces],
195194
}
196195

197196
@protect_grpc
198197
def find_and_remove_logos(self, **kwargs) -> dict: # noqa: D102
199-
from ansys.api.discovery.v1.operations.prepare_pb2 import FindLogoOptions, FindLogosRequest
198+
from ansys.api.discovery.v1.operations.prepare_pb2 import (
199+
FindAndRemoveLogosRequest,
200+
FindLogoOptions,
201+
)
200202

201203
# Check height objects
202204
min_height = (
@@ -211,7 +213,7 @@ def find_and_remove_logos(self, **kwargs) -> dict: # noqa: D102
211213
)
212214

213215
# Create the request - assumes all inputs are valid and of the proper type
214-
request = FindLogosRequest(
216+
request = FindAndRemoveLogosRequest(
215217
body_ids=[build_grpc_id(body) for body in kwargs["bodies"]],
216218
options=FindLogoOptions(
217219
min_height=min_height,
@@ -223,7 +225,7 @@ def find_and_remove_logos(self, **kwargs) -> dict: # noqa: D102
223225
response = self.stub.FindAndRemoveLogos(request)
224226

225227
# Return the response - formatted as a dictionary
226-
return get_standard_tracker_response(response)
228+
return {"success": response.tracked_command_response.command_response.success}
227229

228230
@protect_grpc
229231
def remove_logo(self, **kwargs): # noqa: D102
@@ -238,7 +240,7 @@ def remove_logo(self, **kwargs): # noqa: D102
238240
response = self.stub.RemoveLogo(request)
239241

240242
# Return the response - formatted as a dictionary
241-
return get_standard_tracker_response(response)
243+
return {"success": response.tracked_command_response.command_response.success}
242244

243245
@protect_grpc
244246
def detect_helixes(self, **kwargs) -> dict: # noqa: D102

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def find_missing_faces(self, **kwargs) -> dict: # noqa: D102
157157
response = self.stub.FindMissingFaces(request)
158158

159159
# Return the response - formatted as a dictionary
160-
return response_problem_area_for_face(response)
160+
return response_problem_area_for_edge(response)
161161

162162
@protect_grpc
163163
def find_small_faces(self, **kwargs) -> dict: # noqa: D102
@@ -241,7 +241,7 @@ def find_and_fix_short_edges(self, **kwargs): # noqa: D102
241241
# Call the gRPC service
242242
response = self.stub.FindAndFixShortEdges(request)
243243

244-
return serialize_repair_command_response(response.response_data)
244+
return serialize_repair_command_response(response.result)
245245

246246
@protect_grpc
247247
def find_and_fix_extra_edges(self, **kwargs) -> dict: # noqa: D102
@@ -256,7 +256,7 @@ def find_and_fix_extra_edges(self, **kwargs) -> dict: # noqa: D102
256256
# Call the gRPC service
257257
response = self.stub.FindAndFixExtraEdges(request)
258258

259-
return serialize_repair_command_response(response.response_data)
259+
return serialize_repair_command_response(response.result)
260260

261261
@protect_grpc
262262
def find_and_fix_split_edges(self, **kwargs) -> dict: # noqa: D102
@@ -272,7 +272,7 @@ def find_and_fix_split_edges(self, **kwargs) -> dict: # noqa: D102
272272
# Call the gRPC service
273273
response = self.stub.FindAndFixSplitEdges(request)
274274

275-
return serialize_repair_command_response(response.response_data)
275+
return serialize_repair_command_response(response.result)
276276

277277
@protect_grpc
278278
def find_and_fix_simplify(self, **kwargs) -> dict: # noqa: D102
@@ -287,7 +287,7 @@ def find_and_fix_simplify(self, **kwargs) -> dict: # noqa: D102
287287
# Call the gRPC service
288288
response = self.stub.FindAndSimplify(request)
289289

290-
return serialize_repair_command_response(response.response_data)
290+
return serialize_repair_command_response(response.result)
291291

292292
@protect_grpc
293293
def find_and_fix_stitch_faces(self, **kwargs) -> dict: # noqa: D102
@@ -308,7 +308,7 @@ def find_and_fix_stitch_faces(self, **kwargs) -> dict: # noqa: D102
308308
# Call the gRPC service
309309
response = self.stub.FindAndFixStitchFaces(request)
310310

311-
return serialize_repair_command_response(response.response_data)
311+
return serialize_repair_command_response(response.result)
312312

313313
@protect_grpc
314314
def inspect_geometry(self, **kwargs) -> dict: # noqa: D102
@@ -331,14 +331,14 @@ def repair_geometry(self, **kwargs) -> dict: # noqa: D102
331331

332332
# Create the request - assumes all inputs are valid and of the proper type
333333
request = RepairGeometryRequest(
334-
body_ids=[build_grpc_id(body) for body in kwargs.get("bodies")]
334+
body_ids=[build_grpc_id(body) for body in kwargs.get("body_ids")]
335335
)
336336

337337
# Call the gRPC service
338338
response = self.stub.RepairGeometry(request)
339339

340340
# Return the response - formatted as a dictionary
341-
return serialize_repair_command_response(response)
341+
return serialize_repair_command_response(response.result)
342342

343343
@protect_grpc
344344
def fix_duplicate_faces(self, **kwargs) -> dict: # noqa: D102
@@ -473,7 +473,7 @@ def fix_unsimplified_faces(self, **kwargs) -> dict: # noqa: D102
473473
response = self.stub.FixAdjustSimplify(request)
474474

475475
# Return the response - formatted as a dictionary
476-
return serialize_repair_command_response(response)
476+
return serialize_repair_command_response(response.result)
477477

478478
@protect_grpc
479479
def fix_interference(self, **kwargs) -> dict: # noqa: D102
@@ -493,7 +493,7 @@ def fix_interference(self, **kwargs) -> dict: # noqa: D102
493493
def __serialize_inspect_result_response(self, response) -> dict: # noqa: D102
494494
def serialize_body(body):
495495
return {
496-
"id": body.id,
496+
"id": body.id.id,
497497
"name": body.name,
498498
"can_suppress": body.can_suppress,
499499
"transform_to_master": {
@@ -502,13 +502,13 @@ def serialize_body(body):
502502
"m22": body.transform_to_master.m22,
503503
"m33": body.transform_to_master.m33,
504504
},
505-
"master_id": body.master_id,
506-
"parent_id": body.parent_id,
505+
"master_id": body.master_id.id,
506+
"parent_id": body.parent_id.id,
507507
}
508508

509509
def serialize_face(face):
510510
return {
511-
"id": face.id,
511+
"id": face.id.id,
512512
"surface_type": face.surface_type,
513513
"export_id": face.export_id,
514514
"is_reversed": getattr(face, "is_reversed", False),
@@ -517,7 +517,7 @@ def serialize_face(face):
517517

518518
def serialize_edge(edge):
519519
return {
520-
"id": edge.id,
520+
"id": edge.id.id,
521521
"curve_type": edge.curve_type,
522522
"export_id": edge.export_id,
523523
"length": edge.length,

0 commit comments

Comments
 (0)