Squashed commit of the following: commit 02c7556cdadf8de1ef3c54d2831920927cadbe30 Merge: 6bfa42e0 991003e6 Author: zkk <1007518571@qq.com> Date: Tue Dec 31 15:07:54 2024 +0800 Merge commit '991003e6cbea335eca73d3783aa1837059614724' into release commit 991003e6cbea335eca73d3783aa1837059614724 Author: zkk <1007518571@qq.com> Date: Tue Dec 31 15:03:34 2024 +0800 优化完整 简体中文和繁体中文的翻译 commit 1a177e90d09b9b9949bff2a1e3c6b12173420620 Author: zkk <1007518571@qq.com> Date: Tue Dec 31 14:10:03 2024 +0800 优化排除对象的英文语法错误 commit e8d509cb6c2883b1fadb5ab9f9ca658e61849055 Author: zkk <1007518571@qq.com> Date: Fri Dec 27 16:40:52 2024 +0800 优化耗材检测显示内容 commit 1b7670485a918cb334119175777525f768e670be Author: zkk <1007518571@qq.com> Date: Fri Dec 27 14:56:25 2024 +0800 完善断料自动切头功能描述 commit ecc0c3dd16442497e56f5f8ab3a0c6be00bd180e Author: zkk <1007518571@qq.com> Date: Fri Dec 27 13:40:01 2024 +0800 实现弹窗翻译功能 commit bc6d60fa183af50b7b16fea685139ca9d5df90ea Author: zkk <1007518571@qq.com> Date: Fri Dec 27 09:53:16 2024 +0800 优化不合理名称和不合理大小写 commit 2e650926bdba1c65baa506be1b1dd09621e8d8ea Author: zkk <1007518571@qq.com> Date: Thu Dec 26 15:06:11 2024 +0800 修复10寸屏幕偏移值微调页面出界问题 commit c481b551f777a3a6cadf7be3bfcab38448b51694 Author: zkk <1007518571@qq.com> Date: Wed Dec 25 15:28:26 2024 +0800 优化移轴设置页面没有返回按钮的问题 commit 2b3c9936bd693c8fc265d6352799f382680f4920 Author: zkk <1007518571@qq.com> Date: Wed Dec 25 10:05:04 2024 +0800 删除移动设置页面中轴反转的选项 commit 5e37d59497c54086d3f1e215cbabc03254857a58 Author: zkk <1007518571@qq.com> Date: Wed Dec 25 09:05:03 2024 +0800 优化选择语言标题 commit 5214c3697baac78bd0a465e33d6f4f3c1e30862e Author: zkk <1007518571@qq.com> Date: Tue Dec 24 10:57:41 2024 +0800 增加设置hostname功能 commit 3709a7465cc2e0d677ecc9979fb18144f7e0ec33 Author: zkk <1007518571@qq.com> Date: Tue Dec 24 10:43:46 2024 +0800 增加工厂设置中打包模式 commit 0c2a2618beb68d50601e433beef06122fb0ffd40 Author: zkk <1007518571@qq.com> Date: Mon Dec 23 16:25:37 2024 +0800 实现恢复出厂设置功能 commit e3a38f85613d53a4a063e835c34c701196010c6e Author: zkk <1007518571@qq.com> Date: Mon Dec 23 15:48:17 2024 +0800 一点格式化 commit 4e9e452e8bed4b53eaaae8f0a69142de8aa50611 Author: zkk <1007518571@qq.com> Date: Sat Dec 21 14:20:22 2024 +0800 优化探针偏移值校准时如果当前激活为第一个喷头时不会重复激活喷头 commit 3b85e8e8d59b0d4eae75f80d9e637fe9dc272cbe Merge: 882850db 10ec2029 Author: zkk <1007518571@qq.com> Date: Wed Dec 18 17:26:08 2024 +0800 Merge branch 'develop' of https://server.creatbot.com/Gitea/CreatBot/CreatBotKlipperScreen into develop commit 882850dbde648598e5f91281101d0ea01fd56d56 Author: zkk <1007518571@qq.com> Date: Wed Dec 18 17:21:16 2024 +0800 补充双喷头偏移校准页面二维码图片 commit 10ec2029eb73e66874d5a0ec492c016480641110 Author: ruipeng <1041589370@qq.com> Date: Wed Dec 18 17:17:18 2024 +0800 增加自动切换喷头开关选项 commit 3d6eed9d9526b77472ba7df29014b5768c594026 Author: zkk <1007518571@qq.com> Date: Mon Dec 16 16:33:34 2024 +0800 喷头偏移值校准功能的实现 commit 40ecbb3ea4827c9bac1aa271cccc958c94c1114a Author: zkk <1007518571@qq.com> Date: Fri Dec 13 09:20:00 2024 +0800 z探针校准时指定默认激活工具头为第一个头 commit bce3caa409618ef5bc2067865940d14a1441c0f8 Author: zkk <1007518571@qq.com> Date: Fri Dec 13 09:19:19 2024 +0800 优化z探针校准时候移动过慢问题 commit 6bfa42e036a521c8ff7db1bf8ccb65500eabb6ea Merge: 1a87ced3 4f3aa9aa Author: zkk <1007518571@qq.com> Date: Thu Dec 12 10:33:58 2024 +0800 Merge commit '4f3aa9aa4c581ae9e7a740bd37f9e80ba064c27f' into release commit 4f3aa9aa4c581ae9e7a740bd37f9e80ba064c27f Merge: e3fd413d 1a69b518 Author: zkk <1007518571@qq.com> Date: Thu Dec 12 10:30:00 2024 +0800 Merge branch 'develop' of https://server.creatbot.com/Gitea/CreatBot/CreatBotKlipperScreen into develop commit 1a69b5180de733f15550a1294a7221d6070306a0 Author: ruipeng <1041589370@qq.com> Date: Wed Dec 11 11:44:36 2024 +0800 新增D600pro2、D1000的V0版机型 commit e3fd413d6256414441e9fe653c1132b1799a5cb2 Author: zkk <1007518571@qq.com> Date: Tue Dec 10 14:34:13 2024 +0800 修复打印时没有修改z偏移值 仍提示保存z偏移的按钮的bug commit 594fb668fe94fe907c028bf65ecced43ea8660cb Author: zkk <1007518571@qq.com> Date: Tue Dec 10 14:25:04 2024 +0800 设置自适应调平选项默认为关闭状态 commit 1a87ced3f5725569a6b9a7ee5f5250044d01d852 Merge: 629416d1 6064a6e1 Author: zkk <1007518571@qq.com> Date: Fri Nov 29 10:18:32 2024 +0800 Merge branch 'develop' into release # Conflicts: # panels/advanced.py # panels/nozzle_offset.py # panels/offset_fine_tune.py # panels/zcalibrate.py
151 lines
6.1 KiB
Python
151 lines
6.1 KiB
Python
import logging
|
|
|
|
import gi
|
|
|
|
gi.require_version("Gtk", "3.0")
|
|
from gi.repository import Gdk, Gtk
|
|
|
|
|
|
class ObjectMap(Gtk.DrawingArea):
|
|
def __init__(self, screen, printer, font_size):
|
|
super().__init__()
|
|
self._screen = screen
|
|
self.set_hexpand(True)
|
|
self.set_vexpand(True)
|
|
# self.get_style_context().add_class('objectmap')
|
|
self.printer = printer
|
|
self.max_length = 0
|
|
self.connect('draw', self.draw_graph)
|
|
self.add_events(Gdk.EventMask.TOUCH_MASK)
|
|
self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
|
|
self.connect('button_press_event', self.event_cb)
|
|
self.font_size = round(font_size * 0.75)
|
|
self.font_spacing = round(self.font_size * 1.5)
|
|
self.margin_left = round(self.font_size * 2.75)
|
|
self.margin_right = 15
|
|
self.margin_top = 10
|
|
self.margin_bottom = self.font_size * 2
|
|
self.objects = self.printer.get_stat("exclude_object", "objects")
|
|
self.current_object = self.printer.get_stat("current_object", "current_object")
|
|
self.excluded_objects = self.printer.get_stat("exclude_object", "excluded_objects")
|
|
self.min_x = self.min_y = 99999999
|
|
self.max_x = self.max_y = 0
|
|
|
|
def x_graph_to_bed(self, width, gx):
|
|
return (((gx - self.margin_left) * (self.max_x - self.min_x))
|
|
/ (width - self.margin_left - self.margin_right)) + self.min_x
|
|
|
|
def y_graph_to_bed(self, height, gy):
|
|
return ((1 - ((gy - self.margin_top) / (height - self.margin_top - self.margin_bottom)))
|
|
* (self.max_y - self.min_y)) + self.min_y
|
|
|
|
def event_cb(self, da, ev):
|
|
# Convert coordinates from screen-graph to bed
|
|
x = self.x_graph_to_bed(da.get_allocated_width(), ev.x)
|
|
y = self.y_graph_to_bed(da.get_allocated_height(), ev.y)
|
|
logging.info(f"Touched GRAPH {ev.x:.0f},{ev.y:.0f} BED: {x:.0f},{y:.0f}")
|
|
|
|
for obj in self.objects:
|
|
obj_min_x = obj_max_x = obj["polygon"][0][0]
|
|
obj_min_y = obj_max_y = obj["polygon"][0][1]
|
|
for point in obj["polygon"]:
|
|
obj_min_x = min(obj_min_x, point[0])
|
|
obj_min_y = min(obj_min_y, point[1])
|
|
obj_max_x = max(obj_max_x, point[0])
|
|
obj_max_y = max(obj_max_y, point[1])
|
|
if obj_min_x < x < obj_max_x and obj_min_y < y < obj_max_y:
|
|
logging.info(f"TOUCHED object it's: {obj['name']}")
|
|
if obj['name'] not in self.excluded_objects:
|
|
self.exclude_object(obj['name'])
|
|
break
|
|
|
|
def exclude_object(self, name):
|
|
script = {"script": f"EXCLUDE_OBJECT NAME={name}"}
|
|
self._screen._confirm_send_action(
|
|
None,
|
|
_("Are you sure you want to exclude the object?") + f"\n\n{name}",
|
|
"printer.gcode.script",
|
|
script
|
|
)
|
|
|
|
def draw_graph(self, da, ctx):
|
|
right = da.get_allocated_width() - self.margin_right
|
|
bottom = da.get_allocated_height() - self.margin_bottom
|
|
self.objects = self.printer.get_stat("exclude_object", "objects")
|
|
|
|
for obj in self.objects:
|
|
for point in obj["polygon"]:
|
|
# Find min coords
|
|
self.min_x = min(self.min_x, point[0])
|
|
self.min_y = min(self.min_y, point[1])
|
|
# Find max coords
|
|
self.max_x = max(self.max_x, point[0])
|
|
self.max_y = max(self.max_y, point[1])
|
|
|
|
# Styling
|
|
ctx.set_source_rgb(.5, .5, .5) # Grey
|
|
ctx.set_line_width(1)
|
|
ctx.set_font_size(self.font_size)
|
|
|
|
# Borders
|
|
ctx.move_to(self.margin_left, self.margin_top)
|
|
# logging.info(f"l:{self.margin_left:.0f} t:{self.margin_top:.0f} r:{right:.0f} b:{bottom:.0f}")
|
|
ctx.line_to(right, self.margin_top)
|
|
ctx.line_to(right, bottom)
|
|
ctx.line_to(self.margin_left, bottom)
|
|
ctx.line_to(self.margin_left, self.margin_top)
|
|
ctx.stroke()
|
|
|
|
# Axis labels
|
|
ctx.move_to(0, bottom + self.font_spacing)
|
|
ctx.show_text(f"{self.min_x:.0f},{self.min_y:.0f}")
|
|
ctx.stroke()
|
|
ctx.move_to(right - self.font_spacing * 2, bottom + self.font_spacing)
|
|
ctx.show_text(f"{self.max_x:.0f},{self.min_y:.0f}")
|
|
ctx.stroke()
|
|
ctx.move_to(0, self.font_spacing / 2)
|
|
ctx.show_text(f"{self.min_x:.0f},{self.max_y:.0f}")
|
|
ctx.stroke()
|
|
|
|
# middle markers
|
|
midx = (right - self.margin_left) / 2 + self.margin_left
|
|
ctx.set_dash([1, 1])
|
|
ctx.move_to(midx, self.margin_top)
|
|
ctx.line_to(midx, bottom)
|
|
ctx.stroke()
|
|
midy = (self.margin_top - bottom) / 2 + bottom
|
|
ctx.move_to(self.margin_left, midy)
|
|
ctx.line_to(right, midy)
|
|
ctx.stroke()
|
|
ctx.set_dash([1, 0])
|
|
|
|
# Draw objects
|
|
for obj in self.objects:
|
|
# change the color depending on the status
|
|
if obj['name'] == self.printer.get_stat("exclude_object", "current_object"):
|
|
ctx.set_source_rgb(1, 0, 0) # Red
|
|
elif obj['name'] in self.printer.get_stat("exclude_object", "excluded_objects"):
|
|
ctx.set_source_rgb(0, 0, 0) # Black
|
|
else:
|
|
ctx.set_source_rgb(.5, .5, .5) # Grey
|
|
for i, point in enumerate(obj["polygon"]):
|
|
# Convert coordinates from bed to screen-graph
|
|
x = self.x_bed_to_graph(da.get_allocated_width(), point[0])
|
|
y = self.y_bed_to_graph(da.get_allocated_height(), point[1])
|
|
if i == 0:
|
|
ctx.move_to(x, y)
|
|
continue
|
|
ctx.line_to(x, y)
|
|
# logging.info(f"obj graph: {x=:.0f},{y=:.0f} bed: {point[0]:.0f},{point[1]:.0f}")
|
|
ctx.close_path()
|
|
ctx.fill()
|
|
ctx.stroke()
|
|
|
|
def x_bed_to_graph(self, width, bx):
|
|
return (((bx - self.min_x) * (width - self.margin_left - self.margin_right))
|
|
/ (self.max_x - self.min_x)) + self.margin_left
|
|
|
|
def y_bed_to_graph(self, height, by):
|
|
return ((1 - ((by - self.min_y) / (self.max_y - self.min_y)))
|
|
* (height - self.margin_top - self.margin_bottom)) + self.margin_top
|