feat(pcb): 점퍼선 전용 구멍 — 부품 구멍을 빌리지 않고 배선 위/핀 옆에 Ø0.9 구멍+Ø1.8 패드를 새로 만들어 기판·G-code(구리/드릴)·점퍼 목록에 반영

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
kimandClaude Sonnet 5.5 committed 2026-10-04 13:40:24 +09:00
1 parent 738d2a0449
commit 04f093cc54
5 files changed
+81 -13

No files matched your search

+2 -1
View File
@@ -200,7 +200,8 @@ export function registerPcbRoutes(app: express.Application, requireGatewayAuth:
vias: Array.isArray(rr.vias) ? rr.vias : [],
};
if (!routed.traces.length) { res.status(400).json({ error: '배선 결과가 없습니다. 먼저 자동 배선을 실행하세요.' }); return; }
const jumpers = Array.isArray(rr.jumpers) ? rr.jumpers : [];
const pt = (q: any): [number, number] | undefined => Array.isArray(q) && q.length === 2 && q.every((n: any) => Number.isFinite(n)) ? [q[0], q[1]] : undefined;
const jumpers = (Array.isArray(rr.jumpers) ? rr.jumpers : []).map((j: any) => ({ net: String(j.net), a: String(j.a), b: String(j.b), len: Number(j.len) || 0, smd: !!j.smd, pa: pt(j.pa), pb: pt(j.pb) }));
routed.jumpers = jumpers;
const g = buildGcode(project, routed);
if (jumpers.length) g.files['jumpers.txt'] = jumperList(project, jumpers);
+3 -1
View File
@@ -3,7 +3,7 @@
// 아랫면 가공(mirror)이면 gx = W - x (보드를 좌우로 뒤집어 동박면을 위로 놓고 깎는다).
import { placedPads } from './footprints';
import type { MillSettings, PcbProject, Routed } from './types';
import { DEFAULT_MILL } from './types';
import { DEFAULT_MILL, JUMPER_PAD, JUMPER_DRILL } from './types';
import { layerNames } from './dsn';
// eslint-disable-next-line @typescript-eslint/no-var-requires
@@ -69,6 +69,7 @@ export function copperPolys(p: PcbProject, routed: Routed, layer: string): IP[][
else polys.push(rectPoly(pad.x, pad.y, pad.w, pad.h));
}
for (const v of routed.vias) polys.push(circlePoly(v.x, v.y, p.rules.viaDia));
for (const j of routed.jumpers || []) for (const q of [j.pa, j.pb]) if (q) polys.push(circlePoly(q[0], q[1], JUMPER_PAD));
for (const t of routed.traces) {
if (t.layer !== layer || t.pts.length < 2) continue;
polys.push(...offsetOpen(t.pts.map(([x, y]) => ip(x, y)), t.w / 2));
@@ -153,6 +154,7 @@ export function buildGcode(p: PcbProject, routed: Routed): GcodeResult {
// 드릴
const holes: { x: number; y: number; d: number }[] = [];
for (const pad of placedPads(p.parts)) if (pad.drill > 0) holes.push({ x: pad.x, y: pad.y, d: pad.drill });
for (const j of routed.jumpers || []) for (const q of [j.pa, j.pb]) if (q) holes.push({ x: q[0], y: q[1], d: JUMPER_DRILL });
if (p.rules.layers === 2) for (const v of routed.vias) holes.push({ x: v.x, y: v.y, d: p.rules.viaDrill });
const sizes = [...new Set(holes.map(h => Math.round(h.d * 100) / 100))].sort((a, b) => a - b);
{
+67 -7
View File
@@ -1,15 +1,16 @@
// 미배선 보완: 자동 배선 뒤에도 구리로 이어지지 않은 곳(구리 섬이 나뉜 넷)을 윗면 점퍼선으로 잇는다.
// 점퍼선은 부품면(윗면)에서 기존 관통 구멍 두 곳을 잇는 전선이라, 아랫면 배선을 가로질러도 단락되지 않는다.
// 점퍼선은 부품면(윗면)에서 전용 구멍(Ø0.9, 배선 위 또는 핀 옆에 새로 뚫음) 두 곳을 잇는 전선이라, 아랫면 배선을 가로질러도 단락되지 않는다.
// 연결성은 Freerouting 의 말을 믿지 않고 실제 구리 도형(트레이스+패드)의 합집합으로 직접 판정한다.
import { placedPads } from './footprints';
import type { PcbProject, Routed } from './types';
import type { PcbProject, Routed, JumperDef } from './types';
import { JUMPER_PAD } from './types';
import { copperPolys } from './gcode';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const ClipperLib: any = require('clipper-lib');
const S = 1000;
export interface Jumper { net: string; a: string; b: string; len: number; smd: boolean }
export type Jumper = JumperDef;
interface Island { outer: { X: number; Y: number }[]; holes: { X: number; Y: number }[][] }
@@ -43,12 +44,69 @@ export function findJumpers(p: PcbProject, routed: Routed): JumperResult {
return islands.findIndex(is => inside(pt, is.outer) && !is.holes.some(h => ClipperLib.Clipper.PointInPolygon(pt, h) === 1));
};
const jumpers: Jumper[] = [];
const taken: { x: number; y: number; net: string }[] = []; // 이미 잡은 점퍼 구멍
const R = JUMPER_PAD / 2, CL = p.rules.clearance;
const circle = (x: number, y: number, r: number) => { const o: { X: number; Y: number }[] = []; for (let k = 0; k < 24; k++) o.push({ X: Math.round((x + r * Math.cos(k * Math.PI / 12)) * S), Y: Math.round((y + r * Math.sin(k * Math.PI / 12)) * S) }); return o; };
const hits = (poly: { X: number; Y: number }[], other: { X: number; Y: number }[]) => {
const c = new ClipperLib.Clipper(); c.AddPath(poly, ClipperLib.PolyType.ptSubject, true); c.AddPath(other, ClipperLib.PolyType.ptClip, true);
const sol = new ClipperLib.Paths(); c.Execute(ClipperLib.ClipType.ctIntersection, sol, ClipperLib.PolyFillType.pftNonZero, ClipperLib.PolyFillType.pftNonZero);
return sol.length > 0;
};
/** 한 구리 섬 위에서 점퍼 구멍을 둘 후보점(트레이스 위, 없으면 핀 둘레 + 짧은 연결선). 다른 구리·구멍과 간격이 되는 점만. */
const candidates = (isKey: number, ids: string[], net: string) => {
const out: { x: number; y: number; stub?: [number, number] }[] = [];
const isl = isKey >= 0 ? islands[isKey] : null;
const ok = (x: number, y: number) => {
if (x < R + 0.5 || y < R + 0.5 || x > p.board.w - R - 0.5 || y > p.board.h - R - 0.5) return false;
for (const t of taken) if (Math.hypot(t.x - x, t.y - y) < (t.net === net ? 2.2 : R * 2 + CL + 1.2)) return false;
for (const pd of pads) if (Math.hypot(pd.x - x, pd.y - y) < Math.max(pd.w, pd.h) / 2 + R + (ids.includes(pd.id) ? 0.4 : CL)) return false;
const zone = circle(x, y, R + CL);
return !islands.some((o, oi) => oi !== isKey && hits(zone, o.outer));
};
if (isl) for (const t of routed.traces) {
if (t.net !== net) continue;
for (let k = 1; k < t.pts.length; k++) {
const [x0, y0] = t.pts[k - 1], [x1, y1] = t.pts[k], L = Math.hypot(x1 - x0, y1 - y0), n = Math.max(1, Math.ceil(L / 0.5));
for (let q = 0; q <= n; q++) {
const x = x0 + (x1 - x0) * q / n, y = y0 + (y1 - y0) * q / n;
if (inside({ X: Math.round(x * S), Y: Math.round(y * S) }, isl.outer) && ok(x, y)) out.push({ x, y });
}
}
}
if (out.length < 40) for (const id of ids) { // 핀 둘레(짧은 선으로 이어 붙임)
const pd = byId.get(id)!; if (pd.smd && layer !== 'F.Cu') continue;
for (const dist of [Math.max(pd.w, pd.h) / 2 + R + 0.5, Math.max(pd.w, pd.h) / 2 + R + 1.5]) for (let k = 0; k < 16; k++) {
const x = pd.x + dist * Math.cos(k * Math.PI / 8), y = pd.y + dist * Math.sin(k * Math.PI / 8);
if (ok(x, y)) out.push({ x, y, stub: [pd.x, pd.y] });
}
}
return out;
};
const placeJumperHoles = (jd: Jumper, ga: string[], gb: string[], ka: number, kb: number) => {
const A = candidates(ka, ga, jd.net), B = candidates(kb, gb, jd.net);
if (!A.length || !B.length) return; // 자리가 없으면 옛 방식(부품 구멍에 직접 납땜)
let best: { a: typeof A[0]; b: typeof B[0]; d: number } | null = null;
for (const a of A) for (const b of B) {
const d = Math.hypot(a.x - b.x, a.y - b.y);
if (d < JUMPER_PAD + 0.6) continue; // 두 구멍이 너무 붙지 않게
if (!best || d < best.d) best = { a, b, d };
}
if (!best) return;
for (const c of [best.a, best.b]) {
taken.push({ x: c.x, y: c.y, net: jd.net });
if (c.stub) routed.traces.push({ net: jd.net, layer, w: p.rules.trace, pts: [c.stub, [c.x, c.y]] });
}
jd.pa = [Math.round(best.a.x * 100) / 100, Math.round(best.a.y * 100) / 100];
jd.pb = [Math.round(best.b.x * 100) / 100, Math.round(best.b.y * 100) / 100];
jd.len = Math.round(best.d * 10) / 10; jd.smd = false;
};
const unresolved: string[] = [];
for (const net of p.nets) {
const ids = net.pins.filter(id => byId.has(id) && (!byId.get(id)!.smd || layer === 'F.Cu'));
if (ids.length < 2) continue;
const isl = new Map<number, string[]>();
ids.forEach((id, k) => { const i = padIsland(id); const key = i >= 0 ? i : -1 - k; (isl.get(key) || isl.set(key, []).get(key)!).push(id); });
const keys = [...isl.keys()];
const groups = [...isl.values()];
if (groups.length < 2) continue;
// 섬들 사이 최소 신장 트리(Prim): 두 섬 사이 거리 = 서로 가장 가까운 핀 쌍(관통 구멍 우선)
@@ -63,9 +121,11 @@ export function findJumpers(p: PcbProject, routed: Routed): JumperResult {
};
const used = [0], rest = groups.map((_, i) => i).slice(1);
while (rest.length) {
let pick: { a: string; b: string; d: number; smd: boolean } | null = null, pj = -1;
for (const i of used) for (const j of rest) { const c = best(groups[i], groups[j]); if (!pick || c.d < pick.d) { pick = c; pj = j; } }
jumpers.push({ net: net.name, a: pick!.a, b: pick!.b, len: Math.round(Math.hypot(byId.get(pick!.a)!.x - byId.get(pick!.b)!.x, byId.get(pick!.a)!.y - byId.get(pick!.b)!.y) * 10) / 10, smd: pick!.smd });
let pick: { a: string; b: string; d: number; smd: boolean } | null = null, pj = -1, pi = -1;
for (const i of used) for (const j of rest) { const c = best(groups[i], groups[j]); if (!pick || c.d < pick.d) { pick = c; pj = j; pi = i; } }
const jd: Jumper = { net: net.name, a: pick!.a, b: pick!.b, len: Math.round(Math.hypot(byId.get(pick!.a)!.x - byId.get(pick!.b)!.x, byId.get(pick!.a)!.y - byId.get(pick!.b)!.y) * 10) / 10, smd: pick!.smd };
placeJumperHoles(jd, groups[pi], groups[pj], keys[pi], keys[pj]);
jumpers.push(jd);
used.push(pj); rest.splice(rest.indexOf(pj), 1);
}
}
@@ -74,5 +134,5 @@ export function findJumpers(p: PcbProject, routed: Routed): JumperResult {
export function jumperList(p: PcbProject, jumpers: Jumper[]): string {
if (!jumpers.length) return '점퍼선 없음\n';
return ['점퍼선 목록 (부품면=윗면에서 연결, 단위 mm)', ...jumpers.map((j, i) => `J${i + 1}: ${j.a} ↔ ${j.b} (넷 ${j.net}, 길이 약 ${j.len}${j.smd ? ', SMD 패드 포함 — 납땜 주의' : ''})`)].join('\n') + '\n';
return ['점퍼선 목록 (부품면=윗면에서 연결, 단위 mm)', ...jumpers.map((j, i) => `J${i + 1}: ${j.pa && j.pb ? `구멍(${j.pa.join(', ')}) ↔ 구멍(${j.pb.join(', ')})` : `${j.a} ↔ ${j.b}`} (넷 ${j.net}, 길이 약 ${j.len}${j.smd ? ', SMD 패드 포함 — 납땜 주의' : ''})`)].join('\n') + '\n';
}
+4 -1
View File
@@ -28,7 +28,10 @@ export interface PcbProject {
}
export interface Trace { net: string; layer: string; w: number; pts: [number, number][] } // mm, 에디터 좌표
export interface Via { net: string; x: number; y: number }
export interface Routed { traces: Trace[]; vias: Via[]; jumpers?: { net: string; a: string; b: string; len: number; smd: boolean }[] }
/** 점퍼선 전용 구멍(패드 Ø1.8 / 구멍 Ø0.9) — 부품 구멍을 빌리지 않고 배선 위에 따로 뚫는다. */
export const JUMPER_PAD = 1.8, JUMPER_DRILL = 0.9;
export interface JumperDef { net: string; a: string; b: string; len: number; smd: boolean; pa?: [number, number]; pb?: [number, number] }
export interface Routed { traces: Trace[]; vias: Via[]; jumpers?: JumperDef[] }
export const DEFAULT_RULES: PcbRules = { trace: 0.4, clearance: 0.3, layers: 1, copper: 'B.Cu', viaDia: 0.9, viaDrill: 0.5 };
export const DEFAULT_MILL: MillSettings = {
+5 -3
View File
@@ -327,9 +327,11 @@ function draw(){
if(routed&&routed.jumpers&&routed.jumpers.length){
const pm0=Object.fromEntries(allPads().map(p=>[p.id,p]));
ctx.save();ctx.strokeStyle='#ffa726';ctx.fillStyle='#ffa726';ctx.lineWidth=Math.max(2,0.7*view.s);ctx.lineCap='round';ctx.setLineDash([view.s*1.2,view.s*0.7]);
routed.jumpers.forEach((j,i)=>{const a=pm0[j.a],b=pm0[j.b];if(!a||!b)return;ctx.beginPath();ctx.moveTo(sx(a.x),sy(a.y));ctx.lineTo(sx(b.x),sy(b.y));ctx.stroke();});
const jend=(j)=>{const a=j.pa?{x:j.pa[0],y:j.pa[1]}:pm0[j.a],b=j.pb?{x:j.pb[0],y:j.pb[1]}:pm0[j.b];return a&&b?[a,b]:null;};
routed.jumpers.forEach(j=>{if(!j.pa)return;ctx.setLineDash([]);for(const q of [j.pa,j.pb]){ctx.fillStyle='#cfd8dc';ctx.beginPath();ctx.arc(sx(q[0]),sy(q[1]),0.9*view.s,0,7);ctx.fill();ctx.fillStyle='#000';ctx.beginPath();ctx.arc(sx(q[0]),sy(q[1]),0.45*view.s,0,7);ctx.fill();}ctx.fillStyle='#ffa726';ctx.setLineDash([view.s*1.2,view.s*0.7]);});
routed.jumpers.forEach((j,i)=>{const e=jend(j);if(!e)return;ctx.beginPath();ctx.moveTo(sx(e[0].x),sy(e[0].y));ctx.lineTo(sx(e[1].x),sy(e[1].y));ctx.stroke();});
ctx.setLineDash([]);ctx.font='bold 11px sans-serif';
routed.jumpers.forEach((j,i)=>{const a=pm0[j.a],b=pm0[j.b];if(!a||!b)return;ctx.fillText('J'+(i+1),sx((a.x+b.x)/2)+4,sy((a.y+b.y)/2)-4);});
routed.jumpers.forEach((j,i)=>{const e=jend(j);if(!e)return;ctx.fillText('J'+(i+1),sx((e[0].x+e[1].x)/2)+4,sy((e[0].y+e[1].y)/2)-4);});
ctx.restore();
}
// 부품
@@ -526,7 +528,7 @@ async function doRoute(){
if(pcbKey()!==key0){$('rres').innerHTML='<span class="warn">배선 도중 배치·연결이 바뀌어 결과를 버렸습니다. 다시 눌러 주세요.</span>';return;}
routed={traces:d.traces,vias:d.vias,jumpers:d.jumpers||[]};routedCache={key:pcbKey(),routed};gres=null;$('res').innerHTML='';$('dl').innerHTML='';
const un=d.stats.unrouted, jn=routed.jumpers.length;
const jl=jn?`<div class="note" style="margin-top:4px">점퍼선(윗면, 부품 구멍 사이 전선):<br>`+routed.jumpers.map((j,i)=>`J${i+1}: ${esc(j.a)} ↔ ${esc(j.b)} · ${j.len}mm${j.smd?' ⚠SMD':''}`).join('<br>')+'</div>':'';
const jl=jn?`<div class="note" style="margin-top:4px">점퍼선(윗면 전선, 기판의 전용 구멍 Ø0.9 두 곳을 잇기):<br>`+routed.jumpers.map((j,i)=>`J${i+1}: ${esc(j.a)} ↔ ${esc(j.b)} · ${j.len}mm${j.pa?` · 구멍 (${j.pa}) ↔ (${j.pb})`:' · 부품 구멍에 직접'}${j.smd?' ⚠SMD':''}`).join('<br>')+'</div>':'';
$('rres').innerHTML=(un===0?`<span class="ok">✔ 구리 배선 완료</span> · ${d.traces.length}구간 · 비아 ${d.vias.length}개 · ${d.stats.seconds}초`
:jn?`<span class="ok">✔ 구리 + 점퍼선 ${jn}개로 모두 연결</span> · ${d.traces.length}구간 · ${d.stats.seconds}초`
:`<span class="bad">✖ 미배선 ${un<0?'?':un}건</span> (${d.traces.length}구간 배선됨, ${d.stats.seconds}초)<br>부품을 옮기거나 회전해 교차를 줄이거나, '점퍼선' 옵션을 켜 보세요.`)+jl;