From 1debee7b58be75e27cf6b0a5304cea5b09e59db0 Mon Sep 17 00:00:00 2001 From: alfrix Date: Sun, 21 Apr 2024 14:42:48 -0300 Subject: [PATCH] bed_mesh: show round bed without padded values --- ks_includes/widgets/bedmap.py | 20 +++++++++++++++++++- panels/bed_mesh.py | 4 +++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/ks_includes/widgets/bedmap.py b/ks_includes/widgets/bedmap.py index 75d25ee9..3b477b33 100644 --- a/ks_includes/widgets/bedmap.py +++ b/ks_includes/widgets/bedmap.py @@ -19,8 +19,9 @@ class BedMap(Gtk.DrawingArea): self.rotation = 0 self.mesh_min = [0, 0] self.mesh_max = [0, 0] + self.mesh_radius = 0 - def update_bm(self, bm): + def update_bm(self, bm, radius=None): if not bm: self.bm = None return @@ -29,6 +30,8 @@ class BedMap(Gtk.DrawingArea): if key == 'profiles': continue logging.info(f"{key}: {value}") + if radius: + self.mesh_radius = radius if 'mesh_min' in bm: self.mesh_min = bm['mesh_min'] if 'mesh_max' in bm: @@ -78,6 +81,7 @@ class BedMap(Gtk.DrawingArea): elif self.rotation == 270: new_max = [self.mesh_min[1], self.mesh_max[0]] new_min = [self.mesh_max[1], self.mesh_min[0]] + self.mesh_max = new_max self.mesh_min = new_min return [list(row) for row in zip(*matrix)][::-1] @@ -129,6 +133,8 @@ class BedMap(Gtk.DrawingArea): ty = (gheight / rows * i) by = ty + gheight / rows for j, column in enumerate(row): + if self.mesh_radius > 0 and self.round_bed_skip(i, j, row, rows, columns): + continue lx = (gwidth / columns * j) + self.font_size * 2.2 rx = lx + gwidth / columns # Colors @@ -151,6 +157,18 @@ class BedMap(Gtk.DrawingArea): ctx.show_text(f"{column:.2f}") ctx.stroke() + @staticmethod + def round_bed_skip(i, j, row, rows, columns): + if columns <= 3: + return False + if i != rows // 2 and j != columns // 2: + # Skip if the value is equal to the next but verify that this also happens on the other side + if j < columns // 2 and row[j] == row[j + 1] and row[columns - 1] == row[columns - 1 - j]: + return True + if j > columns // 2 and row[j] == row[j - 1] and row[0] == row[columns - j]: + return True + return False + @staticmethod def colorbar(value): rmax = 0.25 diff --git a/panels/bed_mesh.py b/panels/bed_mesh.py index ef357caa..a0039e92 100644 --- a/panels/bed_mesh.py +++ b/panels/bed_mesh.py @@ -15,6 +15,8 @@ class Panel(ScreenPanel): super().__init__(screen, title) self.show_create = False self.active_mesh = None + section = self._printer.get_config_section("bed_mesh") + self.mesh_radius = section['mesh_radius'] if 'mesh_radius' in section else None self.profiles = {} self.buttons = { 'add': self._gtk.Button("increase", " " + _("Add profile"), "color1", self.bts, Gtk.PositionType.LEFT, 1), @@ -93,7 +95,7 @@ class Panel(ScreenPanel): rotation = 0 self.labels['map'].set_rotation(rotation) logging.info(f"Inversion X: {invert_x} Y: {invert_y} Rotation: {rotation}") - self.labels['map'].update_bm(self.retrieve_bm(profile)) + self.labels['map'].update_bm(self.retrieve_bm(profile), self.mesh_radius) self.labels['map'].queue_draw() def add_profile(self, profile):