Skip to content

Commit

Permalink
REFACTOR: General clean up of modeler modules
Browse files Browse the repository at this point in the history
  • Loading branch information
SMoraisAnsys committed Jan 11, 2025
1 parent a5cbc5e commit a567766
Show file tree
Hide file tree
Showing 5 changed files with 499 additions and 502 deletions.
97 changes: 51 additions & 46 deletions src/ansys/aedt/core/modeler/cad/polylines.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,17 +342,17 @@ def __init__(
self._is_closed = close_surface
self._is_covered = cover_surface

varg1 = self._point_segment_string_array()
arg_1 = self._point_segment_string_array()

Check warning on line 345 in src/ansys/aedt/core/modeler/cad/polylines.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/polylines.py#L345

Added line #L345 was not covered by tests
if non_model:
flag = "NonModel#"
else:
flag = ""
varg2 = self._primitives._default_object_attributes(name=name, material=matname, flags=flag)
arg_2 = self._primitives._default_object_attributes(name=name, material=matname, flags=flag)

Check warning on line 350 in src/ansys/aedt/core/modeler/cad/polylines.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/polylines.py#L350

Added line #L350 was not covered by tests
if self._primitives.design_type in ["Maxwell 2D", "2D Extractor"]:
solve_inside_idx = varg2.index("SolveInside:=")
solve_inside_idx = arg_2.index("SolveInside:=")

Check warning on line 352 in src/ansys/aedt/core/modeler/cad/polylines.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/polylines.py#L352

Added line #L352 was not covered by tests
self._solve_inside = False
varg2[solve_inside_idx + 1] = self._solve_inside
new_object_name = self._oeditor.CreatePolyline(varg1, varg2)
arg_2[solve_inside_idx + 1] = self._solve_inside
new_object_name = self._oeditor.CreatePolyline(arg_1, arg_2)

Check warning on line 355 in src/ansys/aedt/core/modeler/cad/polylines.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/polylines.py#L354-L355

Added lines #L354 - L355 were not covered by tests
Object3d.__init__(self, primitives, name=new_object_name)
self._primitives._create_object(self.name, is_polyline=True)

Expand Down Expand Up @@ -573,11 +573,13 @@ def _point_segment_string_array(self):
segment_types = self.segment_types

# Add a closing point if needed
varg1 = ["NAME:PolylineParameters"]
varg1.append("IsPolylineCovered:=")
varg1.append(self._is_covered)
varg1.append("IsPolylineClosed:=")
varg1.append(self._is_closed)
arg_1 = [

Check warning on line 576 in src/ansys/aedt/core/modeler/cad/polylines.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/polylines.py#L576

Added line #L576 was not covered by tests
"NAME:PolylineParameters",
"IsPolylineCovered:=",
self._is_covered,
"IsPolylineClosed:=",
self._is_closed,
]

# PointsArray
points_str = ["NAME:PolylinePoints"]
Expand Down Expand Up @@ -633,13 +635,13 @@ def _point_segment_string_array(self):
else:
break

varg1.append(points_str)
varg1.append(segment_str)
arg_1.append(points_str)
arg_1.append(segment_str)

Check warning on line 639 in src/ansys/aedt/core/modeler/cad/polylines.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/polylines.py#L638-L639

Added lines #L638 - L639 were not covered by tests

# Poly Line Cross Section
varg1.append(self._xsection)
arg_1.append(self._xsection)

Check warning on line 642 in src/ansys/aedt/core/modeler/cad/polylines.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/polylines.py#L642

Added line #L642 was not covered by tests

return varg1
return arg_1

Check warning on line 644 in src/ansys/aedt/core/modeler/cad/polylines.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/polylines.py#L644

Added line #L644 was not covered by tests

@pyaedt_function_handler()
def _evaluate_arc_angle_extra_points(self, segment, start_point):
Expand Down Expand Up @@ -778,15 +780,16 @@ def clone(self):
>>> P2 = P1.clone()
"""
vArg1 = ["NAME:Selections", "Selections:=", self.name]
self._primitives.oeditor.Copy(vArg1)
arg_1 = ["NAME:Selections", "Selections:=", self.name]
self._primitives.oeditor.Copy(arg_1)

Check warning on line 784 in src/ansys/aedt/core/modeler/cad/polylines.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/polylines.py#L783-L784

Added lines #L783 - L784 were not covered by tests
self._primitives.oeditor.Paste()
return self._add_new_polyline()

@pyaedt_function_handler()
def _add_new_polyline(self):
new_objects = self._primitives.find_new_objects()
assert len(new_objects) == 1
if len(new_objects) != 1:
raise RuntimeError("Cannot create a new polyline object when multiple new objects exist.")

Check warning on line 792 in src/ansys/aedt/core/modeler/cad/polylines.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/polylines.py#L791-L792

Added lines #L791 - L792 were not covered by tests
new_name = new_objects[0]
new_polyline = Polyline(self._primitives, src_object=self, name=new_name)
new_polyline._id = None
Expand Down Expand Up @@ -1008,8 +1011,8 @@ def set_crosssection_properties(
section_bend = "Corner"

# Ensure number-of segments is valid
if num_seg:
assert num_seg > 2, "Number of segments for a cross-section must be 0 or greater than 2."
if num_seg and num_seg < 3:
raise ValueError("Number of segments for a cross-section must be 0 or greater than 2.")

Check warning on line 1015 in src/ansys/aedt/core/modeler/cad/polylines.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/polylines.py#L1014-L1015

Added lines #L1014 - L1015 were not covered by tests

model_units = self._primitives.model_units

Expand Down Expand Up @@ -1220,46 +1223,47 @@ def insert_segment(self, points, segment=None):
points = [end_point, self.points[1]]
break

assert p_insert_position is not None, "Point for the insert is not found."
assert insert_points is not None, "Point for the insert is not found."
if p_insert_position is None or insert_points is None:
raise RuntimeError("Point for the insert is not found.")

Check warning on line 1227 in src/ansys/aedt/core/modeler/cad/polylines.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/polylines.py#L1226-L1227

Added lines #L1226 - L1227 were not covered by tests

if i is None:
raise ValueError("The polyline contains no points. It is impossible to insert a segment.")
segment_index = self._get_segment_id_from_point_n(i, at_start=at_start)

assert isinstance(segment_index, int), "Segment for the insert is not found."
if not isinstance(segment_index, int):
raise ValueError("Segment for the insert is not found.")

Check warning on line 1234 in src/ansys/aedt/core/modeler/cad/polylines.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/polylines.py#L1233-L1234

Added lines #L1233 - L1234 were not covered by tests
if at_start:
s_insert_position = segment_index
else:
s_insert_position = segment_index + 1

type = segment.type

varg1 = ["NAME:Insert Polyline Segment"]
varg1.append("Selections:=")
varg1.append(self._m_name + ":CreatePolyline:1")
varg1.append("Segment Indices:=")
varg1.append([segment_index])
varg1.append("At Start:=")
varg1.append(at_start)
varg1.append("SegmentType:=")
varg1.append(type)
segment_type = segment.type

Check warning on line 1239 in src/ansys/aedt/core/modeler/cad/polylines.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/polylines.py#L1239

Added line #L1239 was not covered by tests

arg_1 = [

Check warning on line 1241 in src/ansys/aedt/core/modeler/cad/polylines.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/polylines.py#L1241

Added line #L1241 was not covered by tests
"NAME:Insert Polyline Segment",
"Selections:=",
self._m_name + ":CreatePolyline:1",
"Segment Indices:=",
[segment_index],
"At Start:=",
at_start,
"SegmentType:=",
segment_type,
]

# Points and segment data
varg2 = ["NAME:PolylinePoints"]

if segment.type == "Line" or segment.type == "Spline" or segment.type == "Arc":
arg_2 = ["NAME:PolylinePoints"]
if segment.type in ("Line", "Spline", "Arc"):

Check warning on line 1255 in src/ansys/aedt/core/modeler/cad/polylines.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/polylines.py#L1254-L1255

Added lines #L1254 - L1255 were not covered by tests
for pt in points[0:num_points]:
varg2.append(self._pl_point(pt))
varg1.append(varg2)
arg_2.append(self._pl_point(pt))
arg_1.append(arg_2)

Check warning on line 1258 in src/ansys/aedt/core/modeler/cad/polylines.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/polylines.py#L1257-L1258

Added lines #L1257 - L1258 were not covered by tests
elif segment.type == "AngularArc":
seg_str = self._segment_array(segment, start_point=start_point)
varg2.append(self._pl_point(start_point))
varg2.append(self._pl_point(segment.extra_points[0]))
varg2.append(self._pl_point(segment.extra_points[1]))
varg1.append(varg2)
varg1 += seg_str[9:]
self._primitives.oeditor.InsertPolylineSegment(varg1)
arg_2.append(self._pl_point(start_point))
arg_2.append(self._pl_point(segment.extra_points[0]))
arg_2.append(self._pl_point(segment.extra_points[1]))
arg_1.append(arg_2)
arg_1 += seg_str[9:]
self._primitives.oeditor.InsertPolylineSegment(arg_1)

Check warning on line 1266 in src/ansys/aedt/core/modeler/cad/polylines.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/polylines.py#L1261-L1266

Added lines #L1261 - L1266 were not covered by tests

# check if the polyline has been modified correctly
if self._check_polyline_health() is False:
Expand All @@ -1279,6 +1283,7 @@ def _check_polyline_health(self):
# Undo operation
self._primitives._app.odesign.Undo()
self._object_type = None
assert self.object_type != "Unclassified", "Undo operation failed."
if self.object_type == "Unclassified":
raise RuntimeError("Undo operation failed.")

Check warning on line 1287 in src/ansys/aedt/core/modeler/cad/polylines.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/polylines.py#L1286-L1287

Added lines #L1286 - L1287 were not covered by tests
return False
return True
Loading

0 comments on commit a567766

Please sign in to comment.