rrplot 1.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cycleplot/__init__.py +22 -0
- rrplot/__init__.py +29 -0
- rrplot/_primitives.py +26 -0
- rrplot/core.py +519 -0
- rrplot/hvac.py +305 -0
- rrplot/part.py +40 -0
- rrplot/parts.py +834 -0
- rrplot/registry.py +213 -0
- rrplot/scene.py +255 -0
- rrplot/scene_renderer.py +137 -0
- rrplot/style.py +74 -0
- rrplot/svgparts.py +230 -0
- rrplot/templates/evi_ftvi.json +460 -0
- rrplot/templates/evi_intermediate.json +424 -0
- rrplot/templates/ftvi.json +323 -0
- rrplot/templates/heat_pump.json +24 -0
- rrplot/templates/heat_pump_receiver.json +27 -0
- rrplot/templates/reversible_heat_pump_cooling.json +456 -0
- rrplot/templates/reversible_heat_pump_heating.json +456 -0
- rrplot/templates/vrf_multisplit_cooling.json +1153 -0
- rrplot/templates/vrf_multisplit_evi_heating.json +1320 -0
- rrplot-1.3.0.dist-info/METADATA +275 -0
- rrplot-1.3.0.dist-info/RECORD +26 -0
- rrplot-1.3.0.dist-info/WHEEL +5 -0
- rrplot-1.3.0.dist-info/licenses/LICENSE +21 -0
- rrplot-1.3.0.dist-info/top_level.txt +2 -0
rrplot/parts.py
ADDED
|
@@ -0,0 +1,834 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""部件库:每个部件是一个绘制函数(以中心为锚点)+ 端口定义。
|
|
3
|
+
|
|
4
|
+
端口 ports: 名称 -> (dx, dy),相对部件锚点的偏移。dx/dy 同时隐含接管方向
|
|
5
|
+
(单轴端口取该轴符号;双轴非零的端口需要显式方向,见 Part.port_dir)。
|
|
6
|
+
|
|
7
|
+
命名约定:贯通式两口元件(阀、过滤器、毛细管等)用 in/out;
|
|
8
|
+
多口/换热类部件用 left/right/top/bottom 表示边中点。
|
|
9
|
+
"""
|
|
10
|
+
import math
|
|
11
|
+
|
|
12
|
+
import numpy as np
|
|
13
|
+
from matplotlib.patches import Circle, FancyBboxPatch, Polygon, Rectangle
|
|
14
|
+
|
|
15
|
+
from ._primitives import line, txt
|
|
16
|
+
from .core import make_partial # noqa: F401 重新导出,维持 from parts import 路径
|
|
17
|
+
from .part import Part, make_part
|
|
18
|
+
from .style import FILL, LINE, LW_FINE, LW_OUTLINE, LW_PART, LW_STRONG
|
|
19
|
+
|
|
20
|
+
_part = make_part
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# =========================
|
|
24
|
+
# 绘制函数(中心锚点)
|
|
25
|
+
# =========================
|
|
26
|
+
def _oil_separator(ax, x, y, label="油分离器", w=64, h=176, stub=16,
|
|
27
|
+
**kw):
|
|
28
|
+
"""油分离器:瘦长矩形壳 + 顶/底/侧三根接管(参考图画法,内部无构件)。
|
|
29
|
+
|
|
30
|
+
进气自上部侧管(接压缩机排气),干燥气自顶管出(接四通阀 D 口),
|
|
31
|
+
回油自底管出(经毛细管接回吸气管)。
|
|
32
|
+
"""
|
|
33
|
+
ax.add_patch(Rectangle((x - w / 2, y - h / 2), w, h,
|
|
34
|
+
facecolor=FILL, edgecolor=LINE, lw=LW_PART))
|
|
35
|
+
y_side = y - h / 4 # 侧管:壳顶下 1/4(参考图比例)
|
|
36
|
+
line(ax, [(x, y - h / 2 - stub), (x, y - h / 2)], lw=LW_PART)
|
|
37
|
+
line(ax, [(x, y + h / 2), (x, y + h / 2 + stub)], lw=LW_PART)
|
|
38
|
+
line(ax, [(x - w / 2 - stub, y_side), (x - w / 2, y_side)], lw=LW_PART)
|
|
39
|
+
if label:
|
|
40
|
+
txt(ax, x + w / 2 + 18, y - 8, label, size=17, ha="left")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _separator_utube(ax, x, y, label=None, w=120, h=118, stub=16,
|
|
44
|
+
flip=False, **kw):
|
|
45
|
+
"""气液分离器(U 形管液封):方壳 + 内置 U 形管 + 弯底放油点。
|
|
46
|
+
|
|
47
|
+
进气短管自壳顶伸入、悬于壳内上部;出气管即 U 形管右腿,穿壳顶引出;
|
|
48
|
+
U 形管兼作液封(液体积于弯底),弯底小圆点为放油/排液口标记。
|
|
49
|
+
flip=True 镜像:进气短管在东侧、出气管为 U 形管左腿(进口在右、出口在左)。
|
|
50
|
+
"""
|
|
51
|
+
s = -1.0 if flip else 1.0
|
|
52
|
+
ax.add_patch(Rectangle((x - w / 2, y - h / 2), w, h,
|
|
53
|
+
facecolor=FILL, edgecolor=LINE, lw=LW_PART))
|
|
54
|
+
y_top = y - h / 2
|
|
55
|
+
lx = 0.435 * w # U 形管两腿半距(约壳宽 87%)
|
|
56
|
+
y_leg = y_top + 0.116 * h # 开口腿上口(壳内开管)
|
|
57
|
+
y_arc = y_top + 0.61 * h # 弯头起点(竖段下端)
|
|
58
|
+
y_bot = y_top + 0.963 * h # 弯底(壳底上方)
|
|
59
|
+
x_in = x - s * 0.365 * w # 进气短管:默认偏西,镜像后偏东
|
|
60
|
+
b = y_bot - y_arc # 弯头竖半轴
|
|
61
|
+
arc = [(x + s * lx * math.cos(math.radians(t)),
|
|
62
|
+
y_arc + b * math.sin(math.radians(t)))
|
|
63
|
+
for t in range(180, -1, -6)] # 开口腿 -> 弯底 -> 出气腿
|
|
64
|
+
line(ax, [(x - s * lx, y_leg)] + arc + [(x + s * lx, y_top - stub)],
|
|
65
|
+
lw=LW_PART) # U 形管 + 出气管
|
|
66
|
+
line(ax, [(x_in, y_top - stub), (x_in, y_top + 0.2 * h)],
|
|
67
|
+
lw=LW_PART) # 进气短管(悬于壳内上部)
|
|
68
|
+
ax.add_patch(Circle((x, y_bot), max(2.0, 0.022 * w),
|
|
69
|
+
facecolor=LINE, edgecolor=LINE, lw=LW_FINE))
|
|
70
|
+
if label:
|
|
71
|
+
# 标签放壳体外侧(默认右侧,镜像后左侧):底部中央留给 drain 放油管
|
|
72
|
+
txt(ax, x + s * (w / 2 + 18), y - 8, label,
|
|
73
|
+
ha="left" if s > 0 else "right")
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def _four_way_round_valve(ax, x, y, label="四通阀", r=40, mark=True, **kw):
|
|
77
|
+
"""四通换向阀(圆体 + 内菱形):菱形四角即四个接管口。
|
|
78
|
+
|
|
79
|
+
top=排气(D) right=冷凝(C) bottom=蒸发(E) left=回气(S)。
|
|
80
|
+
mark=True 在四端点外侧标注 D/S/C/E 口别字母。
|
|
81
|
+
"""
|
|
82
|
+
ax.add_patch(Circle((x, y), r, facecolor=FILL, edgecolor=LINE,
|
|
83
|
+
lw=LW_PART))
|
|
84
|
+
ax.add_patch(Polygon([(x, y - r), (x + r, y), (x, y + r), (x - r, y)],
|
|
85
|
+
closed=True, facecolor=FILL, edgecolor=LINE,
|
|
86
|
+
lw=LW_OUTLINE))
|
|
87
|
+
if mark:
|
|
88
|
+
m = r + 14
|
|
89
|
+
for letter, (px, py) in (("D", (x, y - m)), ("C", (x + m, y)),
|
|
90
|
+
("E", (x, y + m)), ("S", (x - m, y))):
|
|
91
|
+
txt(ax, px, py, letter, size=15)
|
|
92
|
+
if label:
|
|
93
|
+
txt(ax, x, y + r + 34, label, size=17)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _filter(ax, x, y, label=None, w=72, h=36, n=7, stub=12, **kw):
|
|
97
|
+
"""过滤器:矩形 + 菱形网格(双向45° 交叉线),左右接管。
|
|
98
|
+
|
|
99
|
+
网格为两族斜率 ±1 的平行线,按 k 均匀取值后裁剪到矩形内;
|
|
100
|
+
端口在接管两端,沿水平方向(in/w, out/e)。
|
|
101
|
+
"""
|
|
102
|
+
x1, x2 = x - w / 2, x + w / 2
|
|
103
|
+
y1, y2 = y - h / 2, y + h / 2
|
|
104
|
+
ax.add_patch(Rectangle((x1, y1), w, h,
|
|
105
|
+
facecolor=FILL, edgecolor=LINE, lw=LW_PART))
|
|
106
|
+
for k in np.linspace(y1 - x2, y2 - x1, n): # 斜率 +1:y = x + k
|
|
107
|
+
xs, xe = max(x1, y1 - k), min(x2, y2 - k)
|
|
108
|
+
if xs < xe:
|
|
109
|
+
line(ax, [(xs, xs + k), (xe, xe + k)], lw=LW_FINE)
|
|
110
|
+
for k in np.linspace(y1 + x1, y2 + x2, n): # 斜率 -1:y = k - x
|
|
111
|
+
xs, xe = max(x1, k - y2), min(x2, k - y1)
|
|
112
|
+
if xs < xe:
|
|
113
|
+
line(ax, [(xs, k - xs), (xe, k - xe)], lw=LW_FINE)
|
|
114
|
+
line(ax, [(x1 - stub, y), (x1, y)], lw=LW_STRONG)
|
|
115
|
+
line(ax, [(x2, y), (x2 + stub, y)], lw=LW_STRONG)
|
|
116
|
+
if label:
|
|
117
|
+
txt(ax, x, y + h / 2 + 26, label)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _globe_valve(ax, x, y, label=None, w=64, h=48, stem=26, handle=44, **kw):
|
|
121
|
+
"""截止阀(globe valve):左右对顶三角(沙漏) + 阀杆 + 顶部手轮横杆。
|
|
122
|
+
|
|
123
|
+
阀杆自两三角交汇的中点向上引出(不贯穿阀体),顶端接手轮横杆;
|
|
124
|
+
左右竖边中点外侧各引一段接管,端口沿水平方向(in/out)。
|
|
125
|
+
"""
|
|
126
|
+
ax.add_patch(Polygon([(x - w / 2, y - h / 2), (x - w / 2, y + h / 2),
|
|
127
|
+
(x, y)], closed=True, facecolor=FILL,
|
|
128
|
+
edgecolor=LINE, lw=LW_OUTLINE))
|
|
129
|
+
ax.add_patch(Polygon([(x + w / 2, y - h / 2), (x + w / 2, y + h / 2),
|
|
130
|
+
(x, y)], closed=True, facecolor=FILL,
|
|
131
|
+
edgecolor=LINE, lw=LW_OUTLINE))
|
|
132
|
+
top = y - h / 2 - stem
|
|
133
|
+
line(ax, [(x, y), (x, top)], lw=LW_PART) # 阀杆(止于中点)
|
|
134
|
+
line(ax, [(x - handle / 2, top), (x + handle / 2, top)],
|
|
135
|
+
lw=LW_STRONG) # 手轮横杆
|
|
136
|
+
line(ax, [(x - w / 2, y), (x - w / 2 - 12, y)], lw=LW_STRONG)
|
|
137
|
+
line(ax, [(x + w / 2, y), (x + w / 2 + 12, y)], lw=LW_STRONG)
|
|
138
|
+
if label:
|
|
139
|
+
txt(ax, x, y + h / 2 + 24, label)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def _solenoid_valve(ax, x, y, label=None, r=34, stem=20, handle=40, **kw):
|
|
143
|
+
"""电磁阀(solenoid valve):圆体 + 圆内 X(阀芯) + 顶部电磁引线与横杠。
|
|
144
|
+
|
|
145
|
+
X 为圆内接正方形对角线,两端落在圆周上;竖引线自圆心向上出圆,
|
|
146
|
+
顶端接水平横杠表示电磁线圈。端口在圆左右水平方向(in/out)。
|
|
147
|
+
"""
|
|
148
|
+
ax.add_patch(Circle((x, y), r, facecolor=FILL, edgecolor=LINE,
|
|
149
|
+
lw=LW_OUTLINE))
|
|
150
|
+
c = r / math.sqrt(2)
|
|
151
|
+
line(ax, [(x - c, y - c), (x + c, y + c)], lw=LW_PART)
|
|
152
|
+
line(ax, [(x + c, y - c), (x - c, y + c)], lw=LW_PART)
|
|
153
|
+
top = y - r - stem
|
|
154
|
+
line(ax, [(x, y), (x, top)], lw=LW_PART) # 电磁引线
|
|
155
|
+
line(ax, [(x - handle / 2, top), (x + handle / 2, top)],
|
|
156
|
+
lw=LW_STRONG) # 线圈横杠
|
|
157
|
+
line(ax, [(x - r, y), (x - r - 12, y)], lw=LW_STRONG)
|
|
158
|
+
line(ax, [(x + r, y), (x + r + 12, y)], lw=LW_STRONG)
|
|
159
|
+
if label:
|
|
160
|
+
txt(ax, x, y + r + 26, label)
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def _expansion_valve_eng(ax, x, y, label=None, r=34, **kw):
|
|
164
|
+
"""电子膨胀阀(工程画法):圆体 + 圆内 X,无顶部电磁引线与横杠。
|
|
165
|
+
|
|
166
|
+
即电磁阀去掉电磁执行机构后的阀体画法,常见于工程制冷流程图;
|
|
167
|
+
端口在圆左右水平方向(in/out)。
|
|
168
|
+
"""
|
|
169
|
+
ax.add_patch(Circle((x, y), r, facecolor=FILL, edgecolor=LINE,
|
|
170
|
+
lw=LW_OUTLINE))
|
|
171
|
+
c = r / math.sqrt(2)
|
|
172
|
+
line(ax, [(x - c, y - c), (x + c, y + c)], lw=LW_PART)
|
|
173
|
+
line(ax, [(x + c, y - c), (x - c, y + c)], lw=LW_PART)
|
|
174
|
+
line(ax, [(x - r, y), (x - r - 12, y)], lw=LW_STRONG)
|
|
175
|
+
line(ax, [(x + r, y), (x + r + 12, y)], lw=LW_STRONG)
|
|
176
|
+
if label:
|
|
177
|
+
txt(ax, x, y + r + 26, label)
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def _check_valve(ax, x, y, label=None, w=56, h=32, stub=12, point="e",
|
|
181
|
+
style="solid", **kw):
|
|
182
|
+
"""单向阀(止回阀):三角指向流通方向 + 尖端挡条 + 接管。
|
|
183
|
+
|
|
184
|
+
point: "e" 三角指向东(默认,流西→东);"w" 三角指向西(流东→西)。
|
|
185
|
+
style: "solid" 黑色实心(默认);"hollow" 空心黑框,接管不穿过阀体。
|
|
186
|
+
"""
|
|
187
|
+
if point not in ("e", "w"):
|
|
188
|
+
raise ValueError(f"未知 point={point!r},可用:'e' / 'w'")
|
|
189
|
+
if style not in ("solid", "hollow"):
|
|
190
|
+
raise ValueError(f"未知 style={style!r},可用:'solid' / 'hollow'")
|
|
191
|
+
s = 1 if point == "e" else -1
|
|
192
|
+
ax.add_patch(Polygon([(x - s * w / 2, y - h / 2),
|
|
193
|
+
(x - s * w / 2, y + h / 2),
|
|
194
|
+
(x + s * w / 2, y)], closed=True,
|
|
195
|
+
facecolor=LINE if style == "solid" else FILL,
|
|
196
|
+
edgecolor=LINE, lw=LW_PART))
|
|
197
|
+
if style == "solid":
|
|
198
|
+
line(ax, [(x - s * (w / 2 + stub), y),
|
|
199
|
+
(x + s * (w / 2 + stub), y)], lw=LW_STRONG)
|
|
200
|
+
else:
|
|
201
|
+
for end in (-1, 1):
|
|
202
|
+
line(ax, [(x + end * (w / 2 + stub), y),
|
|
203
|
+
(x + end * w / 2, y)], lw=LW_STRONG)
|
|
204
|
+
line(ax, [(x + s * w / 2, y - 0.275 * h), (x + s * w / 2, y + 0.275 * h)],
|
|
205
|
+
lw=LW_STRONG) # 尖端挡条
|
|
206
|
+
if label:
|
|
207
|
+
txt(ax, x, y + h / 2 + 26, label)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
# =========================
|
|
211
|
+
# 标准 PFD 符号(ISA-5.1 / ISO 10628 风格)
|
|
212
|
+
# 由 references/pfd_symbols.py 移植,坐标系统一为 y 向下
|
|
213
|
+
# =========================
|
|
214
|
+
COMPRESSOR_STYLES = ("圆形", "方形")
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def _compressor_circle(ax, x, y, r=95, label="压缩机", **kw):
|
|
218
|
+
"""圆形压缩机:圆体 + 两条对称弦线(原离心式画法),
|
|
219
|
+
弦的上下端点精确落在圆周上。"""
|
|
220
|
+
ax.add_patch(Circle((x, y), r, facecolor=FILL, edgecolor=LINE,
|
|
221
|
+
lw=LW_OUTLINE))
|
|
222
|
+
for s in (-1.0, 1.0):
|
|
223
|
+
ux = 0.40 * r
|
|
224
|
+
uy = math.sqrt(r * r - ux * ux)
|
|
225
|
+
lx = 0.66 * r
|
|
226
|
+
ly = math.sqrt(r * r - lx * lx)
|
|
227
|
+
line(ax, [(x + s * ux, y - uy), (x + s * lx, y + ly)], lw=LW_PART)
|
|
228
|
+
if label:
|
|
229
|
+
txt(ax, x, y + r + 28, label, ha="center")
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def _compressor_capsule(ax, x, y, r=95, label="压缩机", **kw):
|
|
233
|
+
"""方形压缩机:胶囊壳体(圆角竖矩形,宽 r、高 2r,与圆形等高)。"""
|
|
234
|
+
rx = r / 2
|
|
235
|
+
ax.add_patch(FancyBboxPatch((x - rx, y - r), r, 2 * r,
|
|
236
|
+
boxstyle=f"round,pad=0.02,rounding_size={rx}",
|
|
237
|
+
facecolor=FILL, edgecolor=LINE,
|
|
238
|
+
lw=LW_STRONG))
|
|
239
|
+
if label:
|
|
240
|
+
txt(ax, x, y + r + 28, label, ha="center")
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
def _dome(ax, cx, cy, rx, up=True, lw=LW_PART):
|
|
244
|
+
"""半圆穹顶弧(折线近似)。up=True 向上鼓(y 减小),False 向下鼓。"""
|
|
245
|
+
rng = range(0, 181, 6) if up else range(180, 361, 6)
|
|
246
|
+
pts = [(cx + rx * math.cos(math.radians(a)),
|
|
247
|
+
cy - rx * math.sin(math.radians(a))) for a in rng]
|
|
248
|
+
line(ax, pts, lw=lw)
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def _vessel(ax, x, y, w=66, h=150, label="容器", liquid=0.42,
|
|
252
|
+
label_offset=None, label_ha="left", **kw):
|
|
253
|
+
"""立式容器 / 闪发罐:矩形体 + 上下半圆穹顶(胶囊形) + 液位线。
|
|
254
|
+
|
|
255
|
+
liquid ∈ [0,1] 控制液位相对高度(0=底, 1=顶)。
|
|
256
|
+
"""
|
|
257
|
+
rx = w / 2
|
|
258
|
+
body_top = y - h / 2 + rx
|
|
259
|
+
body_bot = y + h / 2 - rx
|
|
260
|
+
line(ax, [(x - rx, body_bot), (x - rx, body_top)], lw=LW_PART)
|
|
261
|
+
line(ax, [(x + rx, body_bot), (x + rx, body_top)], lw=LW_PART)
|
|
262
|
+
_dome(ax, x, body_top, rx, up=True)
|
|
263
|
+
_dome(ax, x, body_bot, rx, up=False)
|
|
264
|
+
y_liq = body_bot + liquid * (body_top - body_bot)
|
|
265
|
+
line(ax, [(x - rx, y_liq), (x + rx, y_liq)], lw=LW_FINE)
|
|
266
|
+
if label:
|
|
267
|
+
dx, dy = label_offset if label_offset is not None else (rx + 20, 30)
|
|
268
|
+
txt(ax, x + dx, y + dy, label, ha=label_ha)
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
def _capillary(ax, x, y, label="毛细管", w=18, h=80, n=5, **kw):
|
|
272
|
+
"""毛细管:竖直弹簧形小螺旋管(半圆弧交替左/右),表示细长节流管。"""
|
|
273
|
+
seg = h / n
|
|
274
|
+
pts = []
|
|
275
|
+
for i in range(n):
|
|
276
|
+
cy = y - h / 2 + seg * (i + 0.5)
|
|
277
|
+
r = seg / 2
|
|
278
|
+
s = -1 if i % 2 == 0 else 1
|
|
279
|
+
for j in range(25):
|
|
280
|
+
theta = np.pi * j / 24
|
|
281
|
+
px = x + s * (w / 2) * np.sin(theta)
|
|
282
|
+
py = cy - r * np.cos(theta)
|
|
283
|
+
pts.append((px, py))
|
|
284
|
+
xs, ys = zip(*pts)
|
|
285
|
+
ax.plot(xs, ys, color=LINE, lw=LW_OUTLINE, solid_capstyle="round",
|
|
286
|
+
solid_joinstyle="round")
|
|
287
|
+
if label:
|
|
288
|
+
txt(ax, x + w / 2 + 18, y, label, ha="left", boxed=True)
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
HEX_SHAPES = ("rect_diag", "rect_x", "rect_zigzag7", "fan_coil")
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
# =========================
|
|
295
|
+
# 按尺寸生成端口的部件工厂
|
|
296
|
+
# =========================
|
|
297
|
+
def make_heat_exchanger(w=80, h=80, shape="rect_zigzag7", orient="h",
|
|
298
|
+
name="冷凝器", stub=0):
|
|
299
|
+
"""换热器部件(蒸发器/冷凝器通用):矩形外壳 + 4 种换热面画法。
|
|
300
|
+
|
|
301
|
+
:param shape: 取值 ``HEX_SHAPES`` 之一:
|
|
302
|
+
|
|
303
|
+
- ``rect_diag`` 矩形外壳 + 左上→右下对角线(简化符号)
|
|
304
|
+
- ``rect_x`` 矩形外壳 + 两条对角线交叉(X 形换热面)
|
|
305
|
+
- ``rect_zigzag7`` 矩形外壳 + 7 点之字盘管
|
|
306
|
+
- ``fan_coil`` 矩形外壳 + 风机和盘管(室内机)
|
|
307
|
+
|
|
308
|
+
:param orient: 之字盘管走向,"h" 左口→右口水平(默认),
|
|
309
|
+
"v" 顶口→底口竖直(对角线与 X 旋转对称,不受影响)。
|
|
310
|
+
|
|
311
|
+
左右端口可通过 stub 增加接管,顶部/底部端口落在边中点。
|
|
312
|
+
"""
|
|
313
|
+
if shape not in HEX_SHAPES:
|
|
314
|
+
raise ValueError(f"未知换热器 shape={shape!r},可用:"
|
|
315
|
+
f"{', '.join(HEX_SHAPES)}")
|
|
316
|
+
if orient not in ("h", "v"):
|
|
317
|
+
raise ValueError(f"未知 orient={orient!r},可用:'h' / 'v'")
|
|
318
|
+
rx, ry = w / 2, h / 2
|
|
319
|
+
ports = {"left": (-rx - stub, 0), "right": (rx + stub, 0),
|
|
320
|
+
"top": (0, -ry), "bottom": (0, ry)}
|
|
321
|
+
dirs = {"top": "n", "bottom": "s"}
|
|
322
|
+
|
|
323
|
+
def draw(ax, x, y, label=None, **kw):
|
|
324
|
+
ax.add_patch(Rectangle((x - rx, y - ry), w, h, facecolor=FILL,
|
|
325
|
+
edgecolor=LINE, lw=LW_PART))
|
|
326
|
+
if shape == "rect_diag":
|
|
327
|
+
line(ax, [(x - rx, y - ry), (x + rx, y + ry)], lw=LW_OUTLINE)
|
|
328
|
+
elif shape == "rect_x":
|
|
329
|
+
for s in (-1, 1):
|
|
330
|
+
line(ax, [(x - rx, y - s * ry), (x + rx, y + s * ry)],
|
|
331
|
+
lw=LW_OUTLINE)
|
|
332
|
+
elif shape == "fan_coil":
|
|
333
|
+
cx = x - w * 0.32
|
|
334
|
+
radius = min(w * 0.13, h * 0.28)
|
|
335
|
+
ax.add_patch(Circle((cx, y), radius, facecolor=FILL,
|
|
336
|
+
edgecolor=LINE, lw=LW_FINE))
|
|
337
|
+
for angle in (0, 120, 240):
|
|
338
|
+
points = [(cx, y)] + [
|
|
339
|
+
(cx + radius * 0.85 * math.cos(math.radians(angle + a)),
|
|
340
|
+
y + radius * 0.85 * math.sin(math.radians(angle + a)))
|
|
341
|
+
for a in (0, 55)]
|
|
342
|
+
ax.add_patch(Polygon(points, facecolor=FILL, edgecolor=LINE,
|
|
343
|
+
lw=LW_FINE))
|
|
344
|
+
for dy in (-0.28 * h, 0, 0.28 * h):
|
|
345
|
+
line(ax, [(x - 0.08 * w, y + dy), (x + 0.40 * w, y + dy)],
|
|
346
|
+
lw=LW_PART)
|
|
347
|
+
elif orient == "v":
|
|
348
|
+
# 之字盘管(竖):顶口中点起笔,底口中点收笔,折点左右交替
|
|
349
|
+
amp = rx * 0.42
|
|
350
|
+
pts = [(x, y - ry)]
|
|
351
|
+
for i in range(7):
|
|
352
|
+
yi = y - ry + 2 * ry * (i + 0.5) / 7
|
|
353
|
+
pts.append((x - amp if i % 2 == 0 else x + amp, yi))
|
|
354
|
+
pts.append((x, y + ry))
|
|
355
|
+
line(ax, pts, lw=LW_OUTLINE)
|
|
356
|
+
else:
|
|
357
|
+
# 之字盘管(横):左口中点起笔,右口中点收笔,折点上下交替
|
|
358
|
+
amp = ry * 0.42
|
|
359
|
+
pts = [(x - rx, y)]
|
|
360
|
+
for i in range(7):
|
|
361
|
+
xi = x - rx + 2 * rx * (i + 0.5) / 7
|
|
362
|
+
pts.append((xi, y - amp if i % 2 == 0 else y + amp))
|
|
363
|
+
pts.append((x + rx, y))
|
|
364
|
+
line(ax, pts, lw=LW_OUTLINE)
|
|
365
|
+
if stub:
|
|
366
|
+
line(ax, [(x - rx - stub, y), (x - rx, y)], lw=LW_PART)
|
|
367
|
+
line(ax, [(x + rx, y), (x + rx + stub, y)], lw=LW_PART)
|
|
368
|
+
if label:
|
|
369
|
+
txt(ax, x, y + ry + 26, label, boxed=True)
|
|
370
|
+
|
|
371
|
+
return Part(name, draw, ports, dirs)
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
# =========================
|
|
375
|
+
# 部件实例(端口表)
|
|
376
|
+
# =========================
|
|
377
|
+
capillary = _part("毛细管", {"in": (0, -40), "out": (0, 40)}, _capillary,
|
|
378
|
+
dirs={"in": "n", "out": "s"})
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
def make_compressor(r=95, style="圆形", name="压缩机"):
|
|
382
|
+
"""压缩机部件,style 见 COMPRESSOR_STYLES。
|
|
383
|
+
|
|
384
|
+
两种机身同一套端口:几何口 left/right/top/bottom,制冷口
|
|
385
|
+
suction=top、discharge=bottom、vapor_inj=right。机身画法:圆形 =
|
|
386
|
+
圆体 + 双弦;方形 = 胶囊壳体,宽 r、高 2r,与圆形等高。历史型式
|
|
387
|
+
(离心/转子/轴流/往复/螺杆/涡旋)已移除,原型见
|
|
388
|
+
references/compressor_symbols.py。
|
|
389
|
+
|
|
390
|
+
r / style 在工厂里锁定,``add(..., r=..., style=...)`` 不会改外形或端口;
|
|
391
|
+
改尺寸请重新调用本工厂。
|
|
392
|
+
"""
|
|
393
|
+
if style not in COMPRESSOR_STYLES:
|
|
394
|
+
raise ValueError(f"未知压缩机 style={style!r},可用:"
|
|
395
|
+
f"{', '.join(COMPRESSOR_STYLES)}")
|
|
396
|
+
rx = r if style == "圆形" else r / 2
|
|
397
|
+
|
|
398
|
+
def draw(ax, x, y, label=None, **kw):
|
|
399
|
+
if style == "圆形":
|
|
400
|
+
_compressor_circle(ax, x, y, r=r, label=label)
|
|
401
|
+
else:
|
|
402
|
+
_compressor_capsule(ax, x, y, r=r, label=label)
|
|
403
|
+
|
|
404
|
+
ports = {"left": (-rx, 0), "right": (rx, 0),
|
|
405
|
+
"top": (0, -r), "bottom": (0, r),
|
|
406
|
+
"suction": (0, -r), "discharge": (0, r),
|
|
407
|
+
"vapor_inj": (rx, 0)}
|
|
408
|
+
dirs = {"top": "n", "bottom": "s", "suction": "n", "discharge": "s"}
|
|
409
|
+
return Part(name, draw, ports, dirs)
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
compressor = make_compressor()
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
def make_vessel(w=66, h=150, liquid=0.42, name="闪发罐"):
|
|
416
|
+
"""立式容器/闪发罐部件。vapor 口在筒体上端右侧(闪发气出口)。"""
|
|
417
|
+
rx = w / 2
|
|
418
|
+
body_top = -(h / 2 - rx)
|
|
419
|
+
|
|
420
|
+
def draw(ax, x, y, label="闪发罐", label_offset=None, label_ha="left",
|
|
421
|
+
**kw):
|
|
422
|
+
_vessel(ax, x, y, w=w, h=h, label=label, liquid=liquid,
|
|
423
|
+
label_offset=label_offset, label_ha=label_ha)
|
|
424
|
+
|
|
425
|
+
return Part(name, draw,
|
|
426
|
+
{"top": (0, -h / 2), "bottom": (0, h / 2),
|
|
427
|
+
"left": (-rx, 0), "right": (rx, 0),
|
|
428
|
+
"vapor": (rx, body_top + 4)},
|
|
429
|
+
{"top": "n", "bottom": "s"})
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
# 默认尺寸实例(尺寸不合适时用上面的工厂函数按需生成)
|
|
433
|
+
vessel = make_vessel()
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
def make_four_way_round(r=40, mark=True, name="四通阀(圆菱形)"):
|
|
437
|
+
"""四通换向阀部件(圆体 + 内菱形),r 为圆体半径,端口随 r 缩放。
|
|
438
|
+
|
|
439
|
+
端口落在菱形四角:exhaust 顶(D)/ condenser 右(C)/
|
|
440
|
+
evaporator 底(E)/ suction 左(S);mark=True 在四端点外侧
|
|
441
|
+
标注 D/S/C/E 口别字母。r 在工厂锁定;mark 可在 add() 时用同名词覆盖。
|
|
442
|
+
"""
|
|
443
|
+
def draw(ax, x, y, label=None, mark=mark, **kw):
|
|
444
|
+
# r 锁定在工厂;mark 等外观项可在 add() 时用同名词覆盖
|
|
445
|
+
_four_way_round_valve(ax, x, y, label=label, r=r, mark=mark)
|
|
446
|
+
|
|
447
|
+
return Part(name, draw,
|
|
448
|
+
{"exhaust": (0, -r), "condenser": (r, 0),
|
|
449
|
+
"evaporator": (0, r), "suction": (-r, 0)},
|
|
450
|
+
{"exhaust": "n", "condenser": "e",
|
|
451
|
+
"evaporator": "s", "suction": "w"})
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
four_way_round = make_four_way_round()
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
def make_globe_valve(w=64, h=48, stem=26, handle=44, name="截止阀"):
|
|
458
|
+
"""截止阀部件:左右对顶三角沙漏 + 阀杆(止于中点,不贯穿阀体) + 手轮横杆。
|
|
459
|
+
|
|
460
|
+
端口落在左右接管外端,沿水平方向(in=w, out=e)。
|
|
461
|
+
"""
|
|
462
|
+
def draw(ax, x, y, label=None, **kw):
|
|
463
|
+
_globe_valve(ax, x, y, label=label, w=w, h=h, stem=stem,
|
|
464
|
+
handle=handle)
|
|
465
|
+
|
|
466
|
+
return Part(name, draw,
|
|
467
|
+
{"in": (-w / 2 - 12, 0), "out": (w / 2 + 12, 0)},
|
|
468
|
+
{"in": "w", "out": "e"})
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
globe_valve = make_globe_valve()
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
def make_solenoid_valve(r=34, stem=20, handle=40, name="电磁阀",
|
|
475
|
+
style="circle_x"):
|
|
476
|
+
"""电磁阀部件:圆体 + 圆内 X + 顶部电磁引线与横杠。端口 in/out。
|
|
477
|
+
|
|
478
|
+
端口落在圆左右接管外端,沿水平方向(in=w, out=e)。
|
|
479
|
+
style="bowtie" 改为对顶三角 + 横杆 + Σ 折线,保留尺寸与端口。
|
|
480
|
+
"""
|
|
481
|
+
if style not in ("circle_x", "bowtie"):
|
|
482
|
+
raise ValueError(f"未知 style={style!r},可用:'circle_x' / 'bowtie'")
|
|
483
|
+
|
|
484
|
+
def draw(ax, x, y, label=None, **kw):
|
|
485
|
+
if style == "bowtie":
|
|
486
|
+
_bowtie_valve(ax, x, y, w=2*r, h=1.2*r, actuator="solenoid",
|
|
487
|
+
sol_len=r+stem, sol_bar=r, sol_width=handle,
|
|
488
|
+
sol_rise=0.65*stem)
|
|
489
|
+
for side in (-1, 1):
|
|
490
|
+
line(ax, [(x + side*r, y), (x + side*(r+12), y)],
|
|
491
|
+
lw=LW_STRONG)
|
|
492
|
+
if label:
|
|
493
|
+
txt(ax, x, y + r + 26, label)
|
|
494
|
+
else:
|
|
495
|
+
_solenoid_valve(ax, x, y, label=label, r=r, stem=stem, handle=handle)
|
|
496
|
+
|
|
497
|
+
return Part(name, draw,
|
|
498
|
+
{"in": (-r - 12, 0), "out": (r + 12, 0)},
|
|
499
|
+
{"in": "w", "out": "e"})
|
|
500
|
+
|
|
501
|
+
|
|
502
|
+
solenoid_valve = make_solenoid_valve()
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
def make_expansion_valve_eng(r=34, name="电子膨胀阀"):
|
|
506
|
+
"""电子膨胀阀部件(工程画法:圆体 + 圆内 X,无执行机构)。端口 in/out。
|
|
507
|
+
|
|
508
|
+
端口落在圆左右接管外端,沿水平方向(in=w, out=e),与电磁阀一致。
|
|
509
|
+
"""
|
|
510
|
+
def draw(ax, x, y, label=None, **kw):
|
|
511
|
+
_expansion_valve_eng(ax, x, y, label=label, r=r)
|
|
512
|
+
|
|
513
|
+
return Part(name, draw,
|
|
514
|
+
{"in": (-r - 12, 0), "out": (r + 12, 0)},
|
|
515
|
+
{"in": "w", "out": "e"})
|
|
516
|
+
|
|
517
|
+
|
|
518
|
+
expansion_valve_eng = make_expansion_valve_eng()
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
def make_expansion_valve_x(r=10, orient="h", name="膨胀阀(圆X)",
|
|
522
|
+
style="circle_x"):
|
|
523
|
+
"""膨胀阀部件,默认圆 + 内接 X,端口无接管短管。
|
|
524
|
+
|
|
525
|
+
圆体与内接 X 旋转对称,水平/竖直管路通用;端口落在圆周上,
|
|
526
|
+
管线分两段接入。orient="h" 时 in 西口/out 东口(流向西→东),
|
|
527
|
+
orient="v" 时 in 顶口/out 底口(流向自上而下)。
|
|
528
|
+
style="dome" 复用对顶三角 + 闭合半圆穹顶,阀体半宽为 r;
|
|
529
|
+
竖直连接时整体顺时针转 90 度,穹顶在右侧。切换样式不改变端口。
|
|
530
|
+
"""
|
|
531
|
+
if orient not in ("h", "v"):
|
|
532
|
+
raise ValueError(f"未知 orient={orient!r},可用:'h' / 'v'")
|
|
533
|
+
if style not in ("circle_x", "dome"):
|
|
534
|
+
raise ValueError(f"未知 style={style!r},可用:'circle_x' / 'dome'")
|
|
535
|
+
|
|
536
|
+
def draw(ax, x, y, label=None, **kw):
|
|
537
|
+
if style == "dome":
|
|
538
|
+
before_lines, before_patches = len(ax.lines), len(ax.patches)
|
|
539
|
+
_bowtie_valve(ax, x, y, w=2 * r, h=1.2 * r, actuator="dome",
|
|
540
|
+
stem=0.5 * r, dome_r=0.55 * r)
|
|
541
|
+
if orient == "v":
|
|
542
|
+
# 旋转实际坐标,让场景外层旋转仍能正确叠加。
|
|
543
|
+
for patch in list(ax.patches)[before_patches:]:
|
|
544
|
+
points = patch.get_xy()
|
|
545
|
+
patch.set_xy(np.column_stack((x - (points[:, 1] - y),
|
|
546
|
+
y + (points[:, 0] - x))))
|
|
547
|
+
for artist in list(ax.lines)[before_lines:]:
|
|
548
|
+
xs = np.asarray(artist.get_xdata())
|
|
549
|
+
ys = np.asarray(artist.get_ydata())
|
|
550
|
+
artist.set_data(x - (ys - y), y + (xs - x))
|
|
551
|
+
else:
|
|
552
|
+
ax.add_patch(Circle((x, y), r, facecolor=FILL, edgecolor=LINE,
|
|
553
|
+
lw=LW_OUTLINE))
|
|
554
|
+
c = 0.72 * r
|
|
555
|
+
for s in (-1, 1):
|
|
556
|
+
line(ax, [(x - c, y - s * c), (x + c, y + s * c)],
|
|
557
|
+
lw=LW_PART)
|
|
558
|
+
if label:
|
|
559
|
+
txt(ax, x, y + r + 24, label)
|
|
560
|
+
|
|
561
|
+
if orient == "h":
|
|
562
|
+
ports = {"in": (-r, 0), "out": (r, 0)}
|
|
563
|
+
dirs = {"in": "w", "out": "e"}
|
|
564
|
+
else:
|
|
565
|
+
ports = {"in": (0, -r), "out": (0, r)}
|
|
566
|
+
dirs = {"in": "n", "out": "s"}
|
|
567
|
+
return Part(name, draw, ports, dirs)
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
expansion_valve_x = make_expansion_valve_x()
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
def make_check_valve(w=56, h=32, stub=12, point="e", name="单向阀",
|
|
574
|
+
style="solid"):
|
|
575
|
+
"""单向阀部件:三角 + 尖端挡条,point 见 _check_valve。
|
|
576
|
+
|
|
577
|
+
端口在两侧接管端点:point="e" 时 in=西口 / out=东口,
|
|
578
|
+
point="w" 时反向;也可 add() 后用法不变。
|
|
579
|
+
style="solid" 为原实心样式,"hollow" 为空心黑框;端口与尺寸不变。
|
|
580
|
+
"""
|
|
581
|
+
if point not in ("e", "w"):
|
|
582
|
+
raise ValueError(f"未知 point={point!r},可用:'e' / 'w'")
|
|
583
|
+
if style not in ("solid", "hollow"):
|
|
584
|
+
raise ValueError(f"未知 style={style!r},可用:'solid' / 'hollow'")
|
|
585
|
+
s = 1 if point == "e" else -1
|
|
586
|
+
xin = -s * (w / 2 + stub)
|
|
587
|
+
|
|
588
|
+
def draw(ax, x, y, label=None, **kw):
|
|
589
|
+
_check_valve(ax, x, y, label=label, w=w, h=h, stub=stub, point=point,
|
|
590
|
+
style=style)
|
|
591
|
+
|
|
592
|
+
return Part(name, draw,
|
|
593
|
+
{"in": (xin, 0), "out": (-xin, 0)},
|
|
594
|
+
{"in": "w" if s > 0 else "e",
|
|
595
|
+
"out": "e" if s > 0 else "w"})
|
|
596
|
+
|
|
597
|
+
|
|
598
|
+
check_valve = make_check_valve()
|
|
599
|
+
check_valve_w = make_check_valve(point="w", name="单向阀(反向)")
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
def make_filter(w=72, h=36, n=7, stub=12, name="过滤器"):
|
|
603
|
+
"""过滤器部件:矩形 + 菱形网格。端口 in(西口)/ out(东口)。
|
|
604
|
+
|
|
605
|
+
n 为每个方向的网格线数(含角点触线),默认 7;尺寸不合用工厂改。
|
|
606
|
+
"""
|
|
607
|
+
def draw(ax, x, y, label=None, **kw):
|
|
608
|
+
_filter(ax, x, y, label=label, w=w, h=h, n=n, stub=stub)
|
|
609
|
+
|
|
610
|
+
return Part(name, draw,
|
|
611
|
+
{"in": (-w / 2 - stub, 0), "out": (w / 2 + stub, 0)},
|
|
612
|
+
{"in": "w", "out": "e"})
|
|
613
|
+
|
|
614
|
+
|
|
615
|
+
line_filter = make_filter()
|
|
616
|
+
filter = line_filter # 兼容名,会覆盖内置 filter;新代码优先用 line_filter
|
|
617
|
+
|
|
618
|
+
BOWTIE_ACTUATORS = ("none", "dome", "solenoid", "tee")
|
|
619
|
+
|
|
620
|
+
|
|
621
|
+
def _bowtie_valve(ax, x, y, label=None, w=76, h=44, actuator="none",
|
|
622
|
+
stem=14, dome_r=21, sol_len=62, handle=30,
|
|
623
|
+
sol_bar=26, sol_width=48, sol_rise=20, **kw):
|
|
624
|
+
"""对顶三角阀(参考图画法):两竖边三角相对,阀杆自中心引出。
|
|
625
|
+
|
|
626
|
+
actuator: "none" 裸阀(通用截断阀符号)
|
|
627
|
+
"dome" 顶部闭合半圆穹顶(热力膨胀阀 / 经济器膨胀器)
|
|
628
|
+
"solenoid" 电磁线圈(横杆 + Σ 折线)
|
|
629
|
+
"tee" T 形阀杆 + 手轮横杆(截止阀画法,不贯穿阀体)
|
|
630
|
+
"""
|
|
631
|
+
if actuator not in BOWTIE_ACTUATORS:
|
|
632
|
+
raise ValueError(f"未知 actuator={actuator!r},可用:"
|
|
633
|
+
f"{', '.join(BOWTIE_ACTUATORS)}")
|
|
634
|
+
for s in (-1, 1):
|
|
635
|
+
ax.add_patch(Polygon(
|
|
636
|
+
[(x + s * w / 2, y - h / 2), (x + s * w / 2, y + h / 2),
|
|
637
|
+
(x, y)], closed=True, facecolor=FILL, edgecolor=LINE,
|
|
638
|
+
lw=LW_OUTLINE))
|
|
639
|
+
if actuator == "dome":
|
|
640
|
+
base = y - h / 2 - stem
|
|
641
|
+
line(ax, [(x, y), (x, base)], lw=LW_PART)
|
|
642
|
+
pts = [(x + dome_r * math.cos(math.radians(a)),
|
|
643
|
+
base - dome_r * math.sin(math.radians(a)))
|
|
644
|
+
for a in range(0, 181, 6)]
|
|
645
|
+
line(ax, pts + [(x + dome_r, base)], lw=LW_PART) # 闭合平底
|
|
646
|
+
elif actuator == "solenoid":
|
|
647
|
+
line(ax, [(x, y), (x, y - sol_len)], lw=LW_PART) # 阀杆
|
|
648
|
+
bar = y - sol_bar
|
|
649
|
+
left, right = x - sol_width*26/48, x + sol_width*22/48
|
|
650
|
+
line(ax, [(left, bar), (right, bar)], lw=LW_PART) # 线圈横杆
|
|
651
|
+
line(ax, [(left, bar), (x - sol_width*7/48, bar - sol_rise),
|
|
652
|
+
(x + sol_width*8/48, bar - sol_rise)],
|
|
653
|
+
lw=LW_PART) # Σ 折线
|
|
654
|
+
elif actuator == "tee":
|
|
655
|
+
top = y - h / 2 - stem
|
|
656
|
+
line(ax, [(x, y), (x, top)], lw=LW_PART) # 阀杆
|
|
657
|
+
line(ax, [(x - handle / 2, top), (x + handle / 2, top)],
|
|
658
|
+
lw=LW_STRONG) # 手轮横杆
|
|
659
|
+
if label:
|
|
660
|
+
txt(ax, x, y + h / 2 + 26, label)
|
|
661
|
+
|
|
662
|
+
|
|
663
|
+
def make_bowtie_valve(w=76, h=44, actuator="none", stem=14, dome_r=21,
|
|
664
|
+
sol_len=62, handle=30, name="对顶三角阀"):
|
|
665
|
+
"""对顶三角阀部件(论文/参考图风格),actuator 见 _bowtie_valve。
|
|
666
|
+
|
|
667
|
+
端口与 globe/solenoid/filter 等两口阀相反:in=东口 / out=西口
|
|
668
|
+
(图内流向东→西)。w/h 在工厂锁定;actuator/stem 等外观项可在
|
|
669
|
+
add() 时以同名词覆盖,如
|
|
670
|
+
d.add(parts.bowtie_valve, "电磁阀", loc=..., actuator="solenoid")。
|
|
671
|
+
"""
|
|
672
|
+
if actuator not in BOWTIE_ACTUATORS:
|
|
673
|
+
raise ValueError(f"未知 actuator={actuator!r},可用:"
|
|
674
|
+
f"{', '.join(BOWTIE_ACTUATORS)}")
|
|
675
|
+
|
|
676
|
+
def draw(ax, x, y, label=None, actuator=actuator, stem=stem,
|
|
677
|
+
dome_r=dome_r, sol_len=sol_len, handle=handle, **kw):
|
|
678
|
+
_bowtie_valve(ax, x, y, label=label, w=w, h=h, actuator=actuator,
|
|
679
|
+
stem=stem, dome_r=dome_r, sol_len=sol_len,
|
|
680
|
+
handle=handle)
|
|
681
|
+
|
|
682
|
+
return Part(name, draw, {"in": (w / 2, 0), "out": (-w / 2, 0)},
|
|
683
|
+
{"in": "e", "out": "w"})
|
|
684
|
+
|
|
685
|
+
|
|
686
|
+
bowtie_valve = make_bowtie_valve()
|
|
687
|
+
bowtie_valve_dome = make_bowtie_valve(actuator="dome", name="膨胀阀(穹顶)")
|
|
688
|
+
bowtie_valve_solenoid = make_bowtie_valve(actuator="solenoid",
|
|
689
|
+
name="电磁阀(对顶三角)")
|
|
690
|
+
bowtie_valve_tee = make_bowtie_valve(actuator="tee",
|
|
691
|
+
name="截止阀(对顶三角)")
|
|
692
|
+
|
|
693
|
+
|
|
694
|
+
def make_separator_utube(w=120, h=118, stub=16, flip=False,
|
|
695
|
+
name="气液分离器(U形管)"):
|
|
696
|
+
"""气液分离器(U 形管液封)部件,形状见 _separator_utube。
|
|
697
|
+
|
|
698
|
+
端口:in 进气(壳顶短管)、out 出气(U 形管腿,穿壳顶引出)、
|
|
699
|
+
drain 放油/排液(U 形弯底,向南引出)。
|
|
700
|
+
flip=True 镜像:in 在东侧、out 为 U 形管左腿(进口在右、出口在左)。
|
|
701
|
+
"""
|
|
702
|
+
y_port = -h / 2 - stub
|
|
703
|
+
s = -1.0 if flip else 1.0
|
|
704
|
+
|
|
705
|
+
def draw(ax, x, y, label=None, **kw):
|
|
706
|
+
_separator_utube(ax, x, y, label=label, w=w, h=h, stub=stub,
|
|
707
|
+
flip=flip)
|
|
708
|
+
|
|
709
|
+
return Part(name, draw,
|
|
710
|
+
{"in": (s * -0.365 * w, y_port),
|
|
711
|
+
"out": (s * 0.435 * w, y_port),
|
|
712
|
+
"drain": (0, 0.463 * h)},
|
|
713
|
+
{"in": "n", "out": "n", "drain": "s"})
|
|
714
|
+
|
|
715
|
+
|
|
716
|
+
separator_utube = make_separator_utube()
|
|
717
|
+
|
|
718
|
+
|
|
719
|
+
def make_oil_separator(w=64, h=176, stub=16, name="油分离器"):
|
|
720
|
+
"""油分离器部件:瘦长矩形壳 + 顶/底/侧三接管(参考图画法)。
|
|
721
|
+
|
|
722
|
+
端口:left 进气(壳顶下 1/4,接压缩机排气)、top 出气(接四通阀 D 口)、
|
|
723
|
+
bottom 回油口(经毛细管接回吸气管)。
|
|
724
|
+
"""
|
|
725
|
+
y_port = -h / 2 - stub
|
|
726
|
+
|
|
727
|
+
def draw(ax, x, y, label=None, **kw):
|
|
728
|
+
_oil_separator(ax, x, y, label=label, w=w, h=h, stub=stub)
|
|
729
|
+
|
|
730
|
+
return Part(name, draw,
|
|
731
|
+
{"top": (0, y_port), "left": (-w / 2 - stub, -h / 4),
|
|
732
|
+
"bottom": (0, -y_port)},
|
|
733
|
+
{"top": "n", "left": "w", "bottom": "s"})
|
|
734
|
+
|
|
735
|
+
|
|
736
|
+
oil_separator = make_oil_separator()
|
|
737
|
+
|
|
738
|
+
|
|
739
|
+
def make_capillary(w=18, h=80, n=5, name="毛细管"):
|
|
740
|
+
"""可调尺寸毛细管,in 顶部、out 底部;端口随高度变化。"""
|
|
741
|
+
if isinstance(n, bool) or not isinstance(n, int) or n < 1:
|
|
742
|
+
raise ValueError("毛细管圈数必须为正整数")
|
|
743
|
+
|
|
744
|
+
def draw(ax, x, y, label=None, **kw):
|
|
745
|
+
_capillary(ax, x, y, label=label, w=w, h=h, n=n)
|
|
746
|
+
|
|
747
|
+
return Part(name, draw, {"in": (0, -h / 2), "out": (0, h / 2)},
|
|
748
|
+
{"in": "n", "out": "s"})
|
|
749
|
+
|
|
750
|
+
|
|
751
|
+
def make_fan_coil(w=120, h=64, stub=12, name="室内风机盘管"):
|
|
752
|
+
"""旧 Python 接口:复用换热器 fan_coil 样式,保留 in/out 端口。"""
|
|
753
|
+
part = make_heat_exchanger(w=w, h=h, shape="fan_coil", stub=stub, name=name)
|
|
754
|
+
|
|
755
|
+
def draw(ax, x, y, label=None, **kw):
|
|
756
|
+
part.draw(ax, x, y, label=None)
|
|
757
|
+
if label:
|
|
758
|
+
txt(ax, x, y + h / 2 + 24, label)
|
|
759
|
+
|
|
760
|
+
return Part(name, draw,
|
|
761
|
+
{"in": part.port("left"), "out": part.port("right")},
|
|
762
|
+
{"in": "w", "out": "e"})
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
def make_muffler(w=36, h=72, stub=12, name="消音器"):
|
|
766
|
+
"""消音器:矩形壳体,in 顶部、out 底部。"""
|
|
767
|
+
def draw(ax, x, y, label=None, **kw):
|
|
768
|
+
ax.add_patch(Rectangle((x - w / 2, y - h / 2), w, h,
|
|
769
|
+
facecolor=FILL, edgecolor=LINE, lw=LW_PART))
|
|
770
|
+
line(ax, [(x, y - h / 2 - stub), (x, y - h / 2)], lw=LW_PART)
|
|
771
|
+
line(ax, [(x, y + h / 2), (x, y + h / 2 + stub)], lw=LW_PART)
|
|
772
|
+
if label:
|
|
773
|
+
txt(ax, x + w / 2 + 18, y, label, ha="left")
|
|
774
|
+
|
|
775
|
+
return Part(name, draw,
|
|
776
|
+
{"in": (0, -h / 2 - stub), "out": (0, h / 2 + stub)},
|
|
777
|
+
{"in": "n", "out": "s"})
|
|
778
|
+
|
|
779
|
+
|
|
780
|
+
def make_sensor(r=14, stub=12, mark="T", name="温度/压力传感器"):
|
|
781
|
+
"""圆圈 T/P 测点,单个底部 tap 口接测量支路,不表示贯通流道。"""
|
|
782
|
+
if mark not in ("T", "P"):
|
|
783
|
+
raise ValueError("传感器标记仅支持 T 或 P")
|
|
784
|
+
|
|
785
|
+
def draw(ax, x, y, label=None, **kw):
|
|
786
|
+
ax.add_patch(Circle((x, y), r, facecolor=FILL,
|
|
787
|
+
edgecolor=LINE, lw=LW_PART))
|
|
788
|
+
txt(ax, x, y, mark, size=0.65 * r)
|
|
789
|
+
line(ax, [(x, y + r), (x, y + r + stub)], lw=LW_PART)
|
|
790
|
+
if label:
|
|
791
|
+
txt(ax, x + r + 18, y, label, ha="left")
|
|
792
|
+
|
|
793
|
+
return Part(name, draw, {"tap": (0, r + stub)}, {"tap": "s"})
|
|
794
|
+
|
|
795
|
+
|
|
796
|
+
def make_intermediate_hex(w=190, h=80, drop=0.275, name="中间换热器",
|
|
797
|
+
orient="h"):
|
|
798
|
+
"""中间换热器部件(过冷器/经济器为同一图元,角色由 label 区分)。
|
|
799
|
+
|
|
800
|
+
矩形 + 上下两条水平通道线:主路沿下侧贯通(main_in 西口进 /
|
|
801
|
+
main_out 东口出),副路沿上侧贯通(sub_in 东口进 / sub_out 西口出),
|
|
802
|
+
两路逆流。orient="v" 时通道竖直:主路右侧上进下出、副路左侧
|
|
803
|
+
下进上出。w/h 始终为外壳宽/高,drop 为通道距中心的偏移比例
|
|
804
|
+
(水平时相对 h,竖直时相对 w,取值 0~0.5)。
|
|
805
|
+
"""
|
|
806
|
+
if orient not in ("h", "v"):
|
|
807
|
+
raise ValueError(f"未知 orient={orient!r},可用:'h' / 'v'")
|
|
808
|
+
if orient == "h":
|
|
809
|
+
offset = drop * h
|
|
810
|
+
ports = {"main_in": (-w / 2, offset), "main_out": (w / 2, offset),
|
|
811
|
+
"sub_in": (w / 2, -offset), "sub_out": (-w / 2, -offset)}
|
|
812
|
+
dirs = {"main_in": "w", "main_out": "e",
|
|
813
|
+
"sub_in": "e", "sub_out": "w"}
|
|
814
|
+
else:
|
|
815
|
+
offset = drop * w
|
|
816
|
+
ports = {"main_in": (offset, -h / 2), "main_out": (offset, h / 2),
|
|
817
|
+
"sub_in": (-offset, h / 2), "sub_out": (-offset, -h / 2)}
|
|
818
|
+
dirs = {"main_in": "n", "main_out": "s",
|
|
819
|
+
"sub_in": "s", "sub_out": "n"}
|
|
820
|
+
|
|
821
|
+
def draw(ax, x, y, label=None, **kw):
|
|
822
|
+
ax.add_patch(Rectangle((x - w / 2, y - h / 2), w, h,
|
|
823
|
+
facecolor=FILL, edgecolor=LINE,
|
|
824
|
+
lw=LW_STRONG))
|
|
825
|
+
for inlet, outlet in (("main_in", "main_out"), ("sub_in", "sub_out")):
|
|
826
|
+
line(ax, [(x + ports[key][0], y + ports[key][1])
|
|
827
|
+
for key in (inlet, outlet)], lw=LW_OUTLINE)
|
|
828
|
+
if label:
|
|
829
|
+
txt(ax, x, y, label, boxed=True)
|
|
830
|
+
|
|
831
|
+
return Part(name, draw, ports, dirs)
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
intermediate_hex = make_intermediate_hex()
|