Skip to content

Commit 4124aa6

Browse files
changed stitch to combine_merge to utilize already in place server method
1 parent 4da5441 commit 4124aa6

File tree

5 files changed

+38
-54
lines changed

5 files changed

+38
-54
lines changed

src/ansys/geometry/core/_grpc/_services/base/bodies.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,6 @@ def create_body_from_loft_profiles_with_guides(self, **kwargs) -> dict:
233233
pass
234234

235235
@abstractmethod
236-
def stitch(self, **kwargs) -> dict:
237-
"""Stitch bodies."""
236+
def combine_merge(self, **kwargs) -> dict:
237+
"""Combine and merge bodies."""
238238
pass

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -892,24 +892,16 @@ def create_body_from_loft_profiles_with_guides(self, **kwargs) -> dict: # noqa:
892892
}
893893

894894
@protect_grpc
895-
def stitch(self, **kwargs) -> dict: # noqa: D102
896-
from ansys.api.geometry.v0.bodies_pb2 import StitchRequest, StitchRequestData
895+
def combine_merge(self, **kwargs) -> dict: # noqa: D102
896+
from ansys.api.geometry.v0.commands_pb2 import CombineMergeBodiesRequest
897897

898898
# Create the request - assumes all inputs are valid and of the proper type
899-
request = StitchRequest(
900-
StitchRequestData(
901-
ids=kwargs["body_ids"],
902-
tolerance=from_measurement_to_server_length(kwargs["tolerance"]),
903-
)
899+
request = CombineMergeBodiesRequest(
900+
target_selection=[build_grpc_id(id) for id in kwargs["body_ids"]],
904901
)
905902

906903
# Call the gRPC service
907-
resp = self.stub.Stitch(request=request)
904+
_ = self.command_stub.CombineMergeBodies(request=request)
908905

909906
# Return the response - formatted as a dictionary
910-
return {
911-
"id": resp.id,
912-
"name": resp.name,
913-
"master_id": resp.master_id,
914-
"is_surface": resp.is_surface,
915-
}
907+
return {}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,7 @@ def split_body(self, **kwargs) -> dict: # noqa: D102
203203
@protect_grpc
204204
def create_body_from_loft_profiles_with_guides(self, **kwargs) -> dict: # noqa: D102
205205
raise NotImplementedError
206+
207+
@protect_grpc
208+
def combine_merge(self, **kwargs) -> dict: # noqa: D102
209+
raise NotImplementedError

src/ansys/geometry/core/designer/body.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,16 @@ def unite(self, other: Union["Body", Iterable["Body"]], keep_other: bool = False
818818
the united body is retained.
819819
"""
820820
return
821+
822+
def combine_merge(self, other: Union["Body", list["Body"]]) -> None:
823+
"""Combine this body with another body or bodies, merging them into a single body.
824+
825+
Parameters
826+
----------
827+
other : Union[Body, list[Body]]
828+
The body or list of bodies to combine with this body.
829+
"""
830+
return
821831

822832

823833
class MasterBody(IBody):
@@ -1359,6 +1369,17 @@ def remove_faces(self, selection: Face | Iterable[Face], offset: Real) -> bool:
13591369
self._grpc_client.log.warning(f"Failed to remove faces from body {self.id}.")
13601370

13611371
return result.success
1372+
1373+
@min_backend_version(25, 2, 0)
1374+
@check_input_types
1375+
def combine_merge(self, other: Union["Body", list["Body"]]) -> None: # noqa: D102
1376+
other = other if isinstance(other, list) else [other]
1377+
check_type_all_elements_in_iterable(other, Body)
1378+
1379+
self._grpc_client.log.debug(f"Combining and merging to body {self.id}.")
1380+
self._grpc_client.services.bodies.combine_merge(
1381+
body_ids=[self.id] + [body.id for body in other]
1382+
)
13621383

13631384
def plot( # noqa: D102
13641385
self,
@@ -1386,7 +1407,7 @@ def unite(self, other: Union["Body", Iterable["Body"]], keep_other: bool = False
13861407
raise NotImplementedError(
13871408
"MasterBody does not implement Boolean methods. Call this method on a body instead."
13881409
)
1389-
1410+
13901411
def __repr__(self) -> str:
13911412
"""Represent the master body as a string."""
13921413
lines = [f"ansys.geometry.core.designer.MasterBody {hex(id(self))}"]
@@ -1903,6 +1924,9 @@ def unite(self, other: Union["Body", Iterable["Body"]], keep_other: bool = False
19031924
else:
19041925
self.__generic_boolean_command(other, False, "unite", "union operation failed")
19051926

1927+
def combine_merge(self, other: Union["Body", list["Body"]]) -> None: # noqa: D102
1928+
self._template.combine_merge(other)
1929+
19061930
@reset_tessellation_cache
19071931
@ensure_design_is_active
19081932
@check_input_types

src/ansys/geometry/core/designer/geometry_commands.py

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,40 +1832,4 @@ def revolve_edges(
18321832
)
18331833

18341834
design = get_design_from_edge(edges[0])
1835-
design._update_design_inplace()
1836-
1837-
@min_backend_version(26, 1, 0)
1838-
def stitch_bodies(self, bodies: list["Body"], tolerance: Distance | Quantity | Real) -> bool:
1839-
"""Stitch bodies together.
1840-
1841-
Parameters
1842-
----------
1843-
bodies : list[Body]
1844-
Bodies to stitch.
1845-
tolerance : Distance | Quantity | Real
1846-
Tolerance to use when stitching bodies. Default units are meters.
1847-
1848-
Returns
1849-
-------
1850-
bool
1851-
``True`` when successful, ``False`` when failed.
1852-
"""
1853-
from ansys.geometry.core.designer.body import Body
1854-
1855-
check_type_all_elements_in_iterable(bodies, Body)
1856-
1857-
for body in bodies:
1858-
body._reset_tessellation_cache()
1859-
1860-
tolerance = tolerance if isinstance(tolerance, Distance) else Distance(tolerance)
1861-
1862-
result = self._grpc_client._services.bodies.stitch(
1863-
body_ids=[body.id for body in bodies],
1864-
tolerance=tolerance,
1865-
)
1866-
1867-
if result.get("success"):
1868-
design = get_design_from_body(bodies[0])
1869-
design._update_design_inplace()
1870-
1871-
return result.get("success")
1835+
design._update_design_inplace()

0 commit comments

Comments
 (0)