gdsfactory / kfactory

gdsfactory with a klayout backend
https://gdsfactory.github.io/kfactory/
MIT License
29 stars 10 forks source link

recommended way of snapping non manhattan components #259

Closed joamatab closed 4 months ago

joamatab commented 4 months ago

What's the recommended way of snapping non manhattan components?

for example, this creates 1nm gaps

"""Snap bends together."""

from __future__ import annotations

import gdsfactory as gf

if __name__ == "__main__":
    # gf.CONF.enforce_ports_on_grid = False
    c = gf.Component("snap_bends")
    b1 = c << gf.c.bend_euler(angle=37, add_pins=False)
    b2 = c << gf.c.bend_euler(angle=37, add_pins=False)
    b2.connect("o1", b1.ports["o2"])
    print(b1["o2"].center)
    # c.flatten()
    c.show()
sebastian-goeldi commented 4 months ago

For non-manhattan cells (basically any cell you don't want snapped until you finished a circuit) you need to use virtual cells. A bend (non-90°) is affected by this.

E.g. this test does almost exactly what you want (test_virtual.py):

def test_virtual_cell_insert(
    LAYER: kf.LayerEnum, straight: kf.KCell, wg_enc: kf.LayerEnclosure
) -> None:
    c = kf.KCell()

    vc = kf.VKCell("test_virtual_insert")

    e_bend = kf.cells.virtual.euler.virtual_bend_euler(
        width=0.5,
        radius=10,
        layer=LAYER.WG,
        angle=25,
        enclosure=wg_enc,
    )
    e1 = vc << e_bend
    e2 = vc << e_bend
    e3 = vc << e_bend
    e4 = vc << e_bend
    _s = kf.cells.virtual.straight.straight(
        width=0.5, length=10, layer=LAYER.WG, enclosure=wg_enc
    )
    s = vc << _s

    s.connect("o1", e1, "o2")

    e2.connect("o1", s, "o2")
    e3.connect("o1", e2, "o2")
    e4.connect("o2", e3, "o2")
    s2 = vc << straight
    s2.connect("o1", e4, "o1")

    vi = kf.VInstance(vc)
    vi.insert_into(c)

    c.show()