import kfactory as kf
from functools import partial
def add_label(c, text="label", layer=1, x=0, y=0):
trans = kf.kdb.DTrans(0, False, x, y)
c.shapes(layer).insert(kf.kdb.DText(text, trans))
return c
@kf.cell
def straight_with_label(add_label=None, width=1, length=10, layer=1):
c = kf.KCell()
c << kf.cells.straight.straight(width=width, length=length, layer=layer)
if add_label:
c = add_label(c)
return c
add_label1 = partial(add_label, text="label1", layer=2, x=0, y=0)
add_label2 = partial(add_label, text="label1", layer=2, x=0, y=0)
straight_with_label1 = partial(straight_with_label, add_label=add_label1)
straight_with_label2 = partial(straight_with_label, add_label=add_label2)
c = kf.KCell()
c << straight_with_label1()
c << straight_with_label2()
c.show()
will raise an error
RuntimeError: The following cell name(s) are used for more than one cell - can't write this layout:
straight_with_label_ALFadd_label_M__main___STlabel1_L2_X0_Y0_W1_L10_L1 in Cell.write
will raise an error
inspired by https://github.com/gdsfactory/gdsfactory/issues/3141