Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply grid size settings to 3d view #1093

Merged
merged 1 commit into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions printrun/gcodeplater.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
22 changes: 12 additions & 10 deletions printrun/gcview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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,
Expand All @@ -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)]

Expand All @@ -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:
Expand All @@ -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
Expand All @@ -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)]

Expand Down Expand Up @@ -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:
Expand Down
16 changes: 8 additions & 8 deletions printrun/gl/libtatlin/actors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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)
Expand All @@ -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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above line is never reached. It would make every other major tick more transparent.
@kliment Do we want it fixed or removed? It's not from this PR.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would instinctively say remove.

else:
if self.light: return False
Expand All @@ -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)
Expand Down
17 changes: 15 additions & 2 deletions printrun/gui/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
6 changes: 4 additions & 2 deletions printrun/pronterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions printrun/stlview.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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
Expand Down