bed_mesh: bedmap draw axis
This commit is contained in:
parent
d23ca4557a
commit
6a1e444f38
@ -1,3 +1,4 @@
|
|||||||
|
import logging
|
||||||
import gi
|
import gi
|
||||||
|
|
||||||
gi.require_version("Gtk", "3.0")
|
gi.require_version("Gtk", "3.0")
|
||||||
@ -16,34 +17,78 @@ class BedMap(Gtk.DrawingArea):
|
|||||||
self.invert_x = False
|
self.invert_x = False
|
||||||
self.invert_y = False
|
self.invert_y = False
|
||||||
self.rotation = 0
|
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):
|
||||||
if bm is None:
|
if not bm:
|
||||||
self.bm = None
|
self.bm = None
|
||||||
return
|
return
|
||||||
print(bm)
|
|
||||||
|
for key, value in bm.items():
|
||||||
|
if key == 'profiles':
|
||||||
|
continue
|
||||||
|
logging.info(f"{key}: {value}")
|
||||||
|
if 'mesh_min' in bm:
|
||||||
|
self.mesh_min = bm['mesh_min']
|
||||||
|
self.mesh_max = bm['mesh_max']
|
||||||
|
if 'mesh_radius' in bm:
|
||||||
|
self.mesh_radius = bm['mesh_radius']
|
||||||
|
if 'probed_matrix' in bm:
|
||||||
|
bm = bm['probed_matrix']
|
||||||
|
elif 'points' in bm:
|
||||||
|
bm = bm['points']
|
||||||
|
else:
|
||||||
|
self.bm = None
|
||||||
|
return
|
||||||
|
|
||||||
if self.invert_x and self.invert_y:
|
if self.invert_x and self.invert_y:
|
||||||
self.bm = [list(reversed(b)) for b in bm]
|
self.rotation = (self.rotation + 180) % 360
|
||||||
elif self.invert_x:
|
self.invert_x = self.invert_y = False
|
||||||
|
if self.invert_x:
|
||||||
|
new_max = [self.mesh_min[0], self.mesh_max[1]]
|
||||||
|
new_min = [self.mesh_max[0], self.mesh_min[1]]
|
||||||
|
self.mesh_max = new_max
|
||||||
|
self.mesh_min = new_min
|
||||||
self.bm = [list(reversed(b)) for b in list(reversed(bm))]
|
self.bm = [list(reversed(b)) for b in list(reversed(bm))]
|
||||||
elif self.invert_y:
|
if self.invert_y:
|
||||||
|
new_max = [self.mesh_max[0], self.mesh_min[1]]
|
||||||
|
new_min = [self.mesh_min[0], self.mesh_max[1]]
|
||||||
|
self.mesh_max = new_max
|
||||||
|
self.mesh_min = new_min
|
||||||
self.bm = list(bm)
|
self.bm = list(bm)
|
||||||
else:
|
else:
|
||||||
self.bm = list(reversed(bm))
|
self.bm = list(reversed(bm))
|
||||||
|
|
||||||
if self.rotation in (90, 180, 270):
|
if self.rotation in (90, 180, 270):
|
||||||
self.bm = self.rotate_matrix(self.bm)
|
self.bm = self.rotate_matrix(self.bm)
|
||||||
|
|
||||||
def rotate_matrix(self, matrix):
|
def rotate_matrix(self, matrix):
|
||||||
if self.rotation == 90:
|
if self.rotation == 90:
|
||||||
|
new_max = [self.mesh_max[1], self.mesh_min[0]]
|
||||||
|
new_min = [self.mesh_min[1], self.mesh_max[0]]
|
||||||
|
self.mesh_max = new_max
|
||||||
|
self.mesh_min = new_min
|
||||||
return [list(row) for row in zip(*matrix[::-1])]
|
return [list(row) for row in zip(*matrix[::-1])]
|
||||||
elif self.rotation == 180:
|
elif self.rotation == 180:
|
||||||
|
new_max = [self.mesh_min[0], self.mesh_min[1]]
|
||||||
|
new_min = [self.mesh_max[0], self.mesh_max[1]]
|
||||||
|
self.mesh_max = new_max
|
||||||
|
self.mesh_min = new_min
|
||||||
return [list(row)[::-1] for row in matrix[::-1]]
|
return [list(row)[::-1] for row in matrix[::-1]]
|
||||||
elif self.rotation == 270:
|
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]
|
return [list(row) for row in zip(*matrix)][::-1]
|
||||||
|
|
||||||
def draw_graph(self, da, ctx):
|
def draw_graph(self, da, ctx):
|
||||||
width = da.get_allocated_width()
|
width = da.get_allocated_width()
|
||||||
height = da.get_allocated_height()
|
height = da.get_allocated_height()
|
||||||
|
gwidth = int(width - self.font_size * 2.2)
|
||||||
|
gheight = int(height - self.font_size * 1.8)
|
||||||
# Styling
|
# Styling
|
||||||
ctx.set_line_width(1)
|
ctx.set_line_width(1)
|
||||||
ctx.set_font_size(self.font_size)
|
ctx.set_font_size(self.font_size)
|
||||||
@ -55,14 +100,37 @@ class BedMap(Gtk.DrawingArea):
|
|||||||
ctx.stroke()
|
ctx.stroke()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not self.mesh_radius:
|
||||||
|
text_side_top = [0, self.font_size]
|
||||||
|
text_side_bottom = [0, height - int(self.font_size * 2)]
|
||||||
|
text_side_middle = [self.font_size, (text_side_top[1] + text_side_bottom[1]) / 2]
|
||||||
|
text_bottom_left = [self.font_size * 1.8, height - int(self.font_size / 2)]
|
||||||
|
text_bottom_right = [width - int(self.font_size * 2.2), height - int(self.font_size / 2)]
|
||||||
|
text_bottom_middle = [int(self.font_size * 2 + gwidth / 2), height - int(self.font_size / 2)]
|
||||||
|
# dibujar ejes
|
||||||
|
ctx.set_source_rgb(0.5, 0.5, 0.5)
|
||||||
|
ctx.move_to(*text_side_top)
|
||||||
|
ctx.show_text(f"{self.mesh_max[1]:.0f}".rjust(4, " "))
|
||||||
|
ctx.move_to(*text_side_bottom)
|
||||||
|
ctx.show_text(f"{self.mesh_min[1]:.0f}".rjust(4, " "))
|
||||||
|
ctx.move_to(*text_bottom_left)
|
||||||
|
ctx.show_text(f"{self.mesh_min[0]:.0f}".rjust(4, " "))
|
||||||
|
ctx.move_to(*text_bottom_right)
|
||||||
|
ctx.show_text(f"{self.mesh_max[0]:.0f}".rjust(4, " "))
|
||||||
|
ctx.move_to(*text_side_middle)
|
||||||
|
ctx.show_text(f"{'Y' if self.rotation == 0 or self.rotation == 180 else 'X'}")
|
||||||
|
ctx.move_to(*text_bottom_middle)
|
||||||
|
ctx.show_text(f"{'X' if self.rotation == 0 or self.rotation == 180 else 'Y'}")
|
||||||
|
ctx.stroke()
|
||||||
|
|
||||||
rows = len(self.bm)
|
rows = len(self.bm)
|
||||||
columns = len(self.bm[0])
|
columns = len(self.bm[0])
|
||||||
for i, row in enumerate(self.bm):
|
for i, row in enumerate(self.bm):
|
||||||
ty = height / rows * i
|
ty = (gheight / rows * i)
|
||||||
by = ty + height / rows
|
by = ty + gheight / rows
|
||||||
for j, column in enumerate(row):
|
for j, column in enumerate(row):
|
||||||
lx = width / columns * j
|
lx = (gwidth / columns * j) + self.font_size * 2.2
|
||||||
rx = lx + width / columns
|
rx = lx + gwidth / columns
|
||||||
# Colors
|
# Colors
|
||||||
ctx.set_source_rgb(*self.colorbar(column))
|
ctx.set_source_rgb(*self.colorbar(column))
|
||||||
ctx.move_to(lx, ty)
|
ctx.move_to(lx, ty)
|
||||||
|
@ -81,19 +81,9 @@ class Panel(ScreenPanel):
|
|||||||
if profile is None:
|
if profile is None:
|
||||||
return None
|
return None
|
||||||
if profile == self.active_mesh:
|
if profile == self.active_mesh:
|
||||||
bm = self._printer.get_stat("bed_mesh")
|
return self._printer.get_stat("bed_mesh")
|
||||||
if bm is None:
|
|
||||||
logging.info(f"Unable to load active mesh: {profile}")
|
|
||||||
return None
|
|
||||||
matrix = 'probed_matrix'
|
|
||||||
else:
|
else:
|
||||||
bm = self._printer.get_config_section(f"bed_mesh {profile}")
|
return self._printer.get_config_section(f"bed_mesh {profile}")
|
||||||
if bm is False:
|
|
||||||
logging.info(f"Unable to load profile: {profile}")
|
|
||||||
self.remove_profile(profile)
|
|
||||||
return None
|
|
||||||
matrix = 'points'
|
|
||||||
return bm[matrix]
|
|
||||||
|
|
||||||
def update_graph(self, widget=None, profile=None):
|
def update_graph(self, widget=None, profile=None):
|
||||||
if self.ks_printer_cfg is not None:
|
if self.ks_printer_cfg is not None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user