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