diff --git a/doc/changelog.d/2303.fixed.md b/doc/changelog.d/2303.fixed.md new file mode 100644 index 0000000000..8a6dabb134 --- /dev/null +++ b/doc/changelog.d/2303.fixed.md @@ -0,0 +1 @@ +Bool command implementation diff --git a/src/ansys/geometry/core/_grpc/_services/v0/bodies.py b/src/ansys/geometry/core/_grpc/_services/v0/bodies.py index 57089dd118..aff774db48 100644 --- a/src/ansys/geometry/core/_grpc/_services/v0/bodies.py +++ b/src/ansys/geometry/core/_grpc/_services/v0/bodies.py @@ -783,58 +783,52 @@ def boolean(self, **kwargs) -> dict: # noqa: D102 @protect_grpc def combine(self, **kwargs) -> dict: # noqa: D102 - from ansys.api.geometry.v0.bodies_pb2 import ( + from ansys.api.geometry.v0.commands_pb2 import ( CombineIntersectBodiesRequest, CombineMergeBodiesRequest, ) + target_body = kwargs["target"] other_bodies = kwargs["other"] type_bool_op = kwargs["type_bool_op"] keep_other = kwargs["keep_other"] if type_bool_op == "intersect": - body_ids = [body._grpc_id for body in other_bodies] - target_ids = [self._grpc_id] + body_ids = [build_grpc_id(body.id) for body in other_bodies] + target_ids = [build_grpc_id(target_body.id)] request = CombineIntersectBodiesRequest( target_selection=target_ids, tool_selection=body_ids, subtract_from_target=False, keep_cutter=keep_other, ) - response = self._template._commands_stub.CombineIntersectBodies(request) + response = self.command_stub.CombineIntersectBodies(request) elif type_bool_op == "subtract": - body_ids = [body._grpc_id for body in other_bodies] - target_ids = [self._grpc_id] + body_ids = [build_grpc_id(body.id) for body in other_bodies] + target_ids = [build_grpc_id(target_body.id)] request = CombineIntersectBodiesRequest( target_selection=target_ids, tool_selection=body_ids, subtract_from_target=True, keep_cutter=keep_other, ) - response = self._template._commands_stub.CombineIntersectBodies(request) + response = self.command_stub.CombineIntersectBodies(request) elif type_bool_op == "unite": - bodies = [self] + bodies = [target_body] bodies.extend(other_bodies) - body_ids = [body._grpc_id for body in bodies] + body_ids = [build_grpc_id(body.id) for body in bodies] request = CombineMergeBodiesRequest(target_selection=body_ids) - response = self._template._commands_stub.CombineMergeBodies(request) + response = self.command_stub.CombineMergeBodies(request) else: raise ValueError("Unknown operation requested") if not response.success: raise ValueError( f"Operation of type '{type_bool_op}' failed: {kwargs['err_msg']}.\n" - f"Involving bodies:{self}, {other_bodies}" + f"Involving bodies:{target_body}, {other_bodies}" ) - if not keep_other: - for b in other_bodies: - b.parent_component.delete_body(b) - - tracker_response = response.result.complete_command_response - serialized_tracker_response = serialize_tracker_command_response(response=tracker_response) - # Return the response - formatted as a dictionary - return {"complete_command_response": serialized_tracker_response} + return {"complete_command_response": serialize_tracker_command_response(response=response)} @protect_grpc def split_body(self, **kwargs) -> dict: # noqa: D102