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

REFACTOR: primitives #721

Merged
merged 17 commits into from
Aug 19, 2024
68 changes: 35 additions & 33 deletions src/pyedb/dotnet/edb.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,13 +454,13 @@ def terminals(self):
@property
def excitations(self):
"""Get all layout excitations."""
terms = [term for term in self.layout.terminals if int(term.GetBoundaryType()) == 0]
terms = [term for term in self.layout.terminals if int(term._edb_object.GetBoundaryType()) == 0]
temp = {}
for ter in terms:
if "BundleTerminal" in ter.GetType().ToString():
temp[ter.GetName()] = BundleWavePort(self, ter)
if "BundleTerminal" in ter._edb_object.GetType().ToString():
temp[ter.name] = BundleWavePort(self, ter._edb_object)
else:
temp[ter.GetName()] = GapPort(self, ter)
temp[ter.name] = GapPort(self, ter._edb_object)
return temp

@property
Expand All @@ -473,41 +473,41 @@ def ports(self):
:class:`pyedb.dotnet.edb_core.edb_data.ports.WavePort`,]]

"""
temp = [term for term in self.layout.terminals if not term.IsReferenceTerminal()]
temp = [term for term in self.layout.terminals if not term.is_reference_terminal]

ports = {}
for t in temp:
t2 = Terminal(self, t)
t2 = Terminal(self, t._edb_object)
if not t2.boundary_type == "PortBoundary":
continue

if t2.is_circuit_port:
port = CircuitPort(self, t)
port = CircuitPort(self, t._edb_object)
ports[port.name] = port
elif t2.terminal_type == "BundleTerminal":
port = BundleWavePort(self, t)
port = BundleWavePort(self, t._edb_object)
ports[port.name] = port
elif t2.hfss_type == "Wave":
ports[t2.name] = WavePort(self, t)
ports[t2.name] = WavePort(self, t._edb_object)
elif t2.terminal_type == "PadstackInstanceTerminal":
ports[t2.name] = CoaxPort(self, t)
ports[t2.name] = CoaxPort(self, t._edb_object)
else:
ports[t2.name] = GapPort(self, t)
ports[t2.name] = GapPort(self, t._edb_object)
return ports

@property
def excitations_nets(self):
"""Get all excitations net names."""
names = list(set([i.GetNet().GetName() for i in self.layout.terminals]))
names = list(set([i.net.name for i in self.layout.terminals]))
names = [i for i in names if i]
return names

@property
def sources(self):
"""Get all layout sources."""
terms = [term for term in self.layout.terminals if int(term.GetBoundaryType()) in [3, 4, 7]]
terms = [term for term in terms if not term.IsReferenceTerminal()]
return {ter.GetName(): ExcitationSources(self, ter) for ter in terms}
terms = [term for term in self.layout.terminals if int(term._edb_object.GetBoundaryType()) in [3, 4, 7]]
terms = [term for term in terms if not term._edb_object.IsReferenceTerminal()]
return {ter.name: ExcitationSources(self, ter._edb_object) for ter in terms}

@property
def voltage_regulator_modules(self):
Expand Down Expand Up @@ -1167,9 +1167,9 @@ def get_connected_objects(self, layout_object_instance):
elif obj_type == LayoutObjType.Primitive.name:
prim_type = i.GetPrimitiveType().ToString()
if prim_type == Primitives.Path.name:
from pyedb.dotnet.edb_core.edb_data.primitives_data import EdbPath
from pyedb.dotnet.edb_core.cell.primitive.path import Path

temp.append(EdbPath(i, self))
temp.append(Path(self, i))
elif prim_type == Primitives.Rectangle.name:
from pyedb.dotnet.edb_core.edb_data.primitives_data import (
EdbRectangle,
Expand Down Expand Up @@ -1669,11 +1669,11 @@ def _smart_cut(self, reference_list=[], expansion_size=1e-12):
from pyedb.dotnet.clr_module import Tuple

_polys = []
terms = [term for term in self.layout.terminals if int(term.GetBoundaryType()) in [0, 3, 4, 7, 8]]
terms = [term for term in self.layout.terminals if int(term._edb_object.GetBoundaryType()) in [0, 3, 4, 7, 8]]
locations = []
for term in terms:
if term.GetTerminalType().ToString() == "PointTerminal" and term.GetNet().GetName() in reference_list:
pd = term.GetParameters()[1]
if term._edb_object.GetTerminalType().ToString() == "PointTerminal" and term.net.name in reference_list:
pd = term._edb_object.GetParameters()[1]
locations.append([pd.X.ToDouble(), pd.Y.ToDouble()])
for point in locations:
pointA = self.edb_api.geometry.point_data(
Expand Down Expand Up @@ -2214,11 +2214,13 @@ def _create_cutout_multithread(
if pin.pingroups:
pins_to_preserve.append(pin.id)
if check_terminals:
terms = [term for term in self.layout.terminals if int(term.GetBoundaryType()) in [0, 3, 4, 7, 8]]
terms = [
term for term in self.layout.terminals if int(term._edb_object.GetBoundaryType()) in [0, 3, 4, 7, 8]
]
for term in terms:
if term.GetTerminalType().ToString() == "PadstackInstanceTerminal":
if term.GetParameters()[1].GetNet().GetName() in reference_list:
pins_to_preserve.append(term.GetParameters()[1].GetId())
if term._edb_object.GetTerminalType().ToString() == "PadstackInstanceTerminal":
if term._edb_object.GetParameters()[1].GetNet().GetName() in reference_list:
pins_to_preserve.append(term._edb_object.GetParameters()[1].GetId())

for i in self.nets.nets.values():
name = i.name
Expand Down Expand Up @@ -2309,7 +2311,7 @@ def subtract(poly, voids):
return poly.Subtract(convert_py_list_to_net_list(poly), convert_py_list_to_net_list(voids))

def clip_path(path):
pdata = path.polygon_data.edb_api
pdata = path.polygon_data._edb_object
int_data = _poly.GetIntersectionType(pdata)
if int_data == 0:
prims_to_delete.append(path)
Expand All @@ -2320,7 +2322,7 @@ def clip_path(path):
reference_prims.append(path)

def clean_prim(prim_1): # pragma: no cover
pdata = prim_1.polygon_data.edb_api
pdata = prim_1.polygon_data._edb_object
int_data = _poly.GetIntersectionType(pdata)
if int_data == 2:
if not inlcude_voids_in_extents:
Expand All @@ -2347,7 +2349,7 @@ def clean_prim(prim_1): # pragma: no cover
# points = list(p.Points)
list_void = []
if voids:
voids_data = [void.polygon_data.edb_api for void in voids]
voids_data = [void.polygon_data._edb_object for void in voids]
list_prims = subtract(p, voids_data)
for prim in list_prims:
if not prim.IsNull():
Expand Down Expand Up @@ -4445,10 +4447,10 @@ def create_model_for_arbitrary_wave_ports(
for poly in polys:
for void in poly.voids:
void_bbox = (
void.polygon_data.edb_api.GetBBox().Item1.X.ToDouble(),
void.polygon_data.edb_api.GetBBox().Item1.Y.ToDouble(),
void.polygon_data.edb_api.GetBBox().Item2.X.ToDouble(),
void.polygon_data.edb_api.GetBBox().Item2.Y.ToDouble(),
void.polygon_data._edb_object.GetBBox().Item1.X.ToDouble(),
void.polygon_data._edb_object.GetBBox().Item1.Y.ToDouble(),
void.polygon_data._edb_object.GetBBox().Item2.X.ToDouble(),
void.polygon_data._edb_object.GetBBox().Item2.Y.ToDouble(),
)
included_instances = list(padstack_instances_index.intersection(void_bbox))
if included_instances:
Expand Down Expand Up @@ -4481,10 +4483,10 @@ def create_model_for_arbitrary_wave_ports(

for void_info in void_padstacks:
port_poly = cloned_edb.modeler.create_polygon(
main_shape=void_info[0].polygon_data.edb_api, layer_name="ref", net_name="GND"
main_shape=void_info[0].polygon_data._edb_object, layer_name="ref", net_name="GND"
)
pec_poly = cloned_edb.modeler.create_polygon(
main_shape=port_poly.polygon_data.edb_api, layer_name="port_pec", net_name="GND"
main_shape=port_poly.polygon_data._edb_object, layer_name="port_pec", net_name="GND"
)
pec_poly.scale(1.5)

Expand Down
11 changes: 11 additions & 0 deletions src/pyedb/dotnet/edb_core/cell/hierarchy/hierarchy_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,14 @@ def location(self):
class Group(HierarchyObj):
def __init__(self, pedb, edb_object):
super().__init__(pedb, edb_object)

def ungroup(self, recursive=False):
"""Dissolve a group.

