Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions gcodeParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import math
import re

class GcodeParser:
class GcodeParser(object):

def __init__(self):
self.model = GcodeModel(self)
Expand Down Expand Up @@ -100,10 +100,10 @@ def parse_G92(self, args):
self.model.do_G92(self.parseArgs(args))

def warn(self, msg):
print "[WARN] Line %d: %s (Text:'%s')" % (self.lineNb, msg, self.line)
print("[WARN] Line %d: %s (Text:'%s')" % (self.lineNb, msg, self.line))

def error(self, msg):
print "[ERROR] Line %d: %s (Text:'%s')" % (self.lineNb, msg, self.line)
print("[ERROR] Line %d: %s (Text:'%s')" % (self.lineNb, msg, self.line))
raise Exception("[ERROR] Line %d: %s (Text:'%s')" % (self.lineNb, msg, self.line))

class BBox(object):
Expand Down Expand Up @@ -139,7 +139,7 @@ def extend(self, coords):
self.zmin = min(self.zmin, coords["Z"])
self.zmax = max(self.zmax, coords["Z"])

class GcodeModel:
class GcodeModel(object):

def __init__(self, parser):
# save parser for messages
Expand Down Expand Up @@ -172,7 +172,7 @@ def do_G1(self, args, type):
coords = dict(self.relative)
# update changed coords
for axis in args.keys():
if coords.has_key(axis):
if axis in coords:
if self.isRelative:
coords[axis] += args[axis]
else:
Expand Down Expand Up @@ -205,11 +205,11 @@ def do_G92(self, args):
# this changes the current coords, without moving, so do not generate a segment

# no axes mentioned == all axes to 0
if not len(args.keys()):
if not args:
args = {"X":0.0, "Y":0.0, "Z":0.0, "E":0.0}
# update specified axes
for axis in args.keys():
if self.offset.has_key(axis):
if axis in self.offset:
# transfer value from relative to offset
self.offset[axis] += self.relative[axis] - args[axis]
self.relative[axis] = args[axis]
Expand Down Expand Up @@ -376,7 +376,7 @@ def postProcess(self):
def __str__(self):
return "<GcodeModel: len(segments)=%d, len(layers)=%d, distance=%f, extrudate=%f, bbox=%s>"%(len(self.segments), len(self.layers), self.distance, self.extrudate, self.bbox)

class Segment:
class Segment(object):
def __init__(self, type, coords, lineNb, line):
self.type = type
self.coords = coords
Expand All @@ -389,7 +389,7 @@ def __init__(self, type, coords, lineNb, line):
def __str__(self):
return "<Segment: type=%s, lineNb=%d, style=%s, layerIdx=%d, distance=%f, extrudate=%f>"%(self.type, self.lineNb, self.style, self.layerIdx, self.distance, self.extrudate)

class Layer:
class Layer(object):
def __init__(self, Z):
self.Z = Z
self.segments = []
Expand All @@ -406,4 +406,4 @@ def __str__(self):
parser = GcodeParser()
model = parser.parseFile(path)

print model
print(model)
52 changes: 26 additions & 26 deletions yagv
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ from gcodeParser import *
import os.path
import time

class App:
class App(object):
def __init__(self):
self.RX = 0.0
self.RZ = 0.0
Expand All @@ -26,7 +26,7 @@ class App:
def main(self):

#### MAIN CODE ####
print "Yet Another GCode Viewer v%s"%YAGV_VERSION
print("Yet Another GCode Viewer v%s"%YAGV_VERSION)

import sys
if len(sys.argv) > 1:
Expand All @@ -42,7 +42,7 @@ class App:
self.load(path)

# default to the middle layer
self.layerIdx = len(self.model.layers)/2
self.layerIdx = int(len(self.model.layers) / 2)

self.window = MyWindow(self, caption="Yet Another GCode Viewer v%s"%YAGV_VERSION, resizable=True)

Expand All @@ -57,35 +57,35 @@ class App:

def load(self, path):

print "loading file %s ..."%repr(path)
print("loading file %s ..."%repr(path))
t1 = time.time()

