feat(pcb): 기판 화면의 부품을 실제 모양으로 — 저항=아령, 콘덴서=타원, 다이오드=띠 원통, LED=평평한 원, 인덕터=코일, DIP=홈 있는 상자, TO-92=D자, TO-220=방열판 상자
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
be505cb610
commit
bfb88b2880
1 file changed
+54
-1
@@ -340,7 +340,8 @@ function draw(){
|
||||
const isSel=sel===part.ref;
|
||||
ctx.strokeStyle=isSel?'#fff176':'rgba(255,255,255,.55)'; ctx.lineWidth=isSel?2:1;
|
||||
const cf=FPM[part.fp]&&FPM[part.fp].circle;
|
||||
if(cf){const cc=rotPoint(cf.cx,cf.cy,part.rot);ctx.beginPath();ctx.arc(sx(part.x+cc[0]),sy(part.y+cc[1]),cf.r*view.s,0,7);ctx.stroke();
|
||||
if(drawPartShape(part,isSel)){}
|
||||
else if(cf){const cc=rotPoint(cf.cx,cf.cy,part.rot);ctx.beginPath();ctx.arc(sx(part.x+cc[0]),sy(part.y+cc[1]),cf.r*view.s,0,7);ctx.stroke();
|
||||
if(/^kicad:Capacitor_THT:CP_/.test(part.fp)){const p1=padsOf(part).find(q=>q.id.endsWith('-1'));if(p1){const dx=p1.x-(part.x+cc[0]),dy=p1.y-(part.y+cc[1]),L=Math.hypot(dx,dy)||1;const ux=dx/L,uy=dy/L,X0=sx(part.x+cc[0]),Y0=sy(part.y+cc[1]),R0=cf.r*view.s; // + 쪽 호(현 너머) 영역에 빗금
|
||||
ctx.save();ctx.beginPath();ctx.arc(X0,Y0,R0,0,7);ctx.clip();ctx.beginPath();ctx.rect(-1e4,-1e4,2e4,2e4);ctx.moveTo(0,0); // 원으로 자름
|
||||
ctx.beginPath();const t=R0*0.35,vx=-uy,vy=ux;ctx.moveTo(X0+ux*t+vx*R0*2,Y0+uy*t+vy*R0*2);ctx.lineTo(X0+ux*t-vx*R0*2,Y0+uy*t-vy*R0*2);ctx.lineTo(X0+ux*R0*2-vx*R0*2,Y0+uy*R0*2-vy*R0*2);ctx.lineTo(X0+ux*R0*2+vx*R0*2,Y0+uy*R0*2+vy*R0*2);ctx.closePath();ctx.clip();
|
||||
@@ -1195,6 +1196,58 @@ function setTab(t){
|
||||
}
|
||||
|
||||
|
||||
// 실제 부품 모양(저항=아령, 콘덴서=타원, 다이오드=띠 있는 원통, LED=평평한 원, 인덕터=코일, DIP=홈 있는 상자, TO-92=D자, TO-220=상자+방열판).
|
||||
// 못 알아보는 부품은 false 를 돌려줘 기본 사각 외곽선으로 그린다. 선 굵기는 화면 1~2px 로 고정.
|
||||
function drawPartShape(part,isSel){
|
||||
const f=FPM[part.fp]; if(!f) return false;
|
||||
const id=part.fp.toLowerCase(), pads=padsOf(part);
|
||||
const lw=(isSel?2:1.2), fillc='rgba(255,255,255,.07)';
|
||||
const fin=()=>{ctx.fillStyle=fillc;ctx.fill();ctx.lineWidth=lw/view.s;ctx.stroke();};
|
||||
// ── 2핀 축 방향 부품 ──
|
||||
if(pads.length===2&&!f.smd){
|
||||
const A=pads.find(q=>q.n==='1')||pads[0], B=pads.find(q=>q!==A), d=Math.hypot(B.x-A.x,B.y-A.y);
|
||||
const ang=Math.atan2(B.y-A.y,B.x-A.x), mx=(A.x+B.x)/2, my=(A.y+B.y)/2;
|
||||
const kind=/^r/i.test(part.ref)?'R':/^l/i.test(part.ref)?'L':/^c/i.test(part.ref)?(/cp_|elko|polar|c_radial/.test(id)&&f.circle?'':'C'):/^d|^led/i.test(part.ref)?(/led/.test(id)?'LED':'D'):'';
|
||||
const local=(fn)=>{ctx.save();ctx.translate(sx(mx),sy(my));ctx.rotate(ang);ctx.scale(view.s,view.s);fn();ctx.restore();};
|
||||
if(kind==='R'&&d>=4.4){ local(()=>{
|
||||
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);
|
||||
ctx.beginPath();ctx.arc(c,0,rb,Math.PI+th,3*Math.PI-th);ctx.arc(-c,0,rb,th,2*Math.PI-th);ctx.closePath();fin();
|
||||
ctx.beginPath();ctx.moveTo(-d/2,0);ctx.lineTo(-bl/2,0);ctx.moveTo(bl/2,0);ctx.lineTo(d/2,0);ctx.lineWidth=lw/view.s;ctx.stroke();}); return true; }
|
||||
if(kind==='C'&&d>=2.2){ local(()=>{ctx.beginPath();ctx.ellipse(0,0,d/2+1.3,Math.min(2.2,Math.max(1.3,d/3)),0,0,2*Math.PI);fin();}); return true; }
|
||||
if(kind==='D'&&d>=4.4){ local(()=>{
|
||||
const bl=Math.max(2.6,Math.min(d-2.2,5.4)), h=1.4; // 1번 핀(음극, 왼쪽)에 띠
|
||||
ctx.beginPath();ctx.roundRect?ctx.roundRect(-bl/2,-h,bl,2*h,0.5):ctx.rect(-bl/2,-h,bl,2*h);fin();
|
||||
ctx.fillStyle=ctx.strokeStyle;ctx.fillRect(-bl/2+0.35,-h,0.9,2*h);
|
||||
ctx.beginPath();ctx.moveTo(-d/2,0);ctx.lineTo(-bl/2,0);ctx.moveTo(bl/2,0);ctx.lineTo(d/2,0);ctx.lineWidth=lw/view.s;ctx.stroke();}); return true; }
|
||||
if(kind==='LED'){ local(()=>{
|
||||
const r=Math.max(1.6,Math.min(2.9,d/2+0.8)), fl=0.82*r, ph=Math.acos(fl/r); // 평평한 쪽이 1번 핀(음극)
|
||||
ctx.beginPath();ctx.arc(0,0,r,Math.PI+ph,3*Math.PI-ph);ctx.closePath();fin();}); return true; }
|
||||
if(kind==='L'&&d>=4.4){ local(()=>{
|
||||
const w=d-2.2, n=Math.max(3,Math.round(w/1.6)), r=w/n/2;
|
||||
ctx.beginPath();ctx.moveTo(-d/2,0);ctx.lineTo(-w/2,0);for(let k=0;k<n;k++)ctx.arc(-w/2+r+k*2*r,0,r,Math.PI,0,false);ctx.lineTo(d/2,0);ctx.lineWidth=lw/view.s;ctx.stroke();}); return true; }
|
||||
return false;
|
||||
}
|
||||
// ── 부품 자체 좌표계 (몸체 상자 기준) ──
|
||||
const b=f.body, bw=b.x1-b.x0, bh=b.y1-b.y0, rot=((Math.round(part.rot/90)*90)%360+360)%360;
|
||||
const loc=(fn)=>{ctx.save();ctx.translate(sx(part.x),sy(part.y));ctx.rotate(rot*Math.PI/180);ctx.scale(view.s,view.s);fn();ctx.restore();};
|
||||
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-|dip_|sip-/.test(id)&&/dip/.test(id)){
|
||||
const p1=f.pads.find(q=>q.n==='1'); if(!p1) return false; const vert=bh>=bw; const x0=b.x0,x1=b.x1,y0=b.y0,y1=b.y1;
|
||||
loc(()=>{ctx.beginPath();ctx.rect(x0,y0,bw,bh);fin();ctx.beginPath();
|
||||
if(vert){const top=Math.abs(p1.y-y0)<Math.abs(p1.y-y1), cy=top?y0:y1; ctx.arc((x0+x1)/2,cy,0.9,top?0:Math.PI,top?Math.PI:2*Math.PI,false);}
|
||||
else{const left=Math.abs(p1.x-x0)<Math.abs(p1.x-x1), cx=left?x0:x1; ctx.arc(cx,(y0+y1)/2,0.9,left?-Math.PI/2:Math.PI/2,left?Math.PI/2:-Math.PI/2,false);}
|
||||
ctx.lineWidth=lw/view.s;ctx.stroke();}); return true; }
|
||||
if(/to-92/.test(id)&&bw>0){
|
||||
loc(()=>{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)*1;
|
||||
ctx.beginPath();ctx.moveTo(b.x0,flat);ctx.lineTo(b.x1,flat);ctx.lineTo(b.x1,cy);ctx.arc(cx,cy,rr,0,Math.PI*sg,sg<0);ctx.closePath();fin();}); return true; }
|
||||
if(/to-220|to-247|to-126/.test(id)){
|
||||
loc(()=>{ctx.beginPath();ctx.rect(b.x0,b.y0,bw,bh);fin();
|
||||
const th=Math.min(1.6,bh*0.3), ty=nearTop?b.y1-th:b.y0; // 핀 반대쪽 방열판 띠 + 고정 구멍
|
||||
ctx.fillStyle='rgba(255,255,255,.18)';ctx.fillRect(b.x0,ty,bw,th);
|
||||
ctx.beginPath();ctx.arc((b.x0+b.x1)/2,ty+th/2,Math.min(0.9,th*0.35),0,7);ctx.lineWidth=lw/view.s;ctx.stroke();}); return true; }
|
||||
return false;
|
||||
}
|
||||
|
||||
// ───────────── 예제 ─────────────
|
||||
const EX_SMPS={
|
||||
board:{w:56,h:40},
|
||||
|
||||
Reference in new issue
Block a user