更新液面diff代码
This commit is contained in:
@ -65,6 +65,8 @@ if lib is None:
|
||||
|
||||
# ====================== 生成 LED 表格 ======================
|
||||
def generate_led_table(data, output_path="led_send.png", font_path="msyh.ttc"):
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
|
||||
try:
|
||||
font_title = ImageFont.truetype(font_path, 24)
|
||||
font_data = ImageFont.truetype(font_path, 20)
|
||||
@ -76,7 +78,7 @@ def generate_led_table(data, output_path="led_send.png", font_path="msyh.ttc"):
|
||||
font_title = font_data = font_data_big = font_small = ImageFont.load_default()
|
||||
header_font = ImageFont.load_default()
|
||||
|
||||
total_width, total_height = 640, 448
|
||||
total_width, total_height = 630, 430
|
||||
img = Image.new("RGB", (total_width, total_height), (0, 0, 0))
|
||||
draw = ImageDraw.Draw(img)
|
||||
|
||||
@ -84,74 +86,95 @@ def generate_led_table(data, output_path="led_send.png", font_path="msyh.ttc"):
|
||||
row_count = 8
|
||||
row_heights = [int(total_height * 0.095)] * 6 + [int(total_height * 0.15), int(total_height * 0.15)]
|
||||
y_positions = [0]
|
||||
for h in row_heights[:-1]:
|
||||
for h in row_heights:
|
||||
y_positions.append(y_positions[-1] + h)
|
||||
col_width = total_width // col_count
|
||||
|
||||
# 表头
|
||||
header_text = "浇筑工序信息屏测试"
|
||||
bbox = draw.textbbox((0, 0), header_text, font=header_font)
|
||||
tw, th = bbox[2] - bbox[0], bbox[3] - bbox[1]
|
||||
draw.text(((total_width - tw) // 2, 7), header_text, fill="Yellow", font=header_font)
|
||||
|
||||
# safe float parse
|
||||
# safe float
|
||||
try:
|
||||
task_quantity = float(data.get("TotMete", 0))
|
||||
task_quantity = float(data.get("TotMete", 0.0))
|
||||
fixed_value = float(data.get("BetonVolumeAlready", 0.0))
|
||||
except Exception:
|
||||
task_quantity = 0.0
|
||||
fixed_value = 0.0
|
||||
task_quantity_str = f"{task_quantity}"
|
||||
fixed_value_str = f"/{fixed_value}"
|
||||
|
||||
table_data = [
|
||||
["本盘方量", "当前模具", "高斗称值", "低斗称值"],
|
||||
[str(data.get("PlateVolume", "")), str(data.get("MouldCode", "")), str(data.get("HighBucketWeighingValue", "")), str(data.get("LowBucketWeighingValue", ""))],
|
||||
[str(data.get("PlateVolume", "")), str(data.get("MouldCode", "")),
|
||||
str(data.get("UpperWeight", "")), str(data.get("LowerWeight", ""))],
|
||||
["投料时间", "当前管片", "砼出料温度", "振捣频率"],
|
||||
[str(data.get("ProduceStartTime", "")), str(data.get("ArtifactID", "")), str(data.get("Temper", "")), str(data.get("VibrationFrequency", ""))],
|
||||
[str(data.get("ProduceStartTime", "")), str(data.get("ArtifactID", "")),
|
||||
str(data.get("Temper", "")), str(data.get("VibrationFrequency", ""))],
|
||||
["累计盘次", "隐蔽验收", "车间环温", "任务方量"],
|
||||
[str(data.get("PlateIDSerial", "任务方量")), str(data.get("CheckResult", "")), str(data.get("WorkshopTemperature", "")), ""],
|
||||
[str(data.get("PlateIDSerial", "")), str(data.get("CheckResult", "")),
|
||||
str(data.get("WorkshopTemperature", "")), ""],
|
||||
["配方比例", "", "", ""],
|
||||
["拆模强度", "", "", ""]
|
||||
]
|
||||
|
||||
# 画表格框
|
||||
for r in range(row_count):
|
||||
y1 = y_positions[r] + 40
|
||||
h = row_heights[r]
|
||||
for c in range(col_count):
|
||||
x1 = c * col_width
|
||||
if r >= 6 and c == 1:
|
||||
draw.rectangle([x1, y1, total_width - 1, y1 + h - 1], outline="white", width=1)
|
||||
break
|
||||
elif r >= 6 and c > 1:
|
||||
continue
|
||||
else:
|
||||
draw.rectangle([x1, y1, x1 + col_width - 1, y1 + h - 1], outline="white", width=1)
|
||||
# =======================
|
||||
# 画表格线(只用 line)
|
||||
# =======================
|
||||
line_color = (255, 255, 255)
|
||||
line_width = 1
|
||||
|
||||
# 横线
|
||||
for r in range(row_count + 1):
|
||||
y = y_positions[r] + 40 if r < row_count else y_positions[-1] + 40
|
||||
draw.line([(0, y), (total_width, y)], fill=line_color, width=line_width)
|
||||
|
||||
# 竖线
|
||||
for c in range(col_count + 1):
|
||||
x = c * col_width
|
||||
# 前6行所有竖线
|
||||
for r in range(6):
|
||||
y1 = y_positions[r] + 40
|
||||
y2 = y_positions[r + 1] + 40
|
||||
draw.line([(x, y1), (x, y2)], fill=line_color, width=line_width)
|
||||
|
||||
# 最后两行
|
||||
y1 = y_positions[6] + 40
|
||||
y2 = y_positions[8] + 40
|
||||
if c == 0 or c == col_count: # 左右边框
|
||||
draw.line([(x, y1), (x, y2)], fill=line_color, width=line_width)
|
||||
elif c == 1: # 第二列竖线(分隔跨列内容)
|
||||
draw.line([(x, y1), (x, y2)], fill=line_color, width=line_width)
|
||||
# 第三列和第四列竖线不画,保持跨列显示
|
||||
|
||||
# =======================
|
||||
# 绘制文本
|
||||
# =======================
|
||||
for r in range(row_count):
|
||||
y1 = y_positions[r] + 40
|
||||
h = row_heights[r]
|
||||
for c in range(col_count):
|
||||
x1 = c * col_width
|
||||
content = table_data[r][c]
|
||||
|
||||
if not content.strip():
|
||||
if r == 5 and c == 3:
|
||||
bbox_task = draw.textbbox((0, 0), task_quantity_str, font=font_data)
|
||||
tw_task = bbox_task[2] - bbox_task[0]
|
||||
th_task = bbox_task[3] - bbox_task[1]
|
||||
# 红色显示任务数量
|
||||
draw.text((x1 + (col_width - 1.8 * tw_task) // 2, y1 + (h - th_task) // 2),
|
||||
task_quantity_str, fill="red", font=font_data)
|
||||
# 亮绿色显示固定值 "/214.1"
|
||||
fixed_text = "/214.1"
|
||||
bbox_fixed = draw.textbbox((0, 0), fixed_text, font=font_data)
|
||||
bbox_fixed = draw.textbbox((0, 0), fixed_value_str, font=font_data)
|
||||
tw_fixed = bbox_fixed[2] - bbox_fixed[0]
|
||||
draw.text((x1 + (col_width - tw_fixed) // 2 + 0.78 * tw_task, y1 + (h - th_task) // 2),
|
||||
fixed_text, fill=(0, 255, 0), font=font_data)
|
||||
draw.text((x1 + (col_width - tw_fixed) // 2 + 0.78 * tw_task,
|
||||
y1 + (h - th_task) // 2),
|
||||
fixed_value_str, fill=(0, 255, 0), font=font_data)
|
||||
continue
|
||||
|
||||
is_header = r in (0, 2, 4, 6, 7)
|
||||
# 亮绿色显示表头
|
||||
color = (0, 255, 0) if is_header else "red"
|
||||
|
||||
if color == "red" and r < 3:
|
||||
font = font_data_big
|
||||
elif color == "red" and r >= 6:
|
||||
@ -164,27 +187,29 @@ def generate_led_table(data, output_path="led_send.png", font_path="msyh.ttc"):
|
||||
th = bbox[3] - bbox[1]
|
||||
draw.text((x1 + (col_width - tw) // 2, y1 + (h - th) // 2), content, fill=color, font=font)
|
||||
|
||||
# 多行文本居中函数
|
||||
# 多行文本居中
|
||||
def draw_multiline_text_center(draw_obj, x, y, width, height, text, font_obj, fill="red"):
|
||||
lines = text.split('\n')
|
||||
bboxs = [draw_obj.textbbox((0, 0), line, font=font_obj) for line in lines]
|
||||
total_h = sum(b[3] - b[1] for b in bboxs)
|
||||
y_start = y + (height - total_h) // 2
|
||||
curr_y = y_start
|
||||
cy = y + (height - total_h) // 2
|
||||
for line, b in zip(lines, bboxs):
|
||||
w = b[2] - b[0]
|
||||
h = b[3] - b[1]
|
||||
draw_obj.text((x + (width - w) // 2, curr_y), line, fill=fill, font=font_obj)
|
||||
curr_y += h
|
||||
draw_obj.text((x + (width - w) // 2, cy), line, fill=fill, font=font_obj)
|
||||
cy += h
|
||||
|
||||
draw_multiline_text_center(draw, col_width * 1, y_positions[6] + 40, col_width * 3, row_heights[6],
|
||||
str(data.get("FormulaProportion", "")).replace("\r", ""), font_small)
|
||||
draw_multiline_text_center(draw, col_width * 1, y_positions[7] + 40, col_width * 3, row_heights[7],
|
||||
f"{data.get('DayStrengthValue', '')}\n{data.get('NihtStrengthValue', '')}", font_small)
|
||||
f"{data.get('DayStrengthValue', '')}\n{data.get('NihtStrengthValue', '')}",
|
||||
font_small)
|
||||
|
||||
img.save(output_path)
|
||||
print(f"已生成参数化表格:{output_path}")
|
||||
|
||||
|
||||
|
||||
# ====================== 动态区结构体 ======================
|
||||
class EQpageHeader_G6(Structure):
|
||||
_fields_ = [
|
||||
@ -208,7 +233,7 @@ def send_dynamic_frame(ip="10.6.242.2", port=5005, frame=None, filename="led_sen
|
||||
print("frame 为空!")
|
||||
return
|
||||
|
||||
target_w, target_h = 640, 448
|
||||
target_w, target_h = 630, 435
|
||||
resized = cv2.resize(frame, (target_w, target_h))
|
||||
save_path = os.path.join(CURRENT_DIR, filename)
|
||||
cv2.imwrite(save_path, resized)
|
||||
|
||||
Reference in New Issue
Block a user