Skip to content

Commit d874b97

Browse files
chore: cleanup blitz PR (#1855)
Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 88fb082 commit d874b97

File tree

6 files changed

+117
-109
lines changed

6 files changed

+117
-109
lines changed

doc/changelog.d/1855.maintenance.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cleanup blitz PR

src/ansys/geometry/core/connection/backend.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,27 @@ def is_core_service(backend_type: "BackendType") -> bool:
5757
BackendType.CORE_LINUX,
5858
)
5959

60+
@staticmethod
61+
def is_headless_service(backend_type: "BackendType") -> bool:
62+
"""Determine whether the backend is a headless service or not.
63+
64+
Parameters
65+
----------
66+
backend_type : BackendType
67+
The backend type to check whether or not it's a headless service.
68+
69+
Returns
70+
-------
71+
bool
72+
True if the backend is a headless service, False otherwise.
73+
"""
74+
return backend_type in (
75+
BackendType.WINDOWS_SERVICE,
76+
BackendType.LINUX_SERVICE,
77+
BackendType.CORE_WINDOWS,
78+
BackendType.CORE_LINUX,
79+
)
80+
6081
@staticmethod
6182
def is_linux_service(backend_type: "BackendType") -> bool:
6283
"""Determine whether the backend is a Linux service or not.

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

Lines changed: 37 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@
9999
from ansys.geometry.core.shapes.curves.trimmed_curve import TrimmedCurve
100100
from ansys.geometry.core.shapes.parameterization import Interval, ParamUV
101101
from ansys.geometry.core.shapes.surfaces import TrimmedSurface
102-
from ansys.geometry.core.sketch.arc import Arc
103102
from ansys.geometry.core.sketch.sketch import Sketch
104103
from ansys.geometry.core.typing import Real
105104

@@ -1149,21 +1148,15 @@ def create_beams(
11491148
self,
11501149
segments: list[tuple[Point3D, Point3D]],
11511150
profile: BeamProfile,
1152-
arcs: list[Arc] = None,
1153-
circles: list[Circle] = None,
11541151
) -> list[Beam]:
11551152
"""Create beams under the component.
11561153
11571154
Parameters
11581155
----------
11591156
segments : list[tuple[Point3D, Point3D]]
1160-
list of start and end pairs, each specifying a single line segment.
1157+
List of start and end pairs, each specifying a single line segment.
11611158
profile : BeamProfile
11621159
Beam profile to use to create the beams.
1163-
arcs : list[Curve], default: None
1164-
list of arcs to create beams from.
1165-
circles : list[Curve], default: None
1166-
list of circles to create beams from.
11671160
11681161
Returns
11691162
-------
@@ -1178,7 +1171,7 @@ def create_beams(
11781171
if self._grpc_client.backend_version < (25, 2, 0):
11791172
return self.__create_beams_legacy(segments, profile)
11801173
else:
1181-
return self.__create_beams(segments, profile, arcs, circles)
1174+
return self.__create_beams(segments, profile)
11821175

11831176
def __create_beams_legacy(
11841177
self, segments: list[tuple[Point3D, Point3D]], profile: BeamProfile
@@ -1192,7 +1185,7 @@ def __create_beams_legacy(
11921185
Parameters
11931186
----------
11941187
segments : list[tuple[Point3D, Point3D]]
1195-
list of start and end pairs, each specifying a single line segment.
1188+
List of start and end pairs, each specifying a single line segment.
11961189
profile : BeamProfile
11971190
Beam profile to use to create the beams.
11981191
@@ -1229,15 +1222,13 @@ def __create_beams(
12291222
self,
12301223
segments: list[tuple[Point3D, Point3D]],
12311224
profile: BeamProfile,
1232-
arcs: list[Arc],
1233-
circles: list[Circle],
12341225
) -> list[Beam]:
12351226
"""Create beams under the component.
12361227
12371228
Parameters
12381229
----------
12391230
segments : list[tuple[Point3D, Point3D]]
1240-
list of start and end pairs, each specifying a single line segment.
1231+
List of start and end pairs, each specifying a single line segment.
12411232
profile : BeamProfile
12421233
Beam profile to use to create the beams.
12431234
@@ -1263,50 +1254,52 @@ def __create_beams(
12631254
beams = []
12641255
for beam in response.created_beams:
12651256
cross_section = BeamCrossSectionInfo(
1266-
SectionAnchorType(beam.cross_section.section_anchor),
1267-
beam.cross_section.section_angle,
1268-
grpc_frame_to_frame(beam.cross_section.section_frame),
1269-
[
1257+
section_anchor=SectionAnchorType(beam.cross_section.section_anchor),
1258+
section_angle=beam.cross_section.section_angle,
1259+
section_frame=grpc_frame_to_frame(beam.cross_section.section_frame),
1260+
section_profile=[
12701261
[
12711262
TrimmedCurve(
1272-
grpc_curve_to_curve(curve.geometry),
1273-
grpc_point_to_point3d(curve.start),
1274-
grpc_point_to_point3d(curve.end),
1275-
Interval(curve.interval_start, curve.interval_end),
1276-
curve.length,
1263+
geometry=grpc_curve_to_curve(curve.geometry),
1264+
start=grpc_point_to_point3d(curve.start),
1265+
end=grpc_point_to_point3d(curve.end),
1266+
interval=Interval(curve.interval_start, curve.interval_end),
1267+
length=curve.length,
12771268
)
12781269
for curve in curve_list
12791270
]
12801271
for curve_list in beam.cross_section.section_profile
12811272
],
12821273
)
12831274
properties = BeamProperties(
1284-
beam.properties.area,
1285-
ParamUV(beam.properties.centroid_x, beam.properties.centroid_y),
1286-
beam.properties.warping_constant,
1287-
beam.properties.ixx,
1288-
beam.properties.ixy,
1289-
beam.properties.iyy,
1290-
ParamUV(beam.properties.shear_center_x, beam.properties.shear_center_y),
1291-
beam.properties.torsional_constant,
1275+
area=beam.properties.area,
1276+
centroid=ParamUV(beam.properties.centroid_x, beam.properties.centroid_y),
1277+
warping_constant=beam.properties.warping_constant,
1278+
ixx=beam.properties.ixx,
1279+
ixy=beam.properties.ixy,
1280+
iyy=beam.properties.iyy,
1281+
shear_center=ParamUV(
1282+
beam.properties.shear_center_x, beam.properties.shear_center_y
1283+
),
1284+
torsion_constant=beam.properties.torsional_constant,
12921285
)
12931286

12941287
beams.append(
12951288
Beam(
1296-
beam.id.id,
1297-
grpc_point_to_point3d(beam.shape.start),
1298-
grpc_point_to_point3d(beam.shape.end),
1299-
profile,
1300-
self,
1301-
beam.name,
1302-
beam.is_deleted,
1303-
beam.is_reversed,
1304-
beam.is_rigid,
1305-
grpc_material_to_material(beam.material),
1306-
cross_section,
1307-
properties,
1308-
beam.shape,
1309-
beam.type,
1289+
id=beam.id.id,
1290+
start=grpc_point_to_point3d(beam.shape.start),
1291+
end=grpc_point_to_point3d(beam.shape.end),
1292+
profile=profile,
1293+
parent_component=self,
1294+
name=beam.name,
1295+
is_deleted=beam.is_deleted,
1296+
is_reversed=beam.is_reversed,
1297+
is_rigid=beam.is_rigid,
1298+
material=grpc_material_to_material(beam.material),
1299+
cross_section=cross_section,
1300+
properties=properties,
1301+
shape=beam.shape,
1302+
beam_type=beam.type,
13101303
)
13111304
)
13121305

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

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,54 +1159,58 @@ def __read_existing_design(self) -> None:
11591159
# Create Beams
11601160
for beam in response.beams:
11611161
cross_section = BeamCrossSectionInfo(
1162-
SectionAnchorType(beam.cross_section.section_anchor),
1163-
beam.cross_section.section_angle,
1164-
grpc_frame_to_frame(beam.cross_section.section_frame),
1165-
[
1162+
section_anchor=SectionAnchorType(beam.cross_section.section_anchor),
1163+
section_angle=beam.cross_section.section_angle,
1164+
section_frame=grpc_frame_to_frame(beam.cross_section.section_frame),
1165+
section_profile=[
11661166
[
11671167
TrimmedCurve(
1168-
grpc_curve_to_curve(curve.curve),
1169-
grpc_point_to_point3d(curve.start),
1170-
grpc_point_to_point3d(curve.end),
1171-
Interval(curve.interval_start, curve.interval_end),
1172-
curve.length,
1168+
geometry=grpc_curve_to_curve(curve.curve),
1169+
start=grpc_point_to_point3d(curve.start),
1170+
end=grpc_point_to_point3d(curve.end),
1171+
interval=Interval(curve.interval_start, curve.interval_end),
1172+
length=curve.length,
11731173
)
11741174
for curve in curve_list.curves
11751175
]
11761176
for curve_list in beam.cross_section.section_profile
11771177
],
11781178
)
11791179
properties = BeamProperties(
1180-
beam.properties.area,
1181-
ParamUV(beam.properties.centroid_x, beam.properties.centroid_y),
1182-
beam.properties.warping_constant,
1183-
beam.properties.ixx,
1184-
beam.properties.ixy,
1185-
beam.properties.iyy,
1186-
ParamUV(beam.properties.shear_center_x, beam.properties.shear_center_y),
1187-
beam.properties.torsional_constant,
1180+
area=beam.properties.area,
1181+
centroid=ParamUV(beam.properties.centroid_x, beam.properties.centroid_y),
1182+
warping_constant=beam.properties.warping_constant,
1183+
ixx=beam.properties.ixx,
1184+
ixy=beam.properties.ixy,
1185+
iyy=beam.properties.iyy,
1186+
shear_center=ParamUV(
1187+
beam.properties.shear_center_x, beam.properties.shear_center_y
1188+
),
1189+
torsion_constant=beam.properties.torsional_constant,
11881190
)
11891191

11901192
new_beam = Beam(
1191-
beam.id.id,
1192-
grpc_point_to_point3d(beam.shape.start),
1193-
grpc_point_to_point3d(beam.shape.end),
1194-
None,
1193+
id=beam.id.id,
1194+
start=grpc_point_to_point3d(beam.shape.start),
1195+
end=grpc_point_to_point3d(beam.shape.end),
1196+
profile=None,
11951197
# TODO: Beams need BeamProfiles imported from existing design
11961198
# https://github.com/ansys/pyansys-geometry/issues/1825
1197-
self,
1198-
beam.name,
1199-
beam.is_deleted,
1200-
beam.is_reversed,
1201-
beam.is_rigid,
1202-
grpc_material_to_material(beam.material),
1203-
cross_section,
1204-
properties,
1205-
beam.shape,
1206-
beam.type,
1199+
parent_component=self,
1200+
name=beam.name,
1201+
is_deleted=beam.is_deleted,
1202+
is_reversed=beam.is_reversed,
1203+
is_rigid=beam.is_rigid,
1204+
material=grpc_material_to_material(beam.material),
1205+
cross_section=cross_section,
1206+
properties=properties,
1207+
shape=beam.shape,
1208+
beam_type=beam.type,
12071209
)
12081210

1209-
self._beams.append(new_beam)
1211+
# Find the component to which the beam belongs
1212+
parent = created_components.get(beam.parent.id, self)
1213+
parent._beams.append(new_beam)
12101214

12111215
# Create NamedSelections
12121216
for ns in response.named_selections:

src/ansys/geometry/core/misc/auxiliary.py

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -120,32 +120,25 @@ def get_design_from_edge(edge: "Edge") -> "Design":
120120
return get_design_from_body(body)
121121

122122

123-
def __traverse_all_bodies(comp: Union["Design", "Component"]) -> list["Body"]:
124-
"""Traverse all bodies in a design and all its subcomponents.
123+
def __traverse_component_elem(elem: str, comp: Union["Design", "Component"]) -> list:
124+
"""Traverses all elements of a component or design, given its name."""
125+
elems = []
126+
comp_elems = getattr(comp, elem)
127+
elems.extend(comp_elems)
128+
for component in comp.components:
129+
elems.extend(__traverse_component_elem(elem, component))
125130

126-
This is a private method. Do not use it directly.
131+
return elems
127132

128-
Parameters
129-
----------
130-
design : Design
131-
Design object to traverse.
132133

133-
Returns
134-
-------
135-
list[Body]
136-
List of all bodies in the design or component.
134+
def __traverse_all_bodies(comp: Union["Design", "Component"]) -> list["Body"]:
135+
"""Traverse all bodies in a design/component and all its subcomponents."""
136+
return __traverse_component_elem("bodies", comp)
137137

138-
Notes
139-
-----
140-
This method is a recursive helper function to traverse all bodies in a
141-
design and all its subcomponents.
142-
"""
143-
bodies = []
144-
bodies.extend(comp.bodies)
145-
for component in comp.components:
146-
bodies.extend(__traverse_all_bodies(component))
147138

148-
return bodies
139+
def __traverse_all_beams(comp: Union["Design", "Component"]) -> list["Body"]:
140+
"""Traverse all beams in a design/component and all its subcomponents."""
141+
return __traverse_component_elem("beams", comp)
149142

150143

151144
def get_all_bodies_from_design(design: "Design") -> list["Body"]:
@@ -257,7 +250,7 @@ def get_beams_from_ids(design: "Design", beam_ids: list[str]) -> list["Beam"]:
257250
-----
258251
This method takes a design and beam ids, and gets their corresponding ``Beam`` objects.
259252
"""
260-
return [beam for beam in design.beams if beam.id in beam_ids] # noqa: E501
253+
return [beam for beam in __traverse_all_beams(design) if beam.id in beam_ids] # noqa: E501
261254

262255

263256
def convert_color_to_hex(

src/ansys/geometry/core/modeler.py

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

2424
import logging
2525
from pathlib import Path
26-
from typing import TYPE_CHECKING, Optional
26+
from typing import TYPE_CHECKING, Generator, Optional
2727

2828
from grpc import Channel
2929

@@ -356,7 +356,7 @@ def _upload_file_stream(
356356

357357
def _generate_file_chunks(
358358
self, file_path: Path, open_file: bool, import_options: ImportOptions
359-
):
359+
) -> Generator[UploadFileRequest, None, None]:
360360
"""Generate appropriate chunk sizes for uploading files.
361361
362362
Parameters
@@ -368,10 +368,10 @@ def _generate_file_chunks(
368368
import_options : ImportOptions
369369
Import options that toggle certain features when opening a file.
370370
371-
Returns
372-
-------
373-
Chunked UploadFileRequest
374-
371+
Yields
372+
------
373+
UploadFileRequest
374+
Request object for uploading a file in chunks.
375375
"""
376376
msg_buffer = 5 * 1024 # 5KB - for additional message data
377377
if pygeom_defaults.MAX_MESSAGE_LENGTH - msg_buffer < 0: # pragma: no cover
@@ -549,11 +549,7 @@ def run_discovery_script_file(
549549

550550
# Check if API version is specified... if so, validate it
551551
if api_version is not None:
552-
if self.client.backend_type in (
553-
BackendType.WINDOWS_SERVICE,
554-
BackendType.CORE_WINDOWS,
555-
BackendType.CORE_LINUX,
556-
):
552+
if BackendType.is_headless_service(self.client.backend_type):
557553
self.client.log.warning(
558554
"The Ansys Geometry Service only supports "
559555
"scripts that are of its same API version."

0 commit comments

Comments
 (0)