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
|
|
|
// Automatic names. Copies and new parts continue a series (D0, D1, D2;
|
|
|
|
|
// A, B, C), and a switch, lamp or pin without a name of its own takes the
|
|
|
|
|
// name of the component pin it is wired to.
|
|
|
|
|
|
|
|
|
|
import type { DefLookup } from './geometry'
|
|
|
|
|
import type { CircuitNode, ComponentDef, NodeKind } from './types'
|
|
|
|
|
|
|
|
|
|
const SERIES = /^(.*?)(\d+)$/
|
|
|
|
|
const LETTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
|
|
|
|
|
|
|
|
|
/** Kinds whose labels share one set of names, so D0 the input and D0 the output can both exist. */
|
|
|
|
|
export function labelSpace(kind: NodeKind): string | null {
|
|
|
|
|
if (kind === 'input' || kind === 'button' || kind === 'clock' || kind === 'panel') return 'in'
|
|
|
|
|
if (kind === 'output' || kind === 'lamp' || kind === 'hex') return 'out'
|
|
|
|
|
if (kind === 'chip') return 'chip'
|
A Loxone-style working aids: named signals, inverted inputs, a project check, values on cables, search, printable sheets; wire ends move by dragging
- Send signal / Use signal: name a signal (CLK, RESET) once and use it anywhere in the circuit without a wire; selecting one lights up all of them, a use with no sender shows dashed
- Inverted inputs: Alt + click an input (or the menu/settings) puts a bubble on it; it reads the signal inverted through one NAND, counted in every transistor total
- Check (Circuit tab): open inputs, parts that drive nothing, duplicate pin names, unsent or doubly sent signals, loops that never settle; click one to show it. Open inputs get an orange marker on the canvas. Components no other circuit uses are listed with a delete
- Cables show the number they carry (= 13 · 0x0D); hovering a wire tells where it runs and its value
- Ctrl+F finds parts, signals, panel rows, notes and components in every circuit, with where each component is used
- Ctrl+P prints the circuit as a sheet with a title block on white paper (or save as PDF); also as an SVG file
- + and − under a selected gate change its number of inputs; swaps keep bubbles in place
- Drag a wire by its end to move that end to another pin; drop a dragged wire on another wire to tap its signal or feed what it fed
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:26:59 +00:00
|
|
|
if (kind === 'tag') return 'signal'
|
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 null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function usedLabels(def: ComponentDef, space: string, except?: Set<string>): Set<string> {
|
|
|
|
|
const used = new Set<string>()
|
|
|
|
|
for (const n of def.nodes) {
|
|
|
|
|
if (except?.has(n.id) || labelSpace(n.kind) !== space) continue
|
|
|
|
|
const l = n.label?.trim()
|
|
|
|
|
if (l) used.add(l)
|
|
|
|
|
}
|
|
|
|
|
return used
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The next free name after `label` in its series: D0 → D1 (D07 → D08), and a
|
|
|
|
|
* single capital letter → the next free letter. Null for names without a series.
|
|
|
|
|
*/
|
|
|
|
|
export function nextInSeries(label: string, used: Set<string>): string | null {
|
|
|
|
|
const m = SERIES.exec(label)
|
|
|
|
|
if (m) {
|
|
|
|
|
const [, stem, digits] = m
|
|
|
|
|
for (let i = Number(digits) + 1; ; i++) {
|
|
|
|
|
const next = `${stem}${String(i).padStart(digits!.length, '0')}`
|
|
|
|
|
if (!used.has(next)) return next
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const at = label.length === 1 ? LETTERS.indexOf(label) : -1
|
|
|
|
|
if (at >= 0) {
|
|
|
|
|
for (const c of LETTERS.slice(at + 1)) if (!used.has(c)) return c
|
|
|
|
|
}
|
|
|
|
|
return null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** `base` itself when free, else a numbered variant (Cin → Cin2, D0 → D0_2). */
|
|
|
|
|
export function uniqueLabel(base: string, used: Set<string>): string {
|
|
|
|
|
if (!used.has(base)) return base
|
|
|
|
|
const sep = /\d$/.test(base) ? '_' : ''
|
|
|
|
|
for (let i = 2; ; i++) if (!used.has(`${base}${sep}${i}`)) return `${base}${sep}${i}`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Renames pasted parts so their series continue: copying D0..D3 next to
|
|
|
|
|
* themselves gives D4..D7. Names without a series stay as they are.
|
|
|
|
|
*/
|
|
|
|
|
export function continueSeries(def: ComponentDef, pasted: CircuitNode[]) {
|
|
|
|
|
const ids = new Set(pasted.map(n => n.id))
|
|
|
|
|
const order = (n: CircuitNode) => Number(SERIES.exec(n.label?.trim() ?? '')?.[2] ?? Infinity)
|
|
|
|
|
const list = pasted.filter(n => labelSpace(n.kind) && n.label?.trim()).sort((a, b) => order(a) - order(b) || a.y - b.y || a.x - b.x)
|
|
|
|
|
const used = new Map<string, Set<string>>()
|
|
|
|
|
for (const n of list) {
|
|
|
|
|
const space = labelSpace(n.kind)!
|
|
|
|
|
if (!used.has(space)) used.set(space, usedLabels(def, space, ids))
|
|
|
|
|
const taken = used.get(space)!
|
|
|
|
|
const label = n.label!.trim()
|
|
|
|
|
const next = taken.has(label) ? nextInSeries(label, taken) : label
|
|
|
|
|
if (next) n.label = next
|
|
|
|
|
taken.add(n.label!)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Name of a component pin as its inside calls it, without the in1/out1 fallback. */
|
|
|
|
|
export function pinName(node: CircuitNode, pin: string, get: DefLookup): string | undefined {
|
|
|
|
|
if (node.kind === 'panel') {
|
|
|
|
|
const row = node.rows?.find(r => r.id === pin)
|
|
|
|
|
return row?.label?.trim() || row?.name?.trim() || undefined
|
|
|
|
|
}
|
2026-10-21 09:51:45 +00:00
|
|
|
// A wire of a cable carries the name of its signal (the cable pin itself has none).
|
|
|
|
|
if (node.kind === 'bundle' || node.kind === 'split') return /^b\d+$/.test(pin) ? node.names?.[Number(pin.slice(1))]?.trim() || undefined : undefined
|
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 (node.kind !== 'chip' || !node.chip) return undefined
|
|
|
|
|
const def = get(node.chip)
|
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
|
|
|
// A pin made from a panel row: panel:row.
|
|
|
|
|
const at = pin.indexOf(':')
|
|
|
|
|
if (at > 0) {
|
|
|
|
|
const row = def?.nodes.find(n => n.id === pin.slice(0, at))?.rows?.find(r => r.id === pin.slice(at + 1))
|
|
|
|
|
return row?.label?.trim() || row?.name?.trim() || undefined
|
|
|
|
|
}
|
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 def?.nodes.find(n => n.id === pin)?.label?.trim() || undefined
|
|
|
|
|
}
|
|
|
|
|
|
A Loxone-style working aids: named signals, inverted inputs, a project check, values on cables, search, printable sheets; wire ends move by dragging
- Send signal / Use signal: name a signal (CLK, RESET) once and use it anywhere in the circuit without a wire; selecting one lights up all of them, a use with no sender shows dashed
- Inverted inputs: Alt + click an input (or the menu/settings) puts a bubble on it; it reads the signal inverted through one NAND, counted in every transistor total
- Check (Circuit tab): open inputs, parts that drive nothing, duplicate pin names, unsent or doubly sent signals, loops that never settle; click one to show it. Open inputs get an orange marker on the canvas. Components no other circuit uses are listed with a delete
- Cables show the number they carry (= 13 · 0x0D); hovering a wire tells where it runs and its value
- Ctrl+F finds parts, signals, panel rows, notes and components in every circuit, with where each component is used
- Ctrl+P prints the circuit as a sheet with a title block on white paper (or save as PDF); also as an SVG file
- + and − under a selected gate change its number of inputs; swaps keep bubbles in place
- Drag a wire by its end to move that end to another pin; drop a dragged wire on another wire to tap its signal or feed what it fed
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-21 11:26:59 +00:00
|
|
|
const ADOPTERS = new Set<NodeKind>(['input', 'button', 'output', 'lamp', 'tag'])
|
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
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* After a new wire: a switch, button, output pin or lamp that has no name
|
|
|
|
|
* of its own (or only an automatic one) takes the name of the component pin
|
|
|
|
|
* at the other end, as long as this is its only connection. A panel row
|
|
|
|
|
* without a name does the same. Returns true if a name changed.
|
|
|
|
|
*/
|
|
|
|
|
export function adoptName(def: ComponentDef, node: CircuitNode, pin: string, other: CircuitNode, otherPin: string, get: DefLookup): boolean {
|
|
|
|
|
const name = pinName(other, otherPin, get)
|
|
|
|
|
if (!name) return false
|
|
|
|
|
const links = def.wires.filter(w => (w.from.node === node.id && w.from.pin === pin) || w.to.node === node.id).length
|
|
|
|
|
if (links !== 1) return false
|
|
|
|
|
if (node.kind === 'panel') {
|
|
|
|
|
const row = node.rows?.find(r => r.id === pin)
|
|
|
|
|
if (!row || row.label?.trim() || row.name === name) return false
|
|
|
|
|
row.name = name
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
if (!ADOPTERS.has(node.kind) || (node.label?.trim() && !node.autoLabel)) return false
|
|
|
|
|
const label = uniqueLabel(name, usedLabels(def, labelSpace(node.kind)!, new Set([node.id])))
|
|
|
|
|
if (node.label === label) return false
|
|
|
|
|
node.label = label
|
|
|
|
|
node.autoLabel = true
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Label for a new input or output pin: continues the series of the last one placed, else the next free letter. */
|
|
|
|
|
export function newPinLabel(def: ComponentDef, kind: 'input' | 'output'): string {
|
|
|
|
|
const used = usedLabels(def, labelSpace(kind)!)
|
|
|
|
|
const last = def.nodes.filter(n => n.kind === kind && n.label?.trim()).at(-1)?.label?.trim()
|
|
|
|
|
if (last && SERIES.test(last)) return nextInSeries(last, used)!
|
|
|
|
|
if (kind === 'input') {
|
|
|
|
|
for (const c of 'ABCDEFGHIJKLMNOPRSTUVWXYZ') if (!used.has(c)) return c
|
|
|
|
|
return uniqueLabel('I1', used)
|
|
|
|
|
}
|
|
|
|
|
if (!used.has('Q')) return 'Q'
|
|
|
|
|
for (let i = 1; ; i++) if (!used.has(`Q${i}`)) return `Q${i}`
|
|
|
|
|
}
|