Parameters
----------
recursive : bool, optional
If True, all subgroups will also be dissolved.

"""
return self._edb_object.Ungroup(recursive)
53 changes: 30 additions & 23 deletions src/pyedb/dotnet/edb_core/cell/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
This module contains these classes: `EdbLayout` and `Shape`.
"""
from pyedb.dotnet.edb_core.cell.hierarchy.component import EDBComponent
from pyedb.dotnet.edb_core.cell.primitive import Bondwire
from pyedb.dotnet.edb_core.cell.primitive.bondwire import Bondwire
from pyedb.dotnet.edb_core.cell.primitive.path import Path
from pyedb.dotnet.edb_core.cell.terminal.bundle_terminal import BundleTerminal
from pyedb.dotnet.edb_core.cell.terminal.edge_terminal import EdgeTerminal
from pyedb.dotnet.edb_core.cell.terminal.padstack_instance_terminal import (
Expand All @@ -42,7 +43,6 @@
from pyedb.dotnet.edb_core.edb_data.padstacks_data import EDBPadstackInstance
from pyedb.dotnet.edb_core.edb_data.primitives_data import (
EdbCircle,
EdbPath,
EdbPolygon,
EdbRectangle,
EdbText,
Expand Down Expand Up @@ -206,26 +206,8 @@ def primitives(self):
"""
prims = []
for p in self._edb_object.Primitives:
if p.GetPrimitiveType().ToString() == "Rectangle":
prims.append(EdbRectangle(p, self._pedb))
elif p.GetPrimitiveType().ToString() == "Circle":
prims.append(EdbCircle(p, self._pedb))
elif p.GetPrimitiveType().ToString() == "Polygon":
prims.append(EdbPolygon(p, self._pedb))
elif p.GetPrimitiveType().ToString() == "Path":
prims.append(EdbPath(p, self._pedb))
elif p.GetPrimitiveType().ToString() == "Bondwire":
prims.append(Bondwire(self._pedb, p))
elif p.GetPrimitiveType().ToString() == "Text":
prims.append(EdbText(p, self._pedb))
elif p.GetPrimitiveType().ToString() == "PrimitivePlugin":
pass
elif p.GetPrimitiveType().ToString() == "Path3D":
pass
elif p.GetPrimitiveType().ToString() == "BoardBendDef":
pass
else:
pass
obj = self.find_object_by_id(p.GetId())
prims.append(obj)
return prims

@property
Expand Down Expand Up @@ -293,8 +275,33 @@ def find_object_by_id(self, value: int):
ID of the object.
"""
obj = self._pedb._edb.Cell.Connectable.FindById(self._edb_object, value)
if obj is None:
raise RuntimeError(f"Object Id {value} not found")

if obj.GetObjType().ToString() == "PadstackInstance":
return EDBPadstackInstance(obj, self._pedb) if obj is not None else None
return EDBPadstackInstance(obj, self._pedb)

if obj.GetObjType().ToString() == "Primitive":
if obj.GetPrimitiveType().ToString() == "Rectangle":
return EdbRectangle(obj, self._pedb)
elif obj.GetPrimitiveType().ToString() == "Circle":
return EdbCircle(obj, self._pedb)
elif obj.GetPrimitiveType().ToString() == "Polygon":
return EdbPolygon(obj, self._pedb)
elif obj.GetPrimitiveType().ToString() == "Path":
return Path(self._pedb, obj)
elif obj.GetPrimitiveType().ToString() == "Bondwire":
return Bondwire(self._pedb, obj)
elif obj.GetPrimitiveType().ToString() == "Text":
return EdbText(obj, self._pedb)
elif obj.GetPrimitiveType().ToString() == "PrimitivePlugin":
pass
elif obj.GetPrimitiveType().ToString() == "Path3D":
pass
elif obj.GetPrimitiveType().ToString() == "BoardBendDef":
pass
else:
pass

def find_net_by_name(self, value: str):
"""Find a net object by name
Expand Down
9 changes: 0 additions & 9 deletions src/pyedb/dotnet/edb_core/cell/layout_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@
class LayoutObj(ObjBase):
"""Manages EDB functionalities for the layout object."""

def __getattr__(self, key): # pragma: no cover
try:
return super().__getattribute__(key)
except AttributeError:
try:
return getattr(self._edb_object, key)
except AttributeError:
raise AttributeError(f"Attribute '{key}' not present")

def __init__(self, pedb, edb_object):
super().__init__(pedb, edb_object)

Expand Down
3 changes: 3 additions & 0 deletions src/pyedb/dotnet/edb_core/cell/primitive/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from pathlib import Path

workdir = Path(__file__).parent
Loading
Loading