mindchainai's picture
Deploy PCB AI Studio: FastAPI + React studio at /, Gradio KiCad check at /gradio
8604d66 verified
Raw History Blame Contribute Delete
4.5 kB
import { CheckCircle2, CircleDashed, Search } from 'lucide-react'
import { useMemo, useState } from 'react'
import { netStats, unroutedNets } from '../lib/geometry'
import type { Design } from '../types/pcb'
import { Badge, EmptyNote } from './ui'
interface Props {
design: Design
highlightNet: string | null
onHighlight: (net: string | null) => void
onHover: (net: string | null) => void
}
export function NetPanel({ design, highlightNet, onHighlight, onHover }: Props) {
const [q, setQ] = useState('')
const [filter, setFilter] = useState<'all' | 'routed' | 'unrouted'>('all')
const stats = useMemo(() => netStats(design), [design])
const unrouted = useMemo(() => unroutedNets(design), [design])
const nets = design.nets.filter((n) => {
if (q && !n.name.toLowerCase().includes(q.toLowerCase())) return false
if (filter === 'routed') return !unrouted.has(n.name)
if (filter === 'unrouted') return unrouted.has(n.name)
return true
})
const sel = design.nets.find((n) => n.name === highlightNet)
return (
<div className="flex h-full min-h-0 flex-col">
<div className="space-y-2 p-2">
<div className="relative">
<Search size={13} className="absolute left-2.5 top-1/2 -translate-y-1/2 text-ink-400" />
<input className="field pl-8" placeholder={`Search ${design.nets.length} nets`} value={q}
onChange={(e) => setQ(e.target.value)} aria-label="Search nets" />
</div>
<div className="flex gap-1" role="tablist">
{(['all', 'routed', 'unrouted'] as const).map((f) => (
<button key={f} type="button" role="tab" aria-selected={filter === f} onClick={() => setFilter(f)}
className={`flex-1 rounded border py-1 text-[11.5px] capitalize ${filter === f ? 'border-accent bg-accent/10 text-accent' : 'border-ink-600 text-ink-300 hover:bg-ink-800'}`}>
{f}{f === 'unrouted' ? ` (${unrouted.size})` : ''}
</button>
))}
</div>
</div>
{sel && (
<div className="mx-2 mb-2 rounded-lg border border-ink-600 bg-ink-800/70 p-2.5 text-[12px]">
<div className="flex items-center gap-2">
<span className="font-mono text-[14px] font-semibold text-white">{sel.name}</span>
<Badge tone={sel.netclass === 'ground' ? 'neutral' : sel.netclass === 'power' ? 'warn' : 'accent'}>{sel.netclass}</Badge>
{unrouted.has(sel.name) ? <Badge tone="warn">unrouted</Badge> : <Badge tone="ok">routed</Badge>}
</div>
<div className="mt-1 text-ink-300">
{sel.pins.length} pins · {(stats.get(sel.name)?.length ?? 0).toFixed(1)} mm · {stats.get(sel.name)?.vias ?? 0} vias
</div>
<div className="mt-1.5 flex flex-wrap gap-1">
{sel.pins.map((p) => (
<span key={`${p.ref}.${p.pad}`} className="rounded bg-ink-700 px-1.5 py-0.5 font-mono text-[11px] text-ink-200">{p.ref}.{p.pad}</span>
))}
</div>
</div>
)}
<ul className="min-h-0 flex-1 overflow-y-auto px-1 pb-2" onMouseLeave={() => onHover(null)} aria-label="Nets">
{nets.map((n) => {
const st = stats.get(n.name)
const open = unrouted.has(n.name)
return (
<li key={n.name}>
<button type="button" onMouseEnter={() => onHover(n.name)}
onClick={() => onHighlight(highlightNet === n.name ? null : n.name)}
className={`flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-[12.5px] hover:bg-ink-800 ${highlightNet === n.name ? 'bg-accent/10 ring-1 ring-accent/40' : ''}`}>
{open ? <CircleDashed size={13} className="shrink-0 text-warn" /> : <CheckCircle2 size={13} className="shrink-0 text-ok" />}
<span className="min-w-0 flex-1 truncate font-mono text-ink-100">{n.name}</span>
<span className="shrink-0 text-[11px] text-ink-400">{n.pins.length}p</span>
<span className="w-14 shrink-0 text-right font-mono text-[11px] text-ink-400">{st ? `${st.length.toFixed(1)}` : '—'}</span>
</button>
</li>
)
})}
{!nets.length && <EmptyNote title="No nets match" />}
</ul>
<div className="border-t border-ink-700 px-3 py-1.5 text-[11px] text-ink-400">Click a net to highlight it; hover to preview.</div>
</div>
)
}