Skip to content

Commit d51b182

Browse files
wip - core design code in place
1 parent 3972eff commit d51b182

File tree

1 file changed

+56
-3
lines changed

1 file changed

+56
-3
lines changed

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

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
from enum import Enum, unique
2525
from pathlib import Path
26-
from typing import Union
26+
from typing import TYPE_CHECKING, Union
2727

2828
from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier
2929
from ansys.api.geometry.v0.commands_pb2 import (
@@ -71,15 +71,22 @@
7171
from ansys.geometry.core.math.plane import Plane
7272
from ansys.geometry.core.math.point import Point3D
7373
from ansys.geometry.core.math.vector import UnitVector3D, Vector3D
74-
from ansys.geometry.core.misc.checks import ensure_design_is_active, min_backend_version
74+
from ansys.geometry.core.misc.checks import (
75+
ensure_design_is_active,
76+
graphics_required,
77+
min_backend_version,
78+
)
7579
from ansys.geometry.core.misc.measurements import DEFAULT_UNITS, Distance
76-
from ansys.geometry.core.misc.options import ImportOptions
80+
from ansys.geometry.core.misc.options import ImportOptions, TessellationOptions
7781
from ansys.geometry.core.modeler import Modeler
7882
from ansys.geometry.core.parameters.parameter import Parameter, ParameterUpdateStatus
7983
from ansys.geometry.core.shapes.curves.trimmed_curve import TrimmedCurve
8084
from ansys.geometry.core.shapes.parameterization import Interval, ParamUV
8185
from ansys.geometry.core.typing import RealSequence
8286

87+
if TYPE_CHECKING: # pragma: no cover
88+
from pyvista import MultiBlock, PolyData
89+
8390

8491
@unique
8592
class DesignFileFormat(Enum):
@@ -139,6 +146,7 @@ def __init__(self, name: str, modeler: Modeler, read_existing_design: bool = Fal
139146
self._design_id = ""
140147
self._is_active = False
141148
self._modeler = modeler
149+
self._tessellation = None
142150

143151
# Check whether we want to process an existing design or create a new one.
144152
if read_existing_design:
@@ -1028,6 +1036,51 @@ def insert_file(
10281036

10291037
# Return the newly inserted component
10301038
return self._components[-1]
1039+
1040+
@min_backend_version(26, 1, 0)
1041+
@check_input_types
1042+
@graphics_required
1043+
def tessellate(
1044+
self, merge: bool = False, tess_options: TessellationOptions | None = None
1045+
) -> Union["PolyData", "MultiBlock"]:
1046+
"""Tessellate the entire design and return the geometry as triangles.
1047+
1048+
Parameters
1049+
----------
1050+
merge : bool, default: False
1051+
Whether to merge all bodies into a single mesh.
1052+
tess_options : TessellationOptions, optional
1053+
Options for the tessellation. If None, default options are used.
1054+
1055+
Returns
1056+
-------
1057+
~pyvista.PolyData | ~pyvista.MultiBlock
1058+
The tessellated mesh. If `merge` is True, a single PolyData is returned.
1059+
Otherwise, a MultiBlock is returned with each block corresponding to a body.
1060+
"""
1061+
import pyvista as pv
1062+
1063+
if not self.is_alive:
1064+
return pv.PolyData() if merge else pv.MultiBlock()
1065+
1066+
self._grpc_client.log.debug(f"Requesting tessellation for body {self.id}.")
1067+
1068+
# cache tessellation
1069+
if not self._tessellation:
1070+
response = self._grpc_client.services.designs.stream_design_tessellation(
1071+
options=tess_options,
1072+
)
1073+
1074+
self._tessellation = response.get("tessellation")
1075+
1076+
pdata = [tess for tess in self._tessellation.values()]
1077+
comp = pv.MultiBlock(pdata)
1078+
1079+
if merge:
1080+
ugrid = comp.combine()
1081+
return pv.PolyData(var_inp=ugrid.points, faces=ugrid.cells)
1082+
else:
1083+
return comp
10311084

10321085
def __repr__(self) -> str:
10331086
"""Represent the ``Design`` as a string."""

0 commit comments

Comments
 (0)