|
| 1 | +# Copyright (C) 2023 - 2024 ANSYS, Inc. and/or its affiliates. |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | +# |
| 4 | +# |
| 5 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | +# of this software and associated documentation files (the "Software"), to deal |
| 7 | +# in the Software without restriction, including without limitation the rights |
| 8 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | +# copies of the Software, and to permit persons to whom the Software is |
| 10 | +# furnished to do so, subject to the following conditions: |
| 11 | +# |
| 12 | +# The above copyright notice and this permission notice shall be included in all |
| 13 | +# copies or substantial portions of the Software. |
| 14 | +# |
| 15 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | +# SOFTWARE. |
| 22 | +"""Provides tools for pulling geometry.""" |
| 23 | + |
| 24 | +from typing import TYPE_CHECKING, List, Union |
| 25 | + |
| 26 | +from ansys.api.geometry.v0.commands_pb2 import ChamferRequest |
| 27 | +from ansys.api.geometry.v0.commands_pb2_grpc import CommandsStub |
| 28 | +from ansys.geometry.core.connection import GrpcClient |
| 29 | +from ansys.geometry.core.errors import protect_grpc |
| 30 | +from ansys.geometry.core.misc.checks import min_backend_version |
| 31 | +from ansys.geometry.core.typing import Real |
| 32 | + |
| 33 | +if TYPE_CHECKING: # pragma: no cover |
| 34 | + from ansys.geometry.core.designer.edge import Edge |
| 35 | + from ansys.geometry.core.designer.face import Face |
| 36 | + |
| 37 | + |
| 38 | +class PullTools: |
| 39 | + """Pull tools for PyAnsys Geometry. |
| 40 | +
|
| 41 | + Parameters |
| 42 | + ---------- |
| 43 | + grpc_client : GrpcClient |
| 44 | + gRPC client to use for the measurement tools. |
| 45 | + """ |
| 46 | + |
| 47 | + @protect_grpc |
| 48 | + def __init__(self, grpc_client: GrpcClient): |
| 49 | + """Initialize pull tools class.""" |
| 50 | + self._grpc_client = grpc_client |
| 51 | + self._commands_stub = CommandsStub(self._grpc_client.channel) |
| 52 | + |
| 53 | + @protect_grpc |
| 54 | + @min_backend_version(25, 1, 0) |
| 55 | + def chamfer( |
| 56 | + self, selection: Union["Edge", List["Edge"], "Face", List["Face"]], distance: Real |
| 57 | + ) -> bool: |
| 58 | + """Create a chamfer on an edge, or adjust the chamfer of a face. |
| 59 | +
|
| 60 | + Parameters |
| 61 | + ---------- |
| 62 | + edges_or_faces : Edge | List[Edge] | Face | List[Face] |
| 63 | + Edge(s) or face(s) to act on. |
| 64 | + distance : Real |
| 65 | + Chamfer distance. |
| 66 | +
|
| 67 | + Returns |
| 68 | + ------- |
| 69 | + bool |
| 70 | + Success of chamfer command. |
| 71 | + """ |
| 72 | + selection = selection if isinstance(selection, list) else [selection] |
| 73 | + |
| 74 | + for ef in selection: |
| 75 | + ef.body._reset_tessellation_cache() |
| 76 | + |
| 77 | + result = self._commands_stub.Chamfer( |
| 78 | + ChamferRequest(ids=[ef.id for ef in selection], distance=distance) |
| 79 | + ) |
| 80 | + |
| 81 | + return result.success |
0 commit comments