2026-10-21 12:38:59 +00:00
|
|
|
// Panels: an input panel is a column of switches, buttons and clocks, an
|
|
|
|
|
// output panel a column of lamps. A panel can be wired like any other part,
|
|
|
|
|
// or docked to a component: an input panel on its left gets a row per free
|
|
|
|
|
// input, an output panel on its right a row per output. A docked panel moves
|
|
|
|
|
// with its component and follows it when the component gains or loses pins.
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
|
2026-10-23 10:59:16 +00:00
|
|
|
import { chipPins, panelOffsets, rowPin, shapeOf, type DefLookup } from './geometry'
|
2026-10-21 12:38:59 +00:00
|
|
|
import { pinName } from './labels'
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
import { lookup, uid } from './ops'
|
|
|
|
|
import type { CircuitNode, ComponentDef, PanelRow, Project } from './types'
|
|
|
|
|
|
|
|
|
|
/** Free space between a docked panel and its component, in grid units. */
|
|
|
|
|
const DOCK_GAP = 3
|
|
|
|
|
|
|
|
|
|
export function newPanelRows(count = 4): PanelRow[] {
|
|
|
|
|
return Array.from({ length: count }, () => ({ id: uid('r'), type: 'switch' as const }))
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-21 12:38:59 +00:00
|
|
|
export const isPanel = (n: CircuitNode) => n.kind === 'panel' || n.kind === 'outpanel'
|
|
|
|
|
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
/** Panels docked to one of the given chip nodes. */
|
|
|
|
|
export function dockedPanels(def: ComponentDef, chipIds: Set<string>): CircuitNode[] {
|
2026-10-21 12:38:59 +00:00
|
|
|
return def.nodes.filter(n => isPanel(n) && n.attach && chipIds.has(n.attach))
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface ChipInput {
|
|
|
|
|
key: string
|
|
|
|
|
label: string
|
|
|
|
|
dy: number
|
|
|
|
|
}
|
|
|
|
|
|
A ports on top of the box, split into lines to wire by hand
On a component's box every connector port now sits at the very top of its
side, above the single pins, in auto and hand-drawn boxes alike. A port
can be split on one placed component (its settings or right click: Split
… into lines): right below the socket the box then gets a pin per line,
named after the line, so lines can be wired by hand without an adapter.
Lines going into the component are inputs, lines coming out outputs, each
facing out of its side; a bar in the type's colour ties them to the
socket. A cable still plugs into the socket at the same time. Dropping a
single wire on a socket (or clicking one while connecting) splits the
port and takes the first free line that runs that way. Join … lines
takes the line pins and their wires away again, as one undo step.
A line wired by hand joins the same net the cable's line reaches inside;
a wire and a cable on one line both drive it, and the check says so.
Line pins are left out of the open-input warning, docked panels and
bubbles; docked panels no longer get a row for a port's socket either.
Saved as an optional list on the placed component (splitPorts); without
it a box only has its ports moved to the top.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:08:27 +00:00
|
|
|
/**
|
|
|
|
|
* The pins of a chip a panel docks to: its inputs for an input panel, its
|
|
|
|
|
* outputs for an output panel. Port sockets and the lines of split ports are
|
|
|
|
|
* left alone: a cable feeds those.
|
|
|
|
|
*/
|
2026-10-21 12:38:59 +00:00
|
|
|
function chipInputs(chip: CircuitNode, get: DefLookup, side: 'in' | 'out' = 'in'): ChipInput[] | null {
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
const child = chip.kind === 'chip' && chip.chip ? get(chip.chip) : undefined
|
|
|
|
|
if (!child) return null
|
2026-10-21 12:38:59 +00:00
|
|
|
const pins = chipPins(child)
|
|
|
|
|
const labels = new Map((side === 'in' ? pins.inputs : pins.outputs).map(p => [p.key, p.label]))
|
|
|
|
|
const shape = shapeOf(chip, get)
|
A ports on top of the box, split into lines to wire by hand
On a component's box every connector port now sits at the very top of its
side, above the single pins, in auto and hand-drawn boxes alike. A port
can be split on one placed component (its settings or right click: Split
… into lines): right below the socket the box then gets a pin per line,
named after the line, so lines can be wired by hand without an adapter.
Lines going into the component are inputs, lines coming out outputs, each
facing out of its side; a bar in the type's colour ties them to the
socket. A cable still plugs into the socket at the same time. Dropping a
single wire on a socket (or clicking one while connecting) splits the
port and takes the first free line that runs that way. Join … lines
takes the line pins and their wires away again, as one undo step.
A line wired by hand joins the same net the cable's line reaches inside;
a wire and a cable on one line both drive it, and the check says so.
Line pins are left out of the open-input warning, docked panels and
bubbles; docked panels no longer get a row for a port's socket either.
Saved as an optional list on the placed component (splitPorts); without
it a box only has its ports moved to the top.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-26 17:08:27 +00:00
|
|
|
return (side === 'in' ? shape.inputs : shape.outputs).filter(p => !p.bus && !p.port).map(p => ({ key: p.key, label: labels.get(p.key) ?? p.label, dy: p.dy }))
|
2026-10-21 12:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const sideOf = (panel: CircuitNode) => (panel.kind === 'outpanel' ? 'out' : 'in')
|
|
|
|
|
|
|
|
|
|
/** A wire between a docked panel's row and its chip's pin, the right way round. */
|
|
|
|
|
function dockWire(panel: CircuitNode, chipId: string, key: string) {
|
|
|
|
|
return panel.kind === 'outpanel'
|
|
|
|
|
? { id: uid('w'), from: { node: chipId, pin: key }, to: { node: panel.id, pin: key } }
|
|
|
|
|
: { id: uid('w'), from: { node: panel.id, pin: key }, to: { node: chipId, pin: key } }
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Lines the rows up with the chip's pins and names them after the pins. */
|
|
|
|
|
function layout(panel: CircuitNode, pins: ChipInput[]) {
|
|
|
|
|
const byKey = new Map(pins.map(p => [p.key, p]))
|
|
|
|
|
const order = new Map(pins.map((p, i) => [p.key, i]))
|
|
|
|
|
const rows = (panel.rows ?? []).filter(r => byKey.has(r.id)).sort((a, b) => order.get(a.id)! - order.get(b.id)!)
|
|
|
|
|
const top = rows.length ? byKey.get(rows[0]!.id)!.dy : 0
|
|
|
|
|
for (const r of rows) {
|
|
|
|
|
const p = byKey.get(r.id)!
|
|
|
|
|
r.dy = p.dy - top
|
|
|
|
|
r.name = p.label
|
|
|
|
|
}
|
|
|
|
|
panel.rows = rows
|
|
|
|
|
return top
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-10-21 12:38:59 +00:00
|
|
|
* Docks a new panel to a placed component: an input panel on its left with
|
|
|
|
|
* a switch for every input that is not wired yet, or an output panel on its
|
|
|
|
|
* right with a lamp for every output. Returns the panel, or null when there
|
|
|
|
|
* is nothing to show.
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
*/
|
2026-10-21 12:38:59 +00:00
|
|
|
export function attachPanel(project: Project, def: ComponentDef, chipId: string, side: 'in' | 'out' = 'in'): CircuitNode | null {
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
const get = lookup(project)
|
|
|
|
|
const chip = def.nodes.find(n => n.id === chipId)
|
2026-10-21 12:38:59 +00:00
|
|
|
const pins = chip && chipInputs(chip, get, side)
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
if (!chip || !pins) return null
|
2026-10-21 12:38:59 +00:00
|
|
|
// Inputs take one wire; outputs can feed a lamp as well as anything else.
|
|
|
|
|
const wired = side === 'in' ? new Set(def.wires.filter(w => w.to.node === chipId).map(w => w.to.pin)) : new Set<string>()
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
const free = pins.filter(p => !wired.has(p.key))
|
|
|
|
|
if (!free.length) return null
|
|
|
|
|
const panel: CircuitNode = {
|
|
|
|
|
id: uid('n'),
|
2026-10-21 12:38:59 +00:00
|
|
|
kind: side === 'in' ? 'panel' : 'outpanel',
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
x: 0,
|
|
|
|
|
y: 0,
|
|
|
|
|
attach: chipId,
|
|
|
|
|
rows: free.map(p => ({ id: p.key, type: 'switch' })),
|
|
|
|
|
}
|
|
|
|
|
if (free.length < pins.length) panel.skip = pins.filter(p => wired.has(p.key)).map(p => p.key)
|
|
|
|
|
const top = layout(panel, pins)
|
2026-10-21 12:38:59 +00:00
|
|
|
const chipBody = shapeOf(chip, get).body
|
|
|
|
|
panel.x = side === 'in' ? chip.x - DOCK_GAP - shapeOf(panel, get).body.w : chip.x + chipBody.x + chipBody.w + DOCK_GAP
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
panel.y = chip.y + top
|
|
|
|
|
def.nodes.push(panel)
|
2026-10-21 12:38:59 +00:00
|
|
|
for (const r of panel.rows!) def.wires.push(dockWire(panel, chipId, r.id))
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
return panel
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Keeps docked panels in step with their components: rows for pins that are
|
|
|
|
|
* gone are dropped, new free pins get a switch, and rows stay lined up with
|
|
|
|
|
* the pins. A panel whose component was removed is undocked. Runs on every
|
|
|
|
|
* structural change; wires to dropped rows are cleaned up afterwards.
|
|
|
|
|
*/
|
|
|
|
|
export function syncPanels(project: Project) {
|
|
|
|
|
const get = lookup(project)
|
|
|
|
|
for (const def of project.components) {
|
2026-10-21 12:38:59 +00:00
|
|
|
nameFreeRows(def, get)
|
|
|
|
|
if (!def.nodes.some(n => isPanel(n) && n.attach)) continue
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
const nodes = new Map(def.nodes.map(n => [n.id, n]))
|
|
|
|
|
for (const panel of def.nodes) {
|
2026-10-21 12:38:59 +00:00
|
|
|
if (!isPanel(panel) || !panel.attach) continue
|
|
|
|
|
const side = sideOf(panel)
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
const chip = nodes.get(panel.attach)
|
2026-10-21 12:38:59 +00:00
|
|
|
const pins = chip && chipInputs(chip, get, side)
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
if (!chip || !pins) {
|
|
|
|
|
delete panel.attach
|
|
|
|
|
delete panel.skip
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
const keys = new Set(pins.map(p => p.key))
|
|
|
|
|
const rows = panel.rows ?? []
|
|
|
|
|
const skip = (panel.skip ?? []).filter(k => keys.has(k))
|
|
|
|
|
const known = new Set([...rows.map(r => r.id), ...skip])
|
2026-10-21 12:38:59 +00:00
|
|
|
const wired = side === 'in' ? new Set(def.wires.filter(w => w.to.node === chip.id).map(w => w.to.pin)) : new Set<string>()
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
for (const p of pins) {
|
|
|
|
|
if (known.has(p.key)) continue
|
|
|
|
|
if (wired.has(p.key)) skip.push(p.key)
|
|
|
|
|
else {
|
|
|
|
|
rows.push({ id: p.key, type: 'switch' })
|
2026-10-21 12:38:59 +00:00
|
|
|
def.wires.push(dockWire(panel, chip.id, p.key))
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
panel.rows = rows
|
|
|
|
|
if (skip.length) panel.skip = skip
|
|
|
|
|
else delete panel.skip
|
|
|
|
|
const top = layout(panel, pins)
|
|
|
|
|
// Keep the first row on its pin, wherever the panel was moved sideways.
|
|
|
|
|
if (panel.rows.length) panel.y = chip.y + top
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-21 12:38:59 +00:00
|
|
|
/**
|
|
|
|
|
* Rows of free panels without a name of their own take the name of the pin
|
|
|
|
|
* they are wired to: an output panel's row the one that feeds it, an input
|
|
|
|
|
* panel's row the one it drives.
|
|
|
|
|
*/
|
|
|
|
|
function nameFreeRows(def: ComponentDef, get: DefLookup) {
|
|
|
|
|
const panels = def.nodes.filter(n => isPanel(n) && !n.attach && n.rows?.some(r => !r.label?.trim()))
|
|
|
|
|
if (!panels.length) return
|
|
|
|
|
const nodes = new Map(def.nodes.map(n => [n.id, n]))
|
|
|
|
|
for (const p of panels) {
|
|
|
|
|
for (const r of p.rows!) {
|
|
|
|
|
if (r.label?.trim()) continue
|
|
|
|
|
const w = p.kind === 'outpanel' ? def.wires.find(x => x.to.node === p.id && x.to.pin === r.id) : def.wires.find(x => x.from.node === p.id && x.from.pin === r.id)
|
|
|
|
|
const other = w && (p.kind === 'outpanel' ? w.from : w.to)
|
|
|
|
|
const node = other && nodes.get(other.node)
|
|
|
|
|
const name = node && (pinName(node, other.pin, get) ?? (['input', 'button', 'clock', 'output', 'lamp'].includes(node.kind) ? node.label?.trim() : undefined))
|
|
|
|
|
if (name) r.name = name
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
/** Removes one row; on a docked panel that pin is left alone from then on. */
|
|
|
|
|
export function removeRow(def: ComponentDef, panel: CircuitNode, rowId: string) {
|
|
|
|
|
panel.rows = (panel.rows ?? []).filter(r => r.id !== rowId)
|
2026-10-21 12:38:59 +00:00
|
|
|
def.wires = def.wires.filter(w => !(w.from.node === panel.id && w.from.pin === rowId) && !(w.to.node === panel.id && w.to.pin === rowId))
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
if (panel.attach) panel.skip = [...new Set([...(panel.skip ?? []), rowId])]
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-23 10:59:16 +00:00
|
|
|
/**
|
|
|
|
|
* A new row at place `index` in a free panel's order (0: above the first,
|
|
|
|
|
* rows.length: below the last), the same kind as its neighbour. It takes the
|
|
|
|
|
* place of the row it goes above; that row and the ones below move down one,
|
|
|
|
|
* keeping the gaps between them.
|
|
|
|
|
*/
|
|
|
|
|
export function insertPanelRow(panel: CircuitNode, index: number): PanelRow {
|
|
|
|
|
const rows = panel.rows ?? []
|
|
|
|
|
const at = panelOffsets(rows)
|
|
|
|
|
const i = Math.max(0, Math.min(Math.round(index), rows.length))
|
|
|
|
|
const row = newPanelRows(1)[0]!
|
|
|
|
|
row.type = rows[i]?.type ?? rows[i - 1]?.type ?? 'switch'
|
|
|
|
|
const place = i < rows.length ? at[i]! : at.length ? at[at.length - 1]! + 1 : 0
|
|
|
|
|
rows.forEach((r, k) => (r.dy = k < i ? at[k]! : at[k]! + 1))
|
|
|
|
|
row.dy = place
|
|
|
|
|
rows.splice(i, 0, row)
|
|
|
|
|
panel.rows = rows
|
|
|
|
|
return row
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Moves a row of a free panel from one place in the order to another. The
|
|
|
|
|
* places stay where they are (gaps too); the rows trade them, and each row
|
|
|
|
|
* keeps its wires. False when nothing moved.
|
|
|
|
|
*/
|
|
|
|
|
export function movePanelRow(panel: CircuitNode, from: number, to: number): boolean {
|
|
|
|
|
const rows = panel.rows ?? []
|
|
|
|
|
if (from === to || from < 0 || to < 0 || from >= rows.length || to >= rows.length) return false
|
|
|
|
|
const at = panelOffsets(rows)
|
|
|
|
|
const [r] = rows.splice(from, 1)
|
|
|
|
|
rows.splice(to, 0, r!)
|
|
|
|
|
rows.forEach((x, k) => (x.dy = at[k]!))
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
A input panels, automatic names, one-by-one wiring, tidy routing, truth table export
- Input panel part: rows of switches, buttons and clocks. "Attach input
panel" docks one to a component with a row per free input; it moves
with the component and follows its pins.
- Copies and new pins continue name series (D0 -> D1, A -> B); unnamed
switches, lamps and pins take the name of the component pin they are
wired to.
- Connecting: target pins are ringed, dropping on a part uses its next
free pin, click-then-click works, and "Connect one by one" (W) wires a
selection's pins in turn.
- Tidy wiring option and "Tidy all wires": sorted, evenly spaced columns
per gap, one trunk per signal, fewer crossings.
- Truth table full screen, CSV download, copy as Markdown, current row
highlighted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-20 17:17:25 +00:00
|
|
|
/** A docked panel's pins drive the component; undocking keeps rows, wires and position. */
|
|
|
|
|
export function detachPanel(panel: CircuitNode) {
|
|
|
|
|
delete panel.attach
|
|
|
|
|
delete panel.skip
|
|
|
|
|
}
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Joins panels into one: the top one keeps its rows, the others' rows follow
|
R Packed panels, Tab adds rows, flyouts at the pointer, steady top bar
Combining switches, buttons, lamps or outputs into a panel, and merging
panels, puts the rows right under each other (space 0). Tab in the last
row's name of a panel, or the last line of a connector type, adds the
next one once it is filled in. The bottom bar's lists open centred above
the pointer. The top bar keeps the width it has with both panels open,
centred, so it no longer grows and shrinks with the panels.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 20:47:38 +00:00
|
|
|
* below in order, packed without gaps, with their wires. The joined panel
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
* is free (no longer docked). Returns it with the pin keys that changed
|
|
|
|
|
* (old → new), so circuits that place this one can keep their wires; null
|
|
|
|
|
* for fewer than two panels.
|
|
|
|
|
*/
|
|
|
|
|
export function mergePanels(def: ComponentDef, ids: string[]): { panel: CircuitNode; renamed: Map<string, string> } | null {
|
2026-10-21 12:38:59 +00:00
|
|
|
const sel = def.nodes.filter(n => isPanel(n) && ids.includes(n.id))
|
|
|
|
|
// Input panels join input panels, output panels output panels.
|
|
|
|
|
const kind = sel[0]?.kind
|
|
|
|
|
const panels = sel.filter(n => n.kind === kind).sort((a, b) => a.y - b.y || a.x - b.x)
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
if (panels.length < 2) return null
|
|
|
|
|
const [target, ...rest] = panels as [CircuitNode, ...CircuitNode[]]
|
|
|
|
|
const rows = target.rows ?? []
|
|
|
|
|
const used = new Set(rows.map(r => r.id))
|
|
|
|
|
const renamed = new Map<string, string>()
|
|
|
|
|
for (const p of rest) {
|
|
|
|
|
const theirs = p.rows ?? []
|
R Packed panels, Tab adds rows, flyouts at the pointer, steady top bar
Combining switches, buttons, lamps or outputs into a panel, and merging
panels, puts the rows right under each other (space 0). Tab in the last
row's name of a panel, or the last line of a connector type, adds the
next one once it is filled in. The bottom bar's lists open centred above
the pointer. The top bar keeps the width it has with both panels open,
centred, so it no longer grows and shrinks with the panels.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 20:47:38 +00:00
|
|
|
theirs.forEach(r => {
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
const id = used.has(r.id) ? uid('r') : r.id
|
|
|
|
|
used.add(id)
|
2026-10-21 12:38:59 +00:00
|
|
|
for (const w of def.wires) {
|
|
|
|
|
if (w.from.node === p.id && w.from.pin === r.id) w.from = { node: target.id, pin: id }
|
|
|
|
|
if (w.to.node === p.id && w.to.pin === r.id) w.to = { node: target.id, pin: id }
|
|
|
|
|
}
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
renamed.set(rowPin(p.id, r.id), rowPin(target.id, id))
|
R Packed panels, Tab adds rows, flyouts at the pointer, steady top bar
Combining switches, buttons, lamps or outputs into a panel, and merging
panels, puts the rows right under each other (space 0). Tab in the last
row's name of a panel, or the last line of a connector type, adds the
next one once it is filled in. The bottom bar's lists open centred above
the pointer. The top bar keeps the width it has with both panels open,
centred, so it no longer grows and shrinks with the panels.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 20:47:38 +00:00
|
|
|
rows.push({ ...r, id })
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
})
|
|
|
|
|
}
|
R Packed panels, Tab adds rows, flyouts at the pointer, steady top bar
Combining switches, buttons, lamps or outputs into a panel, and merging
panels, puts the rows right under each other (space 0). Tab in the last
row's name of a panel, or the last line of a connector type, adds the
next one once it is filled in. The bottom bar's lists open centred above
the pointer. The top bar keeps the width it has with both panels open,
centred, so it no longer grows and shrinks with the panels.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 20:47:38 +00:00
|
|
|
// One row under the other, no space between.
|
|
|
|
|
for (const r of rows) delete r.dy
|
BF input panels are component inputs, cable ends plug in more reliably; A merge panels, hex pass-through, design a component's box
- Inside a component, the switch and button rows of its input panels are now input pins (in order with the other inputs, named after the rows); "Rows are component inputs" can be turned off per panel to keep the old fixed switches
- Select input panels, Merge: one panel with all rows, spacing and wires kept; circuits that place this one keep their wires
- Cable ends plug in more often: bundling orders the wires by the part a side runs to, an end with only some wires on a part still plugs, an end placed by hand next to the pins plugs, and dragging an end near its part shows green rings and plugs it on drop
- Hex displays pass their four bits on (outputs on the right), so they can sit in the middle of a bus
- Design the box: move lamps, displays, the screen and the name on a component's box, draw lines, boxes, circles and text in six colours, size it, leave things off; every placed copy shows it
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:49:29 +00:00
|
|
|
target.rows = rows
|
|
|
|
|
delete target.attach
|
|
|
|
|
delete target.skip
|
|
|
|
|
const gone = new Set(rest.map(p => p.id))
|
|
|
|
|
def.nodes = def.nodes.filter(n => !gone.has(n.id))
|
|
|
|
|
def.wires = def.wires.filter(w => !gone.has(w.from.node) && !gone.has(w.to.node))
|
|
|
|
|
return { panel: target, renamed }
|
|
|
|
|
}
|
2026-10-21 12:38:59 +00:00
|
|
|
|
|
|
|
|
const SOURCES = new Set(['input', 'button', 'clock'])
|
|
|
|
|
const SINKS = new Set(['output', 'lamp'])
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Turns separate switches, buttons and clocks into one input panel, or
|
|
|
|
|
* output pins and lamps into one output panel: a row each, top to bottom,
|
R Packed panels, Tab adds rows, flyouts at the pointer, steady top bar
Combining switches, buttons, lamps or outputs into a panel, and merging
panels, puts the rows right under each other (space 0). Tab in the last
row's name of a panel, or the last line of a connector type, adds the
next one once it is filled in. The bottom bar's lists open centred above
the pointer. The top bar keeps the width it has with both panels open,
centred, so it no longer grows and shrinks with the panels.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 20:47:38 +00:00
|
|
|
* with their names, settings and wires, packed without gaps. Returns the panel and the pin keys that changed
|
2026-10-21 12:38:59 +00:00
|
|
|
* (old → new) for circuits that place this one; null when the parts are
|
|
|
|
|
* not all of one side or fewer than two.
|
|
|
|
|
*/
|
|
|
|
|
export function combineIntoPanel(def: ComponentDef, ids: string[], get: DefLookup): { panel: CircuitNode; renamed: Map<string, string> } | null {
|
|
|
|
|
const sel = def.nodes.filter(n => ids.includes(n.id)).sort((a, b) => a.y - b.y || a.x - b.x)
|
|
|
|
|
const out = sel.length > 0 && sel.every(n => SINKS.has(n.kind))
|
|
|
|
|
if (sel.length < 2 || !(out || sel.every(n => SOURCES.has(n.kind)))) return null
|
|
|
|
|
const panel: CircuitNode = { id: uid('n'), kind: out ? 'outpanel' : 'panel', x: 0, y: sel[0]!.y, rows: [] }
|
|
|
|
|
// Pins stay pins; switches, buttons, clocks and lamps that were not pins stay inside.
|
|
|
|
|
const pinKind = out ? 'output' : 'input'
|
|
|
|
|
if (!sel.some(n => n.kind === pinKind)) panel.inner = true
|
|
|
|
|
const renamed = new Map<string, string>()
|
|
|
|
|
for (const n of sel) {
|
R Packed panels, Tab adds rows, flyouts at the pointer, steady top bar
Combining switches, buttons, lamps or outputs into a panel, and merging
panels, puts the rows right under each other (space 0). Tab in the last
row's name of a panel, or the last line of a connector type, adds the
next one once it is filled in. The bottom bar's lists open centred above
the pointer. The top bar keeps the width it has with both panels open,
centred, so it no longer grows and shrinks with the panels.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-22 20:47:38 +00:00
|
|
|
const row: PanelRow = { id: n.id, type: n.kind === 'button' ? 'button' : n.kind === 'clock' ? 'clock' : 'switch' }
|
2026-10-21 12:38:59 +00:00
|
|
|
const label = n.label?.trim()
|
|
|
|
|
if (label && !n.autoLabel) row.label = label
|
|
|
|
|
else if (label) row.name = label
|
|
|
|
|
if (n.on) row.on = true
|
|
|
|
|
if (n.key) row.key = n.key
|
|
|
|
|
if (n.hz) row.hz = n.hz
|
|
|
|
|
if (n.color) row.color = n.color
|
|
|
|
|
panel.rows!.push(row)
|
|
|
|
|
if (n.kind === pinKind) renamed.set(n.id, rowPin(panel.id, n.id))
|
|
|
|
|
for (const w of def.wires) {
|
|
|
|
|
// A lamp's or output pin's pass-through leaves the row on the right, as before.
|
|
|
|
|
if (w.from.node === n.id) w.from = { node: panel.id, pin: n.id }
|
|
|
|
|
if (w.to.node === n.id) w.to = { node: panel.id, pin: n.id }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Where the parts' pins were: switches' outputs on the panel's right edge, lamps' inputs on its left.
|
|
|
|
|
const w = shapeOf(panel, get).body.w
|
|
|
|
|
panel.x = out ? Math.min(...sel.map(n => n.x)) : Math.max(...sel.map(n => n.x + (shapeOf(n, get).outputs[0]?.dx ?? 2))) - w
|
|
|
|
|
const gone = new Set(sel.map(n => n.id))
|
|
|
|
|
def.nodes = [...def.nodes.filter(n => !gone.has(n.id)), panel]
|
|
|
|
|
return { panel, renamed }
|
|
|
|
|
}
|