2424import grpc
2525import pint
2626
27+ import ansys .geometry .core as pyansys_geom
2728from ansys .geometry .core .errors import protect_grpc
2829from ansys .geometry .core .misc .measurements import DEFAULT_UNITS
2930
4344 from_trimmed_curve_to_grpc_trimmed_curve ,
4445 from_trimmed_surface_to_grpc_trimmed_surface ,
4546 from_unit_vector_to_grpc_direction ,
47+ serialize_tracker_command_response ,
4648)
4749
4850
@@ -714,15 +716,22 @@ def boolean(self, **kwargs) -> dict: # noqa: D102
714716 from ansys .api .geometry .v0 .bodies_pb2 import BooleanRequest
715717
716718 # Call the gRPC service and build the requests accordingly
717- resp = 0
719+ response_success = 0
720+ serialized_tracker_response = {}
718721 try :
719- resp = self .stub .Boolean (
720- request = BooleanRequest (
721- body1 = kwargs ["target" ].id ,
722- tool_bodies = [other .id for other in kwargs ["other" ]],
723- method = kwargs ["method" ],
722+ request = BooleanRequest (
723+ body1 = kwargs ["target" ].id ,
724+ tool_bodies = [other .id for other in kwargs ["other" ]],
725+ method = kwargs ["method" ],
726+ )
727+ if pyansys_geom .USE_TRACKER_TO_UPDATE_DESIGN :
728+ request .keep_other = kwargs ["keep_other" ]
729+ resp = self .stub .Boolean (request = request )
730+ response_success = resp .empty_result
731+ if pyansys_geom .USE_TRACKER_TO_UPDATE_DESIGN :
732+ serialized_tracker_response = serialize_tracker_command_response (
733+ response = resp .response
724734 )
725- ).empty_result
726735 except grpc .RpcError as err : # pragma: no cover
727736 # TODO: to be deleted - old versions did not have "tool_bodies" in the request
728737 # This is a temporary fix to support old versions of the server - should be deleted
@@ -741,26 +750,82 @@ def boolean(self, **kwargs) -> dict: # noqa: D102
741750 all_resp .append (tmp_resp )
742751
743752 if all_resp .count (1 ) > 0 :
744- resp = 1
753+ response_success = 1
745754 elif len (kwargs ["other" ]) == 1 :
746755 resp = self .stub .Boolean (
747756 request = BooleanRequest (
748757 body1 = kwargs ["target" ].id ,
749758 body2 = kwargs ["other" ][0 ].id ,
750759 method = kwargs ["method" ],
751760 )
752- ).empty_result
761+ )
762+ response_success = resp .empty_result
753763 else :
754764 raise err
755765
756- if resp == 1 :
766+ if response_success == 1 :
757767 raise ValueError (
758768 f"Boolean operation of type '{ kwargs ['method' ]} ' failed: { kwargs ['err_msg' ]} .\n "
759769 f"Involving bodies:{ kwargs ['target' ]} , { kwargs ['other' ]} "
760770 )
761771
762772 # Return the response - formatted as a dictionary
763- return {}
773+ return {"complete_command_response" : serialized_tracker_response }
774+
775+ @protect_grpc
776+ def combine (self , ** kwargs ) -> dict : # noqa: D102
777+ from ansys .api .geometry .v0 .bodies_pb2 import (
778+ CombineIntersectBodiesRequest ,
779+ CombineMergeBodiesRequest ,
780+ )
781+
782+ other_bodies = kwargs ["other" ]
783+ type_bool_op = kwargs ["type_bool_op" ]
784+ keep_other = kwargs ["keep_other" ]
785+
786+ if type_bool_op == "intersect" :
787+ body_ids = [body ._grpc_id for body in other_bodies ]
788+ target_ids = [self ._grpc_id ]
789+ request = CombineIntersectBodiesRequest (
790+ target_selection = target_ids ,
791+ tool_selection = body_ids ,
792+ subtract_from_target = False ,
793+ keep_cutter = keep_other ,
794+ )
795+ response = self ._template ._commands_stub .CombineIntersectBodies (request )
796+ elif type_bool_op == "subtract" :
797+ body_ids = [body ._grpc_id for body in other_bodies ]
798+ target_ids = [self ._grpc_id ]
799+ request = CombineIntersectBodiesRequest (
800+ target_selection = target_ids ,
801+ tool_selection = body_ids ,
802+ subtract_from_target = True ,
803+ keep_cutter = keep_other ,
804+ )
805+ response = self ._template ._commands_stub .CombineIntersectBodies (request )
806+ elif type_bool_op == "unite" :
807+ bodies = [self ]
808+ bodies .extend (other_bodies )
809+ body_ids = [body ._grpc_id for body in bodies ]
810+ request = CombineMergeBodiesRequest (target_selection = body_ids )
811+ response = self ._template ._commands_stub .CombineMergeBodies (request )
812+ else :
813+ raise ValueError ("Unknown operation requested" )
814+ if not response .success :
815+ raise ValueError (
816+ f"Operation of type '{ type_bool_op } ' failed: { kwargs ['err_msg' ]} .\n "
817+ f"Involving bodies:{ self } , { other_bodies } "
818+ )
819+
820+ if not keep_other :
821+ for b in other_bodies :
822+ b .parent_component .delete_body (b )
823+
824+ tracker_response = response .result .complete_command_response
825+ serialized_tracker_response = serialize_tracker_command_response (response = tracker_response )
826+
827+ # Return the response - formatted as a dictionary
828+ return {"complete_command_response" : serialized_tracker_response }
764829
765830 @protect_grpc
766831 def split_body (self , ** kwargs ) -> dict : # noqa: D102
0 commit comments