Skip to content

Commit faf079a

Browse files
smereupyansys-ci-botjacobrkerstetterpre-commit-ci[bot]
authored
chore: v1 implementation of repair stubs (#2441)
Co-authored-by: PyAnsys CI Bot <[email protected]> Co-authored-by: Jacob Kerstetter <[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]>
1 parent 5c3c0a2 commit faf079a

File tree

8 files changed

+642
-109
lines changed

8 files changed

+642
-109
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
update CHANGELOG for v0.9.0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Chore: v1 implementation of repair stubs

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

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,7 @@
1919
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
22-
"""Module containing the repair tools service implementation for v0.
23-
24-
This module defines an abstract base class for a gRPC-based repair tools service.
25-
The class provides a set of abstract methods for identifying and repairing various
26-
geometry issues, such as split edges, extra edges, duplicate faces etc.
27-
"""
22+
"""Module containing the repair tools service implementation for v0."""
2823

2924
from google.protobuf.wrappers_pb2 import Int32Value
3025
import grpc
@@ -393,7 +388,7 @@ def find_and_fix_short_edges(self, **kwargs): # noqa: D102
393388
"repaired": response.repaired,
394389
"created_bodies_monikers": [],
395390
"modified_bodies_monikers": [],
396-
"complete_command_response": serialized_tracker_response,
391+
"tracker_response": serialized_tracker_response,
397392
}
398393

399394
@protect_grpc
@@ -420,7 +415,7 @@ def find_and_fix_extra_edges(self, **kwargs) -> dict: # noqa: D102
420415
"repaired": response.repaired,
421416
"created_bodies_monikers": response.created_bodies_monikers,
422417
"modified_bodies_monikers": response.modified_bodies_monikers,
423-
"complete_command_response": serialized_tracker_response,
418+
"tracker_response": serialized_tracker_response,
424419
}
425420

426421
@protect_grpc
@@ -449,7 +444,7 @@ def find_and_fix_split_edges(self, **kwargs) -> dict: # noqa: D102
449444
"repaired": response.repaired,
450445
"created_bodies_monikers": [],
451446
"modified_bodies_monikers": [],
452-
"complete_command_response": serialized_tracker_response,
447+
"tracker_response": serialized_tracker_response,
453448
}
454449

455450
@protect_grpc
@@ -476,7 +471,7 @@ def find_and_fix_simplify(self, **kwargs) -> dict: # noqa: D102
476471
"repaired": response.repaired,
477472
"created_bodies_monikers": [],
478473
"modified_bodies_monikers": [],
479-
"complete_command_response": serialized_tracker_response,
474+
"tracker_response": serialized_tracker_response,
480475
}
481476

482477
@protect_grpc
@@ -514,15 +509,15 @@ def find_and_fix_stitch_faces(self, **kwargs) -> dict: # noqa: D102
514509
"modified_bodies_monikers": response.modified_bodies_monikers,
515510
"found": response.found,
516511
"repaired": response.repaired,
517-
"complete_command_response": serialized_tracker_response,
512+
"tracker_response": serialized_tracker_response,
518513
}
519514

520515
@protect_grpc
521516
def inspect_geometry(self, **kwargs) -> dict: # noqa: D102
522517
from ansys.api.geometry.v0.repairtools_pb2 import InspectGeometryRequest
523518

524519
# Create the request - assumes all inputs are valid and of the proper type
525-
request = InspectGeometryRequest(bodies=kwargs.get("bodies", []))
520+
request = InspectGeometryRequest(bodies=kwargs.get("bodies"))
526521

527522
# Call the gRPC service
528523
inspect_result_response = self.stub.InspectGeometry(request)
@@ -535,7 +530,7 @@ def repair_geometry(self, **kwargs) -> dict: # noqa: D102
535530
from ansys.api.geometry.v0.repairtools_pb2 import RepairGeometryRequest
536531

537532
# Create the request - assumes all inputs are valid and of the proper type
538-
request = RepairGeometryRequest(bodies=kwargs.get("bodies", []))
533+
request = RepairGeometryRequest(bodies=kwargs.get("bodies"))
539534

540535
# Call the gRPC service
541536
response = self.stub.RepairGeometry(request)
@@ -566,7 +561,9 @@ def fix_duplicate_faces(self, **kwargs) -> dict: # noqa: D102
566561
# Return the response - formatted as a dictionary
567562
return {
568563
"tracker_response": serialized_tracker_response,
569-
"repair_tracker_response": self.__serialize_message_response(response),
564+
"success": response.result.success,
565+
"created_bodies_monikers": response.result.created_bodies_monikers,
566+
"modified_bodies_monikers": response.result.modified_bodies_monikers,
570567
}
571568

572569
@protect_grpc
@@ -590,7 +587,9 @@ def fix_missing_faces(self, **kwargs) -> dict: # noqa: D102
590587
# Return the response - formatted as a dictionary
591588
return {
592589
"tracker_response": serialized_tracker_response,
593-
"repair_tracker_response": self.__serialize_message_response(response),
590+
"success": response.result.success,
591+
"created_bodies_monikers": response.result.created_bodies_monikers,
592+
"modified_bodies_monikers": response.result.modified_bodies_monikers,
594593
}
595594

