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

Desc format #42

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
28 changes: 25 additions & 3 deletions gdshelpers/geometry/chip.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,31 @@ def get_dlw_data(self):
return dlw_data

def get_desc(self):
desc = self.desc.copy()
desc['cells'] = {cell['cell'].name: dict(offset=tuple(cell['origin']), angle=cell['angle'] or 0,
**cell['cell'].get_desc()) for cell in self.cells}
"""
Creates and returns a dictionary containing all the 'desc' data of this cell and all children.
The returned dictionary contains two keys:

* `root`: The name of the root cell (the cell from which `get_desc` was called)
* `cells`: Dictionary mapping cell names to the desc data of each cell as well as cell references to other cells
(with origin and angle).

:return: Dictionary containing the `desc` data for this cell and all cells referenced by this cell
"""
def walk_cells(cell, out_dict):
if cell.name not in out_dict:
cellrefs = []
for child in cell.cells:
child_dict = child.copy()
child_dict['cell'] = child_dict['cell'].name
cellrefs.append(child_dict)

out_dict[cell.name] = {'cells': cellrefs, **cell.desc}

for child in cell.cells:
walk_cells(child['cell'], out_dict)

desc = dict(root=self.name, cells=dict())
walk_cells(self, desc['cells'])
return desc

def get_fractured_layer_dict(self, max_points=4000, max_line_points=4000):
Expand Down
14 changes: 14 additions & 0 deletions gdshelpers/tests/test_chip.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,17 @@ def test_dlw(self):
top.add_cell(child2, [0, 0])
with self.assertRaises(ValueError):
top.add_cell(child2, [100, 0])

def test_desc(self):
cell = Cell("desctest")
c1 = Cell("child1")
c1.add_to_desc("foo", 123)
cell.add_cell(c1, origin=(0, 0))
cell.add_cell(c1, origin=(100, 0), angle=2)

d = cell.get_desc()
self.assertTrue("child1" in d["cells"])
self.assertTrue("desctest" in d["cells"])
self.assertEqual("desctest", d["root"])
self.assertEqual(2, len(d["cells"]["desctest"]["cells"]))
self.assertEqual("child1", d["cells"]["desctest"]["cells"][0]["cell"])