Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT: added expand method to class PrimitivesDotNet #605

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions src/pyedb/dotnet/edb_core/dotnet/primitive.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ def __init__(self, api, prim_object=None):
self.edb_api = api._edb
self.prim_obj = prim_object

@property
def id(self):
return self.prim_obj.GetId()

@property
def api_class(self):
return self.api
Expand Down Expand Up @@ -352,6 +356,26 @@ def points_raw(self):
except:
return points

def expand(self, offset=0.001, tolerance=1e-12, round_corners=True, maximum_corner_extension=0.001):
"""Expand the polygon shape by an absolute value in all direction.
Offset can be negative for negative expansion.

Parameters
----------
offset : float, optional
Offset value in meters.
tolerance : float, optional
Tolerance in meters.
round_corners : bool, optional
Whether to round corners or not.
If True, use rounded corners in the expansion otherwise use straight edges (can be degenerate).
maximum_corner_extension : float, optional
The maximum corner extension (when round corners are not used) at which point the corner is clipped.
"""
new_poly = self.polygon_data.edb_api.Expand(offset, tolerance, round_corners, maximum_corner_extension)
self.polygon_data = new_poly[0]
return True


class RectangleDotNet(PrimitiveDotNet):
"""Class representing a rectangle object."""
Expand Down Expand Up @@ -577,6 +601,28 @@ def can_be_zone_primitive(self):
""":obj:`bool`: If a circle can be a zone."""
return True

def expand(self, offset=0.001, tolerance=1e-12, round_corners=True, maximum_corner_extension=0.001):
"""Expand the polygon shape by an absolute value in all direction.
Offset can be negative for negative expansion.

Parameters
----------
offset : float, optional
Offset value in meters.
tolerance : float, optional
Tolerance in meters. Ignored for Circle and Path.
round_corners : bool, optional
Whether to round corners or not.
If True, use rounded corners in the expansion otherwise use straight edges (can be degenerate).
Ignored for Circle and Path.
maximum_corner_extension : float, optional
The maximum corner extension (when round corners are not used) at which point the corner is clipped.
Ignored for Circle and Path.
"""
center_x, center_y, radius = self.get_parameters()
self.set_parameters(center_x, center_y, radius.ToFloat() + offset)
return True


class TextDotNet(PrimitiveDotNet):
"""Class representing a text object."""
Expand Down Expand Up @@ -851,6 +897,27 @@ def can_be_zone_primitive(self):
"""
return True

def expand(self, offset=0.001, tolerance=1e-12, round_corners=True, maximum_corner_extension=0.001):
"""Expand the polygon shape by an absolute value in all direction.
Offset can be negative for negative expansion.

Parameters
----------
offset : float, optional
Offset value in meters.
tolerance : float, optional
Tolerance in meters. Ignored for Circle and Path.
round_corners : bool, optional
Whether to round corners or not.
If True, use rounded corners in the expansion otherwise use straight edges (can be degenerate).
Ignored for Circle and Path.
maximum_corner_extension : float, optional
The maximum corner extension (when round corners are not used) at which point the corner is clipped.
Ignored for Circle and Path.
"""
self.width = self.width + offset
return True


class BondwireDotNet(PrimitiveDotNet):
"""Class representing a bondwire object."""
Expand Down
9 changes: 9 additions & 0 deletions src/pyedb/dotnet/edb_core/edb_data/primitives_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,15 @@ def get_closest_arc_midpoint(self, point):
dist = GeometryOperators.points_distance(mid_point, point)
return [out.X.ToDouble(), out.Y.ToDouble()]

@property
def voids(self):
""":obj:`list` of :class:`Primitive <ansys.edb.primitive.Primitive>`: List of void\
primitive objects inside the primitive.

Read-Only.
"""
return [cast(void, self._app) for void in self.prim_obj.Voids]

@property
def arcs(self):
"""Get the Primitive Arc Data."""
Expand Down
9 changes: 9 additions & 0 deletions tests/legacy/system/test_edb_modeler.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ def test_modeler_polygons(self):
assert isinstance(poly0.arcs[0].points, tuple)
assert isinstance(poly0.intersection_type(poly0), int)
assert poly0.is_intersecting(poly0)
poly_3022 = [i for i in self.edbapp.modeler.polygons if i.id == 3022][0]

for i, k in enumerate(poly_3022.voids):
assert k.id
assert k.expand(0.0005)
# edb.modeler.parametrize_polygon(k, poly_5953, offset_name=f"offset_{i}", origin=centroid)

poly_167 = [i for i in self.edbapp.modeler.paths if i.id == 167][0]
assert poly_167.expand(0.0005)

def test_modeler_paths(self):
"""Evaluate modeler paths"""
Expand Down
Loading