Skip to content

Commit

Permalink
Merge pull request #521 from gdsfactory/fix-tiling-filling
Browse files Browse the repository at this point in the history
Fix fill_tiled segfault
  • Loading branch information
sebastian-goeldi authored Nov 21, 2024
2 parents 6aa4f52 + 6085bdb commit bd38e04
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions src/kfactory/utils/fill.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ def __init__(
self.remaining_polygons = remaining_polygons
self.multi = multi
self.origin = origin
self.filled_cells: list[kdb.Cell] = []
self.temp_ly = kdb.Layout()
self.temp_tc = self.temp_ly.create_cell(top_cell.name)
fc = kcl.layout.cell(fill_cell_index)
self.temp_fc = self.temp_ly.create_cell(fc.name)
self.temp_fc_ind = self.temp_fc.cell_index()
self.temp_fc.copy_shapes(fc)
self.temp_ly.start_changes()

def put(
self,
Expand All @@ -51,14 +59,12 @@ def put(
) -> None:
"""Called by the TilingProcessor."""
if self.multi:
self.top_cell.fill_region_multi(
self.temp_tc.fill_region_multi(
region=region,
fill_cell_index=self.fill_cell_index,
fill_cell_index=self.temp_fc_ind,
fc_bbox=self.fc_bbox,
row_step=self.row_step,
column_step=self.column_step,
origin=self.origin,
remaining_parts=None,
fill_margin=kdb.Vector(
self.row_step.x - self.fc_bbox.width(),
self.column_step.y - self.fc_bbox.height(),
Expand All @@ -67,9 +73,9 @@ def put(
glue_box=tile,
)
else:
self.top_cell.fill_region(
self.temp_tc.fill_region(
region=region,
fill_cell_index=self.fill_cell_index,
fill_cell_index=self.temp_fc_ind,
fc_bbox=self.fc_bbox,
row_step=self.row_step,
column_step=self.column_step,
Expand All @@ -80,6 +86,14 @@ def put(
glue_box=tile,
)

def insert_fill(self) -> None:
"""Insert fill cell into the regions."""
self.temp_ly.end_changes()
for inst in self.temp_tc.each_inst():
cell_inst_array = inst.cell_inst
cell_inst_array.cell_index = self.fill_cell_index
self.top_cell.insert(cell_inst_array)


def fill_tiled(
c: KCell,
Expand Down Expand Up @@ -177,17 +191,18 @@ def fill_tiled(
else:
_col_step = c.kcl.to_dbu(col_step)
fc_bbox = fill_cell.bbox()
operator = FillOperator(
c.kcl,
c,
fill_cell.cell_index(),
fc_bbox=fc_bbox,
row_step=_row_step,
column_step=_col_step,
origin=c.bbox().p1,
)
tp.output(
"to_fill",
FillOperator(
c.kcl,
c,
fill_cell.cell_index(),
fc_bbox=fc_bbox,
row_step=_row_step,
column_step=_col_step,
origin=c.bbox().p1,
),
operator,
)

if layer_names or region_names:
Expand Down Expand Up @@ -255,6 +270,7 @@ def fill_tiled(
)
logger.debug("fill string: '{}'", queue_str)
tp.execute(f"Fill {c.name}")
logger.info("done with filling {}", c.name)
logger.info("done with calculating fill regions for {}", c.name)
operator.insert_fill()
finally:
c.kcl.end_changes()

0 comments on commit bd38e04

Please sign in to comment.