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

Add center_origin flag for circular build plates #960

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions printrun/gui/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def __init__(self, root, parentpanel = None):
build_dimensions = root.build_dimensions_list,
grid = (root.settings.preview_grid_step1, root.settings.preview_grid_step2),
extrusion_width = root.settings.preview_extrusion_width,
center_origin = root.settings.circular_bed,
bgcolor = root.bgcolor)
root.gviz.SetToolTip(wx.ToolTip(_("Click to examine / edit\n layers of loaded file")))
root.gviz.showall = 1
Expand All @@ -103,6 +104,7 @@ def __init__(self, root, parentpanel = None):
root.gwindow = gviz.GvizWindow(build_dimensions = root.build_dimensions_list,
grid = (root.settings.preview_grid_step1, root.settings.preview_grid_step2),
extrusion_width = root.settings.preview_extrusion_width,
center_origin = root.settings.circular_bed,
bgcolor = root.bgcolor)
root.gwindow.Bind(wx.EVT_CLOSE, lambda x: root.gwindow.Hide())
if not isinstance(root.gviz, NoViz):
Expand Down
20 changes: 14 additions & 6 deletions printrun/gviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ def process_slider(self, event):
ID_ABOUT = 101
ID_EXIT = 110
class GvizWindow(GvizBaseFrame):
def __init__(self, f = None, size = (600, 600), build_dimensions = [200, 200, 100, 0, 0, 0], grid = (10, 50), extrusion_width = 0.5, bgcolor = "#000000"):
def __init__(self, f = None, size = (600, 600), build_dimensions = [200, 200, 100, 0, 0, 0], grid = (10, 50), extrusion_width = 0.5, center_origin=False, bgcolor = "#000000"):
super(GvizWindow, self).__init__(None, title = _("Gcode view, shift to move view, mousewheel to set layer"), size = size)

panel, vbox = self.create_base_ui()

self.p = Gviz(panel, size = size, build_dimensions = build_dimensions, grid = grid, extrusion_width = extrusion_width, bgcolor = bgcolor, realparent = self)
self.p = Gviz(panel, size = size, build_dimensions = build_dimensions, grid = grid, extrusion_width = extrusion_width, bgcolor = bgcolor, realparent = self, center_origin = center_origin)

self.toolbar.Realize()
vbox.Add(self.p, 1, wx.EXPAND)
Expand Down Expand Up @@ -171,7 +171,7 @@ def _set_showall(self, showall):
self._showall = showall
showall = property(_get_showall, _set_showall)

def __init__(self, parent, size = (200, 200), build_dimensions = [200, 200, 100, 0, 0, 0], grid = (10, 50), extrusion_width = 0.5, bgcolor = "#000000", realparent = None):
def __init__(self, parent, size = (200, 200), build_dimensions = [200, 200, 100, 0, 0, 0], grid = (10, 50), extrusion_width = 0.5, bgcolor = "#000000", realparent = None, center_origin=False):
wx.Panel.__init__(self, parent, -1)
self.widget = self
size = [max(1.0, x) for x in size]
Expand Down Expand Up @@ -203,6 +203,7 @@ def __init__(self, parent, size = (200, 200), build_dimensions = [200, 200, 100,
self.bgcolor.Set(bgcolor)
self.blitmap = wx.Bitmap(self.GetClientSize()[0], self.GetClientSize()[1], -1)
self.paint_overlay = None
self.center_origin = center_origin

def inject(self):
layer = self.layers[self.layerindex]
Expand Down Expand Up @@ -410,6 +411,7 @@ def paint(self, event):
dc.SetBackground(wx.Brush(self.bgcolor))
dc.Clear()
dc.DrawBitmap(self.blitmap, self.translate[0], self.translate[1])
#dc.DrawBitmap(self.blitmap, 100, -100)
if self.paint_overlay:
self.paint_overlay(dc)

Expand Down Expand Up @@ -468,10 +470,16 @@ def _get_movement(self, start_pos, gline):
return target, None, arc

def _y(self, y):
return self.build_dimensions[1] - (y - self.build_dimensions[4])
if self.center_origin:
return self.build_dimensions[1] - (y - self.build_dimensions[4]) - (self.build_dimensions[1]/2)
else:
return self.build_dimensions[1] - (y - self.build_dimensions[4])

def _x(self, x):
return x - self.build_dimensions[3]
if self.center_origin:
return x - self.build_dimensions[3] + (self.build_dimensions[0] / 2)
else:
return x - self.build_dimensions[3]

def add_parsed_gcodes(self, gcode):
start_time = time.time()
Expand Down Expand Up @@ -549,6 +557,6 @@ def addgcodehighlight(self, gline):
if __name__ == '__main__':
import sys
app = wx.App(False)
main = GvizWindow(open(sys.argv[1], "rU"))
main = GvizWindow(open(sys.argv[1], "rU"), build_dimensions = [200, 200, 100, 0, 0, 0], center_origin=True)
main.Show()
app.MainLoop()
3 changes: 2 additions & 1 deletion printrun/pronterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,9 +572,10 @@ def plate(self, e):
def plate_gcode(self, e):
from . import gcodeplater as plater
self.log(_("G-Code plate function activated"))
bd = self.build_dimensions_list
plater.GcodePlater(size = (800, 580), callback = self.platecb,
parent = self,
build_dimensions = self.build_dimensions_list,
build_dimensions = bd,
circular_platform = self.settings.circular_bed,
antialias_samples = int(self.settings.antialias3dsamples)).Show()

Expand Down