Skip to content
Edit this page

ictdesigntools.cabling.connectors

Connectors and the ports of panels, as parameterised drawing components.

connectors() reads the footprints in data/connectors.toml (RJ45 keystone, LC, SC, SN, MPO, MMC and F, each with its NetBox port type). connector_component is one port's face as an engine Component, so every port of that type is one SVG <use> target and one DXF block. Ports are NetBox ports: one per connector (each LC of a duplex pair is its own port), with the fibers behind it as positions; connectors that share a cutout (two LC in a duplex adapter, two MMC in an SC footprint) are drawn in their adapter_component. panel_layout places ports on a panel face in rows and groups, and patch_panel builds a whole panel face from its parameters: panels with the same parameters share one component, and a 24-port and a 48-port panel come from the same function.

>>> [p.n for p in panel_layout(24, "8p8c", 1)][:3], len(panel_layout(48, "8p8c", 2))
([1, 2, 3], 48)
>>> patch_panel(24, "8p8c") is patch_panel(24, "8p8c")
True

connectors cached

connectors() -> dict[str, Connector]

The connector footprints, by slug.

Source code in src/ictdesigntools/cabling/connectors.py
@cache
def connectors() -> dict[str, Connector]:
    """The connector footprints, by slug."""
    return {
        r["slug"]: Connector(
            r["slug"],
            r["name"],
            r["netbox_type"],
            r["shape"],
            r["width_mm"],
            r["height_mm"],
            r.get("positions", 1),
            r.get("per_adapter", 1),
            r["source"],
        )  # fmt: skip
        for r in rows("connectors", "connector")
    }

connector_for

connector_for(
    netbox_type: str, slug: str = ""
) -> Connector | None

The footprint for a NetBox port type: slug when given (needed for types NetBox has no slug of their own for, such as MMC under other), else the one footprint of that type; None when there is none.

Source code in src/ictdesigntools/cabling/connectors.py
def connector_for(netbox_type: str, slug: str = "") -> Connector | None:
    """The footprint for a NetBox port type: ``slug`` when given (needed for types NetBox has
    no slug of their own for, such as MMC under ``other``), else the one footprint of that type;
    None when there is none."""
    if slug:
        return connector(slug)
    if netbox_type == "other":  # NetBox's catch-all says nothing about the footprint
        return None
    found = [c for c in connectors().values() if c.netbox_type == netbox_type]
    return found[0] if len(found) == 1 else None

adapter_component cached

adapter_component(slug: str) -> Component

The body of an adapter that holds several ports (an LC duplex adapter), centred.

Source code in src/ictdesigntools/cabling/connectors.py
@cache
def adapter_component(slug: str) -> Component:
    """The body of an adapter that holds several ports (an LC duplex adapter), centred."""
    c = connector(slug)
    w, h = c.width_mm, c.height_mm
    return Component(f"adapter-{slug}", (Rect(-w / 2, -h / 2, w, h, rx=0.6, style="port"),),
                     title=f"{c.name} adapter")  # fmt: skip

connector_component cached

connector_component(slug: str) -> Component

One port's face, centred on (0, 0), in mm: the cutout and the opening inside it, or for a connector that shares an adapter, just its own opening (adapter_component draws the body once per adapter).

