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):
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)
self.batches = []
self.rot = 0
......@@ -257,7 +257,7 @@ class GcodeViewPanel(wxGLPanel):
self.canvas.Bind(wx.EVT_KEY_DOWN, self.keypress)
self.initialized = 0
self.canvas.Bind(wx.EVT_MOUSEWHEEL, self.wheel)
self.parent = parent
self.parent = realparent if realparent else parent
self.initpos = None
self.dist = 200
self.bedsize = [200, 200]
......@@ -467,6 +467,40 @@ class GCObject(object):
self.batch = pyglet.graphics.Batch()
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):
'''A simple class for using OpenGL with wxPython.'''
......@@ -498,12 +532,6 @@ class GcodeViewFrame(wx.Frame):
self.objects[-1].model = None
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__":
import sys
app = wx.App(redirect = False)
......
......@@ -197,10 +197,38 @@ class LeftPane(wx.GridBagSizer):
root.graph = Graph(root.panel, wx.ID_ANY, root)
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):
def __init__(self, root):
super(VizPane, self).__init__(wx.VERTICAL)
if root.settings.mainviz == "None":
root.gviz = NoViz()
use2dview = root.settings.mainviz == "2D"
if root.settings.mainviz == "3D":
try:
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),
......@@ -222,9 +250,10 @@ class VizPane(wx.BoxSizer):
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.Bind(wx.EVT_LEFT_DOWN, root.showwin)
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()
self.Add(root.centersizer, 0, flag = wx.EXPAND)
......
......@@ -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):
wx.Panel.__init__(self, parent, -1, size = size)
self.widget = self
self.SetMinSize((150, 150))
self.parent = realparent if realparent else parent
self.size = size
......@@ -166,6 +167,10 @@ class gviz(wx.Panel):
print"Inject code here..."
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):
self.lastpos = [0, 0, 0, 0, 0, 0, 0]
self.lines = {}
......
......@@ -179,6 +179,7 @@ class PronterWindow(MainWindow, pronsole.pronsole):
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(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_file_path", ""))
self.settings._add(HiddenSetting("last_temperature", 0.0))
......@@ -343,8 +344,7 @@ class PronterWindow(MainWindow, pronsole.pronsole):
layer = gline.z
if layer != self.curlayer:
self.curlayer = layer
self.gviz.hilight.clear()
self.gviz.hilightarcs.clear()
self.gviz.clearhilights()
wx.CallAfter(self.gviz.setlayer, layer)
elif gline.command in ["M104", "M109"]:
gline.parse_coordinates(imperial = False, force = True)
......@@ -363,8 +363,10 @@ class PronterWindow(MainWindow, pronsole.pronsole):
self.sentlines.put_nowait(line)
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)
if gline.is_move and hasattr(self.gviz, "set_current_gline"):
wx.CallAfter(self.gviz.set_current_gline, gline)
def do_extrude(self, l = ""):
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