596595
@protect_grpc
@@ -614,7 +613,9 @@ def fix_inexact_edges(self, **kwargs) -> dict: # noqa: D102
614613
# Return the response - formatted as a dictionary
615614
return {
616615
"tracker_response": serialized_tracker_response,
617-
"repair_tracker_response": self.__serialize_message_response(response),
616+
"success": response.result.success,
617+
"created_bodies_monikers": response.result.created_bodies_monikers,
618+
"modified_bodies_monikers": response.result.modified_bodies_monikers,
618619
}
619620

620621
@protect_grpc
@@ -636,7 +637,9 @@ def fix_extra_edges(self, **kwargs) -> dict: # noqa: D102
636637
# Return the response - formatted as a dictionary
637638
return {
638639
"tracker_response": serialized_tracker_response,
639-
"repair_tracker_response": self.__serialize_message_response(response),
640+
"success": response.result.success,
641+
"created_bodies_monikers": response.result.created_bodies_monikers,
642+
"modified_bodies_monikers": response.result.modified_bodies_monikers,
640643
}
641644

642645
@protect_grpc
@@ -658,7 +661,9 @@ def fix_short_edges(self, **kwargs) -> dict: # noqa: D102
658661
# Return the response - formatted as a dictionary
659662
return {
660663
"tracker_response": serialized_tracker_response,
661-
"repair_tracker_response": self.__serialize_message_response(response),
664+
"success": response.result.success,
665+
"created_bodies_monikers": response.result.created_bodies_monikers,
666+
"modified_bodies_monikers": response.result.modified_bodies_monikers,
662667
}
663668

664669
@protect_grpc
@@ -680,7 +685,9 @@ def fix_small_faces(self, **kwargs) -> dict: # noqa: D102
680685
# Return the response - formatted as a dictionary
681686
return {
682687
"tracker_response": serialized_tracker_response,
683-
"repair_tracker_response": self.__serialize_message_response(response),
688+
"success": response.result.success,
689+
"created_bodies_monikers": response.result.created_bodies_monikers,
690+
"modified_bodies_monikers": response.result.modified_bodies_monikers,
684691
}
685692

686693
@protect_grpc
@@ -702,7 +709,9 @@ def fix_split_edges(self, **kwargs) -> dict: # noqa: D102
702709
# Return the response - formatted as a dictionary
703710
return {
704711
"tracker_response": serialized_tracker_response,
705-
"repair_tracker_response": self.__serialize_message_response(response),
712+
"success": response.result.success,
713+
"created_bodies_monikers": response.result.created_bodies_monikers,
714+
"modified_bodies_monikers": response.result.modified_bodies_monikers,
706715
}
707716

708717
@protect_grpc
@@ -726,7 +735,9 @@ def fix_stitch_faces(self, **kwargs) -> dict: # noqa: D102
726735
# Return the response - formatted as a dictionary
727736
return {
728737
"tracker_response": serialized_tracker_response,
729-
"repair_tracker_response": self.__serialize_message_response(response),
738+
"success": response.result.success,
739+
"created_bodies_monikers": response.result.created_bodies_monikers,
740+
"modified_bodies_monikers": response.result.modified_bodies_monikers,
730741
}
731742

732743
@protect_grpc
@@ -750,7 +761,9 @@ def fix_unsimplified_faces(self, **kwargs) -> dict: # noqa: D102
750761
# Return the response - formatted as a dictionary
751762
return {
752763
"tracker_response": serialized_tracker_response,
753-
"repair_tracker_response": self.__serialize_message_response(response),
764+
"success": response.result.success,
765+
"created_bodies_monikers": response.result.created_bodies_monikers,
766+
"modified_bodies_monikers": response.result.modified_bodies_monikers,
754767
}
755768

756769
@protect_grpc
@@ -774,7 +787,9 @@ def fix_interference(self, **kwargs) -> dict: # noqa: D102
774787
# Return the response - formatted as a dictionary
775788
return {
776789
"tracker_response": serialized_tracker_response,
777-
"repair_tracker_response": self.__serialize_message_response(response),
790+
"success": response.result.success,
791+
"created_bodies_monikers": response.result.created_bodies_monikers,
792+
"modified_bodies_monikers": response.result.modified_bodies_monikers,
778793
}
779794

780795
def __serialize_inspect_result_response(self, response) -> dict: # noqa: D102
@@ -830,10 +845,3 @@ def serialize_issue(issue):
830845
for body_issues in response.issues_by_body
831846
]
832847
}
833-
834-
def __serialize_message_response(self, response):
835-
return {
836-
"success": response.result.success,
837-
"created_bodies_monikers": response.result.created_bodies_monikers,
838-
"modified_bodies_monikers": response.result.modified_bodies_monikers,
839-
}

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

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
CurveGeometry as GRPCCurveGeometry,
4545
DrivingDimensionEntity as GRPCDrivingDimension,
4646
EdgeTessellation as GRPCEdgeTessellation,
47+
EnhancedRepairToolMessage as GRPCEnhancedRepairToolResponse,
4748
Geometries as GRPCGeometries,
4849
Knot as GRPCKnot,
4950
MaterialEntity as GRPCMaterial,
@@ -1382,6 +1383,38 @@ def from_angle_to_grpc_quantity(input: "Measurement") -> GRPCQuantity:
13821383
return GRPCQuantity(value_in_geometry_units=input.value.m_as(DEFAULT_UNITS.SERVER_ANGLE))
13831384

