Commit 4f1a0175 authored by Guillaume Seguin's avatar Guillaume Seguin

Add option to switch between 2D/3D/No gcode viewer for main window

parent d1dfdc21
...@@ -248,7 +248,7 @@ def mulquat(q1, rq): ...@@ -248,7 +248,7 @@ def mulquat(q1, rq):
class GcodeViewPanel(wxGLPanel): class GcodeViewPanel(wxGLPanel):
def __init__(self, parent, id = wx.ID_ANY): def __init__(self, parent, id = wx.ID_ANY, realparent = None):
super(GcodeViewPanel, self).__init__(parent, id, wx.DefaultPosition, wx.DefaultSize, 0) super(GcodeViewPanel, self).__init__(parent, id, wx.DefaultPosition, wx.DefaultSize, 0)
self.batches = [] self.batches = []
self.rot = 0 self.rot = 0
...@@ -257,7 +257,7 @@ class GcodeViewPanel(wxGLPanel): ...@@ -257,7 +257,7 @@ class GcodeViewPanel(wxGLPanel):
self.canvas.Bind(wx.EVT_KEY_DOWN, self.keypress) self.canvas.Bind(wx.EVT_KEY_DOWN, self.keypress)
self.initialized = 0 self.initialized = 0
self.canvas.Bind(wx.EVT_MOUSEWHEEL, self.wheel) self.canvas.Bind(wx.EVT_MOUSEWHEEL, self.wheel)
self.parent = parent self.parent = realparent if realparent else parent
self.initpos = None self.initpos = None
self.dist = 200 self.dist = 200
self.bedsize = [200, 200] self.bedsize = [200, 200]
...@@ -467,6 +467,40 @@ class GCObject(object): ...@@ -467,6 +467,40 @@ class GCObject(object):
self.batch = pyglet.graphics.Batch() self.batch = pyglet.graphics.Batch()
self.model = model self.model = model
class GcodeViewMainWrapper(object):
def __init__(self, parent, build_dimensions, *args, **kwargs):
self.glpanel = GcodeViewPanel(parent, realparent = self)
self.glpanel.SetMinSize((150, 150))
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)
self.model = None
self.objects = [GCObject(self.platform), GCObject(None)]
#super(GcodeViewMainPanel, self).__init__(parent, -1, size = (200, 200))
def __getattr__(self, name):
return getattr(self.glpanel, name)
def set_current_gline(self, gline):
if gline.is_move and self.model and self.model.loaded:
self.model.printed_until = gline.gcview_end_vertex
if not self.refresh_timer.IsRunning():
self.refresh_timer.Start()
def addfile(self, gcode = None):
self.model = actors.GcodeModel()
if gcode:
self.model.load_data(gcode)
self.objects[-1].model = self.model
wx.CallAfter(self.Refresh)
def clear(self):
self.model = None
self.objects[-1].model = None
wx.CallAfter(self.Refresh)
class GcodeViewFrame(wx.Frame): class GcodeViewFrame(wx.Frame):
'''A simple class for using OpenGL with wxPython.''' '''A simple class for using OpenGL with wxPython.'''
...@@ -498,12 +532,6 @@ class GcodeViewFrame(wx.Frame): ...@@ -498,12 +532,6 @@ class GcodeViewFrame(wx.Frame):
self.objects[-1].model = None self.objects[-1].model = None
wx.CallAfter(self.Refresh) wx.CallAfter(self.Refresh)
def Show(self, arg = True):
wx.Frame.Show(self, arg)
self.SetClientSize((self.GetClientSize()[0], self.GetClientSize()[1] + 1))
self.SetClientSize((self.GetClientSize()[0], self.GetClientSize()[1] - 1))
self.Refresh()
if __name__ == "__main__": if __name__ == "__main__":
import sys import sys
app = wx.App(redirect = False) app = wx.App(redirect = False)
......
...@@ -197,16 +197,44 @@ class LeftPane(wx.GridBagSizer): ...@@ -197,16 +197,44 @@ class LeftPane(wx.GridBagSizer):
root.graph = Graph(root.panel, wx.ID_ANY, root) root.graph = Graph(root.panel, wx.ID_ANY, root)
self.Add(root.graph, pos = (4, 5), span = (3, 1)) self.Add(root.graph, pos = (4, 5), span = (3, 1))
class NoViz(object):
showall = False
def clear(self):
pass
def addfile(self, gcode):
pass
def addgcode(self, gcode):
pass
def Refresh(self):
pass
def setlayer(self, layer):
pass
class VizPane(wx.BoxSizer): class VizPane(wx.BoxSizer):
def __init__(self, root): def __init__(self, root):
super(VizPane, self).__init__(wx.VERTICAL) super(VizPane, self).__init__(wx.VERTICAL)
root.gviz = gviz.gviz(root.panel, (300, 300), if root.settings.mainviz == "None":
build_dimensions = root.build_dimensions_list, root.gviz = NoViz()
grid = (root.settings.preview_grid_step1, root.settings.preview_grid_step2), use2dview = root.settings.mainviz == "2D"
extrusion_width = root.settings.preview_extrusion_width) if root.settings.mainviz == "3D":
root.gviz.SetToolTip(wx.ToolTip("Click to examine / edit\n layers of loaded file")) try:
root.gviz.showall = 1 import printrun.gcview
root.gviz = printrun.gcview.GcodeViewMainWrapper(root.panel, root.build_dimensions_list)
except:
use2dview = True
print "3D view mode requested, but we failed to initialize it."
print "Falling back to 2D view, and here is the backtrace:"
traceback.print_exc()
if use2dview:
root.gviz = gviz.gviz(root.panel, (300, 300),
build_dimensions = root.build_dimensions_list,
grid = (root.settings.preview_grid_step1, root.settings.preview_grid_step2),
extrusion_width = root.settings.preview_extrusion_width)
root.gviz.SetToolTip(wx.ToolTip("Click to examine / edit\n layers of loaded file"))
root.gviz.showall = 1
use3dview = root.settings.viz3d use3dview = root.settings.viz3d
if use3dview: if use3dview:
try: try:
...@@ -222,9 +250,10 @@ class VizPane(wx.BoxSizer): ...@@ -222,9 +250,10 @@ class VizPane(wx.BoxSizer):
build_dimensions = root.build_dimensions_list, build_dimensions = root.build_dimensions_list,
grid = (root.settings.preview_grid_step1, root.settings.preview_grid_step2), grid = (root.settings.preview_grid_step1, root.settings.preview_grid_step2),
extrusion_width = root.settings.preview_extrusion_width) extrusion_width = root.settings.preview_extrusion_width)
root.gviz.Bind(wx.EVT_LEFT_DOWN, root.showwin)
root.gwindow.Bind(wx.EVT_CLOSE, lambda x:root.gwindow.Hide()) root.gwindow.Bind(wx.EVT_CLOSE, lambda x:root.gwindow.Hide())
self.Add(root.gviz, 1, flag = wx.SHAPED) if not isinstance(root.gviz, NoViz):
root.gviz.Bind(wx.EVT_LEFT_DOWN, root.showwin)
self.Add(root.gviz.widget, 1, flag = wx.SHAPED)
root.centersizer = wx.GridBagSizer() root.centersizer = wx.GridBagSizer()
self.Add(root.centersizer, 0, flag = wx.EXPAND) self.Add(root.centersizer, 0, flag = wx.EXPAND)
......
...@@ -129,6 +129,7 @@ class gviz(wx.Panel): ...@@ -129,6 +129,7 @@ class gviz(wx.Panel):
def __init__(self, parent, size = (200, 200), build_dimensions = [200, 200, 100, 0, 0, 0], grid = (10, 50), extrusion_width = 0.5, realparent = None): def __init__(self, parent, size = (200, 200), build_dimensions = [200, 200, 100, 0, 0, 0], grid = (10, 50), extrusion_width = 0.5, realparent = None):
wx.Panel.__init__(self, parent, -1, size = size) wx.Panel.__init__(self, parent, -1, size = size)
self.widget = self
self.SetMinSize((150, 150)) self.SetMinSize((150, 150))
self.parent = realparent if realparent else parent self.parent = realparent if realparent else parent
self.size = size self.size = size
...@@ -166,6 +167,10 @@ class gviz(wx.Panel): ...@@ -166,6 +167,10 @@ class gviz(wx.Panel):
print"Inject code here..." print"Inject code here..."
print "Layer "+str(self.layerindex +1)+" - Z = "+str(self.layers[self.layerindex])+" mm" print "Layer "+str(self.layerindex +1)+" - Z = "+str(self.layers[self.layerindex])+" mm"
def clearhilights(self):
self.hilight.clear()
self.hilightarcs.clear()
def clear(self): def clear(self):
self.lastpos = [0, 0, 0, 0, 0, 0, 0] self.lastpos = [0, 0, 0, 0, 0, 0, 0]
self.lines = {} self.lines = {}
......
...@@ -179,6 +179,7 @@ class PronterWindow(MainWindow, pronsole.pronsole): ...@@ -179,6 +179,7 @@ class PronterWindow(MainWindow, pronsole.pronsole):
self.settings._add(monitorsetting) self.settings._add(monitorsetting)
self.settings._add(BuildDimensionsSetting("build_dimensions", "200x200x100+0+0+0+0+0+0", _("Build dimensions"), _("Dimensions of Build Platform\n & optional offset of origin\n & optional switch position\n\nExamples:\n XXXxYYY\n XXX,YYY,ZZZ\n XXXxYYYxZZZ+OffX+OffY+OffZ\nXXXxYYYxZZZ+OffX+OffY+OffZ+HomeX+HomeY+HomeZ"))) self.settings._add(BuildDimensionsSetting("build_dimensions", "200x200x100+0+0+0+0+0+0", _("Build dimensions"), _("Dimensions of Build Platform\n & optional offset of origin\n & optional switch position\n\nExamples:\n XXXxYYY\n XXX,YYY,ZZZ\n XXXxYYYxZZZ+OffX+OffY+OffZ\nXXXxYYYxZZZ+OffX+OffY+OffZ+HomeX+HomeY+HomeZ")))
self.settings._add(BooleanSetting("viz3d", False, _("Enable 3D viewer (requires restarting)"), _("Use 3D visualization instead of 2D layered visualization"))) self.settings._add(BooleanSetting("viz3d", False, _("Enable 3D viewer (requires restarting)"), _("Use 3D visualization instead of 2D layered visualization")))
self.settings._add(ComboSetting("mainviz", "2D", ["2D", "3D", "None"], _("Main visualization"), _("Select visualization for main window.")))
self.settings._add(HiddenSetting("last_bed_temperature", 0.0)) self.settings._add(HiddenSetting("last_bed_temperature", 0.0))
self.settings._add(HiddenSetting("last_file_path", "")) self.settings._add(HiddenSetting("last_file_path", ""))
self.settings._add(HiddenSetting("last_temperature", 0.0)) self.settings._add(HiddenSetting("last_temperature", 0.0))
...@@ -343,8 +344,7 @@ class PronterWindow(MainWindow, pronsole.pronsole): ...@@ -343,8 +344,7 @@ class PronterWindow(MainWindow, pronsole.pronsole):
layer = gline.z layer = gline.z
if layer != self.curlayer: if layer != self.curlayer:
self.curlayer = layer self.curlayer = layer
self.gviz.hilight.clear() self.gviz.clearhilights()
self.gviz.hilightarcs.clear()
wx.CallAfter(self.gviz.setlayer, layer) wx.CallAfter(self.gviz.setlayer, layer)
elif gline.command in ["M104", "M109"]: elif gline.command in ["M104", "M109"]:
gline.parse_coordinates(imperial = False, force = True) gline.parse_coordinates(imperial = False, force = True)
...@@ -363,8 +363,10 @@ class PronterWindow(MainWindow, pronsole.pronsole): ...@@ -363,8 +363,10 @@ class PronterWindow(MainWindow, pronsole.pronsole):
self.sentlines.put_nowait(line) self.sentlines.put_nowait(line)
def printsentcb(self, gline): def printsentcb(self, gline):
if gline.is_move: if gline.is_move and hasattr(self.gwindow, "set_current_gline"):
wx.CallAfter(self.gwindow.set_current_gline, gline) wx.CallAfter(self.gwindow.set_current_gline, gline)
if gline.is_move and hasattr(self.gviz, "set_current_gline"):
wx.CallAfter(self.gviz.set_current_gline, gline)
def do_extrude(self, l = ""): def do_extrude(self, l = ""):
try: try:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment