BF jumps always on top of what they cross; R circuit commands in a menu on its name, the side panel only says what it is
A jump is drawn once more over every line, so a cable that arches over another is never hidden under it, whatever order they are drawn in. Cable labels sit on the longest stretch no other line crosses. The circuit's name in the top bar opens what can be done with it: tidy its wires or every circuit's, design its box, duplicate, delete, print, export SVG, publish as a puzzle. The This panel keeps what the circuit is: its health, its numbers (the transistors tile opens their breakdown), its truth table and how it looks as a part. Unused components are a tab of the Components list in the parts bar, with a delete button on each. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
24a62c3601
commit
b355939581
|
|
@ -5157,10 +5157,9 @@ button.tile:hover {
|
|||
|
||||
.part-tabs {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 2px;
|
||||
padding: 2px 2px 4px;
|
||||
overflow-x: auto;
|
||||
scrollbar-width: none;
|
||||
}
|
||||
|
||||
.part-tabs button {
|
||||
|
|
@ -5381,3 +5380,39 @@ button.tile:hover {
|
|||
-webkit-appearance: none;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* A jump drawn once more on top of what it crosses: only for looks. */
|
||||
.wire.jump path {
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.top-bar .bar-btn.here {
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.tile.active {
|
||||
border-color: var(--accent);
|
||||
}
|
||||
|
||||
.part-tabs .unused-tab {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.part-slot .pin-btn.drop-btn:hover {
|
||||
color: var(--danger);
|
||||
}
|
||||
|
||||
.part-slot .pin-btn.drop-btn.confirm {
|
||||
width: auto;
|
||||
gap: 3px;
|
||||
padding: 0 6px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
color: #fff;
|
||||
background: var(--danger);
|
||||
opacity: 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
// builder's: the mouse wheel scrolls it sideways.
|
||||
import { shortCount } from '~/lib/logic/analyze'
|
||||
import { BASIC_GROUPS } from '~/composables/useParts'
|
||||
import { unusedComponents } from '~/lib/logic/check'
|
||||
import type { ComponentDef, NodeKind } from '~/lib/logic/types'
|
||||
|
||||
const ed = useEditor()
|
||||
|
|
@ -73,10 +74,22 @@ function page(dir: number) {
|
|||
|
||||
const placeable = (d: ComponentDef) => d.id !== ed.def.value.id && ed.canPlace(d.id)
|
||||
|
||||
/** Components placed nowhere (not the open one, Main, examples or challenges): a tab of their own, to clear out. */
|
||||
const UNUSED = 'unused'
|
||||
const unused = computed(() => unusedComponents(ed.project.value).filter(d => d.id !== ed.def.value.id && d.id !== ed.mainId.value))
|
||||
const confirmDrop = ref<string | null>(null)
|
||||
function drop(d: ComponentDef) {
|
||||
if (confirmDrop.value !== d.id) return (confirmDrop.value = d.id)
|
||||
confirmDrop.value = null
|
||||
ed.removeComponent(d.id)
|
||||
ed.notify(`Deleted "${d.name}" (Ctrl+Z brings it back)`)
|
||||
}
|
||||
|
||||
/** The component group shown; your own components first. */
|
||||
const compTab = ref('')
|
||||
const compGroup = computed(
|
||||
() =>
|
||||
(compTab.value === UNUSED && unused.value.length ? { name: 'Unused', defs: unused.value } : undefined) ??
|
||||
componentGroups.value.find(g => g.name === compTab.value) ??
|
||||
// Untouched: the first group with something that can go in here.
|
||||
componentGroups.value.find(g => g.defs.some(placeable)) ??
|
||||
|
|
@ -241,17 +254,28 @@ onBeforeUnmount(() => window.removeEventListener('keydown', onKey, true))
|
|||
|
||||
<!-- Components, by group -->
|
||||
<template v-else-if="open === 'components'">
|
||||
<div v-if="componentGroups.length > 1" class="part-tabs" role="tablist">
|
||||
<div v-if="componentGroups.length > 1 || unused.length" class="part-tabs" role="tablist">
|
||||
<button
|
||||
v-for="g in componentGroups"
|
||||
:key="g.name"
|
||||
role="tab"
|
||||
:aria-selected="compGroup?.name === g.name"
|
||||
:class="{ active: compGroup?.name === g.name }"
|
||||
:aria-selected="compGroup?.name === g.name && compTab !== UNUSED"
|
||||
:class="{ active: compGroup?.name === g.name && compTab !== UNUSED }"
|
||||
@click="compTab = g.name"
|
||||
>
|
||||
{{ g.name }} <span class="count">{{ g.defs.length }}</span>
|
||||
</button>
|
||||
<button
|
||||
v-if="unused.length"
|
||||
role="tab"
|
||||
class="unused-tab"
|
||||
:aria-selected="compTab === UNUSED"
|
||||
:class="{ active: compTab === UNUSED }"
|
||||
title="Placed in no other circuit: clear out what you no longer need"
|
||||
@click="compTab = UNUSED"
|
||||
>
|
||||
<Icon name="lucide:archive" class="size-3.5" /> Unused <span class="count">{{ unused.length }}</span>
|
||||
</button>
|
||||
</div>
|
||||
<p v-else class="flyout-head">{{ compGroup?.name ?? 'Components' }}</p>
|
||||
<div class="strip-wrap">
|
||||
|
|
@ -272,7 +296,18 @@ onBeforeUnmount(() => window.removeEventListener('keydown', onKey, true))
|
|||
<span v-if="d.id === ed.def.value.id" class="part-meta">editing</span>
|
||||
<span v-else-if="ed.transistors(d.id)" class="part-meta">{{ shortCount(ed.transistors(d.id)) }} transistors</span>
|
||||
</button>
|
||||
<button class="pin-btn" :class="{ on: isPinned('chip', d) }" :title="isPinned('chip', d) ? 'Unpin from the bar' : 'Pin to the bar'" @click="togglePin('chip', d)">
|
||||
<button
|
||||
v-if="compTab === UNUSED"
|
||||
class="pin-btn drop-btn"
|
||||
:class="{ confirm: confirmDrop === d.id }"
|
||||
:title="confirmDrop === d.id ? 'Click again to delete it' : 'Delete this component'"
|
||||
@click="drop(d)"
|
||||
@pointerleave="confirmDrop === d.id && (confirmDrop = null)"
|
||||
>
|
||||
<Icon name="lucide:trash-2" class="size-3.5" />
|
||||
<span v-if="confirmDrop === d.id">Delete?</span>
|
||||
</button>
|
||||
<button v-else class="pin-btn" :class="{ on: isPinned('chip', d) }" :title="isPinned('chip', d) ? 'Unpin from the bar' : 'Pin to the bar'" @click="togglePin('chip', d)">
|
||||
<Icon :name="isPinned('chip', d) ? 'lucide:pin-off' : 'lucide:pin'" class="size-3.5" />
|
||||
</button>
|
||||
<button v-if="d.id !== ed.def.value.id" class="pin-btn edit" title="Open it and edit inside (or double-click it on the canvas)" @click="ed.open(d.id), (open = null)">
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@ import { CHECKED_INPUTS } from '~/lib/logic/check'
|
|||
import { cableBits, GRID as G, pinKindOf, pinPos, routeWire, type Pt, type Shape } from '~/lib/logic/geometry'
|
||||
import type { CircuitNode, PanelRow, PinRef, Wire } from '~/lib/logic/types'
|
||||
import { branchCorners, branchTo, endGrip, moveCorner, moveSegment, nearEnd, routeTouchesBox, segmentAt, segmentDrag, splitDrag } from '~/lib/logic/wires'
|
||||
import { circuitRoutes, planHops } from '~/lib/logic/routing'
|
||||
import { circuitRoutes, crossingPoints, planHops } from '~/lib/logic/routing'
|
||||
import { seriesLinks, type Link } from '~/lib/logic/bulk'
|
||||
import { dropLinks, dropPins, fitStart, type DropPin } from '~/lib/logic/fit'
|
||||
import type { CanvasOps, MenuEntry } from '~/composables/useMenu'
|
||||
import { LANE, plugLayout, ribbon, RIBBON_MAX } from '~/lib/logic/cables'
|
||||
import { wirePath } from '~/lib/draw'
|
||||
import { wirePath, type HopSpan } from '~/lib/draw'
|
||||
import { downloadSheet, printSheet, sheetSvg } from '~/lib/sheet'
|
||||
import { inputCount } from '~/lib/logic/wide'
|
||||
import { pinName } from '~/lib/logic/labels'
|
||||
|
|
@ -49,22 +49,68 @@ interface Route {
|
|||
port?: { name: string; color?: string }
|
||||
/** It jumps over other lines somewhere. */
|
||||
hops?: boolean
|
||||
/** Each jump once more on its own, drawn on top of everything it crosses: the line, and a cable's lines. */
|
||||
patches?: { d: string; lanes: { i: number; d: string; color?: string }[] }[]
|
||||
}
|
||||
|
||||
/** The middle of a route's longest straight run, where a cable's label goes. */
|
||||
function midOfLongest(draw: Pt[]): Pt | undefined {
|
||||
/**
|
||||
* Short pieces of a route around each of its jumps, from a little before to
|
||||
* a little after, with the jump in them. Drawn over all other lines, a jump
|
||||
* always lies on top of what it crosses, whatever order the lines are in.
|
||||
*/
|
||||
function jumpPieces(pts: Pt[], hops: Map<number, HopSpan[]> | undefined, style: Parameters<typeof wirePath>[2]): { seg: number; from: number; to: number; hop: HopSpan }[] {
|
||||
const out: { seg: number; from: number; to: number; hop: HopSpan }[] = []
|
||||
for (const [seg, list] of hops ?? []) {
|
||||
const a = pts[seg]
|
||||
const b = pts[seg + 1]
|
||||
if (!a || !b || style === 'plain') continue
|
||||
const axis = a[1] === b[1] ? 0 : 1
|
||||
const lo = Math.min(a[axis], b[axis])
|
||||
const hi = Math.max(a[axis], b[axis])
|
||||
for (const hop of list) out.push({ seg, from: Math.max(lo, hop.lo - 0.3), to: Math.min(hi, hop.hi + 0.3), hop })
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
/** One piece of a polyline's segment (or of a lane beside it), drawn with its jump. */
|
||||
function piecePath(line: Pt[], p: { seg: number; from: number; to: number; hop: HopSpan }, style: Parameters<typeof wirePath>[2]): string {
|
||||
const a = line[p.seg]!
|
||||
const b = line[p.seg + 1]!
|
||||
const axis = a[1] === b[1] ? 0 : 1
|
||||
const forward = b[axis] > a[axis]
|
||||
const at = (v: number): Pt => (axis === 0 ? [v, a[1]] : [a[0], v])
|
||||
const [s, e] = forward ? [p.from, p.to] : [p.to, p.from]
|
||||
return wirePath([at(s), at(e)], new Map([[0, [p.hop]]]), style)
|
||||
}
|
||||
|
||||
/**
|
||||
* Where a cable's label goes: the middle of the longest straight stretch
|
||||
* that no other line crosses (keeping clear of the crossings on each side).
|
||||
*/
|
||||
function midOfLongest(draw: Pt[], busy: Pt[] = []): Pt | undefined {
|
||||
const CLEAR = 1.5
|
||||
let best = 0
|
||||
let at: Pt | undefined
|
||||
for (let i = 0; i < draw.length - 1; i++) {
|
||||
const [ax, ay] = draw[i]!
|
||||
const [bx, by] = draw[i + 1]!
|
||||
const len = Math.abs(bx - ax) + Math.abs(by - ay)
|
||||
if (len > best) {
|
||||
best = len
|
||||
at = [(ax + bx) / 2, (ay + by) / 2]
|
||||
const axis = ay === by ? 0 : 1
|
||||
const lo = Math.min(draw[i]![axis], draw[i + 1]![axis])
|
||||
const hi = Math.max(draw[i]![axis], draw[i + 1]![axis])
|
||||
const cuts = busy.filter(p => p[1 - axis] === draw[i]![1 - axis] && p[axis] > lo && p[axis] < hi).map(p => p[axis]).sort((p, q) => p - q)
|
||||
// Stretches between the crossings, each kept clear of them.
|
||||
const edges = [lo - CLEAR, ...cuts, hi + CLEAR]
|
||||
for (let k = 0; k < edges.length - 1; k++) {
|
||||
const from = Math.max(lo, edges[k]! + CLEAR)
|
||||
const to = Math.min(hi, edges[k + 1]! - CLEAR)
|
||||
if (to - from > best) {
|
||||
best = to - from
|
||||
const m = (from + to) / 2
|
||||
at = axis === 0 ? [m, ay] : [ax, m]
|
||||
}
|
||||
}
|
||||
}
|
||||
return at
|
||||
return at ?? (draw.length > 1 ? [(draw[0]![0] + draw[1]![0]) / 2, (draw[0]![1] + draw[1]![1]) / 2] : undefined)
|
||||
}
|
||||
|
||||
const toPath = (pts: Pt[]) => pts.map(([x, y], i) => `${i ? 'L' : 'M'}${x * G} ${y * G}`).join('')
|
||||
|
|
@ -85,6 +131,7 @@ const routes = computed<Route[]>(() => {
|
|||
const byId = new Map(def.value.wires.map(w => [w.id, w]))
|
||||
const routed = circuitRoutes(def.value, shapes.value, { tidy: !!ed.project.value.settings.tidy, widthOf: id => cablePx(byId.get(id)) })
|
||||
const hops = planHops(routed)
|
||||
const crossed = crossingPoints(routed)
|
||||
const style = ed.project.value.settings.crossing ?? 'bow'
|
||||
return routed.map((r, k) => {
|
||||
const wire = byId.get(r.id)!
|
||||
|
|
@ -96,19 +143,25 @@ const routes = computed<Route[]>(() => {
|
|||
const type = ed.getDef.value.conn?.(pin.conn)
|
||||
route.port = { name: type?.name ?? '?', color: type?.color }
|
||||
route.sleeve = Math.min(8, Math.max(2, type?.lines.length ?? 2)) * LANE * G + 3
|
||||
route.mark = midOfLongest(r.draw)
|
||||
route.mark = midOfLongest(r.draw, crossed.get(k))
|
||||
}
|
||||
if (from?.kind === 'bundle') {
|
||||
route.bits = cableBits(from)
|
||||
if (route.bits <= RIBBON_MAX) {
|
||||
// Each wire keeps the colour of the wire that runs into the bundle.
|
||||
const feed = new Map(def.value.wires.filter(w => w.to.node === from.id).map(w => [w.to.pin, w.color]))
|
||||
route.lanes = ribbon(r.draw, route.bits).map((lane, i) => ({ i, d: wirePath(lane, hops.get(k), style), color: feed.get(`b${i}`) }))
|
||||
const lanes = ribbon(r.draw, route.bits)
|
||||
route.lanes = lanes.map((lane, i) => ({ i, d: wirePath(lane, hops.get(k), style), color: feed.get(`b${i}`) }))
|
||||
route.patches = jumpPieces(r.draw, hops.get(k), style).map(p => ({
|
||||
d: piecePath(r.draw, p, style),
|
||||
lanes: lanes.map((lane, i) => ({ i, d: piecePath(lane, p, style), color: feed.get(`b${i}`) })),
|
||||
}))
|
||||
route.sleeve = route.bits * LANE * G + 3
|
||||
}
|
||||
// The width mark sits on the middle of the longest straight run.
|
||||
route.mark = midOfLongest(r.draw)
|
||||
route.mark = midOfLongest(r.draw, crossed.get(k))
|
||||
}
|
||||
route.patches ??= jumpPieces(r.draw, hops.get(k), style).map(p => ({ d: piecePath(r.draw, p, style), lanes: [] }))
|
||||
return route
|
||||
})
|
||||
})
|
||||
|
|
@ -1514,6 +1567,25 @@ defineExpose({ fit, zoomAt })
|
|||
</g>
|
||||
<title v-if="hoverWire === r.wire.id">{{ wireTip(r) }}</title>
|
||||
</g>
|
||||
<!-- Jumps once more on top: a line always lies over what it jumps -->
|
||||
<template v-for="r in routes" :key="`p${r.wire.id}`">
|
||||
<g v-if="r.patches?.length" class="wire jump" :class="wireClass(r)">
|
||||
<template v-for="(p, n) in r.patches" :key="n">
|
||||
<template v-if="r.lanes || r.port">
|
||||
<path :d="p.d" class="cable-sleeve" :style="{ strokeWidth: `${r.sleeve! + 3}px` }" />
|
||||
<path :d="p.d" class="cable-core" :style="{ strokeWidth: `${r.sleeve}px` }" />
|
||||
<path
|
||||
v-for="l in p.lanes"
|
||||
:key="l.i"
|
||||
:d="l.d"
|
||||
class="lane"
|
||||
:class="[l.color ? `c-${l.color}` : '', { on: ed.val(r.wire.from.node, `b${l.i}`) === 1 }]"
|
||||
/>
|
||||
</template>
|
||||
<path v-else :d="p.d" class="wire-line" />
|
||||
</template>
|
||||
</g>
|
||||
</template>
|
||||
<g v-for="(j, i) in junctions" :key="`j${i}`" class="wire" :class="[j.color ? `c-${j.color}` : '', { on: srcVal(j.src) === 1 }]">
|
||||
<circle :cx="j.x * G" :cy="j.y * G" r="3.2" class="junction" :data-junction="j.src" />
|
||||
</g>
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
<script setup lang="ts">
|
||||
// "This": the circuit you are in. Its name and health on top, four numbers,
|
||||
// then everything else folded away.
|
||||
import { shortCount, TRANSISTORS_PER_NAND } from '~/lib/logic/analyze'
|
||||
// "This": what the circuit you are in is. Its name and health on top, four
|
||||
// numbers (the transistors open their breakdown), its truth table and how it
|
||||
// looks as a part. Things to do with it are in the menu on its name in the
|
||||
// top bar; unused components are with the components in the parts bar.
|
||||
import { TRANSISTORS_PER_NAND } from '~/lib/logic/analyze'
|
||||
import { transistorBreakdown } from '~/lib/logic/bulk'
|
||||
import { chipPins } from '~/lib/logic/geometry'
|
||||
import { unusedComponents } from '~/lib/logic/check'
|
||||
import { usages } from '~/lib/logic/ops'
|
||||
import type { SymbolKind } from '~/lib/logic/types'
|
||||
|
||||
|
|
@ -53,11 +54,8 @@ const problems = computed(() => ed.issues.value.filter(i => i.level !== 'info'))
|
|||
const worst = computed<'error' | 'warn' | 'ok'>(() => (problems.value.some(i => i.level === 'error') ? 'error' : problems.value.length ? 'warn' : 'ok'))
|
||||
const shownIssues = computed(() => ed.issues.value.filter(i => showInfo.value || i.level !== 'info'))
|
||||
const infoCount = computed(() => ed.issues.value.filter(i => i.level === 'info').length)
|
||||
const unused = computed(() => unusedComponents(ed.project.value).filter(d => d.id !== def.value.id))
|
||||
const confirmRemove = ref<string | null>(null)
|
||||
|
||||
const confirmDelete = ref(false)
|
||||
watch(() => def.value.id, () => (confirmDelete.value = false))
|
||||
/** The transistors tile shows where they are. */
|
||||
const showCost = ref(false)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
@ -110,17 +108,36 @@ watch(() => def.value.id, () => (confirmDelete.value = false))
|
|||
<span class="tile-label">Outputs</span>
|
||||
<span class="tile-value">{{ pins.outputs.length }}</span>
|
||||
</button>
|
||||
<div class="tile" title="CMOS: 4 per NAND gate, at every depth">
|
||||
<button class="tile" :class="{ active: showCost }" :aria-expanded="showCost" title="CMOS: 4 per NAND gate, at every depth. Click for where they are" @click="showCost = !showCost">
|
||||
<span class="tile-label">Transistors</span>
|
||||
<span class="tile-value">{{ total.toLocaleString() }}</span>
|
||||
<span class="tile-note">{{ ed.circuitStats.value.nands.toLocaleString() }} NAND</span>
|
||||
</div>
|
||||
</button>
|
||||
<div class="tile" :title="ed.circuitStats.value.sequential ? 'It has feedback loops, so it can hold state' : 'Longest path from an input to an output'">
|
||||
<span class="tile-label">{{ ed.circuitStats.value.sequential ? 'Memory' : 'Delay' }}</span>
|
||||
<span class="tile-value">{{ ed.circuitStats.value.sequential ? 'Yes' : ed.circuitStats.value.delay }}</span>
|
||||
<span class="tile-note">{{ ed.circuitStats.value.sequential ? 'feedback loops' : 'gates deep' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<template v-if="showCost">
|
||||
<p v-if="!breakdown.length" class="hint mt-2">No gates here yet. Switches, lamps, displays and cables need no transistors.</p>
|
||||
<ul v-else class="cost-list mt-2">
|
||||
<li v-for="l in breakdown" :key="l.key" title="Select these parts" @click="ed.selectOnly(l.ids)">
|
||||
<span class="cost-name">
|
||||
<span class="truncate">{{ l.name }}</span>
|
||||
<span class="cost-each">{{ l.count }} × {{ l.each.toLocaleString() }}</span>
|
||||
</span>
|
||||
<span class="cost-total">{{ l.total.toLocaleString() }}</span>
|
||||
</li>
|
||||
<li class="cost-sum">
|
||||
<span class="cost-name">
|
||||
<span>Total</span>
|
||||
<span class="cost-each">{{ (total / TRANSISTORS_PER_NAND).toLocaleString() }} NAND × 4</span>
|
||||
</span>
|
||||
<span class="cost-total">{{ total.toLocaleString() }}</span>
|
||||
</li>
|
||||
</ul>
|
||||
</template>
|
||||
</section>
|
||||
|
||||
<section class="folds">
|
||||
|
|
@ -154,73 +171,5 @@ watch(() => def.value.id, () => (confirmDelete.value = false))
|
|||
<Icon name="lucide:pen-tool" class="size-4" /> Design the box
|
||||
</button>
|
||||
</EditorFold>
|
||||
|
||||
<EditorFold id="circuit-transistors" title="Transistors" :note="total ? shortCount(total) : ''">
|
||||
<p v-if="!breakdown.length" class="hint">No gates here yet. Switches, lamps, displays and cables need no transistors.</p>
|
||||
<ul v-else class="cost-list">
|
||||
<li v-for="l in breakdown" :key="l.key" title="Select these parts" @click="ed.selectOnly(l.ids)">
|
||||
<span class="cost-name">
|
||||
<span class="truncate">{{ l.name }}</span>
|
||||
<span class="cost-each">{{ l.count }} × {{ l.each.toLocaleString() }}</span>
|
||||
</span>
|
||||
<span class="cost-total">{{ l.total.toLocaleString() }}</span>
|
||||
</li>
|
||||
<li class="cost-sum">
|
||||
<span class="cost-name">
|
||||
<span>Total</span>
|
||||
<span class="cost-each">{{ (total / TRANSISTORS_PER_NAND).toLocaleString() }} NAND × 4</span>
|
||||
</span>
|
||||
<span class="cost-total">{{ total.toLocaleString() }}</span>
|
||||
</li>
|
||||
</ul>
|
||||
</EditorFold>
|
||||
|
||||
<EditorFold v-if="unused.length" id="circuit-unused" title="Unused components" :note="String(unused.length)">
|
||||
<p class="hint">Not placed in any other circuit. Circuits you work in directly show up here too, so delete only what you don't need.</p>
|
||||
<ul class="unused-list">
|
||||
<li v-for="d in unused" :key="d.id">
|
||||
<a href="#" class="grow truncate" @click.prevent="ed.open(d.id)">{{ d.name }}</a>
|
||||
<template v-if="confirmRemove === d.id">
|
||||
<button class="btn-sm danger" @click="ed.removeComponent(d.id), (confirmRemove = null)">Delete</button>
|
||||
<button class="btn-sm" @click="confirmRemove = null">Keep</button>
|
||||
</template>
|
||||
<button v-else class="icon-btn" title="Delete this component" @click="confirmRemove = d.id"><Icon name="lucide:trash-2" class="size-3.5" /></button>
|
||||
</li>
|
||||
</ul>
|
||||
</EditorFold>
|
||||
|
||||
<EditorFold id="circuit-tools" title="Tools">
|
||||
<div class="grid gap-2">
|
||||
<div class="sel-row">
|
||||
<button class="btn grow" title="Remove hand-placed bends in this circuit and lay out every wire tidily (undo brings them back)" @click="ed.tidyAll()">
|
||||
<Icon name="lucide:wand-sparkles" class="size-4" /> Tidy this circuit
|
||||
</button>
|
||||
<button class="btn grow" title="The same in every circuit of the project, in one go (undo brings them all back)" @click="ed.tidyEverything()">
|
||||
<Icon name="lucide:sparkles" class="size-4" /> Tidy every circuit
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
v-if="!ed.task.value"
|
||||
class="btn w-full"
|
||||
title="Turn this circuit into a puzzle link: others build the same behaviour, your circuit stays private"
|
||||
@click="ed.dialog.value = 'publish'"
|
||||
>
|
||||
<Icon name="lucide:puzzle" class="size-4" /> Publish as puzzle
|
||||
</button>
|
||||
<div class="sel-row">
|
||||
<button class="btn grow" :disabled="!def.nodes.length" title="A wiring sheet with a title block on white paper (Ctrl+P); choose Save as PDF in the print dialog" @click="ed.exportSheet('print')">
|
||||
<Icon name="lucide:printer" class="size-4" /> Print / PDF
|
||||
</button>
|
||||
<button class="btn grow" :disabled="!def.nodes.length" title="As on screen, to open in a browser or drawing program" @click="ed.exportSheet('svg')">
|
||||
<Icon name="lucide:file-image" class="size-4" /> SVG
|
||||
</button>
|
||||
</div>
|
||||
<div class="sel-row">
|
||||
<button class="btn grow" title="A copy of this circuit as a new component" @click="ed.copyComponent(def.id)"><Icon name="lucide:copy" class="size-4" /> Duplicate</button>
|
||||
<button v-if="!confirmDelete" class="btn grow" @click="confirmDelete = true"><Icon name="lucide:trash-2" class="size-4" /> Delete</button>
|
||||
<button v-else class="btn btn-danger grow" @click="ed.removeComponent(def.id); confirmDelete = false">Really delete?</button>
|
||||
</div>
|
||||
</div>
|
||||
</EditorFold>
|
||||
</section>
|
||||
</template>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
// The bar along the top, floating like the parts bar below: menu and where
|
||||
// you are on the left, the clock in the middle, the rest on the right.
|
||||
import { CHALLENGES } from '~/lib/logic/challenges'
|
||||
import type { MenuEntry } from '~/composables/useMenu'
|
||||
|
||||
const ed = useEditor()
|
||||
|
||||
|
|
@ -25,6 +26,43 @@ const path = computed(() =>
|
|||
)
|
||||
const atMain = computed(() => ed.def.value.id === ed.mainId.value)
|
||||
|
||||
// The circuit you are in: its name opens what can be done with all of it.
|
||||
const circuitMenu = ref<{ x: number; y: number } | null>(null)
|
||||
function openCircuitMenu(e: MouseEvent) {
|
||||
const r = (e.currentTarget as HTMLElement).getBoundingClientRect()
|
||||
circuitMenu.value = circuitMenu.value ? null : { x: r.left, y: r.bottom + 6 }
|
||||
}
|
||||
const circuitEntries = computed<MenuEntry[]>(() => {
|
||||
const d = ed.def.value
|
||||
const empty = !d.nodes.length
|
||||
return [
|
||||
{ head: 'Wires' },
|
||||
{ label: 'Tidy this circuit', icon: 'lucide:wand-sparkles', disabled: !d.wires.length, run: () => ed.tidyAll() },
|
||||
{ label: 'Tidy every circuit', icon: 'lucide:sparkles', run: () => ed.tidyEverything() },
|
||||
'sep',
|
||||
{ head: 'As a part' },
|
||||
{ label: 'Design its box…', icon: 'lucide:pen-tool', run: () => ed.designFace(d.id) },
|
||||
{ label: 'Duplicate', icon: 'lucide:copy', run: () => ed.copyComponent(d.id) },
|
||||
{
|
||||
label: 'Delete this circuit',
|
||||
icon: 'lucide:trash-2',
|
||||
danger: true,
|
||||
disabled: atMain.value,
|
||||
note: atMain.value ? 'the main circuit stays' : undefined,
|
||||
run: () => {
|
||||
const name = d.name
|
||||
ed.removeComponent(d.id)
|
||||
ed.notify(`Deleted "${name}" (Ctrl+Z brings it back)`)
|
||||
},
|
||||
},
|
||||
'sep',
|
||||
{ head: 'Share' },
|
||||
{ label: 'Print or save as PDF', icon: 'lucide:printer', keys: 'Ctrl+P', disabled: empty, run: () => ed.exportSheet('print') },
|
||||
{ label: 'Export as SVG', icon: 'lucide:file-image', disabled: empty, run: () => ed.exportSheet('svg') },
|
||||
{ label: 'Publish as a puzzle…', icon: 'lucide:puzzle', disabled: !!ed.task.value || empty, run: () => (ed.dialog.value = 'publish') },
|
||||
]
|
||||
})
|
||||
|
||||
// Challenges and puzzles open below their button.
|
||||
const showChallenges = ed.challengesOpen
|
||||
const challengesEl = ref<HTMLElement>()
|
||||
|
|
@ -63,17 +101,30 @@ const linkIcon = computed(() => {
|
|||
</button>
|
||||
<span class="bar-sep" />
|
||||
<nav class="crumbs" aria-label="Where you are">
|
||||
<button class="bar-btn" :class="{ here: atMain }" :disabled="atMain" title="Go to Main (components open with a double-click)" @click="ed.goMain()">
|
||||
<button
|
||||
class="bar-btn"
|
||||
:class="{ here: atMain, open: atMain && !!circuitMenu }"
|
||||
:title="atMain ? 'This circuit: tidy its wires, print, publish, duplicate' : 'Go to Main (components open with a double-click)'"
|
||||
@click="atMain ? openCircuitMenu($event) : ed.goMain()"
|
||||
>
|
||||
<Icon name="lucide:house" class="size-4" />
|
||||
<span>Main</span>
|
||||
<Icon v-if="atMain" name="lucide:chevron-down" class="size-3.5 text-(--muted)" />
|
||||
</button>
|
||||
<template v-for="p in path" :key="`${p.id}-${p.i}`">
|
||||
<Icon name="lucide:chevron-right" class="crumb-sep size-3.5" />
|
||||
<button class="bar-btn crumb" :class="{ here: p.i < 0 }" :disabled="p.i < 0" :title="p.i < 0 ? 'Editing this one' : `Back to ${p.name}`" @click="ed.goTo(p.i)">
|
||||
<button
|
||||
class="bar-btn crumb"
|
||||
:class="{ here: p.i < 0, open: p.i < 0 && !!circuitMenu }"
|
||||
:title="p.i < 0 ? 'This circuit: tidy its wires, design its box, print, publish, duplicate, delete' : `Back to ${p.name}`"
|
||||
@click="p.i < 0 ? openCircuitMenu($event) : ed.goTo(p.i)"
|
||||
>
|
||||
<span class="truncate">{{ p.name }}</span>
|
||||
<Icon v-if="p.i < 0" name="lucide:chevron-down" class="size-3.5 shrink-0 text-(--muted)" />
|
||||
</button>
|
||||
</template>
|
||||
</nav>
|
||||
<EditorContextMenu v-if="circuitMenu" :x="circuitMenu.x" :y="circuitMenu.y" :entries="circuitEntries" @close="circuitMenu = null" />
|
||||
</div>
|
||||
|
||||
<div class="tb-group">
|
||||
|
|
|
|||
|
|
@ -749,6 +749,37 @@ export function planHops(routes: Routed[], minR = 5): Map<number, Map<number, Ho
|
|||
return out
|
||||
}
|
||||
|
||||
/** Where each route is crossed by (or crosses) a line of another signal, for labels to keep clear of. */
|
||||
export function crossingPoints(routes: Routed[]): Map<number, Pt[]> {
|
||||
const out = new Map<number, Pt[]>()
|
||||
const verticals: { r: number; x: number; lo: number; hi: number }[] = []
|
||||
routes.forEach((route, r) => {
|
||||
const p = route.draw
|
||||
for (let i = 0; i < p.length - 1; i++) {
|
||||
const [ax, ay] = p[i]!
|
||||
const [bx, by] = p[i + 1]!
|
||||
if (ax === bx && ay !== by) verticals.push({ r, x: ax, lo: Math.min(ay, by), hi: Math.max(ay, by) })
|
||||
}
|
||||
})
|
||||
routes.forEach((route, r) => {
|
||||
const p = route.draw
|
||||
for (let i = 0; i < p.length - 1; i++) {
|
||||
const [ax, ay] = p[i]!
|
||||
const [bx, by] = p[i + 1]!
|
||||
if (ay !== by || ax === bx) continue
|
||||
const lo = Math.min(ax, bx)
|
||||
const hi = Math.max(ax, bx)
|
||||
for (const v of verticals) {
|
||||
if (routes[v.r]!.net === route.net || v.x <= lo + EPS || v.x >= hi - EPS || ay <= v.lo + EPS || ay >= v.hi - EPS) continue
|
||||
const pt: Pt = [v.x, ay]
|
||||
out.set(r, [...(out.get(r) ?? []), pt])
|
||||
out.set(v.r, [...(out.get(v.r) ?? []), pt])
|
||||
}
|
||||
}
|
||||
})
|
||||
return out
|
||||
}
|
||||
|
||||
// ── Tidy routing ────────────────────────────────────────────────────
|
||||
// The way a panel builder wires a cabinet. Every forward wire takes its
|
||||
// vertical step in the free gap right in front of the part it feeds. All
|
||||
|
|
|
|||
Loading…
Reference in New Issue