layerindex module#

Layer indexing and side definitions#

This module provides classes for representing board sides and layer sets for specifying which layers features apply to.

class Side(*values)[source]#

Bases: IntEnum

Board side enumeration.

Represents the top and bottom sides of a circuit board.

Top = 0#
Bottom = -1#
flip()[source]#

Return the opposite side. Top becomes Bottom, Bottom becomes Top.

class LayerSet(*layers: Layers)[source]#
class LayerSet(*, ranges: Sequence[tuple[int, int]] = ())

Set of board layers specified by ranges.

Defines which layers a feature or element applies to using layer index ranges.

Basic construction with individual layers:

>>> # Single layer
>>> top_layer = LayerSet(0)
>>> top_layer.ranges
[(0, 0)]
>>> # Multiple individual layers
>>> signal_layers = LayerSet(0, 2, 4)
>>> signal_layers.ranges
[(0, 0), (2, 2), (4, 4)]
>>> # From a sequence of layers
>>> power_layers = LayerSet([1, 3, 5])
>>> power_layers.ranges
[(1, 1), (3, 3), (5, 5)]

Range construction using class methods:

>>> # Range from start to end (exclusive)
>>> inner_layers = LayerSet.range(1, to=4)
>>> inner_layers.ranges
((1, 3),)
>>> # Range from start through end (inclusive)
>>> outer_layers = LayerSet.range(0, through=2)
>>> outer_layers.ranges
((0, 2),)
>>> # All layers
>>> all_layers = LayerSet.all()
>>> all_layers.ranges
((0, -1),)

Combining multiple LayerSet objects:

>>> # Combine different layer sets
>>> top_and_bottom = LayerSet(0, -1)
>>> inner_range = LayerSet.range(1, to=3)
>>> combined = LayerSet(top_and_bottom, inner_range)
>>> combined.ranges
[(0, 0), (-1, -1), (1, 2)]

Using with explicit ranges:

>>> # Direct range specification
>>> custom_ranges = LayerSet(ranges=[(0, 2), (4, 6)])
>>> custom_ranges.ranges
[(0, 2), (4, 6)]

Common use cases:

>>> # Keepout layers
>>> keepout = KeepOut(layers=LayerSet(1), pour=False, via=True, route=True)
Parameters:
ranges: Sequence[tuple[int, int]]#

Sequence of (start, end) layer index ranges.

invert()[source]#

Return a layer set with all layers inverted.

Return type:

LayerSet

classmethod range(start, *, to=None, through=None)[source]#

Create a layer set from a start and end layer.

Parameters:
  • start (int) – Starting layer index.

  • to (int | None) – Ending layer index (exclusive).

  • through (int | None) – Ending layer index (inclusive).

Return type:

LayerSet

Returns:

LayerSet covering the specified range.

classmethod all()[source]#

Create a layer set covering all layers.

Return type:

LayerSet

Returns:

LayerSet covering all layers from 0 to -1 (bottom).