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
// Checking a circuit for mistakes that still simulate but rarely mean what
// was intended: inputs left open (they read 0), parts that drive nothing,
// pins that share a name, and signals nothing sends or two parts send.
import { chipPins , shapeOf , type DefLookup } from './geometry'
import { KIND_NAMES } from './progress'
import type { CircuitNode , ComponentDef , Project } from './types'
export type IssueLevel = 'error' | 'warn' | 'info'
export interface Issue {
level : IssueLevel
text : string
/** Parts to show for it; the first one is centred. */
nodes : string [ ]
}
/** Parts whose open inputs are worth a warning (a cable bundle's spare wires are not). */
2026-10-21 12:38:59 +00:00
export const CHECKED_INPUTS = new Set ( [ 'nand' , 'chip' , 'output' , 'lamp' , 'hex' , 'pixel' , 'tag' , 'outpanel' ] )
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
function partName ( n : CircuitNode , get : DefLookup ) : string {
const own = ! n . autoLabel && n . label ? . trim ( )
const kind = n . kind === 'chip' ? ( ( n . chip && get ( n . chip ) ? . name ) ? ? 'Missing component' ) : ( KIND_NAMES [ n . kind ] ? ? n . kind )
if ( n . kind === 'tag' || n . kind === 'ref' ) return ` ${ kind } " ${ n . label ? . trim ( ) || '?' } " `
return own ? ` ${ kind } ${ own } ` : ( n . label ? . trim ( ) ? ` ${ kind } ${ n . label . trim ( ) } ` : kind )
}
/** Input pins of a part that have no wire. */
export function openInputs ( def : ComponentDef , n : CircuitNode , get : DefLookup ) : string [ ] {
if ( ! CHECKED_INPUTS . has ( n . kind ) ) return [ ]
const wired = new Set ( def . wires . filter ( w = > w . to . node === n . id ) . map ( w = > w . to . pin ) )
return shapeOf ( n , get ) . inputs . filter ( p = > ! p . bus && ! wired . has ( p . key ) ) . map ( p = > p . key )
}
export function checkCircuit ( def : ComponentDef , get : DefLookup ) : Issue [ ] {
const issues : Issue [ ] = [ ]
const fed = new Set ( def . wires . map ( w = > ` ${ w . from . node } : ${ w . from . pin } ` ) )
const name = ( n : CircuitNode ) = > partName ( n , get )
for ( const n of def . nodes ) {
if ( n . kind === 'chip' && ( ! n . chip || ! get ( n . chip ) ) ) {
issues . push ( { level : 'error' , text : 'A placed component no longer exists' , nodes : [ n . id ] } )
continue
}
const open = openInputs ( def , n , get )
if ( open . length ) {
const shape = shapeOf ( n , get )
const labels = open . map ( k = > shape . inputs . find ( p = > p . key === k ) ? . label || k )
const all = open . length === shape . inputs . length
const text =
n . kind === 'chip' || n . kind === 'nand' || n . kind === 'hex'
? ` ${ name ( n ) } : ${ all ? 'no input connected' : ` ${ labels . join ( ', ' ) } not connected ` } (reads 0) `
: ` ${ name ( n ) } : nothing connected `
issues . push ( { level : 'warn' , text , nodes : [ n . id ] } )
}
if ( n . kind === 'split' && ! def . wires . some ( w = > w . to . node === n . id ) ) issues . push ( { level : 'warn' , text : 'Cable split without a cable' , nodes : [ n . id ] } )
// Parts that drive nothing.
if ( ( n . kind === 'input' || n . kind === 'button' || n . kind === 'clock' || n . kind === 'nand' ) && ! fed . has ( ` ${ n . id } :q ` ) ) {
issues . push ( { level : 'info' , text : n.kind === 'nand' ? 'NAND gate: its output goes nowhere' : ` ${ name ( n ) } : goes nowhere ` , nodes : [ n . id ] } )
}
if ( n . kind === 'chip' && n . chip ) {
const outs = chipPins ( get ( n . chip ) ! ) . outputs
if ( outs . length && ! outs . some ( p = > fed . has ( ` ${ n . id } : ${ p . key } ` ) ) ) issues . push ( { level : 'info' , text : ` ${ name ( n ) } : none of its outputs is used ` , nodes : [ n . id ] } )
}
}
// Pins of the same name can't be told apart from outside.
for ( const kind of [ 'input' , 'output' ] as const ) {
const by = new Map < string , CircuitNode [ ] > ( )
for ( const n of def . nodes ) {
const l = n . kind === kind ? n . label ? . trim ( ) : ''
if ( l ) by . set ( l . toLowerCase ( ) , [ . . . ( by . get ( l . toLowerCase ( ) ) ? ? [ ] ) , n ] )
}
for ( const list of by . values ( ) ) {
if ( list . length > 1 ) issues . push ( { level : 'warn' , text : ` ${ list . length } ${ kind } pins are called ${ list [ 0 ] ! . label ! . trim ( ) } ` , nodes : list.map ( n = > n . id ) } )
}
}
// Signals: sent once, used somewhere.
const tags = new Map < string , CircuitNode [ ] > ( )
const refs = new Map < string , CircuitNode [ ] > ( )
for ( const n of def . nodes ) {
const l = n . label ? . trim ( ) ? ? ''
if ( n . kind === 'tag' ) tags . set ( l , [ . . . ( tags . get ( l ) ? ? [ ] ) , n ] )
if ( n . kind === 'ref' ) refs . set ( l , [ . . . ( refs . get ( l ) ? ? [ ] ) , n ] )
}
for ( const [ l , list ] of tags ) {
if ( ! l ) issues . push ( { level : 'warn' , text : 'A "Send signal" has no name' , nodes : list.map ( n = > n . id ) } )
else if ( list . length > 1 ) issues . push ( { level : 'error' , text : ` Signal " ${ l } " is sent by ${ list . length } parts: they drive it against each other ` , nodes : list.map ( n = > n . id ) } )
else if ( ! refs . has ( l ) ) issues . push ( { level : 'info' , text : ` Signal " ${ l } " is sent but not used ` , nodes : list.map ( n = > n . id ) } )
}
for ( const [ l , list ] of refs ) {
if ( ! tags . has ( l ) ) issues . push ( { level : 'error' , text : l ? ` Nothing sends signal " ${ l } " (reads 0) ` : 'A "Use signal" has no name' , nodes : list.map ( n = > n . id ) } )
}
const rank : Record < IssueLevel , number > = { error : 0 , warn : 1 , info : 2 }
return issues . sort ( ( a , b ) = > rank [ a . level ] - rank [ b . level ] )
}
/ * *
* Components made in this project that no other circuit places . Some are
* circuits you work in directly ; the rest can go . The examples are left out .
* /
export function unusedComponents ( project : Project ) : ComponentDef [ ] {
const used = new Set < string > ( )
for ( const d of project . components ) for ( const n of d . nodes ) if ( n . kind === 'chip' && n . chip && n . chip !== d . id ) used . add ( n . chip )
return project . components . filter ( d = > ! used . has ( d . id ) && ! d . id . startsWith ( 'ex-' ) && ! d . challenge )
}