Commit 61728a7a authored by Guillaume Seguin's avatar Guillaume Seguin

Merge branch '2dvizfixes'

parents f4365c46 a73bfc12
......@@ -96,7 +96,8 @@ class Layer(list):
self.z = z
def _preprocess(self, current_x, current_y, current_z,
offset_x, offset_y, offset_z, ignore_noe = False):
offset_x, offset_y, offset_z,
ignore_noe = False, host_mode = True):
xmin = float("inf")
ymin = float("inf")
zmin = 0
......@@ -117,22 +118,22 @@ class Layer(list):
y = current_y + (y or 0)
z = current_z + (z or 0)
else:
if line.x: x = line.x + offset_x
if line.y: y = line.y + offset_y
if line.z: z = line.z + offset_z
if x is not None: x = x + offset_x
if y is not None: y = y + offset_y
if z is not None: z = z + offset_z
current_x = x or current_x
current_y = y or current_y
current_z = z or current_z
if line.e or not ignore_noe:
if x:
if x is not None:
xmin = min(xmin, x)
xmax = max(xmax, x)
if y:
if y is not None:
ymin = min(ymin, y)
ymax = max(ymax, y)
if current_z:
if current_z is not None:
zmin = min(zmin, current_z)
zmax = max(zmax, current_z)
......@@ -140,14 +141,19 @@ class Layer(list):
if not any([line.x, line.y, line.z]):
current_x = current_y = current_z = 0
else:
if line.x: current_x = 0
if line.y: current_y = 0
if line.z: current_z = 0
if line.x is not None: current_x = 0
if line.y is not None: current_y = 0
if line.z is not None: current_z = 0
elif line.command == "G92":
if line.x: offset_x = current_x - line.x
if line.y: offset_y = current_y - line.y
if line.z: offset_z = current_z - line.z
if host_mode:
current_x = line.x or current_x
current_y = line.y or current_y
current_z = line.z or current_z
else:
if line.x is not None: offset_x = current_x - line.x
if line.y is not None: offset_y = current_y - line.y
if line.z is not None: offset_z = current_z - line.z
line.current_x = current_x
line.current_y = current_y
......@@ -184,14 +190,14 @@ class GCode(object):
est_layer_height = None
def __init__(self, data):
def __init__(self, data, host_mode = True):
self.lines = [Line(l2) for l2 in
(l.strip() for l in data)
if l2]
self._preprocess_lines()
self.filament_length = self._preprocess_extrusion()
self._create_layers()
self._preprocess_layers()
self._preprocess_layers(host_mode = host_mode)
def __len__(self):
return len(self.line_idxs)
......@@ -368,7 +374,7 @@ class GCode(object):
def num_layers(self):
return len(self.layers)
def _preprocess_layers(self):
def _preprocess_layers(self, host_mode = True):
xmin = float("inf")
ymin = float("inf")
zmin = 0
......@@ -388,7 +394,7 @@ class GCode(object):
for l in self.all_layers:
meta = l._preprocess(current_x, current_y, current_z,
offset_x, offset_y, offset_z,
ignore_noe)
ignore_noe, host_mode)
current_x, current_y, current_z = meta[0]
offset_x, offset_y, offset_z = meta[1]
(xm, xM), (ym, yM), (zm, zM) = meta[2:]
......
......@@ -290,7 +290,7 @@ class GcodeViewMainWrapper(object):
def setlayer(self, *a):
pass
def addfile(self, gcode = None):
def addfile(self, gcode = None, showall = False):
self.model = create_model(self.root.settings.light3d
if self.root else False)
if gcode:
......
......@@ -16,6 +16,7 @@
from Queue import Queue
from collections import deque
import wx
import time
from printrun import gcoder
from printrun_utils import imagefile, install_locale
......@@ -382,8 +383,9 @@ class Gviz(wx.Panel):
if self.paint_overlay:
self.paint_overlay(dc)
def addfile(self, gcode):
def addfile(self, gcode, showall = False):
self.clear()
self.showall = showall
self.add_parsed_gcodes(gcode)
max_layers = len(self.layers)
if hasattr(self.parent, "layerslider"):
......@@ -401,6 +403,8 @@ class Gviz(wx.Panel):
def _x(x):
return x - self.build_dimensions[3]
start_time = time.time()
for layer_idx, layer in enumerate(gcode.all_layers):
has_move = False
for gline in layer:
......@@ -413,7 +417,6 @@ class Gviz(wx.Panel):
self.pens[layer.z] = []
self.arcs[layer.z] = []
self.arcpens[layer.z] = []
self.layers.append(layer.z)
for gline in layer:
if not gline.is_move:
continue
......@@ -450,8 +453,16 @@ class Gviz(wx.Panel):
self.arcpens[layer.z].append(self.arcpen)
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.Refresh()
wx.CallAfter(self.Refresh)
self.dirty = 1
wx.CallAfter(self.Refresh)
def addgcode(self, gcode = "M105", hilight = 0):
gcode = gcode.split("*")[0]
......@@ -521,7 +532,7 @@ class Gviz(wx.Panel):
self.dirty = 1
else:
self.hilightpos = target
self.Refresh()
wx.CallAfter(self.Refresh)
if __name__ == '__main__':
import sys
......
......@@ -1704,9 +1704,8 @@ Printrun. If not, see <http://www.gnu.org/licenses/>."""
print _("Estimated duration: %s") % gcode.estimate_duration()
self.gviz.clear()
self.gwindow.p.clear()
self.gviz.addfile(gcode)
self.gviz.addfile(gcode, True)
self.gwindow.p.addfile(gcode)
self.gviz.showall = 1
wx.CallAfter(self.gviz.Refresh)
def printfile(self, event):
......
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