Commit 06b0368d authored by Guillaume Seguin's avatar Guillaume Seguin

Don't process gcode twice when having two 3d viewers

parent d730755e
...@@ -17,10 +17,10 @@ ...@@ -17,10 +17,10 @@
import os import os
import math import math
import stltool import copy
import wx import wx
from wx import glcanvas from wx import glcanvas
import gcoder
import pyglet import pyglet
pyglet.options['debug_gl'] = True pyglet.options['debug_gl'] = True
...@@ -29,6 +29,8 @@ from pyglet.gl import * ...@@ -29,6 +29,8 @@ from pyglet.gl import *
from pyglet import gl from pyglet import gl
from pyglet.graphics.vertexbuffer import create_buffer from pyglet.graphics.vertexbuffer import create_buffer
from printrun import gcoder
from printrun import stltool
from printrun.libtatlin import actors from printrun.libtatlin import actors
class wxGLPanel(wx.Panel): class wxGLPanel(wx.Panel):
...@@ -464,7 +466,7 @@ class GCObject(object): ...@@ -464,7 +466,7 @@ class GCObject(object):
class GcodeViewMainWrapper(object): class GcodeViewMainWrapper(object):
def __init__(self, parent, build_dimensions, *args, **kwargs): def __init__(self, parent, build_dimensions):
self.glpanel = GcodeViewPanel(parent, realparent = self) self.glpanel = GcodeViewPanel(parent, realparent = self)
self.glpanel.SetMinSize((150, 150)) self.glpanel.SetMinSize((150, 150))
self.clickcb = None self.clickcb = None
...@@ -474,7 +476,6 @@ class GcodeViewMainWrapper(object): ...@@ -474,7 +476,6 @@ class GcodeViewMainWrapper(object):
self.platform = actors.Platform(build_dimensions) self.platform = actors.Platform(build_dimensions)
self.model = None self.model = None
self.objects = [GCObject(self.platform), GCObject(None)] self.objects = [GCObject(self.platform), GCObject(None)]
#super(GcodeViewMainPanel, self).__init__(parent, -1, size = (200, 200))
def __getattr__(self, name): def __getattr__(self, name):
return getattr(self.glpanel, name) return getattr(self.glpanel, name)
...@@ -500,13 +501,15 @@ class GcodeViewMainWrapper(object): ...@@ -500,13 +501,15 @@ class GcodeViewMainWrapper(object):
class GcodeViewFrame(wx.Frame): class GcodeViewFrame(wx.Frame):
'''A simple class for using OpenGL with wxPython.''' '''A simple class for using OpenGL with wxPython.'''
def __init__(self, parent, ID, title, build_dimensions, pos = wx.DefaultPosition, def __init__(self, parent, ID, title, build_dimensions, objects = None,
size = wx.DefaultSize, style = wx.DEFAULT_FRAME_STYLE): pos = wx.DefaultPosition, size = wx.DefaultSize,
style = wx.DEFAULT_FRAME_STYLE):
super(GcodeViewFrame, self).__init__(parent, ID, title, pos, size, style) super(GcodeViewFrame, self).__init__(parent, ID, title, pos, size, style)
self.refresh_timer = wx.CallLater(100, self.Refresh) self.refresh_timer = wx.CallLater(100, self.Refresh)
self.p = self # Hack for backwards compatibility with gviz API self.p = self # Hack for backwards compatibility with gviz API
self.clonefrom = objects
self.platform = actors.Platform(build_dimensions) self.platform = actors.Platform(build_dimensions)
self.model = None self.model = objects[1].model
self.objects = [GCObject(self.platform), GCObject(None)] self.objects = [GCObject(self.platform), GCObject(None)]
self.glpanel = GcodeViewPanel(self) self.glpanel = GcodeViewPanel(self)
...@@ -517,9 +520,12 @@ class GcodeViewFrame(wx.Frame): ...@@ -517,9 +520,12 @@ class GcodeViewFrame(wx.Frame):
self.refresh_timer.Start() self.refresh_timer.Start()
def addfile(self, gcode = None): def addfile(self, gcode = None):
self.model = actors.GcodeModel() if self.clonefrom:
if gcode: self.model = copy.deepcopy(self.clonefrom[-1].model)
self.model.load_data(gcode) else:
self.model = actors.GcodeModel()
if gcode:
self.model.load_data(gcode)
self.objects[-1].model = self.model self.objects[-1].model = self.model
wx.CallAfter(self.Refresh) wx.CallAfter(self.Refresh)
......
...@@ -241,7 +241,10 @@ class VizPane(wx.BoxSizer): ...@@ -241,7 +241,10 @@ class VizPane(wx.BoxSizer):
if use3dview: if use3dview:
try: try:
import printrun.gcview import printrun.gcview
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 = 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)
except: except:
use3dview = False use3dview = False
print "3D view mode requested, but we failed to initialize it." print "3D view mode requested, but we failed to initialize it."
......
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