Skip to content

Commit 20f9db4

Browse files
Merge branch 'main' into chore/v1_implementation_of_file_stub
2 parents 441c6b5 + faf079a commit 20f9db4

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
@@ -48,6 +48,7 @@
4848
DatumPointEntity as GRPCDesignPoint,
4949
DrivingDimensionEntity as GRPCDrivingDimension,
5050
EdgeTessellation as GRPCEdgeTessellation,
51+
EnhancedRepairToolMessage as GRPCEnhancedRepairToolResponse,
5152
Geometries as GRPCGeometries,
5253
Knot as GRPCKnot,
5354
MaterialEntity as GRPCMaterial,
@@ -1443,6 +1444,38 @@ def from_angle_to_grpc_quantity(input: "Measurement") -> GRPCQuantity:
14431444
return GRPCQuantity(value_in_geometry_units=input.value.m_as(DEFAULT_UNITS.SERVER_ANGLE))
14441445

14451446

1447+
def from_area_to_grpc_quantity(input: "Measurement") -> GRPCQuantity:
1448+
"""Convert a ``Measurement`` containing an area to a gRPC quantity.
1449+
1450+
Parameters
1451+
----------
1452+
input : Measurement
1453+
Source measurement data.
1454+
1455+
Returns
1456+
-------
1457+
GRPCQuantity
1458+
Converted gRPC quantity.
1459+
"""
1460+
return GRPCQuantity(value_in_geometry_units=input.value.m_as(DEFAULT_UNITS.SERVER_AREA))
1461+
1462+
1463+
def from_volume_to_grpc_quantity(input: "Measurement") -> GRPCQuantity:
1464+
"""Convert a ``Measurement`` containing a volume to a gRPC quantity.
1465+
1466+
Parameters
1467+
----------
1468+
input : Measurement
1469+
Source measurement data.
1470+
1471+
Returns
1472+
-------
1473+
GRPCQuantity
1474+
Converted gRPC quantity.
1475+
"""
1476+
return GRPCQuantity(value_in_geometry_units=input.value.m_as(DEFAULT_UNITS.SERVER_VOLUME))
1477+
1478+
14461479
def from_grpc_volume_to_volume(grpc_quantity: GRPCQuantity) -> "pint.Quantity":
14471480
"""Convert a gRPC quantity representing volume to a pint Quantity.
14481481
@@ -1677,3 +1710,93 @@ def get_tracker_response_with_created_bodies(response) -> dict:
16771710
"created_bodies", []
16781711
)
16791712
return serialized_response
1713+
1714+
1715+
def serialize_repair_command_response(response: GRPCEnhancedRepairToolResponse) -> dict:
1716+
"""Serialize a EnhancedRepairToolResponse object into a dictionary.
1717+
1718+
Parameters
1719+
----------
1720+
response : GRPCEnhancedRepairToolResponse
1721+
The gRPC EnhancedRepairToolResponse object to serialize.
1722+
A dictionary representation of the EnhancedRepairToolResponse object.
1723+
"""
1724+
return {
1725+
"success": response.tracked_command_response.command_response.success,
1726+
"found": response.found,
1727+
"repaired": response.repaired,
1728+
"complete_command_response": serialize_tracked_command_response(response.tracked_changes),
1729+
"created_bodies_monikers": [
1730+
created_body.id for created_body in response.tracked_changes.get("created_bodies", [])
1731+
],
1732+
"modified_bodies_monikers": [
1733+
modified_body.id
1734+
for modified_body in response.tracked_changes.get("modified_bodies", [])
1735+
],
1736+
"deleted_bodies_monikers": [
1737+
deleted_body.id for deleted_body in response.tracked_changes.get("deleted_bodies", [])
1738+
],
1739+
}
1740+
1741+
1742+
def response_problem_area_for_body(response) -> dict:
1743+
"""Get a dictionary response from problem areas for a body.
1744+
1745+
Parameters
1746+
----------
1747+
response
1748+
The response to convert.
1749+
1750+
Returns
1751+
-------
1752+
dict
1753+
A dictionary representation of the ProblemAreaForBody object.
1754+
"""
1755+
return {
1756+
"problems": [
1757+
{"id": res.problem_area_id, "bodies": [body.id for body in res.body_ids]}
1758+
for res in response.result
1759+
]
1760+
}
1761+
1762+
1763+
def response_problem_area_for_face(response) -> dict:
1764+
"""Get a dictionary response from problem areas for a face.
1765+
1766+
Parameters
1767+
----------
1768+
response
1769+
The response to convert.
1770+
1771+
Returns
1772+
-------
1773+
dict
1774+
A dictionary representation of the ProblemAreaForFace object.
1775+
"""
1776+
return {
1777+
"problems": [
1778+
{"id": res.problem_area_id, "faces": [face.id for face in res.face_ids]}
1779+
for res in response.result
1780+
]
1781+
}
1782+
1783+
1784+
def response_problem_area_for_edge(response) -> dict:
1785+
"""Get a dictionary response from problem areas for an edge.
1786+
1787+
Parameters
1788+
----------
1789+
response
1790+
The response to convert.
1791+
1792+
Returns
1793+
-------
1794+
dict
1795+
A dictionary representation of the ProblemAreaForEdge object.
1796+
"""
1797+
return {
1798+
"problems": [
1799+
{"id": res.problem_area_id, "edges": [edge.id for edge in res.edge_ids]}
1800+
for res in response.result
1801+
]
1802+
}

0 commit comments

Comments
 (0)