Skip to content

Commit

Permalink
padstack instances query using Rtree class. (#416)
Browse files Browse the repository at this point in the history
  • Loading branch information
svandenb-dev committed Apr 26, 2024
1 parent e848db8 commit 5bfdfcd
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ dependencies = [
"dotnetcore2 ==3.1.23;platform_system=='Linux'",
"pydantic>=2.6.4,<2.8",
"toml == 0.10.2",
]
"Rtree >= 1.2.0",
]

[project.optional-dependencies]
tests = [
Expand Down
53 changes: 53 additions & 0 deletions src/pyedb/dotnet/edb_core/padstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import math
import warnings

import rtree

from pyedb.dotnet.clr_module import Array
from pyedb.dotnet.edb_core.edb_data.padstacks_data import (
EDBPadstack,
Expand Down Expand Up @@ -1460,3 +1462,54 @@ def get_reference_pins(
pin_dict = {GeometryOperators.points_distance(positive_pin.position, p.position): p for p in pinlist}
pinlist = [pin[1] for pin in sorted(pin_dict.items())[:max_limit]]
return pinlist

@pyedb_function_handler()
def get_padstack_instances_rtree_index(self, nets=None):
"""Returns padstack instances Rtree index.
Parameters
----------
nets : str or list, optional
net name of list of nets name applying filtering on padstack instances selection. If ``None`` is provided
all instances are included in the index. Default value is ``None``.
Returns
-------
Rtree index object.
"""
if isinstance(nets, str):
nets = [nets]
padstack_instances_index = rtree.index.Index()
if nets:
instances = [inst for inst in list(self.instances.values()) if inst.net_name in nets]
else:
instances = list(self.instances.values())
for inst in instances:
padstack_instances_index.insert(inst.id, inst.position)
return padstack_instances_index

@pyedb_function_handler()
def get_padstack_instances_intersecting_bounding_box(self, bounding_box, nets=None):
"""Returns the list of padstack instances ID intersecting a given bounding box and nets.
Parameters
----------
bounding_box : tuple or list.
bounding box, [x1, y1, x2, y2]
nets : str or list, optional
net name of list of nets name applying filtering on padstack instances selection. If ``None`` is provided
all instances are included in the index. Default value is ``None``.
Returns
-------
List of padstack instances ID intersecting the bounding box.
"""
if not bounding_box:
raise Exception("No bounding box was provided")
index = self.get_padstack_instances_rtree_index(nets=nets)
if not len(bounding_box) == 4:
raise Exception("The bounding box length must be equal to 4")
if isinstance(bounding_box, list):
bounding_box = tuple(bounding_box)
return list(index.intersection(bounding_box))
19 changes: 19 additions & 0 deletions tests/legacy/system/test_edb_padstacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,22 @@ def test_hole(self):
edbapp = Edb(target_path, edbversion=desktop_version)
edbapp.padstacks.definitions["v35h15"].hole_diameter = "0.16mm"
assert edbapp.padstacks.definitions["v35h15"].hole_diameter == 0.00016

def test_padstack_instances_rtree_index(self):
source_path = os.path.join(local_path, "example_models", test_subfolder, "ANSYS-HSD_V1.aedb")
target_path = os.path.join(self.local_scratch.path, "test_padstack_rtree_index", "ANSYS-HSD_V1.aedb")
self.local_scratch.copyfolder(source_path, target_path)
edbapp = Edb(target_path, edbversion=desktop_version)
index = edbapp.padstacks.get_padstack_instances_rtree_index()
assert index.bounds == [-0.0137849991, -0.00225000058, 0.14800000118, 0.07799999894]
stats = edbapp.get_statistics()
bbox = (0.0, 0.0, stats.layout_size[0], stats.layout_size[1])
test = list(index.intersection(bbox))
assert len(test) == 5689
index = edbapp.padstacks.get_padstack_instances_rtree_index(nets="GND")
test = list(index.intersection(bbox))
assert len(test) == 2048
test = edbapp.padstacks.get_padstack_instances_intersecting_bounding_box(
bounding_box=[0, 0, 0.05, 0.08], nets="GND"
)
assert len(test) == 194

0 comments on commit 5bfdfcd

Please sign in to comment.