print
print "Parsing '%s'..."%path
print
print()
print("Parsing '%s'..."%path)
print()

self.path = path

parser = GcodeParser()
self.model = parser.parseFile(path)

print
print "Done! %s"%self.model
print
print()
print("Done! %s"%self.model)
print()

# render the model
print "rendering vertices..."
print("rendering vertices...")
self.renderVertices()
print "rendering indexed colors..."
print("rendering indexed colors...")
self.renderIndexedColors()
print "rendering true colors..."
print("rendering true colors...")
self.renderColors()
print "generating graphics..."
print("generating graphics...")
self.generateGraphics()
print "Done"
print("Done")

t2 = time.time()
print "loaded file in %0.3f ms" % ((t2-t1)*1000.0, )
print("loaded file in %0.3f ms" % ((t2-t1)*1000.0, ))

def renderVertices(self):
t1 = time.time()
Expand Down Expand Up @@ -113,7 +113,7 @@ class App:
self.vertices.append(layer_vertices)

t2 = time.time()
print "end renderColors in %0.3f ms" % ((t2-t1)*1000.0, )
print("end renderColors in %0.3f ms" % ((t2-t1)*1000.0, ))

def renderIndexedColors(self):
t1 = time.time()
Expand Down Expand Up @@ -142,7 +142,7 @@ class App:
# append layer to all layers
self.vertex_indexed_colors.append(layer_vertex_indexed_colors)
t2 = time.time()
print "end renderIndexedColors in %0.3f ms" % ((t2-t1)*1000.0, )
print("end renderIndexedColors in %0.3f ms" % ((t2-t1)*1000.0, ))

def renderColors(self):
t1 = time.time()
Expand All @@ -160,24 +160,24 @@ class App:
]

# for all 3 types
for display_type in xrange(3):
for display_type in range(3):

type_color_map = colorMap[display_type]

# for all preindexed layer colors
for indexes in self.vertex_indexed_colors:

# render color indexes to colors
colors = map(lambda e: type_color_map[e], indexes)
colors = [type_color_map[e] for e in indexes]
# flatten color values
fcolors = []
map(fcolors.extend, colors)
list(map(fcolors.extend, colors))

# push colors to vertex list
self.vertex_colors[display_type].append(fcolors)

t2 = time.time()
print "end renderColors in %0.3f ms" % ((t2-t1)*1000.0, )
print("end renderColors in %0.3f ms" % ((t2-t1)*1000.0, ))

def generateGraphics(self):
t1 = time.time()
Expand All @@ -186,8 +186,8 @@ class App:
self.graphics_current = []
self.graphics_limbo = []

for layer_idx in xrange(len(self.vertices)):
nb_layer_vertices = len(self.vertices[layer_idx])/3
for layer_idx in range(len(self.vertices)):
nb_layer_vertices = int(len(self.vertices[layer_idx])/3)
vertex_list = pyglet.graphics.vertex_list(nb_layer_vertices,
('v3f/static', self.vertices[layer_idx]),
('c4B/static', self.vertex_colors[0][layer_idx])
Expand All @@ -208,7 +208,7 @@ class App:
# print nb_layer_vertices, len(self.vertices[layer_idx]), len(self.colors[0][layer_idx])

t2 = time.time()
print "end generateGraphics in %0.3f ms" % ((t2-t1)*1000.0, )
print("end generateGraphics in %0.3f ms" % ((t2-t1)*1000.0, ))


def rotate_drag_start(self, x, y, button, modifiers):
Expand Down Expand Up @@ -358,7 +358,7 @@ class MyWindow(pyglet.window.Window):
self.app.layer_drag_end(x, y, button, modifiers)

def on_key_release(self, symbol, modifiers):
print "pressed key: %s, mod: %s"%(symbol, modifiers)
print("pressed key: %s, mod: %s"%(symbol, modifiers))
#print "pressed key: %s, mod: %s"%(pyglet.window.key.R, pyglet.window.key.MOD_CTRL)
if symbol==pyglet.window.key.R and modifiers & pyglet.window.key.MOD_CTRL:
self.app.reload()
Expand Down