"""The placement chain for cell references: at, move_by, rotate_by.

Every `c.Place(thing)` returns a chain. For references, `move_by` is a
parent-coordinate shift regardless of whether it precedes `rotate_by`.
"""
import lumicron as lm
import lumicron.pdks.elyon_demo.all as pdk


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

    pad = lm.CELL("PlacementPad")
    pad.add(lm.Rectangle(x_dim=60, y_dim=60, layer=pdk.LAYER.MTL1))

    # 1. Plain placement.
    first = c.add(pad)
    c.Place(first).at((0, 0))

    # 2. Place + rotate 30°. The rotation is about the reference center.
    second = c.add(pad)
    c.Place(second).at((150, 0)).rotate_by(30)

    # 3. Place + rotate 90° + nudge by (10, 5) µm.
    third = c.add(pad)
    c.Place(third).at((300, 0)).move_by(10, 5).rotate_by(90)
    return c


if __name__ == "__main__":
    PlacementChain().to_gds("placement_chain.gds")
