From 033eb80f0a999a825cca890253d0c2dcfa54554f Mon Sep 17 00:00:00 2001 From: fbeutel Date: Mon, 28 Dec 2020 20:19:03 +0100 Subject: [PATCH] Allow multiple children cells with equal names --- gdshelpers/geometry/chip.py | 12 +++++++----- gdshelpers/tests/test_chip.py | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/gdshelpers/geometry/chip.py b/gdshelpers/geometry/chip.py index c85ff0e..62d737a 100644 --- a/gdshelpers/geometry/chip.py +++ b/gdshelpers/geometry/chip.py @@ -214,11 +214,13 @@ def get_desc(self): """ def walk_cells(cell, out_dict): if cell.name not in out_dict: - out_dict[cell.name] = { - 'cells': {child['cell'].name: dict(offset=tuple(child['origin']), - angle=child['angle'] or 0) for child in cell.cells}, - **cell.desc - } + 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) diff --git a/gdshelpers/tests/test_chip.py b/gdshelpers/tests/test_chip.py index 2c74989..935bc7a 100644 --- a/gdshelpers/tests/test_chip.py +++ b/gdshelpers/tests/test_chip.py @@ -158,3 +158,4 @@ def test_desc(self): 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"])