120 行
5.7 KiB
Python
120 行
5.7 KiB
Python
# -*- coding: utf-8 -*-
|
||
u"""派生 topshell_v6.py / place_v6.py(2026-09-13 用户:两侧都改为风扇格栅)。
|
||
v5 的东墙格栅内联代码 → 函数 grille_cut(tag, xw, sg),西墙(朝外 −x)和东墙(朝外 +x)各调一次;
|
||
西墙原 Ø60 圆孔那一刀删掉。纯文本补丁,锚点断言次数。"""
|
||
import io
|
||
import sys
|
||
|
||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', write_through=True)
|
||
T = u'C:\\Users\\35138\\.claude\\jobs\\11836093\\tmp\\'
|
||
s = open(T + 'topshell_v5.py', encoding='utf-8').read()
|
||
|
||
|
||
def rep(old, new, n=1):
|
||
global s
|
||
c = s.count(old)
|
||
if c != n:
|
||
raise SystemExit(u'锚点 %r 出现 %d 次(期望 %d)' % (old[:70], c, n))
|
||
s = s.replace(old, new)
|
||
|
||
|
||
rep(u"TopShell_v5.SLDPRT'", u"TopShell_v6.SLDPRT'")
|
||
rep(u"'TOPSHELL_V5'", u"'TOPSHELL_V6'")
|
||
rep(u"cut_shapes(u'西端墙', (0, -1, X0), [((X0, cy, L(cz)), r) for cy, cz, r in END_CIRCLES], [], end_verify(X0))\n", u"")
|
||
|
||
a = s.index(u'# ── B:东端墙 Ø60 圆孔 → 竖向圆头槽格栅')
|
||
end_marker = u" P(u' ⛔⛔ 格栅不对,停手、不存盘'); sys.exit(5)"
|
||
b = s.index(end_marker) + len(end_marker)
|
||
|
||
NEW = u'''# ── B:两端墙 Ø60 圆孔 → 竖向圆头槽格栅(2026-09-13 用户:两侧都改格栅)──────────────
|
||
GR_R, GR_W, GR_RIB = 32.0, 4.5, 1.2
|
||
|
||
|
||
def grille_slots():
|
||
p, out = GR_W + GR_RIB, []
|
||
n = int((GR_R - GR_W / 2) // p)
|
||
for k in range(-n, n + 1):
|
||
y = k * p
|
||
e = abs(y) + GR_W / 2
|
||
if e >= GR_R:
|
||
continue
|
||
L_ = 2 * math.sqrt(GR_R * GR_R - e * e)
|
||
if L_ <= GR_W + 1:
|
||
continue
|
||
out.append((FAN_CY + y, L_))
|
||
return out
|
||
|
||
|
||
GRS = grille_slots()
|
||
A_SLOTS = sum(GR_W * (L_ - GR_W) + math.pi * (GR_W / 2) ** 2 for _, L_ in GRS)
|
||
A_HOLES = 4 * math.pi * R_FAN ** 2
|
||
P(u' 格栅:%d 条槽 宽 %.1f 筋 %.1f 外包 R%.0f,槽面积 %.1f(原 Ø60 = %.1f,%.1f%%)'
|
||
% (len(GRS), GR_W, GR_RIB, GR_R, A_SLOTS, math.pi * 900, A_SLOTS / (math.pi * 900) * 100))
|
||
|
||
|
||
def grille_cut(tag, xw, sg):
|
||
def face_area():
|
||
return sum(a_ for ax_, sgn, fb, a_, _ in planes()
|
||
if ax_ == 0 and sgn == sg and abs(fb[0] - xw) < 0.02 and abs(fb[3] - xw) < 0.02)
|
||
|
||
ends0 = sum(1 for rr, ax_, fb in cyls() if abs(rr - GR_W / 2) < 0.01 and ax_ == 0)
|
||
a_before = face_area()
|
||
nbefore = len(faces())
|
||
X = open_face_sketch((0, sg, xw), tag)
|
||
sm.AddToDB = True
|
||
for cy, cz, r in END_CIRCLES[1:]:
|
||
q = to_sketch(X, (xw, cy, L(cz)))
|
||
sm.CreateCircleByRadius(q[0], q[1], 0.0, M(r))
|
||
zc = L(FAN_CZ)
|
||
for ys, L_ in GRS:
|
||
r, a = GR_W / 2, L_ / 2 - GR_W / 2
|
||
for p0, p1 in (((ys + r, zc - a), (ys + r, zc + a)), ((ys - r, zc + a), (ys - r, zc - a))):
|
||
q0, q1 = to_sketch(X, (xw, p0[0], p0[1])), to_sketch(X, (xw, p1[0], p1[1]))
|
||
sm.CreateLine(q0[0], q0[1], 0.0, q1[0], q1[1], 0.0)
|
||
for cz_, s_ in ((zc + a, 1), (zc - a, -1)):
|
||
qc = to_sketch(X, (xw, ys, cz_))
|
||
q1 = to_sketch(X, (xw, ys + r, cz_))
|
||
q2 = to_sketch(X, (xw, ys - r, cz_))
|
||
qm = to_sketch(X, (xw, ys, cz_ + s_ * r))
|
||
sm.CreateArc(qc[0], qc[1], 0.0, q1[0], q1[1], 0.0, q2[0], q2[1], 0.0, arc_dir(qc, q1, qm))
|
||
sm.AddToDB = False
|
||
sm.InsertSketch(True)
|
||
c = do_cut(T + 0.2)
|
||
d_area = a_before - face_area()
|
||
ok_area = abs(d_area - (A_SLOTS + A_HOLES)) < 0.5
|
||
ends = sum(1 for rr, ax_, fb in cyls() if abs(rr - GR_W / 2) < 0.01 and ax_ == 0) - ends0
|
||
caps_ok = all(abs((fb[4] - fb[1]) - GR_W) < 0.02 and abs((fb[5] - fb[2]) - GR_W / 2) < 0.02
|
||
for rr, ax_, fb in cyls() if abs(rr - GR_W / 2) < 0.01 and ax_ == 0)
|
||
fan_ok = all(any(abs(rr - R_FAN) < 0.01 and ax_ == 0 and abs((fb[1] + fb[4]) / 2 - cy) < 0.05 and
|
||
abs((fb[2] + fb[5]) / 2 - L(cz)) < 0.05 and min(abs(fb[0] - xw), abs(fb[3] - xw)) < 0.05
|
||
for rr, ax_, fb in cyls()) for cy, cz, _ in END_CIRCLES[1:])
|
||
P(u' %s 切除 → %-12r 面数 %d→%d' % (tag, prop(c, 'Name') if c else c, nbefore, len(faces())))
|
||
P(u' 外表面面积减少 %.2f(理论 槽 %.2f + 螺丝孔 %.2f = %.2f)%s'
|
||
% (d_area, A_SLOTS, A_HOLES, A_SLOTS + A_HOLES, u'✅' if ok_area else u'⛔'))
|
||
P(u' 新增槽端半圆柱 %d(期望 %d),全部「y 跨槽宽、z 跨半径」= 竖槽 %s;风扇孔 4 个在位 %s'
|
||
% (ends, 2 * len(GRS), u'✅' if caps_ok else u'⛔', u'✅' if fan_ok else u'⛔'))
|
||
if not (ok_area and ends == 2 * len(GRS) and caps_ok and fan_ok):
|
||
P(u' ⛔⛔ %s 格栅不对,停手、不存盘' % tag); sys.exit(5)
|
||
|
||
|
||
grille_cut(u'西端墙', X0, -1)
|
||
grille_cut(u'东端墙', X1, +1)'''
|
||
s = s[:a] + NEW + s[b:]
|
||
rep(u"WANT_H = {0.7: 8, 0.75: 2 * SLOT_N, 0.8: 1, 1.5: 4, 2.1: 4, round(GR_W / 2, 2): 2 * len(GRS), 2.6: 8, 3.0: 4, 30.0: 1}",
|
||
u"WANT_H = {0.7: 8, 0.75: 2 * SLOT_N, 0.8: 1, 1.5: 4, 2.1: 4, round(GR_W / 2, 2): 4 * len(GRS), 2.6: 8, 3.0: 4, 30.0: 0}")
|
||
s = s.replace(u'# -*- coding: utf-8 -*-\n', u'# -*- coding: utf-8 -*-\n# v6:两端墙都用竖槽格栅(西端 Ø60 圆孔取消),其余同 v5\n', 1)
|
||
if u"end_verify(X0)" in s:
|
||
raise SystemExit(u'⛔ 西墙圆孔那一刀还在')
|
||
open(T + 'topshell_v6.py', 'w', encoding='utf-8').write(s)
|
||
print(u'写出 topshell_v6.py')
|
||
|
||
p = open(T + 'place_v5.py', encoding='utf-8').read()
|
||
for old, new in ((u"(u'TopShell_v5.SLDPRT',", u"(u'TopShell_v6.SLDPRT',"),
|
||
(u"((u'v5_iso', 7), (u'v5_east', 0), (u'v5_south', 6), (u'v5_bottom', 2), (u'v5_top', 1))",
|
||
u"((u'v6_iso', 7),)")):
|
||
if p.count(old) != 1:
|
||
raise SystemExit(u'place 锚点 %r ×%d' % (old, p.count(old)))
|
||
p = p.replace(old, new)
|
||
open(T + 'place_v6.py', 'w', encoding='utf-8').write(p)
|
||
print(u'写出 place_v6.py')
|