"""Defining layers with design rules and a LayerTable.

Each `lpdk.Layer` carries a (layer, datatype) pair plus optional design
rules. A `LayerTable` collects them with attribute access — the lookup
your end-users will reach for as `pdk.LAYER.SILC`.
"""
import lumicron as lm
import lumicron_pdk as lpdk

LAYER = lpdk.LayerTable(
    OXID = lpdk.Layer(1, 0, color="#87ceeb"),
    SILC = lpdk.Layer(9, 0, color="#008000",
                    min_width=0.2, min_spacing=0.2, min_radius=5.0),
    SILN = lpdk.Layer(5, 0, color="#ff69b4",
                    min_width=0.4, min_spacing=0.3, min_radius=10.0),
    MTL1 = lpdk.Layer(4, 0, color="#ffd700",
                    min_width=1.0, min_spacing=1.0),
)


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

    # One swatch per layer to render the palette.
    for i, name in enumerate(["OXID", "SILC", "SILN", "MTL1"]):
        rect = lm.Rectangle(x_dim=120, y_dim=40, layer=getattr(LAYER, name))
        c.add(rect)
        c.Place(rect).at((i * 140, 0))
    return c


if __name__ == "__main__":
    LAYER.print_rules()
    LayerSwatch().to_gds("layer_swatch.gds")