13841385

1386+
def from_area_to_grpc_quantity(input: "Measurement") -> GRPCQuantity:
1387+
"""Convert a ``Measurement`` containing an area to a gRPC quantity.
1388+
1389+
Parameters
1390+
----------
1391+
input : Measurement
1392+
Source measurement data.
1393+
1394+
Returns
1395+
-------
1396+
GRPCQuantity
1397+
Converted gRPC quantity.
1398+
"""
1399+
return GRPCQuantity(value_in_geometry_units=input.value.m_as(DEFAULT_UNITS.SERVER_AREA))
1400+
1401+
1402+
def from_volume_to_grpc_quantity(input: "Measurement") -> GRPCQuantity:
1403+
"""Convert a ``Measurement`` containing a volume to a gRPC quantity.
1404+
1405+
Parameters
1406+
----------
1407+
input : Measurement
1408+
Source measurement data.
1409+
1410+
Returns
1411+
-------
1412+
GRPCQuantity
1413+
Converted gRPC quantity.
1414+
"""
1415+
return GRPCQuantity(value_in_geometry_units=input.value.m_as(DEFAULT_UNITS.SERVER_VOLUME))
1416+
1417+
13851418
def from_grpc_volume_to_volume(grpc_quantity: GRPCQuantity) -> "pint.Quantity":
13861419
"""Convert a gRPC quantity representing volume to a pint Quantity.
13871420
@@ -1633,3 +1666,93 @@ def get_tracker_response_with_created_bodies(response) -> dict:
16331666
"created_bodies", []
16341667
)
16351668
return serialized_response
1669+
1670+
1671+
def serialize_repair_command_response(response: GRPCEnhancedRepairToolResponse) -> dict:
1672+
"""Serialize a EnhancedRepairToolResponse object into a dictionary.
1673+
1674+
Parameters
1675+
----------
1676+
response : GRPCEnhancedRepairToolResponse
1677+
The gRPC EnhancedRepairToolResponse object to serialize.
1678+
A dictionary representation of the EnhancedRepairToolResponse object.
1679+
"""
1680+
return {
1681+
"success": response.tracked_command_response.command_response.success,
1682+
"found": response.found,
1683+
"repaired": response.repaired,
1684+
"complete_command_response": serialize_tracked_command_response(response.tracked_changes),
1685+
"created_bodies_monikers": [
1686+
created_body.id for created_body in response.tracked_changes.get("created_bodies", [])
1687+
],
1688+
"modified_bodies_monikers": [
1689+
modified_body.id
1690+
for modified_body in response.tracked_changes.get("modified_bodies", [])
1691+
],
1692+
"deleted_bodies_monikers": [
1693+
deleted_body.id for deleted_body in response.tracked_changes.get("deleted_bodies", [])
1694+
],
1695+
}
1696+
1697+
1698+
def response_problem_area_for_body(response) -> dict:
1699+
"""Get a dictionary response from problem areas for a body.
1700+
1701+
Parameters
1702+
----------
1703+
response
1704+
The response to convert.
1705+
1706+
Returns
1707+
-------
1708+
dict
1709+
A dictionary representation of the ProblemAreaForBody object.
1710+
"""
1711+
return {
1712+
"problems": [
1713+
{"id": res.problem_area_id, "bodies": [body.id for body in res.body_ids]}
1714+
for res in response.result
1715+
]
1716+
}
1717+
1718+
1719+
def response_problem_area_for_face(response) -> dict:
1720+
"""Get a dictionary response from problem areas for a face.
1721+
1722+
Parameters
1723+
----------
1724+
response
1725+
The response to convert.
1726+
1727+
Returns
1728+
-------
1729+
dict
1730+
A dictionary representation of the ProblemAreaForFace object.
1731+
"""
1732+
return {
1733+
"problems": [
1734+
{"id": res.problem_area_id, "faces": [face.id for face in res.face_ids]}
1735+
for res in response.result
1736+
]
1737+
}
1738+
1739+
1740+
def response_problem_area_for_edge(response) -> dict:
1741+
"""Get a dictionary response from problem areas for an edge.
1742+
1743+
Parameters
1744+
----------
1745+
response
1746+
The response to convert.
1747+
1748+
Returns
1749+
-------
1750+
dict
1751+
A dictionary representation of the ProblemAreaForEdge object.
1752+
"""
1753+
return {
1754+
"problems": [
1755+
{"id": res.problem_area_id, "edges": [edge.id for edge in res.edge_ids]}
1756+
for res in response.result
1757+
]
1758+
}

0 commit comments

Comments
 (0)