From f33bab3b2eaeb349eeeae21ec6d2773c0f073f01 Mon Sep 17 00:00:00 2001 From: Igor Yeremin Date: Mon, 10 Aug 2020 12:20:40 -0400 Subject: [PATCH] Apply grid size settings to 3d view --- printrun/gcodeplater.py | 7 +++++-- printrun/gcview.py | 22 ++++++++++++---------- printrun/gl/libtatlin/actors.py | 16 ++++++++-------- printrun/gui/viz.py | 17 +++++++++++++++-- printrun/pronterface.py | 6 ++++-- printrun/stlview.py | 6 ++++-- 6 files changed, 48 insertions(+), 26 deletions(-) diff --git a/printrun/gcodeplater.py b/printrun/gcodeplater.py index c9dc6d2b5..5528cd6d4 100755 --- a/printrun/gcodeplater.py +++ b/printrun/gcodeplater.py @@ -79,13 +79,16 @@ class GcodePlaterPanel(PlaterPanel): def prepare_ui(self, filenames = [], callback = None, parent = None, build_dimensions = None, - circular_platform = False, antialias_samples = 0): + circular_platform = False, + antialias_samples = 0, + grid = (1, 10)): super(GcodePlaterPanel, self).prepare_ui(filenames, callback, parent, build_dimensions) viewer = gcview.GcodeViewPanel(self, build_dimensions = self.build_dimensions, antialias_samples = antialias_samples) self.set_viewer(viewer) self.platform = actors.Platform(self.build_dimensions, - circular = circular_platform) + circular = circular_platform, + grid = grid) self.platform_object = gcview.GCObject(self.platform) def get_objects(self): diff --git a/printrun/gcview.py b/printrun/gcview.py index 8b582bfc8..a929714d4 100755 --- a/printrun/gcview.py +++ b/printrun/gcview.py @@ -51,8 +51,8 @@ def set_model_colors(model, root): if hasattr(root, root_fieldname): setattr(model, field, getattr(root, root_fieldname)) -def recreate_platform(self, build_dimensions, circular): - self.platform = actors.Platform(build_dimensions, circular = circular) +def recreate_platform(self, build_dimensions, circular, grid): + self.platform = actors.Platform(build_dimensions, circular = circular, grid = grid) self.objects[0].model = self.platform wx.CallAfter(self.Refresh) @@ -348,7 +348,7 @@ def set_gcview_params(self, path_width, path_height): from printrun.gviz import BaseViz class GcodeViewMainWrapper(GcodeViewLoader, BaseViz): - def __init__(self, parent, build_dimensions, root, circular, antialias_samples): + def __init__(self, parent, build_dimensions, root, circular, antialias_samples, grid): self.root = root self.glpanel = GcodeViewPanel(parent, realparent = self, build_dimensions = build_dimensions, @@ -360,7 +360,8 @@ def __init__(self, parent, build_dimensions, root, circular, antialias_samples): self.widget = self.glpanel self.refresh_timer = wx.CallLater(100, self.Refresh) self.p = self # Hack for backwards compatibility with gviz API - self.platform = actors.Platform(build_dimensions, circular = circular) + self.grid = grid + self.platform = actors.Platform(build_dimensions, circular = circular, grid = grid) self.model = None self.objects = [GCObject(self.platform), GCObject(None)] @@ -381,8 +382,8 @@ def set_current_gline(self, gline): if not self.refresh_timer.IsRunning(): self.refresh_timer.Start() - def recreate_platform(self, build_dimensions, circular): - return recreate_platform(self, build_dimensions, circular) + def recreate_platform(self, build_dimensions, circular, grid): + return recreate_platform(self, build_dimensions, circular, grid) def setlayer(self, layer): if layer in self.model.layer_idxs_map: @@ -401,7 +402,8 @@ class GcodeViewFrame(GvizBaseFrame, GcodeViewLoader): def __init__(self, parent, ID, title, build_dimensions, objects = None, pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_FRAME_STYLE, root = None, circular = False, - antialias_samples = 0): + antialias_samples = 0, + grid = (1, 10)): GvizBaseFrame.__init__(self, parent, ID, title, pos, size, style) self.root = root @@ -411,7 +413,7 @@ def __init__(self, parent, ID, title, build_dimensions, objects = None, self.refresh_timer = wx.CallLater(100, self.Refresh) self.p = self # Hack for backwards compatibility with gviz API self.clonefrom = objects - self.platform = actors.Platform(build_dimensions, circular = circular) + self.platform = actors.Platform(build_dimensions, circular = circular, grid = grid) self.model = objects[1].model if objects else None self.objects = [GCObject(self.platform), GCObject(None)] @@ -465,8 +467,8 @@ def set_current_gline(self, gline): if not self.refresh_timer.IsRunning(): self.refresh_timer.Start() - def recreate_platform(self, build_dimensions, circular): - return recreate_platform(self, build_dimensions, circular) + def recreate_platform(self, build_dimensions, circular, grid): + return recreate_platform(self, build_dimensions, circular, grid) def addfile(self, gcode = None): if self.clonefrom: diff --git a/printrun/gl/libtatlin/actors.py b/printrun/gl/libtatlin/actors.py index 4c1170d3d..a61eb6d4b 100644 --- a/printrun/gl/libtatlin/actors.py +++ b/printrun/gl/libtatlin/actors.py @@ -93,9 +93,8 @@ class Platform: """ Platform on which models are placed. """ - graduations_major = 10 - def __init__(self, build_dimensions, light = False, circular = False): + def __init__(self, build_dimensions, light = False, circular = False, grid = (1, 10)): self.light = light self.circular = circular self.width = build_dimensions[0] @@ -104,6 +103,7 @@ def __init__(self, build_dimensions, light = False, circular = False): self.xoffset = build_dimensions[3] self.yoffset = build_dimensions[4] self.zoffset = build_dimensions[5] + self.grid = grid self.color_grads_minor = (0xaf / 255, 0xdf / 255, 0x5f / 255, 0.1) self.color_grads_interm = (0xaf / 255, 0xdf / 255, 0x5f / 255, 0.2) @@ -122,9 +122,9 @@ def draw(self): glTranslatef(self.xoffset, self.yoffset, self.zoffset) def color(i): - if i % self.graduations_major == 0: + if i % self.grid[1] == 0: glColor4f(*self.color_grads_major) - elif i % (self.graduations_major // 2) == 0: + elif i % (self.grid[1] // 2) == 0: glColor4f(*self.color_grads_interm) else: if self.light: return False @@ -134,26 +134,26 @@ def color(i): # draw the grid glBegin(GL_LINES) if self.circular: # Draw a circular grid - for i in range(0, int(math.ceil(self.width + 1))): + for i in numpy.arange(0, int(math.ceil(self.width + 1)), self.grid[0]): angle = math.asin(2 * float(i) / self.width - 1) x = (math.cos(angle) + 1) * self.depth / 2 if color(i): glVertex3f(float(i), self.depth - x, 0.0) glVertex3f(float(i), x, 0.0) - for i in range(0, int(math.ceil(self.depth + 1))): + for i in numpy.arange(0, int(math.ceil(self.depth + 1)), self.grid[0]): angle = math.acos(2 * float(i) / self.depth - 1) x = (math.sin(angle) + 1) * self.width / 2 if color(i): glVertex3f(self.width - x, float(i), 0.0) glVertex3f(x, float(i), 0.0) else: # Draw a rectangular grid - for i in range(0, int(math.ceil(self.width + 1))): + for i in numpy.arange(0, int(math.ceil(self.width + 1)), self.grid[0]): if color(i): glVertex3f(float(i), 0.0, 0.0) glVertex3f(float(i), self.depth, 0.0) - for i in range(0, int(math.ceil(self.depth + 1))): + for i in numpy.arange(0, int(math.ceil(self.depth + 1)), self.grid[0]): if color(i): glVertex3f(0, float(i), 0.0) glVertex3f(self.width, float(i), 0.0) diff --git a/printrun/gui/viz.py b/printrun/gui/viz.py index c69478980..1aa1a5898 100644 --- a/printrun/gui/viz.py +++ b/printrun/gui/viz.py @@ -67,7 +67,13 @@ def __init__(self, root, parentpanel = None): if root.settings.mainviz == "3D": try: import printrun.gcview - root.gviz = printrun.gcview.GcodeViewMainWrapper(parentpanel, root.build_dimensions_list, root = root, circular = root.settings.circular_bed, antialias_samples = int(root.settings.antialias3dsamples)) + root.gviz = printrun.gcview.GcodeViewMainWrapper( + parentpanel, + root.build_dimensions_list, + root = root, + circular = root.settings.circular_bed, + antialias_samples = int(root.settings.antialias3dsamples), + grid = (root.settings.preview_grid_step1, root.settings.preview_grid_step2)) root.gviz.clickcb = root.show_viz_window except: use2dview = True @@ -91,7 +97,14 @@ def __init__(self, root, parentpanel = None): objects = None if isinstance(root.gviz, printrun.gcview.GcodeViewMainWrapper): objects = root.gviz.objects - root.gwindow = printrun.gcview.GcodeViewFrame(None, wx.ID_ANY, 'Gcode view, shift to move view, mousewheel to set layer', size = (600, 600), build_dimensions = root.build_dimensions_list, objects = objects, root = root, circular = root.settings.circular_bed, antialias_samples = int(root.settings.antialias3dsamples)) + root.gwindow = printrun.gcview.GcodeViewFrame(None, wx.ID_ANY, 'Gcode view, shift to move view, mousewheel to set layer', + size = (600, 600), + build_dimensions = root.build_dimensions_list, + objects = objects, + root = root, + circular = root.settings.circular_bed, + antialias_samples = int(root.settings.antialias3dsamples), + grid = (root.settings.preview_grid_step1, root.settings.preview_grid_step2)) except: use3dview = False logging.error("3D view mode requested, but we failed to initialize it.\n" diff --git a/printrun/pronterface.py b/printrun/pronterface.py index 6732fc590..75464bfb1 100644 --- a/printrun/pronterface.py +++ b/printrun/pronterface.py @@ -1034,9 +1034,11 @@ def update_build_dimensions(self, param, value): def update_bed_viz(self, *args): """Update bed visualization when size/type changed""" if hasattr(self, "gviz") and hasattr(self.gviz, "recreate_platform"): - self.gviz.recreate_platform(self.build_dimensions_list, self.settings.circular_bed) + self.gviz.recreate_platform(self.build_dimensions_list, self.settings.circular_bed, + grid = (self.settings.preview_grid_step1, self.settings.preview_grid_step2)) if hasattr(self, "gwindow") and hasattr(self.gwindow, "recreate_platform"): - self.gwindow.recreate_platform(self.build_dimensions_list, self.settings.circular_bed) + self.gwindow.recreate_platform(self.build_dimensions_list, self.settings.circular_bed, + grid = (self.settings.preview_grid_step1, self.settings.preview_grid_step2)) def update_gcview_params(self, *args): need_reload = False diff --git a/printrun/stlview.py b/printrun/stlview.py index 5420ab1b0..524839aa6 100755 --- a/printrun/stlview.py +++ b/printrun/stlview.py @@ -71,7 +71,8 @@ class StlViewPanel(wxGLPanel): def __init__(self, parent, size, build_dimensions = None, circular = False, - antialias_samples = 0): + antialias_samples = 0, + grid = (1, 10)): super().__init__(parent, wx.DefaultPosition, size, 0, antialias_samples = antialias_samples) self.batches = [] @@ -87,7 +88,8 @@ def __init__(self, parent, size, else: self.build_dimensions = [200, 200, 100, 0, 0, 0] self.platform = actors.Platform(self.build_dimensions, - circular = circular) + circular = circular, + grid = grid) self.dist = max(self.build_dimensions[0], self.build_dimensions[1]) self.basequat = [0, 0, 0, 1] wx.CallAfter(self.forceresize) #why needed