Source code in src/ictdesigntools/cabling/connectors.py
@cache
def connector_component(slug: str) -> Component:
    """One port's face, centred on (0, 0), in mm: the cutout and the opening inside it, or for
    a connector that shares an adapter, just its own opening (``adapter_component`` draws the
    body once per adapter)."""
    c = connector(slug)
    w, h = c.width_mm, c.height_mm
    if c.per_adapter > 1:
        oh, ow = h / c.per_adapter * 0.72, w * (0.62 if c.positions > 2 else 0.5)
        items = (Rect(-ow / 2, -oh / 2, ow, oh, rx=0.3, style="port-core"),)
    elif c.shape == "round":
        items = (Circle(0, 0, w / 2, style="port"), Circle(0, 0, w * 0.12, style="port-core"))
    elif slug == "8p8c":
        # The jack's opening, with the latch notch, inside the keystone.
        jw, jh = w * 0.78, h * 0.5
        items = (
            Rect(-w / 2, -h / 2, w, h, rx=0.8, style="port"),
            Rect(-jw / 2, -jh / 2 + h * 0.08, jw, jh, rx=0.4, style="port-core"),
            Rect(-w * 0.17, -jh / 2 + h * 0.08 - 1.4, w * 0.34, 1.6, style="port-core"),
        )
    else:
        # A simplex adapter: its body and the ferrule or MPO opening.
        ow = w * (0.6 if c.positions > 2 else 0.5)
        items = (Rect(-w / 2, -h / 2, w, h, rx=0.6, style="port"),
                 Rect(-ow / 2, -h * 0.2, ow, h * 0.4, rx=0.3, style="port-core"))  # fmt: skip
    return Component(f"connector-{slug}", items, title=c.name)

panel_layout

panel_layout(
    ports: int,
    slug: str,
    u_height: float = 1.0,
    rows_: int | None = None,
    group: int = 6,
    label_mm: float = 0.0,
    right_mm: float = 0.0,
) -> list[PortPlace]

Where ports connectors of type slug go on a panel u_height units high, in adapters of per_adapter ports (two LC to a duplex adapter, numbered top then bottom): adapters in rows_ rows (as few as fit when None), left to right and top to bottom, in groups of group adapters with a wider gap between groups, centred in the rack opening after label_mm kept free on its left and right_mm on its right. Raises ValueError when they do not fit.

