Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/2303.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bool command implementation
32 changes: 13 additions & 19 deletions src/ansys/geometry/core/_grpc/_services/v0/bodies.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading