feat(pcb): G-code 실크 — 부품 윤곽(저항 아령·콘덴서 타원·전해콘덴서 원 등)을 silk.nc 로 새김, 배선·패드와 겹치는 부분은 잘라냄(깊이·켜기 설정)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bfb88b2880
commit
8371f5dab3
4 files changed
+116
-3
No files matched your search
@@ -5,6 +5,7 @@ import { placedPads } from './footprints';
|
||||
import type { MillSettings, PcbProject, Routed } from './types';
|
||||
import { DEFAULT_MILL, JUMPER_PAD, JUMPER_DRILL } from './types';
|
||||
import { layerNames } from './dsn';
|
||||
import { silkLines } from './silk';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
const ClipperLib: any = require('clipper-lib');
|
||||
@@ -171,6 +172,40 @@ export function buildGcode(p: PcbProject, routed: Routed): GcodeResult {
|
||||
files['drill.nc'] = L.filter(Boolean).join('\n') + '\n';
|
||||
}
|
||||
|
||||
// 실크(부품 윤곽): 동박면에 얕게 새긴다. 배선·패드(+공구 반지름+여유)와 겹치는 부분은 잘라내 배선이 끊기지 않게 한다.
|
||||
if (m.silk !== false && p.parts.length) {
|
||||
const silkLayer = p.rules.layers === 2 ? 'F.Cu' : p.rules.copper;
|
||||
const subj: IP[][] = silkLines(p.parts).map(l => l.map(([x, y]) => ip(x, y)));
|
||||
const copper = offsetClosed(copperUnion(p, routed, silkLayer), m.toolDia / 2 + 0.15);
|
||||
const diff = (() => {
|
||||
const c = new ClipperLib.Clipper();
|
||||
c.AddPaths(subj, ClipperLib.PolyType.ptSubject, false);
|
||||
c.AddPaths(copper, ClipperLib.PolyType.ptClip, true);
|
||||
const tree = new ClipperLib.PolyTree();
|
||||
c.Execute(ClipperLib.ClipType.ctDifference, tree, ClipperLib.PolyFillType.pftNonZero, ClipperLib.PolyFillType.pftNonZero);
|
||||
const open = (ClipperLib.Clipper.OpenPathsFromPolyTree(tree) as IP[][]).filter(pp => pp.length > 1);
|
||||
const c2 = new ClipperLib.Clipper(); // 보드 가장자리 0.3mm 안쪽으로만
|
||||
c2.AddPaths(open, ClipperLib.PolyType.ptSubject, false);
|
||||
c2.AddPath([ip(0.3, 0.3), ip(W - 0.3, 0.3), ip(W - 0.3, H - 0.3), ip(0.3, H - 0.3)], ClipperLib.PolyType.ptClip, true);
|
||||
const t2 = new ClipperLib.PolyTree();
|
||||
c2.Execute(ClipperLib.ClipType.ctIntersection, t2, ClipperLib.PolyFillType.pftNonZero, ClipperLib.PolyFillType.pftNonZero);
|
||||
return orderPaths((ClipperLib.Clipper.OpenPathsFromPolyTree(t2) as IP[][]).filter(pp => pp.length > 1));
|
||||
})();
|
||||
const inBoard = diff;
|
||||
if (inBoard.length) {
|
||||
const mir = mirrorFor(silkLayer), z = m.silkZ ?? -0.05;
|
||||
const L = head(`실크(부품 윤곽) 새기기 (Ø${m.toolDia}mm 비트, 깊이 ${z}mm)`);
|
||||
for (const pp of inBoard) {
|
||||
const pts = pp.map(toMm);
|
||||
L.push(`G0 X${tx(pts[0][0], mir)} Y${ty(pts[0][1])}`, `G1 Z${f(z)} F${f(m.plunge)}`);
|
||||
for (let k = 1; k < pts.length; k++) L.push(`G1 X${tx(pts[k][0], mir)} Y${ty(pts[k][1])} F${f(m.feed)}`);
|
||||
L.push(`G0 Z${f(m.safeZ)}`);
|
||||
}
|
||||
L.push(...tail);
|
||||
files['silk.nc'] = L.filter(Boolean).join('\n') + '\n';
|
||||
} else warnings.push('실크 선이 모두 배선·패드와 겹치거나 보드 밖이라 silk.nc 를 만들지 않았습니다.');
|
||||
}
|
||||
|
||||
// 외곽 컷 (공구 중심은 보드 바깥으로 반지름만큼 오프셋)
|
||||
const outline: Pt[] = (() => {
|
||||
const r = offsetClosed([[ip(0, 0), ip(W, 0), ip(W, H), ip(0, H)]], m.outlineDia / 2)[0] || [];
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
// 실크(부품 윤곽) 선 — 화면(pcb-app.html drawPartShape)과 같은 모양을 mm 좌표 폴리라인으로 만든다.
|
||||
// 저항=아령, 콘덴서=타원, 전해콘덴서=원(+쪽 현·'+'), 다이오드=몸통+띠, LED=평평한 원, 인덕터=코일, DIP=상자+홈, TO-92=D자, TO-220=상자+방열판 띠.
|
||||
import { getFootprint, rotPoint, placedPads } from './footprints';
|
||||
import type { PartInst } from './footprints';
|
||||
|
||||
type Pt = [number, number];
|
||||
export type Line = Pt[];
|
||||
|
||||
const arc = (cx: number, cy: number, r: number, a0: number, a1: number, n = 0): Pt[] => {
|
||||
const k = n || Math.max(8, Math.ceil(Math.abs(a1 - a0) / (Math.PI / 12)));
|
||||
return Array.from({ length: k + 1 }, (_, i) => { const a = a0 + (a1 - a0) * i / k; return [cx + r * Math.cos(a), cy + r * Math.sin(a)] as Pt; });
|
||||
};
|
||||
const rectL = (x0: number, y0: number, x1: number, y1: number): Line => [[x0, y0], [x1, y0], [x1, y1], [x0, y1], [x0, y0]];
|
||||
|
||||
export function silkLines(parts: PartInst[]): Line[] {
|
||||
const out: Line[] = [];
|
||||
for (const part of parts) {
|
||||
const f = getFootprint(part.fp); if (!f) continue;
|
||||
const id = part.fp.toLowerCase(), pads = placedPads([part]);
|
||||
const at = (fr: (x: number, y: number) => Pt, ls: Line[]) => { for (const l of ls) out.push(l.map(q => fr(q[0], q[1]))); };
|
||||
if (pads.length === 2 && !f.smd) {
|
||||
const A = pads.find(q => q.n === '1') || pads[0], B = pads.find(q => q !== A)!;
|
||||
const d = Math.hypot(B.x - A.x, B.y - A.y), ang = Math.atan2(B.y - A.y, B.x - A.x), mx = (A.x + B.x) / 2, my = (A.y + B.y) / 2;
|
||||
const fr = (x: number, y: number): Pt => [mx + x * Math.cos(ang) - y * Math.sin(ang), my + x * Math.sin(ang) + y * Math.cos(ang)];
|
||||
const ref = part.ref.toUpperCase();
|
||||
const kind = /^R/.test(ref) ? 'R' : /^L/.test(ref) ? 'L' : /^C/.test(ref) ? (/cp_|elko|polar|c_radial/.test(id) && f.circle ? '' : 'C') : /^D|^LED/.test(ref) ? (/led/.test(id) ? 'LED' : 'D') : '';
|
||||
if (kind === 'R' && d >= 4.4) {
|
||||
const bl = Math.max(2.6, Math.min(d - 2.2, 6.8)), rb = 1.4, n = 0.7, c = bl / 2 - rb, th = Math.asin(n / rb);
|
||||
at(fr, [[...arc(c, 0, rb, Math.PI + th, 3 * Math.PI - th), ...arc(-c, 0, rb, th, 2 * Math.PI - th), [c + Math.cos(Math.PI + th) * rb, -n]]]); continue;
|
||||
}
|
||||
if (kind === 'C' && d >= 2.2) { const rx = d / 2 + 1.3, ry = Math.min(2.2, Math.max(1.3, d / 3)); at(fr, [Array.from({ length: 33 }, (_, i) => [rx * Math.cos(i * Math.PI / 16), ry * Math.sin(i * Math.PI / 16)] as Pt)]); continue; }
|
||||
if (kind === 'D' && d >= 4.4) { const bl = Math.max(2.6, Math.min(d - 2.2, 5.4)), h = 1.4; at(fr, [rectL(-bl / 2, -h, bl / 2, h), [[-bl / 2 + 0.35, -h], [-bl / 2 + 0.35, h]], [[-bl / 2 + 1.25, -h], [-bl / 2 + 1.25, h]]]); continue; }
|
||||
if (kind === 'LED') { const r = Math.max(1.6, Math.min(2.9, d / 2 + 0.8)), ph = Math.acos(0.82); const a = arc(0, 0, r, Math.PI + ph, 3 * Math.PI - ph); at(fr, [[...a, a[0]]]); continue; }
|
||||
if (kind === 'L' && d >= 4.4) { const w = d - 2.2, n = Math.max(3, Math.round(w / 1.6)), r = w / n / 2; const l: Line = []; for (let k = 0; k < n; k++) l.push(...arc(-w / 2 + r + k * 2 * r, 0, r, Math.PI, 2 * Math.PI)); at(fr, [l]); continue; }
|
||||
}
|
||||
// 부품 자체 좌표계
|
||||
const b = f.body, bw = b.x1 - b.x0, bh = b.y1 - b.y0;
|
||||
const fr = (x: number, y: number): Pt => { const [dx, dy] = rotPoint(x, y, part.rot); return [part.x + dx, part.y + dy]; };
|
||||
const padCy = f.pads.reduce((a, q) => a + q.y, 0) / Math.max(1, f.pads.length), nearTop = (b.y0 + b.y1) / 2 > padCy;
|
||||
if (/dip/.test(id)) {
|
||||
const p1 = f.pads.find(q => q.n === '1');
|
||||
if (p1) {
|
||||
const lines: Line[] = [rectL(b.x0, b.y0, b.x1, b.y1)];
|
||||
if (bh >= bw) { const top = Math.abs(p1.y - b.y0) < Math.abs(p1.y - b.y1); lines.push(arc((b.x0 + b.x1) / 2, top ? b.y0 : b.y1, 0.9, top ? 0 : Math.PI, top ? Math.PI : 2 * Math.PI)); }
|
||||
else { const left = Math.abs(p1.x - b.x0) < Math.abs(p1.x - b.x1); lines.push(arc(left ? b.x0 : b.x1, (b.y0 + b.y1) / 2, 0.9, left ? -Math.PI / 2 : Math.PI / 2, left ? Math.PI / 2 : 3 * Math.PI / 2)); }
|
||||
at(fr, lines); continue;
|
||||
}
|
||||
}
|
||||
if (/to-92/.test(id) && bw > 0) {
|
||||
const cx = (b.x0 + b.x1) / 2, rr = bw / 2, flat = nearTop ? b.y0 : b.y1, sg = nearTop ? 1 : -1, cy = flat + sg * Math.max(0, bh - rr);
|
||||
at(fr, [[[b.x0, flat], [b.x1, flat], [b.x1, cy], ...(sg > 0 ? arc(cx, cy, rr, 0, Math.PI) : arc(cx, cy, rr, 0, -Math.PI)), [b.x0, flat]]]); continue;
|
||||
}
|
||||
if (/to-220|to-247|to-126/.test(id)) {
|
||||
const th = Math.min(1.6, bh * 0.3), ty = nearTop ? b.y1 - th : b.y0;
|
||||
at(fr, [rectL(b.x0, b.y0, b.x1, b.y1), [[b.x0, nearTop ? ty : ty + th], [b.x1, nearTop ? ty : ty + th]], arc((b.x0 + b.x1) / 2, ty + th / 2, Math.min(0.9, th * 0.35), 0, 2 * Math.PI)]); continue;
|
||||
}
|
||||
if (f.circle) {
|
||||
const c = f.circle, [dx, dy] = rotPoint(c.cx, c.cy, part.rot), X = part.x + dx, Y = part.y + dy;
|
||||
out.push(arc(X, Y, c.r, 0, 2 * Math.PI));
|
||||
if (/capacitor_tht:cp_/.test(id)) {
|
||||
const p1 = pads.find(q => q.n === '1');
|
||||
if (p1) { // + 쪽: 현(0.35r) 한 줄 + '+' 표시
|
||||
const L = Math.hypot(p1.x - X, p1.y - Y) || 1, ux = (p1.x - X) / L, uy = (p1.y - Y) / L, t = c.r * 0.35, w = Math.sqrt(c.r * c.r - t * t);
|
||||
out.push([[X + ux * t - uy * w, Y + uy * t + ux * w], [X + ux * t + uy * w, Y + uy * t - ux * w]]);
|
||||
const px = X + ux * c.r * 0.68, py = Y + uy * c.r * 0.68;
|
||||
out.push([[px - 0.5, py], [px + 0.5, py]], [[px, py - 0.5], [px, py + 0.5]]);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
at(fr, [rectL(b.x0, b.y0, b.x1, b.y1)]);
|
||||
}
|
||||
return out;
|
||||
}
|
||||
@@ -18,6 +18,8 @@ export interface MillSettings {
|
||||
drillZ: number; // 드릴 깊이 (음수, 기판 두께 + 여유)
|
||||
outlineDia: number; outlineZ: number; outlineStep: number;
|
||||
mirror: boolean; // 아랫면 가공: 좌우 반전
|
||||
silk?: boolean; // 실크(부품 윤곽) 새기기 — silk.nc (기본 켜짐)
|
||||
silkZ?: number; // 실크 새김 깊이 (음수, 기본 -0.05)
|
||||
}
|
||||
export interface PcbProject {
|
||||
board: { w: number; h: number };
|
||||
@@ -36,5 +38,5 @@ 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 = {
|
||||
toolDia: 0.2, passes: 2, overlap: 0.3, cutZ: -0.1, safeZ: 2, feed: 200, plunge: 60, rpm: 10000,
|
||||
drillZ: -1.8, outlineDia: 1.0, outlineZ: -1.8, outlineStep: 0.6, mirror: true,
|
||||
drillZ: -1.8, outlineDia: 1.0, outlineZ: -1.8, outlineStep: 0.6, mirror: true, silk: true, silkZ: -0.05,
|
||||
};
|
||||
@@ -196,6 +196,8 @@ details{margin-bottom:6px}summary{cursor:pointer;font-weight:700;font-size:12.5p
|
||||
<div><label>외곽 비트 Ø mm</label><input type="number" id="m_outlineDia" step="0.1" onchange="applyMill()"></div>
|
||||
<div><label>외곽 깊이 Z</label><input type="number" id="m_outlineZ" step="0.1" onchange="applyMill()"></div>
|
||||
<div><label>외곽 단차 mm</label><input type="number" id="m_outlineStep" step="0.1" onchange="applyMill()"></div>
|
||||
<div><label>실크 깊이 Z</label><input type="number" id="m_silkZ" step="0.01" onchange="applyMill()"></div>
|
||||
<div style="align-self:end"><label><input type="checkbox" id="m_silk" style="width:auto" onchange="applyMill()"> 실크(부품 윤곽) 새기기</label></div>
|
||||
<div style="grid-column:1/3"><label><input type="checkbox" id="m_mirror" style="width:auto" onchange="applyMill()"> 아랫면 단면: 좌우 반전(뒤집어서 가공)</label></div>
|
||||
</div>
|
||||
<div class="note">V비트라면 "가공 폭"은 깊이에서의 유효 폭입니다. 최소 간격은 가공 폭 이상이어야 배선 사이가 분리됩니다.</div>
|
||||
@@ -239,7 +241,7 @@ async function api(url,body,method){
|
||||
|
||||
// ───────────── 모델 ─────────────
|
||||
const DEF_RULES={trace:0.4,clearance:0.3,layers:1,copper:'B.Cu',viaDia:0.9,viaDrill:0.5};
|
||||
const DEF_MILL={toolDia:0.2,passes:2,overlap:0.3,cutZ:-0.1,safeZ:2,feed:200,plunge:60,rpm:10000,drillZ:-1.8,outlineDia:1.0,outlineZ:-1.8,outlineStep:0.6,mirror:true};
|
||||
const DEF_MILL={toolDia:0.2,passes:2,overlap:0.3,cutZ:-0.1,safeZ:2,feed:200,plunge:60,rpm:10000,drillZ:-1.8,outlineDia:1.0,outlineZ:-1.8,outlineStep:0.6,mirror:true,silk:true,silkZ:-0.05};
|
||||
let tab='pcb';
|
||||
let FP=[],FPM={};
|
||||
let P=null, routed=null, gres=null;
|
||||
@@ -554,7 +556,7 @@ async function doGcode(){
|
||||
gres=await api('/api/pcb/gcode',{project:P,routed});
|
||||
const s=gres.stats;
|
||||
$('res').innerHTML=`구멍 ${s.holes}개(드릴 ${s.drillSizes.join(', ')||'-'}mm) · 격리 경로 ${s.isolationLengthMm}mm · 예상 약 ${s.estMinutes}분`+gres.warnings.map(w=>`<div class="warn">⚠ ${esc(w)}</div>`).join('');
|
||||
$('dl').innerHTML=Object.keys(gres.files).map(n=>`<a href="#" onclick="dlFile('${esc(n)}');return false">⬇ ${esc(n)}</a>`).join('')+'<div class="note">순서: 격리(copper) → 드릴(공구 교체 시 M0 일시정지) → 외곽. jumpers.txt 는 조립 시 윗면에 납땜할 점퍼선 목록입니다. 가공 전 Z 영점·고정을 확인하세요.</div>';
|
||||
$('dl').innerHTML=Object.keys(gres.files).map(n=>`<a href="#" onclick="dlFile('${esc(n)}');return false">⬇ ${esc(n)}</a>`).join('')+'<div class="note">순서: 격리(copper) → 실크(silk.nc, 선택) → 드릴(공구 교체 시 M0 일시정지) → 외곽. jumpers.txt 는 조립 시 윗면에 납땜할 점퍼선 목록입니다. 가공 전 Z 영점·고정을 확인하세요.</div>';
|
||||
millPaths={};renderMill();draw();
|
||||
if(P.name&&!pconflict){
|
||||
try{ if(projDirty||!P.rev) await serverSave(false);
|
||||
|
||||
Reference in new issue
Block a user