Commit 62e31e73 authored by Guillaume Seguin's avatar Guillaume Seguin

Refresh 2D view every 0.2s during viz loading

parent e2b25795
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
from Queue import Queue from Queue import Queue
from collections import deque from collections import deque
import wx import wx
import time
from printrun import gcoder from printrun import gcoder
from printrun_utils import imagefile, install_locale from printrun_utils import imagefile, install_locale
...@@ -380,8 +381,9 @@ class Gviz(wx.Panel): ...@@ -380,8 +381,9 @@ class Gviz(wx.Panel):
if self.paint_overlay: if self.paint_overlay:
self.paint_overlay(dc) self.paint_overlay(dc)
def addfile(self, gcode): def addfile(self, gcode, showall = False):
self.clear() self.clear()
self.showall = showall
self.add_parsed_gcodes(gcode) self.add_parsed_gcodes(gcode)
max_layers = len(self.layers) max_layers = len(self.layers)
if hasattr(self.parent, "layerslider"): if hasattr(self.parent, "layerslider"):
...@@ -399,6 +401,8 @@ class Gviz(wx.Panel): ...@@ -399,6 +401,8 @@ class Gviz(wx.Panel):
def _x(x): def _x(x):
return x - self.build_dimensions[3] return x - self.build_dimensions[3]
start_time = time.time()
for layer_idx, layer in enumerate(gcode.all_layers): for layer_idx, layer in enumerate(gcode.all_layers):
has_move = False has_move = False
for gline in layer: for gline in layer:
...@@ -411,7 +415,6 @@ class Gviz(wx.Panel): ...@@ -411,7 +415,6 @@ class Gviz(wx.Panel):
self.pens[layer.z] = [] self.pens[layer.z] = []
self.arcs[layer.z] = [] self.arcs[layer.z] = []
self.arcpens[layer.z] = [] self.arcpens[layer.z] = []
self.layers.append(layer.z)
for gline in layer: for gline in layer:
if not gline.is_move: if not gline.is_move:
continue continue
...@@ -448,8 +451,16 @@ class Gviz(wx.Panel): ...@@ -448,8 +451,16 @@ class Gviz(wx.Panel):
self.arcpens[layer.z].append(self.arcpen) self.arcpens[layer.z].append(self.arcpen)
self.lastpos = target self.lastpos = target
# Only add layer.z to self.layers now to prevent the display of an
# unfinished layer
self.layers.append(layer.z)
# Refresh display if more than 0.2s have passed
if time.time() - start_time > 0.2:
start_time = time.time()
self.dirty = 1 self.dirty = 1
self.Refresh() wx.CallAfter(self.Refresh)
self.dirty = 1
wx.CallAfter(self.Refresh)
def addgcode(self, gcode = "M105", hilight = 0): def addgcode(self, gcode = "M105", hilight = 0):
gcode = gcode.split("*")[0] gcode = gcode.split("*")[0]
...@@ -519,7 +530,7 @@ class Gviz(wx.Panel): ...@@ -519,7 +530,7 @@ class Gviz(wx.Panel):
self.dirty = 1 self.dirty = 1
else: else:
self.hilightpos = target self.hilightpos = target
self.Refresh() wx.CallAfter(self.Refresh)
if __name__ == '__main__': if __name__ == '__main__':
import sys import sys
......
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