Source code in src/ictdesigntools/cabling/connectors.py
def panel_layout(ports: int, slug: str, u_height: float = 1.0, rows_: int | None = None,
                 group: int = 6, label_mm: float = 0.0, right_mm: float = 0.0
                 ) -> list[PortPlace]:  # fmt: skip
    """Where ``ports`` connectors of type ``slug`` go on a panel ``u_height`` units high, in
    adapters of ``per_adapter`` ports (two LC to a duplex adapter, numbered top then bottom):
    adapters in ``rows_`` rows (as few as fit when None), left to right and top to bottom, in
    groups of ``group`` adapters with a wider gap between groups, centred in the rack opening after
    ``label_mm`` kept free on its left and ``right_mm`` on its right. Raises ValueError when
    they do not fit."""
    if ports < 1:
        raise ValueError("A panel needs at least one port.")
    c = connector(slug)
    ports_in = ports
    ports = math.ceil(ports / c.per_adapter)  # adapters, laid out below
    height = u_height * RACK_UNIT_MM
    x0 = (RACK_WIDTH_MM - OPENING_MM) / 2 + label_mm + 2.0
    room = OPENING_MM - label_mm - right_mm - 4.0

    def width(n: int, gap: float) -> float:
        groups = math.ceil(n / group) if group else 1
        return n * c.width_mm + (n - 1) * gap + (groups - 1) * GROUP_GAP_MM

    most_rows = max(1, int((height - 2.0) // (c.height_mm + 1.0)))
    if rows_ is None:
        fits = [r for r in range(1, most_rows + 1)
                if width(math.ceil(ports / r), MIN_GAP_MM) <= room]  # fmt: skip
        # As few rows as fit, preferring rows of whole groups (4 × 24 over 3 × 32).
        whole = [r for r in fits[:2] if group and ports % r == 0 and (ports // r) % group == 0]
        rows_ = (whole or fits or [most_rows + 1])[0]
    per_row = math.ceil(ports / rows_)
    if rows_ > most_rows or width(per_row, MIN_GAP_MM) > room:
        raise ValueError(f"{ports_in} {c.name} ports do not fit a {u_height:g}U panel face.")
    # Spread a row up to twice the minimum gap, then centre it.
    spare = room - width(per_row, MIN_GAP_MM)
    gap = MIN_GAP_MM + (min(spare / max(per_row - 1, 1), MIN_GAP_MM) if per_row > 1 else 0)
    used = width(per_row, gap)
    start = x0 + (room - used) / 2 + c.width_mm / 2
    pitch_y = height / rows_
    offsets = _offsets(c)
    out = []
    for n in range(ports_in):
        a, j = divmod(n, c.per_adapter)
        r, k = divmod(a, per_row)
        g = k // group if group else 0
        ax, ay = start + k * (c.width_mm + gap) + g * GROUP_GAP_MM, pitch_y * (r + 0.5)
        out.append(PortPlace(n + 1, ax, ay + offsets[j], a + 1, ax, ay))
    return out

adapters

adapters(
    places: list[PortPlace],
    slug: str,
    dx: float = 0.0,
    dy: float = 0.0,
) -> list

The adapter bodies for places (none when each port is its own cutout).

Source code in src/ictdesigntools/cabling/connectors.py
def adapters(places: list[PortPlace], slug: str, dx: float = 0.0, dy: float = 0.0) -> list:
    """The adapter bodies for ``places`` (none when each port is its own cutout)."""
    if connector(slug).per_adapter == 1:
        return []
    comp = adapter_component(slug)
    seen = dict.fromkeys((p.adapter, p.ax, p.ay) for p in places)
    return [Use(comp, translate(dx + ax, dy + ay)) for _, ax, ay in seen]

patch_panel cached

patch_panel(
    ports: int,
    slug: str,
    u_height: float = 1.0,
    rows_: int | None = None,
    numbers: bool = True,
) -> Component

A panel face built from its parameters: the faceplate, and each port as a placement of the connector's component, with port numbers above. Calls with the same parameters return the same component, so a page or a DXF file holds it once.

Source code in src/ictdesigntools/cabling/connectors.py
@cache
def patch_panel(ports: int, slug: str, u_height: float = 1.0, rows_: int | None = None,
                numbers: bool = True) -> Component:  # fmt: skip
    """A panel face built from its parameters: the faceplate, and each port as a placement of
    the connector's component, with port numbers above. Calls with the same parameters return
    the same component, so a page or a DXF file holds it once."""
    c = connector(slug)
    height = u_height * RACK_UNIT_MM
    items: list = [Rect(0, 0, RACK_WIDTH_MM, height, rx=1.0, style="panel")]
    places = panel_layout(ports, slug, u_height, rows_)
    items += adapters(places, slug)
    comp = connector_component(slug)
    for p in places:
        items.append(Use(comp, translate(p.x, p.y), title=f"Port {p.n}"))
        if numbers and p.y == min(q.y for q in places if q.adapter == p.adapter):
            label = str(p.n) if c.per_adapter == 1 else f"{p.n}–{p.n + c.per_adapter - 1}"
            items.append(Text(p.ax, p.ay - c.height_mm / 2 - 1.6, label, 2.2,
                              style="port-label"))  # fmt: skip
    rows_label = f", {rows_} rows" if rows_ else ""
    return Component(f"panel-{slug}-{ports}-{u_height:g}u{rows_label.replace(', ', '-')}",
                     tuple(items), title=f"{ports}-port {c.name} panel, {u_height:g}U")  # fmt: skip

panel_drawing

panel_drawing(
    ports: int,
    slug: str,
    u_height: float = 1.0,
    rows_: int | None = None,
) -> Drawing

A panel on its own, for a data sheet or a check of the layout.

Source code in src/ictdesigntools/cabling/connectors.py
def panel_drawing(ports: int, slug: str, u_height: float = 1.0, rows_: int | None = None
                  ) -> Drawing:  # fmt: skip
    """A panel on its own, for a data sheet or a check of the layout."""
    height = u_height * RACK_UNIT_MM
    d = Drawing(
        view=(-4, -4, RACK_WIDTH_MM + 8, height + 8),
        units="mm",
        stroke=0.3,
        title=f"{ports}-port {connector(slug).name} panel",
        styles=dict(PORT_STYLES),
    )
    d.add(Use(patch_panel(ports, slug, u_height, rows_)))
    return d