Commit 7ee9d169 authored by Guillaume Seguin's avatar Guillaume Seguin

Continue work towards #423 by making gcview and gviz yieldy

parent edaa0e93
......@@ -258,7 +258,29 @@ class GCObject(object):
self.scale = [1.0, 1.0, 1.0]
self.model = model
class GcodeViewMainWrapper(object):
class GcodeViewLoader(object):
def addfile_perlayer(self, gcode = None, showall = False):
self.model = create_model(self.root.settings.light3d
if self.root else False)
if self.root:
set_model_colors(self.model, self.root)
if gcode:
generator = self.model.load_data(gcode)
generator_output = generator.next()
while generator_output is not None:
yield generator_output
generator_output = generator.next()
self.objects[-1].model = self.model
wx.CallAfter(self.Refresh)
yield None
def addfile(self, gcode = None, showall = False):
generator = self.addfile_perlayer(gcode, showall)
while generator.next() is not None:
continue
class GcodeViewMainWrapper(GcodeViewLoader):
def __init__(self, parent, build_dimensions, root, circular):
self.root = root
......@@ -299,28 +321,18 @@ class GcodeViewMainWrapper(object):
self.parent.model.num_layers_to_draw = viz_layer
wx.CallAfter(self.Refresh)
def addfile(self, gcode = None, showall = False):
self.model = create_model(self.root.settings.light3d
if self.root else False)
if self.root:
set_model_colors(self.model, self.root)
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(GvizBaseFrame):
class GcodeViewFrame(GvizBaseFrame, GcodeViewLoader):
'''A simple class for using OpenGL with wxPython.'''
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):
super(GcodeViewFrame, self).__init__(parent, ID, title,
GvizBaseFrame.__init__(self, parent, ID, title,
pos, size, style)
self.root = root
......@@ -375,14 +387,9 @@ class GcodeViewFrame(GvizBaseFrame):
def addfile(self, gcode = None):
if self.clonefrom:
self.model = self.clonefrom[-1].model.copy()
else:
self.model = create_model(self.root.settings.light3d
if self.root else False)
if self.root:
set_model_colors(self.model, self.root)
if gcode:
self.model.load_data(gcode)
self.objects[-1].model = self.model
else:
GcodeViewLoader.addfile(self, gcode)
self.layerslider.SetRange(1, self.model.max_layers + 1)
self.layerslider.SetValue(self.model.max_layers + 1)
wx.CallAfter(self.Refresh)
......
......@@ -448,6 +448,7 @@ class GcodeModel(Model):
if callback:
callback(layer_idx + 1, num_layers)
yield layer_idx
layer_idx += 1
self.count_travel_indices = count_travel_indices
......@@ -473,6 +474,7 @@ class GcodeModel(Model):
logging.debug(_('Initialized 3D visualization in %.2f seconds') % (t_end - t_start))
logging.debug(_('Vertex count: %d') % ((len(self.vertices) + len(self.travels)) / 3))
yield None
def copy(self):
copy = GcodeModel()
......@@ -713,6 +715,7 @@ class GcodeModelLight(Model):
if callback:
callback(layer_idx + 1, num_layers)
yield layer_idx
layer_idx += 1
self.vertices = numpy.fromiter(vertex_list, dtype = GLfloat,
......@@ -731,6 +734,7 @@ class GcodeModelLight(Model):
logging.debug(_('Initialized 3D visualization in %.2f seconds') % (t_end - t_start))
logging.debug(_('Vertex count: %d') % (len(self.vertices) / 3))
yield None
def copy(self):
copy = GcodeModelLight()
......
......@@ -384,14 +384,24 @@ class Gviz(wx.Panel):
if self.paint_overlay:
self.paint_overlay(dc)
def addfile(self, gcode, showall = False):
def addfile_perlayer(self, gcode, showall = False):
self.clear()
self.showall = showall
self.add_parsed_gcodes(gcode)
generator = self.add_parsed_gcodes(gcode)
generator_output = generator.next()
while generator_output is not None:
yield generator_output
generator_output = generator.next()
max_layers = len(self.layers)
if hasattr(self.parent, "layerslider"):
self.parent.layerslider.SetRange(0, max_layers - 1)
self.parent.layerslider.SetValue(0)
yield None
def addfile(self, gcode = None, showall = False):
generator = self.addfile_perlayer(gcode, showall)
while generator.next() is not None:
continue
def _get_movement(self, start_pos, gline):
"""Takes a start position and a gcode, and returns a 3-uple containing
......@@ -445,6 +455,8 @@ class Gviz(wx.Panel):
has_move = True
break
if not has_move:
yield layer_idx
layer_idx += 1
continue
viz_layer = len(self.layers)
self.lines[viz_layer] = []
......@@ -476,10 +488,12 @@ class Gviz(wx.Panel):
self.dirty = 1
wx.CallAfter(self.Refresh)
yield layer_idx
layer_idx += 1
self.dirty = 1
wx.CallAfter(self.Refresh)
yield None
def addgcodehighlight(self, gcode = "M105"):
gcode = gcode.split("*")[0]
......
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