Skip to content

Commit ffd4df2

Browse files
committed
Merge branch 'feat/chamfer' into feat/fillet
2 parents 150c19b + c00e7be commit ffd4df2

File tree

11 files changed

+228
-1
lines changed

11 files changed

+228
-1
lines changed

doc/changelog.d/1495.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
add chamfer tool
47.6 KB
Loading

doc/source/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ def intersphinx_pyansys_geometry(switcher_version: str):
293293
"examples/03_modeling/design_tree": "_static/thumbnails/design_tree.png",
294294
"examples/03_modeling/service_colors": "_static/thumbnails/service_colors.png",
295295
"examples/03_modeling/surface_bodies": "_static/thumbnails/quarter_sphere.png",
296+
"examples/03_modeling/chamfer": "_static/thumbnails/chamfer.png",
296297
"examples/04_applied/01_naca_airfoils": "_static/thumbnails/naca_airfoils.png",
297298
"examples/04_applied/02_naca_fluent": "_static/thumbnails/naca_fluent.png",
298299
}

doc/source/examples.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ These examples demonstrate service-based modeling operations.
4848
examples/03_modeling/design_tree.mystnb
4949
examples/03_modeling/service_colors.mystnb
5050
examples/03_modeling/surface_bodies.mystnb
51+
examples/03_modeling/chamfer.mystnb
5152

5253
Applied examples
5354
----------------
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
---
2+
jupytext:
3+
text_representation:
4+
extension: .mystnb
5+
format_name: myst
6+
format_version: 0.13
7+
jupytext_version: 1.16.4
8+
kernelspec:
9+
display_name: Python 3 (ipykernel)
10+
language: python
11+
name: python3
12+
---
13+
14+
# Modeling: Chamfer edges and faces
15+
A chamfer is an angled cut on an edge. Chamfers can be created through the `Modeler.pull_tools` module.
16+
17+
+++
18+
19+
## Create a block
20+
Launch the modeler and create a block.
21+
22+
```{code-cell} ipython3
23+
from ansys.geometry.core import launch_modeler, Modeler
24+
25+
modeler = Modeler()
26+
print(modeler)
27+
```
28+
29+
```{code-cell} ipython3
30+
from ansys.geometry.core.sketch import Sketch
31+
from ansys.geometry.core.math import Point2D
32+
33+
design = modeler.create_design("chamfer_block")
34+
body = design.extrude_sketch("block", Sketch().box(Point2D([0, 0]), 1, 1), 1)
35+
36+
body.plot()
37+
```
38+
39+
## Chamfer edges
40+
Create a uniform chamfer on all edges of the block.
41+
42+
```{code-cell} ipython3
43+
modeler.pull_tools.chamfer(body.edges, distance=0.1)
44+
45+
body.plot()
46+
```
47+
48+
## Chamfer faces
49+
The chamfer of a face can also be modified. Create a chamfer on a single edge, then modify the chamfer distance value by providing the newly created face that represents the chamfer.
50+
51+
```{code-cell} ipython3
52+
body = design.extrude_sketch("box", Sketch().box(Point2D([0,0]), 1, 1), 1)
53+
54+
modeler.pull_tools.chamfer(body.edges[0], distance=0.1)
55+
56+
body.plot()
57+
```
58+
59+
```{code-cell} ipython3
60+
modeler.pull_tools.chamfer(body.faces[-1], distance=0.3)
61+
62+
body.plot()
63+
```

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1206,11 +1206,15 @@ def reset_tessellation_cache(func): # noqa: N805
12061206

12071207
@wraps(func)
12081208
def wrapper(self: "Body", *args, **kwargs):
1209-
self._template._tessellation = None
1209+
self._reset_tessellation_cache()
12101210
return func(self, *args, **kwargs)
12111211

12121212
return wrapper
12131213

1214+
def _reset_tessellation_cache(self): # noqa: N805
1215+
"""Reset the cached tessellation for a body."""
1216+
self._template._tessellation = None
1217+
12141218
@property
12151219
def id(self) -> str: # noqa: D102
12161220
return self._id

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ def _grpc_id(self) -> EntityIdentifier:
100100
"""Entity ID of this edge on the server side."""
101101
return EntityIdentifier(id=self._id)
102102

103+
@property
104+
def body(self) -> "Body":
105+
"""Body of the edge."""
106+
return self._body
107+
103108
@property
104109
def is_reversed(self) -> bool:
105110
"""Flag indicating if the edge is reversed."""

src/ansys/geometry/core/modeler.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
from ansys.geometry.core.misc.options import ImportOptions
4343
from ansys.geometry.core.tools.measurement_tools import MeasurementTools
4444
from ansys.geometry.core.tools.prepare_tools import PrepareTools
45+
from ansys.geometry.core.tools.pull_tools import PullTools
4546
from ansys.geometry.core.tools.repair_tools import RepairTools
4647
from ansys.geometry.core.typing import Real
4748

@@ -128,6 +129,7 @@ def __init__(
128129
self._repair_tools = RepairTools(self._grpc_client)
129130
self._prepare_tools = PrepareTools(self._grpc_client)
130131
self._measurement_tools = MeasurementTools(self._grpc_client)
132+
self._pull_tools = PullTools(self._grpc_client)
131133

132134
# Maintaining references to all designs within the modeler workspace
133135
self._designs: dict[str, "Design"] = {}
@@ -497,3 +499,8 @@ def prepare_tools(self) -> PrepareTools:
497499
def measurement_tools(self) -> MeasurementTools:
498500
"""Access to measurement tools."""
499501
return self._measurement_tools
502+
503+
@property
504+
def pull_tools(self) -> PullTools:
505+
"""Access to pull tools."""
506+
return self._pull_tools

src/ansys/geometry/core/tools/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@
2828
ExtraEdgeProblemAreas,
2929
InexactEdgeProblemAreas,
3030
)
31+
from ansys.geometry.core.tools.pull_tools import PullTools
3132
from ansys.geometry.core.tools.repair_tool_message import RepairToolMessage
3233
from ansys.geometry.core.tools.repair_tools import RepairTools
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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

Comments
 (0)