|
55 | 55 | CombineMergeBodiesRequest, |
56 | 56 | ImprintCurvesRequest, |
57 | 57 | ProjectCurvesRequest, |
| 58 | + RemoveFacesRequest, |
| 59 | + ShellRequest, |
58 | 60 | ) |
59 | 61 | from ansys.api.geometry.v0.commands_pb2_grpc import CommandsStub |
60 | 62 | from ansys.geometry.core.connection.client import GrpcClient |
61 | 63 | from ansys.geometry.core.connection.conversions import ( |
62 | 64 | frame_to_grpc_frame, |
| 65 | + grpc_material_to_material, |
63 | 66 | plane_to_grpc_plane, |
64 | 67 | point3d_to_grpc_point, |
65 | 68 | sketch_shapes_to_grpc_geometries, |
|
79 | 82 | from ansys.geometry.core.misc.auxiliary import get_design_from_body |
80 | 83 | from ansys.geometry.core.misc.checks import ( |
81 | 84 | check_type, |
| 85 | + check_type_all_elements_in_iterable, |
82 | 86 | ensure_design_is_active, |
83 | 87 | min_backend_version, |
84 | 88 | ) |
@@ -254,6 +258,17 @@ def assign_material(self, material: Material) -> None: |
254 | 258 | """ |
255 | 259 | return |
256 | 260 |
|
| 261 | + @abstractmethod |
| 262 | + def get_assigned_material(self) -> Material: |
| 263 | + """Get the assigned material of the body. |
| 264 | +
|
| 265 | + Returns |
| 266 | + ------- |
| 267 | + Material |
| 268 | + Material assigned to the body. |
| 269 | + """ |
| 270 | + return |
| 271 | + |
257 | 272 | @abstractmethod |
258 | 273 | def add_midsurface_thickness(self, thickness: Quantity) -> None: |
259 | 274 | """Add a mid-surface thickness to a surface body. |
@@ -555,6 +570,39 @@ def tessellate(self, merge: bool = False) -> Union["PolyData", "MultiBlock"]: |
555 | 570 | """ |
556 | 571 | return |
557 | 572 |
|
| 573 | + @abstractmethod |
| 574 | + def shell_body(self, offset: Real) -> bool: |
| 575 | + """Shell the body to the thickness specified. |
| 576 | +
|
| 577 | + Parameters |
| 578 | + ---------- |
| 579 | + offset : Real |
| 580 | + Shell thickness. |
| 581 | +
|
| 582 | + Returns |
| 583 | + ------- |
| 584 | + bool |
| 585 | + ``True`` when successful, ``False`` when failed. |
| 586 | + """ |
| 587 | + return |
| 588 | + |
| 589 | + @abstractmethod |
| 590 | + def remove_faces(self, selection: Union["Face", list["Face"]], offset: Real) -> bool: |
| 591 | + """Shell by removing a given set of faces. |
| 592 | +
|
| 593 | + Parameters |
| 594 | + ---------- |
| 595 | + selection : Face | List[Face] |
| 596 | + Face or faces to be removed. |
| 597 | + offset : Real |
| 598 | + Shell thickness. |
| 599 | +
|
| 600 | + Returns |
| 601 | + ------- |
| 602 | + bool |
| 603 | + ``True`` when successful, ``False`` when failed. |
| 604 | + """ |
| 605 | + |
558 | 606 | @abstractmethod |
559 | 607 | def plot( |
560 | 608 | self, |
@@ -871,6 +919,13 @@ def assign_material(self, material: Material) -> None: # noqa: D102 |
871 | 919 | SetAssignedMaterialRequest(id=self._id, material=material.name) |
872 | 920 | ) |
873 | 921 |
|
| 922 | + @property |
| 923 | + @protect_grpc |
| 924 | + def get_assigned_material(self) -> Material: # noqa: D102 |
| 925 | + self._grpc_client.log.debug(f"Retrieving assigned material for body {self.id}.") |
| 926 | + material_response = self._bodies_stub.GetAssignedMaterial(self._grpc_id) |
| 927 | + return grpc_material_to_material(material_response) |
| 928 | + |
874 | 929 | @protect_grpc |
875 | 930 | @check_input_types |
876 | 931 | def add_midsurface_thickness(self, thickness: Quantity) -> None: # noqa: D102 |
@@ -1161,6 +1216,43 @@ def tessellate( # noqa: D102 |
1161 | 1216 | else: |
1162 | 1217 | return comp |
1163 | 1218 |
|
| 1219 | + @protect_grpc |
| 1220 | + @check_input_types |
| 1221 | + def shell_body(self, offset: Real) -> bool: # noqa: D102 |
| 1222 | + self._grpc_client.log.debug(f"Shelling body {self.id} to offset {offset}.") |
| 1223 | + |
| 1224 | + result = self._commands_stub.Shell( |
| 1225 | + ShellRequest( |
| 1226 | + selection=self._grpc_id, |
| 1227 | + offset=offset, |
| 1228 | + ) |
| 1229 | + ) |
| 1230 | + |
| 1231 | + return result.success |
| 1232 | + |
| 1233 | + @protect_grpc |
| 1234 | + @reset_tessellation_cache |
| 1235 | + @check_input_types |
| 1236 | + def remove_faces(self, selection: Union["Face", list["Face"]], offset: Real) -> bool: # noqa: D102 |
| 1237 | + selection: list[Face] = selection if isinstance(selection, list) else [selection] |
| 1238 | + check_type_all_elements_in_iterable(selection, Face) |
| 1239 | + |
| 1240 | + # check if faces belong to this body |
| 1241 | + for face in selection: |
| 1242 | + if face.body.id != self.id: |
| 1243 | + raise ValueError(f"Face {face.id} does not belong to body {self.id}.") |
| 1244 | + |
| 1245 | + self._grpc_client.log.debug(f"Removing faces to shell body {self.id}.") |
| 1246 | + |
| 1247 | + result = self._commands_stub.RemoveFaces( |
| 1248 | + RemoveFacesRequest( |
| 1249 | + selection=[face._grpc_id for face in selection], |
| 1250 | + offset=offset, |
| 1251 | + ) |
| 1252 | + ) |
| 1253 | + |
| 1254 | + return result.success |
| 1255 | + |
1164 | 1256 | def plot( # noqa: D102 |
1165 | 1257 | self, |
1166 | 1258 | merge: bool = True, |
@@ -1389,6 +1481,11 @@ def volume(self) -> Quantity: # noqa: D102 |
1389 | 1481 | def assign_material(self, material: Material) -> None: # noqa: D102 |
1390 | 1482 | self._template.assign_material(material) |
1391 | 1483 |
|
| 1484 | + @property |
| 1485 | + @ensure_design_is_active |
| 1486 | + def get_assigned_material(self) -> Material: # noqa: D102 |
| 1487 | + return self._template.get_assigned_material |
| 1488 | + |
1392 | 1489 | @ensure_design_is_active |
1393 | 1490 | def add_midsurface_thickness(self, thickness: Quantity) -> None: # noqa: D102 |
1394 | 1491 | self._template.add_midsurface_thickness(thickness) |
@@ -1578,6 +1675,14 @@ def tessellate( # noqa: D102 |
1578 | 1675 | ) -> Union["PolyData", "MultiBlock"]: |
1579 | 1676 | return self._template.tessellate(merge, self.parent_component.get_world_transform()) |
1580 | 1677 |
|
| 1678 | + @ensure_design_is_active |
| 1679 | + def shell_body(self, offset: Real) -> bool: # noqa: D102 |
| 1680 | + return self._template.shell_body(offset) |
| 1681 | + |
| 1682 | + @ensure_design_is_active |
| 1683 | + def remove_faces(self, selection: Union["Face", list["Face"]], offset: Real) -> bool: # noqa: D102 |
| 1684 | + return self._template.remove_faces(selection, offset) |
| 1685 | + |
1581 | 1686 | def plot( # noqa: D102 |
1582 | 1687 | self, |
1583 | 1688 | merge: bool = True, |
|
0 commit comments