Files
wheel/scripts/render_washer_grid_4x4.py

42 lines
2.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""Top-view layout guide using the STEP geometry and actual connector layout."""
from pathlib import Path
import math
import FreeCAD as App
import Part, MeshPart
from PIL import Image,ImageDraw,ImageFont
R=Path(__file__).resolve().parent.parent
O=R/'models'/'washer_grid_4x4'
V=App.Vector
image=Image.new('RGB',(1120,1250),'#f4f7fb'); d=ImageDraw.Draw(image)
font='C:/Windows/Fonts/msyh.ttc'
heading=ImageFont.truetype(font,38); text=ImageFont.truetype(font,27); small=ImageFont.truetype(font,21)
d.text((55,40),'4 × 4 垫片拼件:16 片',font=heading,fill='#173451')
d.text((55,104),'上两行 0.5 mm,下两行 1.0 mm',font=text,fill='#425e78')
scale=14
def xy(x,y): return (130+(x+6)*scale,180+(y+6)*scale)
off=1.5; edge=math.sqrt(36-off**2); pitch=2*edge+2; start=edge-.8; length=pitch-2*start
for row in range(4):
for col in range(3):
x=col*pitch+start;y=row*pitch-off-1
d.rectangle((xy(x,y),xy(x+length,y+2)),fill='#75889c')
for row in range(3):
for col in range(4):
x=col*pitch-off-1;y=row*pitch+start
d.rectangle((xy(x,y),xy(x+2,y+length)),fill='#75889c')
for row in range(4):
shape=Part.read(str(R/'models'/'pcd50_open_pillar_v1'/('Shim05.step' if row<2 else 'Shim10.step')))
shape.translate(V(-10,-10,0));shape.rotate(V(),V(0,0,1),22.5)
m=MeshPart.meshFromShape(Shape=shape,LinearDeflection=.04,AngularDeflection=.2,Relative=False)
points,faces=m.Topology
for col in range(4):
x=col*pitch;y=row*pitch
for triangle in faces:
poly=[xy(points[i].x+x,points[i].y+y) for i in triangle]
d.polygon(poly,fill='#dc9b40' if row<2 else '#319b91')
d.text((70,975),'连接杆截面 2 × 2 mm;中心线净跨度约 2 mm',font=text,fill='#294660')
d.text((70,1025),'颜色仅表示厚度;建议拆除前分开标记。',font=text,fill='#294660')
d.text((70,1085),'16 片超过商家单个拼件少于 10 件的规则,',font=small,fill='#a34c1c')
d.text((70,1120),'请先确认能否接单;杆与薄片接合处需商家评估。',font=small,fill='#a34c1c')
image.save(str(O/'拼件预览.png'))