Skip to content

Commit 6af4805

Browse files
umutsoysalansyspyansys-ci-botRobPasMueMaxJPReypre-commit-ci[bot]
authored
feat: name setter and fill style getter setters (#1299)
Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: Roberto Pastor Muela <[email protected]> Co-authored-by: Maxime Rey <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent c6ae5c1 commit 6af4805

File tree

3 files changed

+136
-1
lines changed

3 files changed

+136
-1
lines changed

doc/changelog.d/1299.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
feat: name setter and fill style getter setters

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

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
RotateRequest,
3636
ScaleRequest,
3737
SetAssignedMaterialRequest,
38+
SetFillStyleRequest,
39+
SetNameRequest,
3840
TranslateRequest,
3941
)
4042
from ansys.api.geometry.v0.bodies_pb2_grpc import BodiesStub
@@ -105,6 +107,15 @@ class CollisionType(Enum):
105107
CONTAINEDTOUCH = 4
106108

107109

110+
@unique
111+
class FillStyle(Enum):
112+
"""Provides values for fill styles supported."""
113+
114+
DEFAULT = 0
115+
OPAQUE = 1
116+
TRANSPARENT = 2
117+
118+
108119
class IBody(ABC):
109120
"""Defines the common methods for a body, providing the abstract body interface.
110121
@@ -122,6 +133,21 @@ def name(self) -> str:
122133
"""Get the name of the body."""
123134
return
124135

136+
@abstractmethod
137+
def set_name(self, str) -> None:
138+
"""Set the name of the body."""
139+
return
140+
141+
@abstractmethod
142+
def fill_style(self) -> FillStyle:
143+
"""Get the fill style of the body."""
144+
return
145+
146+
@abstractmethod
147+
def set_fill_style(self, fill_style: FillStyle) -> None:
148+
"""Set the fill style of the body."""
149+
return
150+
125151
@abstractmethod
126152
def faces(self) -> List[Face]:
127153
"""Get a list of all faces within the body.
@@ -659,6 +685,7 @@ def __init__(
659685
self._bodies_stub = BodiesStub(self._grpc_client.channel)
660686
self._commands_stub = CommandsStub(self._grpc_client.channel)
661687
self._tessellation = None
688+
self._fill_style = FillStyle.DEFAULT
662689

663690
def reset_tessellation_cache(func): # noqa: N805
664691
"""Decorate ``MasterBody`` methods that need tessellation cache update.
@@ -694,6 +721,18 @@ def id(self) -> str: # noqa: D102
694721
def name(self) -> str: # noqa: D102
695722
return self._name
696723

724+
@name.setter
725+
def name(self, value: str): # noqa: D102
726+
self.set_name(value)
727+
728+
@property
729+
def fill_style(self) -> str: # noqa: D102
730+
return self._fill_style
731+
732+
@fill_style.setter
733+
def fill_style(self, value: FillStyle): # noqa: D102
734+
self.set_fill_style(value)
735+
697736
@property
698737
def is_surface(self) -> bool: # noqa: D102
699738
return self._is_surface
@@ -856,6 +895,36 @@ def translate( # noqa: D102
856895
)
857896
)
858897

898+
@protect_grpc
899+
@check_input_types
900+
@min_backend_version(25, 1, 0)
901+
def set_name( # noqa: D102
902+
self, name: str
903+
) -> None:
904+
self._grpc_client.log.debug(f"Renaming body {self.id} from '{self.name}' to '{name}'.")
905+
self._bodies_stub.SetName(
906+
SetNameRequest(
907+
body_id=self.id,
908+
name=name,
909+
)
910+
)
911+
self._name = name
912+
913+
@protect_grpc
914+
@check_input_types
915+
@min_backend_version(25, 1, 0)
916+
def set_fill_style( # noqa: D102
917+
self, fill_style: FillStyle
918+
) -> None:
919+
self._grpc_client.log.debug(f"Setting body fill style {self.id}.")
920+
self._bodies_stub.SetFillStyle(
921+
SetFillStyleRequest(
922+
body_id=self.id,
923+
fill_style=fill_style.value,
924+
)
925+
)
926+
self._fill_style = fill_style
927+
859928
@protect_grpc
860929
@check_input_types
861930
@reset_tessellation_cache
@@ -1058,6 +1127,18 @@ def id(self) -> str: # noqa: D102
10581127
def name(self) -> str: # noqa: D102
10591128
return self._template.name
10601129

1130+
@name.setter
1131+
def name(self, value: str): # noqa: D102
1132+
self._template.name = value
1133+
1134+
@property
1135+
def fill_style(self) -> str: # noqa: D102
1136+
return self._template.fill_style
1137+
1138+
@fill_style.setter
1139+
def fill_style(self, fill_style: FillStyle) -> str: # noqa: D102
1140+
self._template.fill_style = fill_style
1141+
10611142
@property
10621143
def parent_component(self) -> "Component": # noqa: D102
10631144
return self._parent_component
@@ -1277,6 +1358,14 @@ def imprint_projected_curves( # noqa: D102
12771358

12781359
return imprinted_faces
12791360

1361+
@ensure_design_is_active
1362+
def set_name(self, name: str) -> None: # noqa: D102
1363+
return self._template.set_name(name)
1364+
1365+
@ensure_design_is_active
1366+
def set_fill_style(self, fill_style: FillStyle) -> None: # noqa: D102
1367+
return self._template.set_fill_style(fill_style)
1368+
12801369
@ensure_design_is_active
12811370
def translate( # noqa: D102
12821371
self, direction: UnitVector3D, distance: Union[Quantity, Distance, Real]

tests/integration/test_design.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
SharedTopologyType,
3939
SurfaceType,
4040
)
41-
from ansys.geometry.core.designer.body import CollisionType
41+
from ansys.geometry.core.designer.body import CollisionType, FillStyle
4242
from ansys.geometry.core.designer.face import FaceLoopType
4343
from ansys.geometry.core.errors import GeometryExitedError
4444
from ansys.geometry.core.materials import Material, MaterialProperty, MaterialPropertyType
@@ -1964,6 +1964,51 @@ def test_get_collision(modeler: Modeler):
19641964
assert body2.get_collision(body3) == CollisionType.NONE
19651965

19661966

1967+
def test_set_body_name(modeler: Modeler):
1968+
"""Test the setting the name of a body."""
1969+
skip_if_linux(modeler, test_set_body_name.__name__, "set_name") # Skip test on Linux
1970+
1971+
design = modeler.create_design("simple_cube")
1972+
unit = DEFAULT_UNITS.LENGTH
1973+
plane = Plane(
1974+
Point3D([1 / 2, 1 / 2, 0.0], unit=unit),
1975+
UNITVECTOR3D_X,
1976+
UNITVECTOR3D_Y,
1977+
)
1978+
box_plane = Sketch(plane)
1979+
box_plane.box(Point2D([0.0, 0.0]), width=1 * unit, height=1 * unit)
1980+
box = design.extrude_sketch("first_name", box_plane, 1 * unit)
1981+
assert box.name == "first_name"
1982+
box.set_name("updated_name")
1983+
assert box.name == "updated_name"
1984+
box.name = "updated_name2"
1985+
assert box.name == "updated_name2"
1986+
1987+
1988+
def test_set_fill_style(modeler: Modeler):
1989+
"""Test the setting the fill style of a body."""
1990+
skip_if_linux(modeler, test_set_fill_style.__name__, "set_fill_style") # Skip test on Linux
1991+
1992+
design = modeler.create_design("RVE")
1993+
unit = DEFAULT_UNITS.LENGTH
1994+
1995+
plane = Plane(
1996+
Point3D([1 / 2, 1 / 2, 0.0], unit=unit),
1997+
UNITVECTOR3D_X,
1998+
UNITVECTOR3D_Y,
1999+
)
2000+
2001+
box_plane = Sketch(plane)
2002+
box_plane.box(Point2D([0.0, 0.0]), width=1 * unit, height=1 * unit)
2003+
box = design.extrude_sketch("Matrix", box_plane, 1 * unit)
2004+
2005+
assert box.fill_style == FillStyle.DEFAULT
2006+
box.set_fill_style(FillStyle.TRANSPARENT)
2007+
assert box.fill_style == FillStyle.TRANSPARENT
2008+
box.fill_style = FillStyle.OPAQUE
2009+
assert box.fill_style == FillStyle.OPAQUE
2010+
2011+
19672012
def test_body_scale(modeler: Modeler):
19682013
"""Verify the correct scaling of a body."""
19692014
design = modeler.create_design("BodyScale_Test")

0 commit comments

Comments
 (0)