Skip to content

Commit f5c5581

Browse files
added design point and components get_named_selections functions
1 parent cba074d commit f5c5581

File tree

3 files changed

+90
-1
lines changed

3 files changed

+90
-1
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
if TYPE_CHECKING: # pragma: no cover
6868
from pyvista import MultiBlock, PolyData
6969

70+
from ansys.geometry.core.designer.selection import NamedSelection
71+
7072

7173
@unique
7274
class SharedTopologyType(Enum):
@@ -1980,3 +1982,20 @@ def make_independent(self, others: list["Component"] = None) -> None:
19801982
"""
19811983
ids = [self.id, *[o.id for o in others or []]]
19821984
self._grpc_client._services.components.make_independent(ids=ids)
1985+
1986+
def get_named_selections(self) -> list["NamedSelection"]:
1987+
"""Get the named selections of the component.
1988+
1989+
Returns
1990+
-------
1991+
list[NamedSelection]
1992+
List of named selections belonging to the component.
1993+
"""
1994+
named_selections = get_design_from_component(self).named_selections
1995+
1996+
included_ns = []
1997+
for ns in named_selections:
1998+
if self in ns.components:
1999+
included_ns.append(ns)
2000+
2001+
return included_ns

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@
2424
from typing import TYPE_CHECKING, Union
2525

2626
from ansys.geometry.core.math.point import Point3D
27+
from ansys.geometry.core.misc.auxiliary import get_design_from_component
2728
from ansys.geometry.core.misc.checks import graphics_required
2829
from ansys.geometry.core.misc.units import UNITS
2930

3031
if TYPE_CHECKING: # pragma: no cover
3132
import pyvista as pv
3233

3334
from ansys.geometry.core.designer.component import Component
35+
from ansys.geometry.core.designer.selection import NamedSelection
3436

3537

3638
class DesignPoint:
@@ -77,6 +79,26 @@ def value(self) -> Point3D:
7779
def parent_component(self) -> "Component":
7880
"""Component node that the design point is under."""
7981
return self._parent_component
82+
83+
def get_named_selections(self) -> list["NamedSelection"]:
84+
"""Get named selections that contain this design point.
85+
86+
Returns
87+
-------
88+
list[NamedSelection]
89+
List of named selections that contain this design point.
90+
"""
91+
if self.parent_component is None:
92+
raise ValueError("Design point does not have a parent component.")
93+
94+
named_selections = get_design_from_component(self.parent_component).named_selections
95+
96+
included_ns = []
97+
for ns in named_selections:
98+
if self.id in [dp.id for dp in ns.design_points]:
99+
included_ns.append(ns)
100+
101+
return included_ns
80102

81103
def __repr__(self) -> str:
82104
"""Represent the design points as a string."""

tests/integration/test_design.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4192,4 +4192,52 @@ def test_vertices_get_named_selections(modeler: Modeler):
41924192
assert len(ns_list) == 2
41934193
assert any(ns.name == "vertex_ns_3" for ns in ns_list)
41944194
else:
4195-
assert len(ns_list) == 0 # No named selection for this vertex
4195+
assert len(ns_list) == 0 # No named selection for this vertex
4196+
4197+
4198+
def test_components_get_named_selections(modeler: Modeler):
4199+
# Test getting named selections associated with components
4200+
design = modeler.create_design("component_named_selections")
4201+
comp1 = design.add_component("Component1")
4202+
comp2 = design.add_component("Component2")
4203+
comp3 = design.add_component("Component3")
4204+
4205+
# create named selection from components
4206+
design.create_named_selection("component_ns_1", components=[comp1])
4207+
design.create_named_selection("component_ns_2", components=[comp2])
4208+
4209+
# Check that components return the correct named selections
4210+
for component in design.components:
4211+
ns_list = component.get_named_selections()
4212+
if component.id == comp1.id:
4213+
assert len(ns_list) == 1
4214+
assert any(ns.name == "component_ns_1" for ns in ns_list)
4215+
elif component.id == comp2.id:
4216+
assert len(ns_list) == 1
4217+
assert any(ns.name == "component_ns_2" for ns in ns_list)
4218+
else:
4219+
assert len(ns_list) == 0 # No named selection for this component
4220+
4221+
4222+
def test_design_point_get_named_selections(modeler: Modeler):
4223+
# Test getting named selections associated with design points
4224+
design = modeler.create_design("design_point_named_selections")
4225+
dp1 = design.add_design_point("DesignPoint1", Point3D([0, 0, 0]))
4226+
dp2 = design.add_design_point("DesignPoint2", Point3D([1, 1, 1]))
4227+
dp3 = design.add_design_point("DesignPoint3", Point3D([2, 2, 2]))
4228+
4229+
# create named selection from design points
4230+
design.create_named_selection("design_point_ns_1", design_points=[dp1])
4231+
design.create_named_selection("design_point_ns_2", design_points=[dp2])
4232+
4233+
# Check that design points return the correct named selections
4234+
for design_point in design.design_points:
4235+
ns_list = design_point.get_named_selections()
4236+
if design_point.id == dp1.id:
4237+
assert len(ns_list) == 1
4238+
assert any(ns.name == "design_point_ns_1" for ns in ns_list)
4239+
elif design_point.id == dp2.id:
4240+
assert len(ns_list) == 1
4241+
assert any(ns.name == "design_point_ns_2" for ns in ns_list)
4242+
else:
4243+
assert len(ns_list) == 0 # No named selection for this design point

0 commit comments

Comments
 (0)