From 9db4255195fa14e0a3c429fe67bee42718be5c09 Mon Sep 17 00:00:00 2001 From: Caspar Date: Mon, 15 Apr 2024 11:13:16 +0300 Subject: [PATCH] Allow placing mask name labels on chips during mask export This commit makes it possible to add mask name labels to each chip as overlay during mask export, instead of coding the label inside the chip cell. To use this feature, set name_mask="_3" in the chip to add a 4-character placeholder, and set add_mask_name_to_chips=True in MaskSet to enable the label overlay. --- .../python/kqcircuits/masks/mask_layout.py | 22 +++++++++++++++---- .../python/kqcircuits/masks/mask_set.py | 7 +++++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/klayout_package/python/kqcircuits/masks/mask_layout.py b/klayout_package/python/kqcircuits/masks/mask_layout.py index 741f20fd3..a2ba87e9b 100644 --- a/klayout_package/python/kqcircuits/masks/mask_layout.py +++ b/klayout_package/python/kqcircuits/masks/mask_layout.py @@ -333,12 +333,13 @@ def insert_chips(self): for params in self.graphical_representation_inputs: self._add_chip_graphical_representation_layer(*params) - def insert_chip_copy_labels(self, labels_cell, layers): + def insert_chip_copy_labels(self, labels_cell, layers, mask_name_for_chip=None): """Inserts chip copy labels to all chips in this mask layout and its submasks Args: labels_cell: Cell to which the labels are inserted layers: list of layer names (without face_ids) where the labels are produced + mask_name_for_chip: mask name to place on each chip, or None (default) to not add mask names to the chip. """ # find labels_cell for this mask and each submask @@ -401,7 +402,8 @@ def insert_chip_copy_labels(self, labels_cell, layers): # update position label into chips_dict chips_dict[(x, y)] = (chip_name, _, bbox, dtrans, position_label, mask_layout) used_position_labels.add(position_label) - bbox_x1 = bbox.left if (bool(dtrans.is_mirror()) ^ bool(self.mirror_labels)) else bbox.right + total_mirror_label = bool(dtrans.is_mirror()) ^ bool(self.mirror_labels) + bbox_x1, bbox_x2 = (bbox.left, bbox.right) if total_mirror_label else (bbox.right, bbox.left) produce_label( labels_cell_2, position_label, @@ -413,9 +415,21 @@ def insert_chip_copy_labels(self, labels_cell, layers): mask_layout.face()["ground_grid_avoidance"], mirror=self.mirror_labels, ) - bbox_x2 = bbox.right if dtrans.is_mirror() else bbox.left + if mask_name_for_chip is not None: + produce_label( + labels_cell_2, + mask_name_for_chip, + dtrans * (pya.DPoint(bbox_x2, bbox.top)), + LabelOrigin.TOPLEFT, + mask_layout.dice_width, + mask_layout.text_margin, + [mask_layout.face()[layer] for layer in layers], + mask_layout.face()["ground_grid_avoidance"], + mirror=self.mirror_labels, + ) + bbox_xr = bbox.right if dtrans.is_mirror() else bbox.left self.graphical_representation_inputs.append( - (chip_name, dtrans * (pya.DPoint(bbox_x2, bbox.bottom)), position_label, bbox.width(), labels_cell_2) + (chip_name, dtrans * (pya.DPoint(bbox_xr, bbox.bottom)), position_label, bbox.width(), labels_cell_2) ) chip_box = pya.DBox(dtrans * bbox) diff --git a/klayout_package/python/kqcircuits/masks/mask_set.py b/klayout_package/python/kqcircuits/masks/mask_set.py index 5cbf4b8dd..f987fec7e 100644 --- a/klayout_package/python/kqcircuits/masks/mask_set.py +++ b/klayout_package/python/kqcircuits/masks/mask_set.py @@ -79,6 +79,7 @@ def __init__( export_drc=False, mask_export_layers=None, export_path=TMP_PATH, + add_mask_name_to_chips=False, ): self._time = {"INIT": perf_counter(), "ADD_CHIPS": 0, "BUILD": 0, "EXPORT": 0, "END": 0} @@ -95,6 +96,7 @@ def __init__( self.mask_layouts = [] self.mask_export_layers = mask_export_layers if mask_export_layers is not None else [] self.used_chips = {} + self.add_mask_name_to_chips = add_mask_name_to_chips self._extra_params = {} self._mask_set_dir = Path(export_path) / f"{name}_v{version}" @@ -327,12 +329,15 @@ def build(self, remove_guiding_shapes=True): self.mask_layouts = submask_layouts + [ml for ml in self.mask_layouts if ml not in mask_layouts_to_remove] # add chip copy labels for every mask layout + mask_name_for_chip = self.name if self.add_mask_name_to_chips else None for mask_layout in tqdm(self.mask_layouts, desc="Adding chip copy labels", bar_format=default_bar_format): labels_cell = mask_layout.layout.create_cell("ChipLabels") mask_layout.top_cell.insert(pya.DCellInstArray(labels_cell.cell_index(), pya.DTrans(pya.DVector(0, 0)))) if mask_layout not in submask_layouts: - chips_dict = mask_layout.insert_chip_copy_labels(labels_cell, chip_copy_label_layers) + chips_dict = mask_layout.insert_chip_copy_labels( + labels_cell, chip_copy_label_layers, mask_name_for_chip + ) mask_layout.overwrite_chips_by_position_label(chips_dict) # remove "$1" or similar unnecessary postfix from cell name mask_layout.top_cell.name = f"{mask_layout.name}"