diff --git a/app/assets/css/main.css b/app/assets/css/main.css index 9c56072..690fa0b 100644 --- a/app/assets/css/main.css +++ b/app/assets/css/main.css @@ -5416,3 +5416,20 @@ button.tile:hover { background: var(--danger); opacity: 1; } + +/* A part latched onto another: a contact strip along the joint, a clamp at each end. */ +.part-latch { + pointer-events: none; +} + +.part-latch .contact { + stroke: #3a4554; + stroke-width: 2.5; + stroke-linecap: round; +} + +.part-latch rect { + fill: #7a8698; + stroke: #10151c; + stroke-width: 1; +} diff --git a/app/components/editor/Canvas.vue b/app/components/editor/Canvas.vue index 1328bc4..c0f3232 100644 --- a/app/components/editor/Canvas.vue +++ b/app/components/editor/Canvas.vue @@ -9,6 +9,7 @@ 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 { latchLayout, latchSeam } from '~/lib/logic/latch' import { wirePath, type HopSpan } from '~/lib/draw' import { downloadSheet, printSheet, sheetSvg } from '~/lib/sheet' import { inputCount } from '~/lib/logic/wide' @@ -916,7 +917,8 @@ function onPointerUp(e: PointerEvent) { if (d.row && !d.moved) ed.pressRow(d.node, d.row, false) if (d.moved && d.plug) { ed.unplugMoved(new Set(d.orig.keys())) - ed.plugEnd(d.node) + if (d.node.kind === 'bundle' || d.node.kind === 'split') ed.plugEnd(d.node) + else ed.latchPart(d.node) } else if (d.moved && d.snap?.links.length) { const [sx, sy] = d.snap.shift for (const id of d.orig.keys()) { @@ -1420,10 +1422,25 @@ function openMenuForSelection() { /** * A free cable end dragged to within a square or so of where it would sit - * on its part's pins: the pins it would plug into. + * on its part's pins: the pins it would plug into. Any other part brought as + * close to where it would latch onto the part it is wired to: the pins it + * would latch onto. */ function plugNear(n: CircuitNode): { part: string; rings: Pt[] } | null { - if ((n.kind !== 'bundle' && n.kind !== 'split') || n.plug) return null + if (n.kind !== 'bundle' && n.kind !== 'split') { + const host = ed.latchTargetOf({ ...n, latch: undefined }) + const lay = host && latchLayout(def.value, n, host, ed.getDef.value) + // Not onto a part that is latched onto this one (it moves along anyway). + if (!host || !lay || ed.withFollowers([n.id]).has(host.id) || Math.hypot(n.x - lay.x, n.y - lay.y) > 1.6) return null + const s = shapes.value.get(n.id)! + const shared = def.value.wires.filter(w => (w.from.node === host.id && w.to.node === n.id) || (w.from.node === n.id && w.to.node === host.id)) + const rings = shared + .map(w => (w.to.node === n.id ? s.inputs.find(p => p.key === w.to.pin) : s.outputs.find(p => p.key === w.from.pin))) + .filter(p => !!p) + .map(p => [lay.x + p.dx, lay.y + p.dy] as Pt) + return { part: host.id, rings } + } + if (n.plug) return null const part = ed.plugTarget(n) const lay = part && plugLayout(def.value, n, part, ed.getDef.value) if (!part || !lay || Math.hypot(n.x - lay.x, n.y - lay.y) > 1.6) return null @@ -1431,6 +1448,14 @@ function plugNear(n: CircuitNode): { part: string; rings: Pt[] } | null { return { part: part.id, rings: lay.offsets.map(o => [x, lay.y + o] as Pt) } } +/** Where latched parts touch their part: a contact strip along the joint, held by a clamp at each end. */ +const latchMarks = computed(() => + def.value.nodes.flatMap(n => { + const seam = n.latch ? latchSeam(def.value, n, ed.getDef.value) : null + return seam ? [{ id: n.id, x: n.x + seam.x, y0: n.y + seam.y0, y1: n.y + seam.y1 }] : [] + }), +) + /** Pins a dragged part will connect to when dropped, shown as green rings. */ const dropRings = computed(() => { const g = ghostLanding.value @@ -1603,6 +1628,12 @@ defineExpose({ fit, zoomAt }) :open="openPins.get(n.id)" /> + + + + + + n.value.kind === 'bundle' || n.value.kind === 'split') +/** The part this one fits straight onto (its pins line up with the ones it is wired to). */ +const latchHost = computed(() => (isCableEnd.value ? undefined : ed.latchTargetOf(n.value))) const plugPart = computed(() => (isCableEnd.value && !n.value.plug ? ed.plugTarget(n.value) : undefined)) const pitch = computed(() => { const o = cableOffsets(n.value) @@ -601,6 +603,16 @@ function setRowHz(row: PanelRow, e: Event) { + +

+ + Latched onto {{ partName(n.latch) }}: it moves with it + +

+ +