A pick pins for a cable, buttons on pointing, right-click on pins; docked panels move freely
- Pointing at a part shows its round buttons, as if it were selected; they stay while the pointer goes to them. - A box around some pins of one part (not over its middle), or Shift + click on pins, picks exactly those pins: a cable plug on them, wire them one by one, invert or unwire them, from buttons beside them or a right-click. - Right-click on a pin offers what can be done right there first: split a component's cable socket into wires (or join), pull a cable out of a cable end, invert an input. - A docked panel moves both ways now: moved up or down off its component's pins it lets go and stays a panel of its own (rows and wires kept); moved sideways it stays docked. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
4dfd97d192
commit
fa849d7a05
|
|
@ -5665,3 +5665,11 @@ button.tile:hover {
|
||||||
stroke: #10151c;
|
stroke: #10151c;
|
||||||
stroke-width: 1;
|
stroke-width: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* A picked pin: ready for a cable or wires on exactly the picked ones. */
|
||||||
|
.picked-pin {
|
||||||
|
fill: rgb(76 194 255 / 0.18);
|
||||||
|
stroke: var(--accent);
|
||||||
|
stroke-width: 2;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -445,24 +445,21 @@ function cableOfEnd(n: CircuitNode): CircuitNode | undefined {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Buttons beside the selection. A component (or panel, or hex display): a
|
* Buttons beside a part: a cable onto its outputs and its inputs, and each
|
||||||
* cable onto its outputs and its inputs, and each connector port split into
|
* connector port split into its wires or joined again. A cable end: plug in
|
||||||
* its wires or joined again. A cable end: plug in or out, take the cable
|
* or out, take the cable apart.
|
||||||
* apart. A cable: take it apart. Several wires: bundle them into a cable.
|
|
||||||
*/
|
*/
|
||||||
const actionButtons = computed<ActionButton[]>(() => {
|
function nodeButtons(n: CircuitNode): ActionButton[] {
|
||||||
if (drag.value || ed.linking.value || ed.placing.value || ed.cabling.value) return []
|
|
||||||
const out: ActionButton[] = []
|
const out: ActionButton[] = []
|
||||||
const sel = ed.selection.value
|
const s = shapes.value.get(n.id)
|
||||||
const n = sel.length === 1 && !ed.wireSel.value.length ? nodeMap.value.get(sel[0]!) : undefined
|
if (!s) return out
|
||||||
if (n) {
|
const key = (k: string) => `${n.id}|${k}`
|
||||||
const s = shapes.value.get(n.id)!
|
|
||||||
// Connector ports: beside the socket, out of the box.
|
// Connector ports: beside the socket, out of the box.
|
||||||
for (const p of [...s.inputs, ...s.outputs]) {
|
for (const p of [...s.inputs, ...s.outputs]) {
|
||||||
if (!p.conn || n.kind !== 'chip') continue
|
if (!p.conn || n.kind !== 'chip') continue
|
||||||
const split = !!n.splitPorts?.includes(p.key)
|
const split = !!n.splitPorts?.includes(p.key)
|
||||||
out.push({
|
out.push({
|
||||||
key: `port:${p.key}`,
|
key: key(`port:${p.key}`),
|
||||||
x: n.x + p.dx + (p.dx === 0 ? -1.3 : 1.3),
|
x: n.x + p.dx + (p.dx === 0 ? -1.3 : 1.3),
|
||||||
y: n.y + p.dy,
|
y: n.y + p.dy,
|
||||||
title: split ? `Join the ${p.label} wires back into its socket` : `Split ${p.label} into wires`,
|
title: split ? `Join the ${p.label} wires back into its socket` : `Split ${p.label} into wires`,
|
||||||
|
|
@ -481,14 +478,29 @@ const actionButtons = computed<ActionButton[]>(() => {
|
||||||
}
|
}
|
||||||
if (choices.out.length && outs.length) {
|
if (choices.out.length && outs.length) {
|
||||||
const x = n.x + Math.max(...outs.map(p => p.dx)) + 1.3
|
const x = n.x + Math.max(...outs.map(p => p.dx)) + 1.3
|
||||||
out.push({ key: 'cable:out', x, y: clear(x, n.y + mid(outs)), title: 'A cable plug on these outputs', run: e => onCableButton('out', e) })
|
out.push({ key: key('cable:out'), x, y: clear(x, n.y + mid(outs)), title: 'A cable plug on these outputs', run: e => onCableButton(n, 'out', e) })
|
||||||
}
|
}
|
||||||
if (choices.in.length && ins.length) {
|
if (choices.in.length && ins.length) {
|
||||||
const x = n.x + Math.min(...ins.map(p => p.dx)) - 1.3
|
const x = n.x + Math.min(...ins.map(p => p.dx)) - 1.3
|
||||||
out.push({ key: 'cable:in', x, y: clear(x, n.y + mid(ins)), title: 'A cable plug on these inputs', flip: true, run: e => onCableButton('in', e) })
|
out.push({ key: key('cable:in'), x, y: clear(x, n.y + mid(ins)), title: 'A cable plug on these inputs', flip: true, run: e => onCableButton(n, 'in', e) })
|
||||||
}
|
}
|
||||||
if (n.kind === 'bundle' || n.kind === 'split') {
|
if (n.kind === 'bundle' || n.kind === 'split') {
|
||||||
// On the cable's side of the end, clear of its cable pin: pull a cable out, plug in or out, take the cable apart.
|
// On the cable's side of the end, clear of its cable pin: pull a cable out, plug in or out, take the cable apart.
|
||||||
|
const x = n.kind === 'bundle' ? n.x + s.body.x + s.body.w + 1 : n.x + s.body.x - 1
|
||||||
|
const busY = n.y + (n.kind === 'bundle' ? s.outputs : s.inputs).find(p => p.bus)!.dy
|
||||||
|
// From its top row down, stepping over the cable pin's row.
|
||||||
|
let y = n.y + s.body.y + 0.5
|
||||||
|
for (const b of endActions(n)) {
|
||||||
|
if (Math.abs(y - busY) < 0.9) y = busY + 1
|
||||||
|
out.push({ ...b, key: key(b.key), x, y })
|
||||||
|
y += 1.2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
/** What can be done at a cable end: pull a cable out, plug in or out, take the cable apart. */
|
||||||
|
function endActions(n: CircuitNode): Omit<ActionButton, 'x' | 'y'>[] {
|
||||||
const ends: Omit<ActionButton, 'x' | 'y'>[] = []
|
const ends: Omit<ActionButton, 'x' | 'y'>[] = []
|
||||||
const bus = n.kind === 'bundle' ? { pin: 'q', dir: 'out' as const } : { pin: 'a', dir: 'in' as const }
|
const bus = n.kind === 'bundle' ? { pin: 'q', dir: 'out' as const } : { pin: 'a', dir: 'in' as const }
|
||||||
if (pullable({ node: n.id, ...bus }) && !linked.value[bus.dir].has(`${n.id}:${bus.pin}`)) {
|
if (pullable({ node: n.id, ...bus }) && !linked.value[bus.dir].has(`${n.id}:${bus.pin}`)) {
|
||||||
|
|
@ -503,16 +515,53 @@ const actionButtons = computed<ActionButton[]>(() => {
|
||||||
else if (ed.plugTarget(n)) ends.push({ key: 'plug', title: 'Plug straight onto the pins its wires run to', icon: 'lucide:plug', run: () => ed.plugEnd(n) })
|
else if (ed.plugTarget(n)) ends.push({ key: 'plug', title: 'Plug straight onto the pins its wires run to', icon: 'lucide:plug', run: () => ed.plugEnd(n) })
|
||||||
const cable = cableOfEnd(n)
|
const cable = cableOfEnd(n)
|
||||||
if (cable) ends.push({ key: 'apart', title: 'Split the cable into single wires', icon: 'lucide:split', run: () => ed.removeCable(cable.id) })
|
if (cable) ends.push({ key: 'apart', title: 'Split the cable into single wires', icon: 'lucide:split', run: () => ed.removeCable(cable.id) })
|
||||||
const x = n.kind === 'bundle' ? n.x + s.body.x + s.body.w + 1 : n.x + s.body.x - 1
|
return ends
|
||||||
const busY = n.y + (n.kind === 'bundle' ? s.outputs : s.inputs).find(p => p.bus)!.dy
|
}
|
||||||
// From its top row down, stepping over the cable pin's row.
|
|
||||||
let y = n.y + s.body.y + 0.5
|
/** Buttons beside picked pins: a cable plug on exactly them, or wire them one by one. */
|
||||||
for (const b of ends) {
|
function pickedButtons(): ActionButton[] {
|
||||||
if (Math.abs(y - busY) < 0.9) y = busY + 1
|
const sel = ed.pinSel.value
|
||||||
out.push({ ...b, x, y })
|
const n = sel && nodeMap.value.get(sel.node)
|
||||||
y += 1.2
|
const s = n && shapes.value.get(n.id)
|
||||||
}
|
if (!sel || !n || !s) return []
|
||||||
}
|
const pins = (sel.dir === 'out' ? s.outputs : s.inputs).filter(p => sel.pins.includes(p.key))
|
||||||
|
if (!pins.length) return []
|
||||||
|
const side = sel.dir === 'out' ? 1 : -1
|
||||||
|
const x = n.x + (side > 0 ? Math.max(...pins.map(p => p.dx)) : Math.min(...pins.map(p => p.dx))) + side * 1.3
|
||||||
|
const mid = n.y + (Math.min(...pins.map(p => p.dy)) + Math.max(...pins.map(p => p.dy))) / 2
|
||||||
|
const count = `${pins.length} ${sel.dir === 'out' ? 'output' : 'input'}${pins.length === 1 ? '' : 's'}`
|
||||||
|
const out: ActionButton[] = []
|
||||||
|
if (pins.length >= 2) out.push({ key: 'picked|cable', x, y: mid - 0.6, title: `A cable plug on these ${count}`, flip: side < 0, run: () => ed.cablePicked() })
|
||||||
|
out.push({ key: 'picked|link', x, y: out.length ? mid + 0.6 : mid, title: `Wire these ${count} one by one: click where each goes`, icon: 'lucide:cable', run: () => ed.linkPicked() })
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── A part pointed at shows its buttons too, as if it were selected ──
|
||||||
|
const hoverNode = ref<string | null>(null)
|
||||||
|
let hoverTimer: ReturnType<typeof setTimeout> | undefined
|
||||||
|
/** Pointing at a part (after a moment), or at one of its buttons, keeps them; leaving lets them go a moment later. */
|
||||||
|
function trackHover(target: Element | null) {
|
||||||
|
if (target?.closest('[data-action]')) return clearTimeout(hoverTimer)
|
||||||
|
const id = target?.closest('[data-node]')?.getAttribute('data-node') ?? null
|
||||||
|
if (id === hoverNode.value) return clearTimeout(hoverTimer)
|
||||||
|
clearTimeout(hoverTimer)
|
||||||
|
hoverTimer = setTimeout(() => (hoverNode.value = id), id ? 150 : 600)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Buttons beside the selection, and beside a part pointed at. Picked pins:
|
||||||
|
* a cable on them, or wire them one by one. A cable: take it apart. Several
|
||||||
|
* wires: bundle them into a cable.
|
||||||
|
*/
|
||||||
|
const actionButtons = computed<ActionButton[]>(() => {
|
||||||
|
if (drag.value || ed.linking.value || ed.placing.value || ed.cabling.value) return []
|
||||||
|
const out: ActionButton[] = [...pickedButtons()]
|
||||||
|
const sel = ed.selection.value
|
||||||
|
const picked = sel.length === 1 && !ed.wireSel.value.length ? sel[0] : undefined
|
||||||
|
for (const id of new Set([picked, hoverNode.value])) {
|
||||||
|
const n = id ? nodeMap.value.get(id) : undefined
|
||||||
|
// With pins of it picked, the buttons for those pins stand in for its own.
|
||||||
|
if (n && n.id !== ed.pinSel.value?.node) out.push(...nodeButtons(n))
|
||||||
}
|
}
|
||||||
// Wires: a cable can be taken apart, several single wires bundled.
|
// Wires: a cable can be taken apart, several single wires bundled.
|
||||||
const wires = sel.length ? [] : routes.value.filter(r => wireSelected.value.has(r.wire.id))
|
const wires = sel.length ? [] : routes.value.filter(r => wireSelected.value.has(r.wire.id))
|
||||||
|
|
@ -532,9 +581,7 @@ const actionButtons = computed<ActionButton[]>(() => {
|
||||||
})
|
})
|
||||||
|
|
||||||
/** A cable button: with one way to do it, it is done; with several, they are offered. */
|
/** A cable button: with one way to do it, it is done; with several, they are offered. */
|
||||||
function onCableButton(side: 'out' | 'in', e: PointerEvent) {
|
function onCableButton(n: CircuitNode, side: 'out' | 'in', e: PointerEvent) {
|
||||||
const n = nodeMap.value.get(ed.selection.value[0]!)
|
|
||||||
if (!n) return
|
|
||||||
const groups = ed.cableChoices(n)[side]
|
const groups = ed.cableChoices(n)[side]
|
||||||
const run = (pins: string[]) => (side === 'out' ? ed.cableOut(n.id, pins) : ed.cableIn(n.id, pins))
|
const run = (pins: string[]) => (side === 'out' ? ed.cableOut(n.id, pins) : ed.cableIn(n.id, pins))
|
||||||
if (groups.length === 1) return run(groups[0]!.pins)
|
if (groups.length === 1) return run(groups[0]!.pins)
|
||||||
|
|
@ -699,6 +746,11 @@ function onPointerDown(e: PointerEvent) {
|
||||||
const n = nodeMap.value.get(pinEl.getAttribute('data-node')!)
|
const n = nodeMap.value.get(pinEl.getAttribute('data-node')!)
|
||||||
if (n && ed.canInvert(n, pinEl.getAttribute('data-pin')!)) return ed.toggleInvert(n, pinEl.getAttribute('data-pin')!)
|
if (n && ed.canInvert(n, pinEl.getAttribute('data-pin')!)) return ed.toggleInvert(n, pinEl.getAttribute('data-pin')!)
|
||||||
}
|
}
|
||||||
|
if (pinEl && e.shiftKey) {
|
||||||
|
// Shift + click on a pin: in or out of the picked pins.
|
||||||
|
ed.pickPin(pinEl.getAttribute('data-node')!, pinEl.getAttribute('data-dir') as 'in' | 'out', pinEl.getAttribute('data-pin')!)
|
||||||
|
return
|
||||||
|
}
|
||||||
if (pinEl) {
|
if (pinEl) {
|
||||||
drag.value = {
|
drag.value = {
|
||||||
kind: 'wire',
|
kind: 'wire',
|
||||||
|
|
@ -811,7 +863,7 @@ function onPointerMove(e: PointerEvent) {
|
||||||
cursor.value = w
|
cursor.value = w
|
||||||
altDown.value = e.altKey
|
altDown.value = e.altKey
|
||||||
const d = drag.value
|
const d = drag.value
|
||||||
if (!d) return
|
if (!d) return trackHover(e.target as Element)
|
||||||
switch (d.kind) {
|
switch (d.kind) {
|
||||||
case 'pan':
|
case 'pan':
|
||||||
ed.views[def.value.id] = { ...view.value, x: d.vx + e.clientX - d.sx, y: d.vy + e.clientY - d.sy }
|
ed.views[def.value.id] = { ...view.value, x: d.vx + e.clientX - d.sx, y: d.vy + e.clientY - d.sy }
|
||||||
|
|
@ -829,7 +881,7 @@ function onPointerMove(e: PointerEvent) {
|
||||||
}
|
}
|
||||||
if (d.still && d.from) {
|
if (d.still && d.from) {
|
||||||
// Dropped onto pins it can join, it connects there (Alt: just place it).
|
// Dropped onto pins it can join, it connects there (Alt: just place it).
|
||||||
const at = d.from.map(p => ({ ...p, x: p.x + dx, y: d.orig.lockY.has(p.node) ? p.y : p.y + dy }))
|
const at = d.from.map(p => ({ ...p, x: p.x + dx, y: p.y + dy }))
|
||||||
d.snap = e.altKey ? null : dropLinks(at, d.still, d.grabbed === 1 ? 1 : 0)
|
d.snap = e.altKey ? null : dropLinks(at, d.still, d.grabbed === 1 ? 1 : 0)
|
||||||
}
|
}
|
||||||
if (dx !== d.at[0] || dy !== d.at[1]) {
|
if (dx !== d.at[0] || dy !== d.at[1]) {
|
||||||
|
|
@ -858,6 +910,20 @@ function onPointerMove(e: PointerEvent) {
|
||||||
// Dragged right to left, or across wires without touching any part: every wire the box
|
// Dragged right to left, or across wires without touching any part: every wire the box
|
||||||
// crosses. Otherwise only wires lying fully inside, so a box over some parts doesn't
|
// crosses. Otherwise only wires lying fully inside, so a box over some parts doesn't
|
||||||
// catch (and on Delete remove) unrelated wires passing through.
|
// catch (and on Delete remove) unrelated wires passing through.
|
||||||
|
// Around pins of one part, all inputs or all outputs, and not over its middle: those pins.
|
||||||
|
const pinsIn = allPins.value.filter(p => !p.bus && p.x > x0 && p.x < x1 && p.y > y0 && p.y < y1)
|
||||||
|
const owner = pinsIn[0]?.node
|
||||||
|
const host = owner ? nodeMap.value.get(owner) : undefined
|
||||||
|
if (host && pinsIn.every(p => p.node === owner && p.dir === pinsIn[0]!.dir) && nodes.every(id => id === owner)) {
|
||||||
|
const b = shapes.value.get(owner!)!.body
|
||||||
|
const cx = host.x + b.x + b.w / 2
|
||||||
|
const cy = host.y + b.y + b.h / 2
|
||||||
|
if (!(cx > x0 && cx < x1 && cy > y0 && cy < y1)) {
|
||||||
|
ed.pickPins(owner!, pinsIn[0]!.dir, pinsIn.map(p => p.pin))
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (ed.pinSel.value) ed.pinSel.value = null
|
||||||
const box = { x0, y0, x1, y1 }
|
const box = { x0, y0, x1, y1 }
|
||||||
const crossing = w[0] < d.start[0] || !nodes.length
|
const crossing = w[0] < d.start[0] || !nodes.length
|
||||||
const wires = routes.value
|
const wires = routes.value
|
||||||
|
|
@ -1165,12 +1231,12 @@ const ARROWS: Record<string, Pt> = { ArrowLeft: [-1, 0], ArrowRight: [1, 0], Arr
|
||||||
function nudge(dx: number, dy: number) {
|
function nudge(dx: number, dy: number) {
|
||||||
const ids = ed.withFollowers(ed.selection.value)
|
const ids = ed.withFollowers(ed.selection.value)
|
||||||
if (!ids.size && !ed.wireSel.value.length) return
|
if (!ids.size && !ed.wireSel.value.length) return
|
||||||
ed.unplugMoved(ids)
|
|
||||||
// A wire moved on its own keeps the shape it has.
|
// A wire moved on its own keeps the shape it has.
|
||||||
for (const r of routes.value) {
|
for (const r of routes.value) {
|
||||||
if (wireSelected.value.has(r.wire.id) && !r.wire.pts && !ids.has(r.wire.from.node) && !ids.has(r.wire.to.node)) r.wire.pts = r.pts.slice(1, -1)
|
if (wireSelected.value.has(r.wire.id) && !r.wire.pts && !ids.has(r.wire.from.node) && !ids.has(r.wire.to.node)) r.wire.pts = r.pts.slice(1, -1)
|
||||||
}
|
}
|
||||||
moveTo(moveStart(def.value, ids, ed.wireSel.value), dx, dy)
|
moveTo(moveStart(def.value, ids, ed.wireSel.value), dx, dy)
|
||||||
|
ed.unplugMoved(ids)
|
||||||
ed.commit(false)
|
ed.commit(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1252,7 +1318,7 @@ function onKey(e: KeyboardEvent) {
|
||||||
}
|
}
|
||||||
if (ed.linking.value) return ed.stopLinking()
|
if (ed.linking.value) return ed.stopLinking()
|
||||||
// Nothing to cancel: Esc pauses, like in a game.
|
// Nothing to cancel: Esc pauses, like in a game.
|
||||||
if (!ed.placing.value && !ed.selection.value.length && !ed.wireSel.value.length) return ed.pause()
|
if (!ed.placing.value && !ed.selection.value.length && !ed.wireSel.value.length && !ed.pinSel.value) return ed.pause()
|
||||||
ed.placing.value = null
|
ed.placing.value = null
|
||||||
ed.clearSelection()
|
ed.clearSelection()
|
||||||
} else if (ARROWS[e.key]) {
|
} else if (ARROWS[e.key]) {
|
||||||
|
|
@ -1534,8 +1600,10 @@ function openMenuAt(target: Element, at: Pt, x: number, y: number) {
|
||||||
const nodeId = target.closest('[data-node]')?.getAttribute('data-node')
|
const nodeId = target.closest('[data-node]')?.getAttribute('data-node')
|
||||||
const wireId = target.closest('[data-wire]')?.getAttribute('data-wire')
|
const wireId = target.closest('[data-wire]')?.getAttribute('data-wire')
|
||||||
const junction = target.closest('[data-junction]')?.getAttribute('data-junction')
|
const junction = target.closest('[data-junction]')?.getAttribute('data-junction')
|
||||||
|
// On a picked pin the picked pins stay picked (selecting the part would put them down).
|
||||||
|
const onPicked = !!ed.pinSel.value && ed.pinSel.value.node === nodeId && ed.pinSel.value.pins.includes(target.closest('[data-pin]')?.getAttribute('data-pin') ?? '')
|
||||||
if (nodeId && nodeMap.value.has(nodeId)) {
|
if (nodeId && nodeMap.value.has(nodeId)) {
|
||||||
if (!selected.value.has(nodeId)) {
|
if (!selected.value.has(nodeId) && !onPicked) {
|
||||||
ed.selection.value = [nodeId]
|
ed.selection.value = [nodeId]
|
||||||
ed.wireSel.value = []
|
ed.wireSel.value = []
|
||||||
}
|
}
|
||||||
|
|
@ -1551,12 +1619,42 @@ function openMenuAt(target: Element, at: Pt, x: number, y: number) {
|
||||||
const onThing = !!(nodeId || wireId || junction)
|
const onThing = !!(nodeId || wireId || junction)
|
||||||
const entries = build(onThing ? { kind: 'selection' } : { kind: 'canvas', at }, canvasOps)
|
const entries = build(onThing ? { kind: 'selection' } : { kind: 'canvas', at }, canvasOps)
|
||||||
// On an input pin: its bubble first (the same as Alt + click, which some desktops take for themselves).
|
// On an input pin: its bubble first (the same as Alt + click, which some desktops take for themselves).
|
||||||
const pin = target.closest('[data-pin][data-dir="in"]')?.getAttribute('data-pin')
|
const pinEl = target.closest('[data-pin]')
|
||||||
|
const pin = pinEl?.getAttribute('data-pin')
|
||||||
|
const dir = pinEl?.getAttribute('data-dir') as 'in' | 'out' | undefined
|
||||||
const n = nodeId ? nodeMap.value.get(nodeId) : undefined
|
const n = nodeId ? nodeMap.value.get(nodeId) : undefined
|
||||||
if (pin && n && ed.canInvert(n, pin)) {
|
const here: MenuEntry[] = []
|
||||||
const on = n.invert?.includes(pin)
|
if (pin && dir && n) {
|
||||||
entries.unshift({ label: on ? 'Take the bubble off this input' : 'Invert this input', icon: 'lucide:circle-dot', keys: 'Alt+click', run: () => ed.toggleInvert(n, pin) }, 'sep')
|
const shape = shapes.value.get(n.id)!
|
||||||
|
const p = (dir === 'in' ? shape.inputs : shape.outputs).find(x => x.key === pin)
|
||||||
|
// A cable socket on a component: split it into its wires right here, or join them.
|
||||||
|
if (p?.conn && n.kind === 'chip') {
|
||||||
|
const split = !!n.splitPorts?.includes(pin)
|
||||||
|
here.push({ label: split ? `Join the ${p.label} wires` : `Split ${p.label} into wires here`, icon: split ? 'lucide:merge' : 'lucide:split', run: () => ed.toggleSplit(n, pin) })
|
||||||
}
|
}
|
||||||
|
// A cable end's cable pin: pull the cable out right here (plugging and taking apart are in the end's own menu below).
|
||||||
|
if (p?.bus && (n.kind === 'bundle' || n.kind === 'split')) {
|
||||||
|
const pull = endActions(n).find(x => x.key === 'pull')
|
||||||
|
if (pull) here.push({ label: 'Pull the cable out', icon: pull.icon, run: () => pull.run(new PointerEvent('pointerdown')) })
|
||||||
|
}
|
||||||
|
if (dir === 'in' && ed.canInvert(n, pin)) {
|
||||||
|
const on = n.invert?.includes(pin)
|
||||||
|
here.push({ label: on ? 'Take the bubble off this input' : 'Invert this input', icon: 'lucide:circle-dot', keys: 'Alt+click', run: () => ed.toggleInvert(n, pin) })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Picked pins (right-clicked on one of them): what can be done with all of them.
|
||||||
|
const sel = ed.pinSel.value
|
||||||
|
if (sel && n && sel.node === n.id && (!pin || sel.pins.includes(pin))) {
|
||||||
|
const count = `${sel.pins.length} ${sel.dir === 'out' ? 'output' : 'input'}${sel.pins.length === 1 ? '' : 's'}`
|
||||||
|
here.unshift(
|
||||||
|
{ head: `${count} picked` },
|
||||||
|
...(sel.pins.length >= 2 ? [{ label: 'A cable plug on them', icon: sel.dir === 'out' ? 'lucide:merge' : 'lucide:split', run: () => ed.cablePicked() }] : []),
|
||||||
|
{ label: 'Wire them one by one', icon: 'lucide:cable', run: () => ed.linkPicked() },
|
||||||
|
...(sel.dir === 'in' ? [{ label: 'Invert them', icon: 'lucide:circle-dot', run: () => ed.invertPicked() }] : []),
|
||||||
|
{ label: 'Remove their wires', icon: 'lucide:unlink', danger: true, run: () => ed.unwirePicked() },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (here.length) entries.unshift(...here, 'sep')
|
||||||
menu.value = entries.length ? { x: x + 2, y: y + 2, entries } : null
|
menu.value = entries.length ? { x: x + 2, y: y + 2, entries } : null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1613,6 +1711,14 @@ const latchMarks = computed(() =>
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/** The picked pins, where they are. */
|
||||||
|
const pickedPins = computed(() => {
|
||||||
|
const sel = ed.pinSel.value
|
||||||
|
if (!sel) return []
|
||||||
|
const keep = new Set(sel.pins)
|
||||||
|
return allPins.value.filter(p => p.node === sel.node && p.dir === sel.dir && keep.has(p.pin))
|
||||||
|
})
|
||||||
|
|
||||||
/** Pins a dragged part will connect to when dropped, shown as green rings. */
|
/** Pins a dragged part will connect to when dropped, shown as green rings. */
|
||||||
const dropRings = computed(() => {
|
const dropRings = computed(() => {
|
||||||
const g = ghostLanding.value
|
const g = ghostLanding.value
|
||||||
|
|
@ -1681,7 +1787,7 @@ defineExpose({ fit, zoomAt })
|
||||||
@pointermove="onPointerMove"
|
@pointermove="onPointerMove"
|
||||||
@pointerup="onPointerUp"
|
@pointerup="onPointerUp"
|
||||||
@pointercancel="onPointerUp"
|
@pointercancel="onPointerUp"
|
||||||
@pointerleave="cursor = null"
|
@pointerleave="(cursor = null), trackHover(null)"
|
||||||
@wheel.prevent="onWheel"
|
@wheel.prevent="onWheel"
|
||||||
@contextmenu.prevent
|
@contextmenu.prevent
|
||||||
@dragover.prevent="onDragOver"
|
@dragover.prevent="onDragOver"
|
||||||
|
|
@ -1847,6 +1953,7 @@ defineExpose({ fit, zoomAt })
|
||||||
</template>
|
</template>
|
||||||
</g>
|
</g>
|
||||||
<circle v-for="(p, i) in dropRings" :key="`d${i}`" :cx="p.x * G" :cy="p.y * G" r="7" class="drop-ring" />
|
<circle v-for="(p, i) in dropRings" :key="`d${i}`" :cx="p.x * G" :cy="p.y * G" r="7" class="drop-ring" />
|
||||||
|
<circle v-for="p in pickedPins" :key="`pk${p.pin}`" :cx="p.x * G" :cy="p.y * G" r="6.5" class="picked-pin" />
|
||||||
<g
|
<g
|
||||||
v-for="b in actionButtons"
|
v-for="b in actionButtons"
|
||||||
:key="b.key"
|
:key="b.key"
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,10 @@ const SHORTCUTS: [string, string][] = [
|
||||||
['Split into lines (right-click a component)', 'A pin per line below a port\'s socket, to wire lines by hand; dropping a wire on the socket does the same. Join lines takes them away'],
|
['Split into lines (right-click a component)', 'A pin per line below a port\'s socket, to wire lines by hand; dropping a wire on the socket does the same. Join lines takes them away'],
|
||||||
['Select wires, Ctrl+G', 'Bundle them into one cable; an end whose wires all meet one part plugs straight into it'],
|
['Select wires, Ctrl+G', 'Bundle them into one cable; an end whose wires all meet one part plugs straight into it'],
|
||||||
['Select a component, cable button beside its pins', 'A plug on S0–S3 (or any group); drag the cable out of its pin and let go where it goes, or on the next part\'s pins'],
|
['Select a component, cable button beside its pins', 'A plug on S0–S3 (or any group); drag the cable out of its pin and let go where it goes, or on the next part\'s pins'],
|
||||||
|
['Point at a part', 'Its round buttons show, as if it were selected: cable plugs, split ports, plug in or out'],
|
||||||
|
['Drag a box around some pins of a part, or Shift + click pins', 'Picks exactly those pins: a cable plug on them, wire them one by one, invert or unwire them (buttons beside them, or right-click)'],
|
||||||
|
['Right-click a pin', 'What can be done right there: split a cable socket into wires, pull a cable out, invert an input'],
|
||||||
|
['Drag a docked panel up or down', 'It lets go of its component and stays a panel of its own; sideways it stays docked'],
|
||||||
['Round buttons beside the selection', 'Split a port into wires (or join them), pull a cable out of a plug, plug in or out, split a cable into wires, bundle selected wires'],
|
['Round buttons beside the selection', 'Split a port into wires (or join them), pull a cable out of a plug, plug in or out, split a cable into wires, bundle selected wires'],
|
||||||
['Drag a part from the list onto pins', 'It lands on them and connects (green rings show where); Alt just places it'],
|
['Drag a part from the list onto pins', 'It lands on them and connects (green rings show where); Alt just places it'],
|
||||||
['Drag a part onto the pins it is wired to', 'When its pins line up with theirs one for one, it latches on (green rings): pins touching, no wires, and it moves with that part. Right-click: Latch onto / Unlatch'],
|
['Drag a part onto the pins it is wired to', 'When its pins line up with theirs one for one, it latches on (green rings): pins touching, no wires, and it moves with that part. Right-click: Latch onto / Unlatch'],
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ import { cleanBundle, importBundle, importProblem, LIBRARY_LIMITS, libraryBundle
|
||||||
import { compile, INVERTIBLE, invertedPins, rowSource } from '~/lib/logic/compile'
|
import { compile, INVERTIBLE, invertedPins, rowSource } from '~/lib/logic/compile'
|
||||||
import { chipPins, MAX_BITS, panelOffsets, pinKindOf, shapeOf, type Pt } from '~/lib/logic/geometry'
|
import { chipPins, MAX_BITS, panelOffsets, pinKindOf, shapeOf, type Pt } from '~/lib/logic/geometry'
|
||||||
import { adoptName, continueSeries, newPinLabel, uniqueLabel, usedLabels } from '~/lib/logic/labels'
|
import { adoptName, continueSeries, newPinLabel, uniqueLabel, usedLabels } from '~/lib/logic/labels'
|
||||||
import { attachPanel, combineIntoPanel, detachPanel, dockedPanels, insertPanelRow, mergePanels, movePanelRow, newPanelRows, removeRow, syncPanels } from '~/lib/logic/panels'
|
import { attachPanel, combineIntoPanel, detachPanel, dockedPanels, insertPanelRow, mergePanels, movePanelRow, newPanelRows, offItsPins, removeRow, syncPanels } from '~/lib/logic/panels'
|
||||||
import {
|
import {
|
||||||
addExamples,
|
addExamples,
|
||||||
containsDef,
|
containsDef,
|
||||||
|
|
@ -210,6 +210,92 @@ function create() {
|
||||||
function clearSelection() {
|
function clearSelection() {
|
||||||
selection.value = []
|
selection.value = []
|
||||||
wireSel.value = []
|
wireSel.value = []
|
||||||
|
pinSel.value = null
|
||||||
|
}
|
||||||
|
|
||||||
|
// ── Picked pins ───────────────────────────────────────────────────
|
||||||
|
/**
|
||||||
|
* Pins picked on one part, all inputs or all outputs (a box around them,
|
||||||
|
* or Shift + click): a cable plug or wires on exactly those pins.
|
||||||
|
*/
|
||||||
|
const pinSel = ref<{ node: string; dir: 'in' | 'out'; pins: string[] } | null>(null)
|
||||||
|
// Picking parts or wires puts picked pins down, and so does another circuit.
|
||||||
|
watch([() => selection.value.length, () => wireSel.value.length], ([a, b]) => {
|
||||||
|
if (a || b) pinSel.value = null
|
||||||
|
})
|
||||||
|
watch(() => def.value.id, () => (pinSel.value = null))
|
||||||
|
|
||||||
|
/** Pins of a part in their order on it, top to bottom. */
|
||||||
|
function pinOrder(node: string, dir: 'in' | 'out', pins: string[]): string[] {
|
||||||
|
const n = def.value.nodes.find(x => x.id === node)
|
||||||
|
if (!n) return []
|
||||||
|
const all = (dir === 'in' ? shapeOf(n, getDef.value).inputs : shapeOf(n, getDef.value).outputs).map(p => p.key)
|
||||||
|
return all.filter(k => pins.includes(k))
|
||||||
|
}
|
||||||
|
|
||||||
|
function pickPins(node: string, dir: 'in' | 'out', pins: string[]) {
|
||||||
|
selection.value = []
|
||||||
|
wireSel.value = []
|
||||||
|
const list = pinOrder(node, dir, pins)
|
||||||
|
pinSel.value = list.length ? { node, dir, pins: list } : null
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Shift + click on a pin: in or out of the picked pins (pins of another part or side start a new pick). */
|
||||||
|
function pickPin(node: string, dir: 'in' | 'out', pin: string) {
|
||||||
|
const s = pinSel.value
|
||||||
|
const same = s && s.node === node && s.dir === dir
|
||||||
|
pickPins(node, dir, same ? (s.pins.includes(pin) ? s.pins.filter(p => p !== pin) : [...s.pins, pin]) : [pin])
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A cable plug on exactly the picked pins. */
|
||||||
|
function cablePicked() {
|
||||||
|
const s = pinSel.value
|
||||||
|
if (!s) return
|
||||||
|
pinSel.value = null
|
||||||
|
if (s.dir === 'out') cableOut(s.node, s.pins)
|
||||||
|
else cableIn(s.node, s.pins)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Wire the picked pins one after another: click where each one goes. */
|
||||||
|
function linkPicked() {
|
||||||
|
const s = pinSel.value
|
||||||
|
const n = s && def.value.nodes.find(x => x.id === s.node)
|
||||||
|
if (!s || !n) return
|
||||||
|
const shape = shapeOf(n, getDef.value)
|
||||||
|
const label = (k: string) => (s.dir === 'in' ? shape.inputs : shape.outputs).find(p => p.key === k)?.label ?? ''
|
||||||
|
pinSel.value = null
|
||||||
|
placing.value = null
|
||||||
|
linking.value = { queue: s.pins.map(pin => ({ node: s.node, pin, dir: s.dir, label: label(pin) })), at: 0 }
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Bubbles on every picked input (or off, when they all have one). */
|
||||||
|
function invertPicked() {
|
||||||
|
const s = pinSel.value
|
||||||
|
const n = s && s.dir === 'in' ? def.value.nodes.find(x => x.id === s.node) : undefined
|
||||||
|
if (!s || !n) return
|
||||||
|
const pins = s.pins.filter(p => canInvert(n, p))
|
||||||
|
if (!pins.length) return notify('These inputs can not take a bubble', 'error')
|
||||||
|
const all = pins.every(p => n.invert?.includes(p))
|
||||||
|
const set = new Set(n.invert ?? [])
|
||||||
|
for (const p of pins) {
|
||||||
|
if (all) set.delete(p)
|
||||||
|
else set.add(p)
|
||||||
|
}
|
||||||
|
if (set.size) n.invert = [...set]
|
||||||
|
else delete n.invert
|
||||||
|
commit()
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Removes the wires on the picked pins. */
|
||||||
|
function unwirePicked() {
|
||||||
|
const s = pinSel.value
|
||||||
|
if (!s) return
|
||||||
|
const pins = new Set(s.pins)
|
||||||
|
const before = def.value.wires.length
|
||||||
|
def.value.wires = def.value.wires.filter(w => !(s.dir === 'out' ? w.from.node === s.node && pins.has(w.from.pin) : w.to.node === s.node && pins.has(w.to.pin)))
|
||||||
|
const n = before - def.value.wires.length
|
||||||
|
commit()
|
||||||
|
notify(n ? `Removed ${n} wire${n === 1 ? '' : 's'}` : 'No wires on these pins')
|
||||||
}
|
}
|
||||||
|
|
||||||
// ── Saving ────────────────────────────────────────────────────────
|
// ── Saving ────────────────────────────────────────────────────────
|
||||||
|
|
@ -1229,11 +1315,16 @@ function create() {
|
||||||
commit()
|
commit()
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Ends dragged away from the part they are plugged into come loose. */
|
/**
|
||||||
|
* Parts moved away from the part they hang on come loose: cable ends
|
||||||
|
* unplug, latched parts let go, and a docked panel moved up or down off its
|
||||||
|
* component's pins becomes a panel of its own (rows and wires kept).
|
||||||
|
*/
|
||||||
function unplugMoved(ids: Set<string>) {
|
function unplugMoved(ids: Set<string>) {
|
||||||
for (const n of def.value.nodes) {
|
for (const n of def.value.nodes) {
|
||||||
if (n.plug && ids.has(n.id) && !ids.has(n.plug)) delete n.plug
|
if (n.plug && ids.has(n.id) && !ids.has(n.plug)) delete n.plug
|
||||||
if (n.latch && ids.has(n.id) && !ids.has(n.latch)) delete n.latch
|
if (n.latch && ids.has(n.id) && !ids.has(n.latch)) delete n.latch
|
||||||
|
if (n.attach && ids.has(n.id) && !ids.has(n.attach) && offItsPins(def.value, n, getDef.value)) detachPanel(n)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2620,6 +2711,13 @@ function create() {
|
||||||
wireSel,
|
wireSel,
|
||||||
selectedWires,
|
selectedWires,
|
||||||
clearSelection,
|
clearSelection,
|
||||||
|
pinSel,
|
||||||
|
pickPins,
|
||||||
|
pickPin,
|
||||||
|
cablePicked,
|
||||||
|
linkPicked,
|
||||||
|
invertPicked,
|
||||||
|
unwirePicked,
|
||||||
placing,
|
placing,
|
||||||
nav,
|
nav,
|
||||||
views,
|
views,
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,6 @@ import type { ComponentDef } from './types'
|
||||||
export interface MoveStart {
|
export interface MoveStart {
|
||||||
/** Parts that move (followers included), where they were. */
|
/** Parts that move (followers included), where they were. */
|
||||||
nodes: Map<string, Pt>
|
nodes: Map<string, Pt>
|
||||||
/** Panels docked to a part that stays: they only slide sideways. */
|
|
||||||
lockY: Set<string>
|
|
||||||
/** Corners of every wire that has hand-placed ones. */
|
/** Corners of every wire that has hand-placed ones. */
|
||||||
pts: Map<string, Pt[]>
|
pts: Map<string, Pt[]>
|
||||||
/** Wires picked along with the parts. */
|
/** Wires picked along with the parts. */
|
||||||
|
|
@ -22,15 +20,13 @@ export interface MoveStart {
|
||||||
|
|
||||||
export function moveStart(def: ComponentDef, ids: Set<string>, wires: Iterable<string> = []): MoveStart {
|
export function moveStart(def: ComponentDef, ids: Set<string>, wires: Iterable<string> = []): MoveStart {
|
||||||
const nodes = new Map<string, Pt>()
|
const nodes = new Map<string, Pt>()
|
||||||
const lockY = new Set<string>()
|
|
||||||
for (const n of def.nodes) {
|
for (const n of def.nodes) {
|
||||||
if (!ids.has(n.id)) continue
|
if (!ids.has(n.id)) continue
|
||||||
nodes.set(n.id, [n.x, n.y])
|
nodes.set(n.id, [n.x, n.y])
|
||||||
if (n.attach && !ids.has(n.attach)) lockY.add(n.id)
|
|
||||||
}
|
}
|
||||||
const pts = new Map<string, Pt[]>()
|
const pts = new Map<string, Pt[]>()
|
||||||
for (const w of def.wires) if (w.pts) pts.set(w.id, w.pts.map(p => [p[0], p[1]] as Pt))
|
for (const w of def.wires) if (w.pts) pts.set(w.id, w.pts.map(p => [p[0], p[1]] as Pt))
|
||||||
return { nodes, lockY, pts, wires: new Set(wires) }
|
return { nodes, pts, wires: new Set(wires) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -45,7 +41,7 @@ export function moveParts(def: ComponentDef, start: MoveStart, dx: number, dy: n
|
||||||
for (const n of def.nodes) {
|
for (const n of def.nodes) {
|
||||||
const at = start.nodes.get(n.id)
|
const at = start.nodes.get(n.id)
|
||||||
if (!at) continue
|
if (!at) continue
|
||||||
const step: Pt = [dx, start.lockY.has(n.id) ? 0 : dy]
|
const step: Pt = [dx, dy]
|
||||||
n.x = at[0] + step[0]
|
n.x = at[0] + step[0]
|
||||||
n.y = at[1] + step[1]
|
n.y = at[1] + step[1]
|
||||||
if (step[0] || step[1]) by.set(n.id, step)
|
if (step[0] || step[1]) by.set(n.id, step)
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,20 @@ function layout(panel: CircuitNode, pins: ChipInput[]) {
|
||||||
return top
|
return top
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A docked panel moved up or down off its component's pins: its first row no
|
||||||
|
* longer sits level with that row's pin. Moved only sideways, it still does.
|
||||||
|
*/
|
||||||
|
export function offItsPins(def: ComponentDef, panel: CircuitNode, get: DefLookup): boolean {
|
||||||
|
const chip = panel.attach ? def.nodes.find(n => n.id === panel.attach) : undefined
|
||||||
|
const pins = chip && chipInputs(chip, get, sideOf(panel))
|
||||||
|
if (!chip || !pins) return false
|
||||||
|
const order = new Map(pins.map((p, i) => [p.key, i]))
|
||||||
|
const first = (panel.rows ?? []).filter(r => order.has(r.id)).sort((a, b) => order.get(a.id)! - order.get(b.id)!)[0]
|
||||||
|
const pin = first && pins.find(p => p.key === first.id)
|
||||||
|
return !!pin && panel.y !== chip.y + pin.dy
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Docks a new panel to a placed component: an input panel on its left with
|
* 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
|
* a switch for every input that is not wired yet, or an output panel on its
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue