"""A frame, a ring, two pads — the canonical first chip.

Three concepts in one file:
    1. Multiple shapes on different layers.
    2. Placement at explicit coordinates.
    3. Hierarchy: this cell is reusable later.
"""
import lumicron as lm

OUTLINE = lm.LayerSpec(layer=63, datatype=0)
METAL = lm.LayerSpec(layer=4, datatype=0)
SILICON = lm.LayerSpec(layer=9, datatype=0)


@lm.pcell
def FirstChip():
    c = lm.CELL("FirstChip")

    # Die outline: 2 mm × 1 mm. Place anchored at the south-west corner
    # so the chip occupies (0, 0) → (2000, 1000).
    frame = lm.Rectangle(x_dim=2000, y_dim=1000, layer=OUTLINE)
    c.add(frame)
    c.Place(frame).using("SW").at((0, 0))

    # A silicon ring resonator, off-center.
    ring = lm.Ring(outer_radius=50, width=4, layer=SILICON)
    c.add(ring)
    c.Place(ring).at((600, 500))

    # Two metal pads. We capture each handle from c.add() so each call
    # to Place() targets a distinct instance — re-using the same `pad`
    # spec without capturing would just move the most-recent placement.
    pad = lm.Rectangle(x_dim=80, y_dim=80, layer=METAL)
    pad_top = c.add(pad)
    pad_bot = c.add(pad)
    c.Place(pad_top).at((1700, 750))
    c.Place(pad_bot).at((1700, 250))
    return c


if __name__ == "__main__":
    FirstChip().to_gds("first_chip.gds")
