Skip to content

Commit f998d96

Browse files
committed
Suggestion for new format for the desc data.
1 parent 3edb9a1 commit f998d96

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

gdshelpers/geometry/chip.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,29 @@ def get_dlw_data(self):
202202
return dlw_data
203203

204204
def get_desc(self):
205-
desc = self.desc.copy()
206-
desc['cells'] = {cell['cell'].name: dict(offset=tuple(cell['origin']), angle=cell['angle'] or 0,
207-
**cell['cell'].get_desc()) for cell in self.cells}
205+
"""
206+
Creates and returns a dictionary containing all the 'desc' data of this cell and all children.
207+
The returned dictionary contains two keys:
208+
209+
* `root`: The name of the root cell (the cell from which `get_desc` was called)
210+
* `cells`: Dictionary mapping cell names to the desc data of each cell as well as cell references to other cells
211+
(with origin and angle).
212+
213+
:return: Dictionary containing the `desc` data for this cell and all cells referenced by this cell
214+
"""
215+
def walk_cells(cell, out_dict):
216+
if cell.name not in out_dict:
217+
out_dict[cell.name] = {
218+
'cells': {child['cell'].name: dict(offset=tuple(child['origin']),
219+
angle=child['angle'] or 0) for child in cell.cells},
220+
**cell.desc
221+
}
222+
223+
for child in cell.cells:
224+
walk_cells(child['cell'], out_dict)
225+
226+
desc = dict(root=self.name, cells=dict())
227+
walk_cells(self, desc['cells'])
208228
return desc
209229

210230
def get_fractured_layer_dict(self, max_points=4000, max_line_points=4000):

0 commit comments

Comments
 (0)