Files
wheel/scripts/render_kfl_plate_v3_alt.py

64 lines
3.7 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.
"""Draw a clearly provisional dimension diagram for the KFL001 plate."""
from pathlib import Path
from reportlab.pdfgen import canvas
from reportlab.lib.pagesizes import landscape,A4
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
from reportlab.lib.colors import HexColor
import pypdfium2
import math
out=Path(r'C:\projects\wheel\models\kfl001_plate_v3_alt')
pdfmetrics.registerFont(TTFont('Chinese',r'C:\Windows\Fonts\simhei.ttf'))
p=out/'KFL001固定板_尺寸图.pdf'
c=canvas.Canvas(str(p),pagesize=landscape(A4));W,H=landscape(A4)
c.setTitle('KFL001 mounting plate V3 - prototype')
def txt(x,y,t,size=11,color='#17202a'):
c.setFillColor(HexColor(color));c.setFont('Chinese',size);c.drawString(x,y,t)
def ln(x1,y1,x2,y2,col='#444444',width=.7):
c.setStrokeColor(HexColor(col));c.setLineWidth(width);c.line(x1,y1,x2,y2)
def tick(x,y):ln(x-3,y-3,x+3,y+3)
txt(36,555,'KFL001 固定板尺寸图 V3',23)
txt(36,532,'试制版:中心孔直径 39,适配直径 38 凸起',13,'#B42318')
txt(36,512,'两块几何相同;厚 8 mm;下方尺寸单位均为 mm',11)
k=3.6;x0=110;y0=125;w=76*k;h=75*k;cx=x0+w/2;cy=y0+51*k
c.setFillColor(HexColor('#eef2f6'));c.setStrokeColor(HexColor('#263444'));c.setLineWidth(1.1)
# Exterior as manufactured: R3 tangent corners and R60 arch, symmetric around x=38.
path=c.beginPath();path.moveTo(x0+3*k,y0);path.lineTo(x0+73*k,y0)
def arc_poly(cx0,cy0,r,a0,a1,n=20):
for j in range(1,n+1):
a=math.radians(a0+(a1-a0)*j/n)
path.lineTo(x0+(cx0+r*math.cos(a))*k,y0+(cy0+r*math.sin(a))*k)
arc_poly(73,3,3,-90,0)
y_corner=15+math.sqrt(57**2-35**2)
path.lineTo(x0+76*k,y0+y_corner*k)
theta=math.degrees(math.atan2(y_corner-15,35))
arc_poly(73,y_corner,3,0,theta)
arc_poly(38,15,60,theta,180-theta,80)
arc_poly(3,y_corner,3,180-theta,180)
path.lineTo(x0,y0+3*k)
arc_poly(3,3,3,180,270)
path.close();c.drawPath(path,fill=1,stroke=1)
c.setFillColor(HexColor('#ffffff'));c.setStrokeColor(HexColor('#263444'));c.setLineWidth(1.0)
c.circle(cx,cy,19.5*k,stroke=1,fill=1)
for xx in (-24,24):c.circle(cx+xx*k,cy,3.5*k,stroke=1,fill=1)
for xx in (-23.5,23.5):c.roundRect(cx+(xx-4.75)*k,y0+(9-2.75)*k,9.5*k,5.5*k,2.75*k,stroke=1,fill=1)
c.setDash(4,3);ln(cx-23*k,cy,cx+23*k,cy,'#858b93',.5);ln(cx,cy-23*k,cx,cy+23*k,'#858b93',.5);c.setDash()
# Outside dimensions: overall width, height, axis height and KFL bolt pitch.
for x in (x0,x0+w):ln(x,y0-3,x,y0-31)
ln(x0,y0-23,x0+w,y0-23);tick(x0,y0-23);tick(x0+w,y0-23);txt(cx-8,y0-19,'76',10)
for y in (y0,y0+h):ln(x0-2,y,x0-38,y)
ln(x0-30,y0,x0-30,y0+h);tick(x0-30,y0);tick(x0-30,y0+h);txt(x0-50,y0+h/2,'75',10)
ln(x0+w+10,y0,x0+w+38,y0);ln(x0+w+10,cy,x0+w+38,cy)
ln(x0+w+30,y0,x0+w+30,cy);tick(x0+w+30,y0);tick(x0+w+30,cy);txt(x0+w+34,y0+(cy-y0)/2,'51',10)
by=cy+30*k
for x in (cx-24*k,cx+24*k):ln(x,cy+4*k,x,by+4)
ln(cx-24*k,by,cx+24*k,by);tick(cx-24*k,by);tick(cx+24*k,by);txt(cx-8,by+5,'48',10)
txt(472,454,'孔位说明',15)
for i,t in enumerate(['1 中心孔:直径 39,适配直径 38 凸起','2 两侧轴承孔:直径 7,孔距 48','3 底部两槽:9.5 × 5.5,横向','4 两槽中心距 47,槽心距底边 9','5 上边圆弧 R60,圆心距底 15','6 平面过渡 R3;外轮廓双面 C1','7 中心孔到轴承孔边名义余量仅 1','8 直径 12 垫圈向中心孔悬出约 1.5']):txt(472,424-i*24,t,11,'#B42318' if i in (6,7) else '#17202a')
ln(472,217,805,217,'#b9c0c9');txt(472,196,'轴承及连接件先试装,',11,'#B42318');txt(472,178,'紧固和动态强度需实物验证。',11,'#B42318')
txt(36,42,'注:圆孔和长槽均贯穿;两块相同。按孔心尺寸加工,无螺纹。',10)
c.showPage();c.save()
doc=pypdfium2.PdfDocument(str(p));page=doc[0];page.render(scale=1.6).to_pil().save(str(out/'KFL001固定板_尺寸图.png'))