Files
wheel/scripts/compose_kfl_flange57.py

36 lines
2.3 KiB
Python
Raw Permalink 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.
from PIL import Image, ImageChops, ImageDraw, ImageFont
from pathlib import Path
root = Path(r'C:\projects\wheel\models')
a = root / 'kfl_100_flange57_concept'
b = root / 'kfl_100_flange57_shift_concept'
font = r'C:\Windows\Fonts\msyh.ttc'
title = ImageFont.truetype(font, 38)
normal = ImageFont.truetype(font, 23)
small = ImageFont.truetype(font, 21)
im = Image.new('RGB', (1920, 1300), 'white')
d = ImageDraw.Draw(im)
d.text((40, 20), '更新法兰尺寸:100 mm 轴装配空间检查', fill='#1a304d', font=title)
d.text((40, 82), '电机侧法兰:Ø57 底盘厚 4 mm,Ø30 凸台高 20 mm(从底盘表面量起)', fill='#52657b', font=normal)
d.rounded_rectangle((40, 125, 1880, 180), radius=8, fill='#fff0eb')
d.text((55, 137), '示意布局存在干涉或插入不足风险,不能认定 100 mm 轴可用', fill='#9b2b22', font=normal)
def panel(path, box):
view = Image.open(path).convert('RGB').rotate(90, expand=True)
mask = ImageChops.difference(view, Image.new('RGB', view.size, 'white')).convert('L').point(lambda p:255 if p>12 else 0)
bounds = mask.getbbox()
if bounds: view = view.crop(bounds)
view.thumbnail((box[2]-box[0],box[3]-box[1]))
im.paste(view, (box[0] + (box[2]-box[0]-view.width)//2, box[1]))
d.text((40, 200), 'A:沿用原位置,电机侧轴插入 18 mm;新凸台与后轴承示意外形相交', font=normal, fill='#243a55')
panel(a / 'side.png', (35, 240, 1885, 610))
d.text((40, 625), 'B:轴前移 6 mm、轴承和开关前移 10 mm;电机侧插入 12 mm,前端仅剩 5 mm', font=normal, fill='#243a55')
panel(b / 'side.png', (35, 665, 1885, 1035))
d.line((40, 1060, 1880, 1060), fill='#d8e0e9', width=2)
d.text((42, 1080), '绿色为 50 mm 开关包络占位;开关内孔、白色回正机构未实测。', font=small, fill='#405b4a')
d.text((42, 1120), 'KFL 凸起和板孔尺寸、前端轮毂、键槽及电机中心 M3 螺母均未实测。', font=small, fill='#46586b')
d.text((42, 1160), 'B 的后端轴承仅有约 0.5 mm 名义间隙,前端轮毂仍干涉;5 mm 插入深度未经验证。', font=small, fill='#9b2b22')
d.text((42, 1200), '此前 12 + 14.5 + 50 + 14.5 + 9 的预算不再适用;凸台高 20 不等于必须插入 20 mm。', font=small, fill='#46586b')
im.save(a / '更新尺寸_装配示意.png')