Commit 3826dd17 authored by Ken Aaker's avatar Ken Aaker

Merge branch 'experimental' of git://github.com/kenaaker/Printrun into experimental

parents 2aac06f9 7363497c
P-face.png

8.85 KB

...@@ -16,6 +16,17 @@ ...@@ -16,6 +16,17 @@
import sys import sys
import re import re
import math
def deltalen(a,b):
d = object()
d.x = b.x - a.x
d.y = b.y - a.y
d.z = b.z - a.z
return math.sqrt((d.x*d.x)+(d.y*d.y)+(d.z*d.z))
class Line(object): class Line(object):
def __init__(self,l): def __init__(self,l):
...@@ -29,6 +40,7 @@ class Line(object): ...@@ -29,6 +40,7 @@ class Line(object):
self.raw = l.upper().lstrip() self.raw = l.upper().lstrip()
self.imperial = False self.imperial = False
self.relative = False self.relative = False
self.relative_e = False
if ";" in self.raw: if ";" in self.raw:
self.raw = self.raw.split(";")[0] self.raw = self.raw.split(";")[0]
...@@ -77,51 +89,53 @@ class Line(object): ...@@ -77,51 +89,53 @@ class Line(object):
return "" return ""
def _get_float(self,which): def _get_float(self,which):
try:
return float(self.regex.findall(self.raw.split(which)[1])[0]) return float(self.regex.findall(self.raw.split(which)[1])[0])
except:
return None
def _parse_coordinates(self): def _parse_coordinates(self):
try:
if "X" in self.raw: if "X" in self.raw:
self._x = self._get_float("X") self._x = self._get_float("X")
except:
pass
try:
if "Y" in self.raw: if "Y" in self.raw:
self._y = self._get_float("Y") self._y = self._get_float("Y")
except:
pass
try:
if "Z" in self.raw: if "Z" in self.raw:
self._z = self._get_float("Z") self._z = self._get_float("Z")
except:
pass
try:
if "E" in self.raw: if "E" in self.raw:
self.e = self._get_float("E") self.e = self._get_float("E")
except:
pass
try:
if "F" in self.raw: if "F" in self.raw:
self.f = self._get_float("F") self.f = self._get_float("F")
except:
pass
def is_move(self): def is_move(self):
return "G1" in self.raw or "G0" in self.raw return self.command() and ("G1" in self.raw or "G0" in self.raw)
class GCode(object): def __str__(self):
def __init__(self,data): return self.raw
self.lines = [Line(i) for i in data]
self._preprocess()
def _preprocess(self): class Layer(object):
#checks for G20, G21, G90 and G91, sets imperial and relative flags def __init__(self,lines):
imperial = False self.lines = lines
relative = False
for line in self.lines:
if line.command() == "G20":
imperial = True
elif line.command() == "G21":
imperial = False
elif line.command() == "G90":
relative = False
elif line.command() == "G91":
relative = True
elif line.is_move():
line.imperial = imperial
line.relative = relative
def measure(self): def measure(self):
...@@ -132,6 +146,7 @@ class GCode(object): ...@@ -132,6 +146,7 @@ class GCode(object):
ymax = -999999999 ymax = -999999999
zmax = -999999999 zmax = -999999999
relative = False relative = False
relative_e = False
current_x = 0 current_x = 0
current_y = 0 current_y = 0
...@@ -174,17 +189,132 @@ class GCode(object): ...@@ -174,17 +189,132 @@ class GCode(object):
current_y = y or current_y current_y = y or current_y
current_z = z or current_z current_z = z or current_z
return ( (xmin,xmax),(ymin,ymax),(zmin,zmax) )
class GCode(object):
def __init__(self,data):
self.lines = [Line(i) for i in data]
self._preprocess()
self._create_layers()
def _preprocess(self):
#checks for G20, G21, G90 and G91, sets imperial and relative flags
imperial = False
relative = False
relative_e = False
for line in self.lines:
if line.command() == "G20":
imperial = True
elif line.command() == "G21":
imperial = False
elif line.command() == "G90":
relative = False
relative_e = False
elif line.command() == "G91":
relative = True
relative_e = True
elif line.command() == "M82":
relative_e = False
elif line.command() == "M83":
relative_e = True
elif line.is_move():
line.imperial = imperial
line.relative = relative
line.relative_e = relative_e
def _create_layers(self):
self.layers = []
prev_z = None
cur_z = 0
cur_lines = []
layer_index = []
temp_layers = {}
for line in self.lines:
if line.command() == "G92" and line.z != None:
cur_z = line.z
elif line.is_move():
if line.z != None:
if line.relative:
cur_z += line.z
else:
cur_z = line.z
if cur_z != prev_z:
old_lines = temp_layers.pop(prev_z,[])
old_lines += cur_lines
temp_layers[prev_z] = old_lines
if not prev_z in layer_index:
layer_index.append(prev_z)
cur_lines = []
cur_lines.append(line)
prev_z = cur_z
old_lines = temp_layers.pop(prev_z,[])
old_lines += cur_lines
temp_layers[prev_z] = old_lines
if not prev_z in layer_index:
layer_index.append(prev_z)
layer_index.sort()
for idx in layer_index:
cur_lines = temp_layers[idx]
has_movement = False
for l in cur_lines:
if l.is_move() and l.e != None:
has_movement = True
break
if has_movement:
self.layers.append(Layer(cur_lines))
def num_layers(self):
return len(self.layers)
def measure(self):
xmin = 999999999
ymin = 999999999
zmin = 0
xmax = -999999999
ymax = -999999999
zmax = -999999999
for l in self.layers:
xd,yd,zd = l.measure()
if xd[0] < xmin:
xmin = xd[0]
if xd[1] > xmax:
xmax = xd[1]
if yd[0] < ymin:
ymin = yd[0]
if yd[1] > ymax:
ymax = yd[1]
if zd[0] < zmin:
zmin = zd[0]
if zd[1] > zmax:
zmax = zd[1]
self.xmin = xmin self.xmin = xmin
self.ymin = ymin
self.zmin = zmin
self.xmax = xmax self.xmax = xmax
self.ymin = ymin
self.ymax = ymax self.ymax = ymax
self.zmin = zmin
self.zmax = zmax self.zmax = zmax
self.width = xmax - xmin
self.width = xmax-xmin self.depth = ymax - ymin
self.depth = ymax-ymin self.height = zmax - zmin
self.height = zmax-zmin
def filament_length(self): def filament_length(self):
total_e = 0 total_e = 0
...@@ -196,7 +326,7 @@ class GCode(object): ...@@ -196,7 +326,7 @@ class GCode(object):
total_e += cur_e total_e += cur_e
cur_e = line.e cur_e = line.e
elif line.is_move() and line.e: elif line.is_move() and line.e:
if line.relative: if line.relative_e:
cur_e += line.e cur_e += line.e
else: else:
cur_e = line.e cur_e = line.e
...@@ -210,6 +340,8 @@ def main(): ...@@ -210,6 +340,8 @@ def main():
print "usage: %s filename.gcode" % sys.argv[0] print "usage: %s filename.gcode" % sys.argv[0]
return return
# d = [i.replace("\n","") for i in open(sys.argv[1])]
# gcode = GCode(d)
gcode = GCode(list(open(sys.argv[1]))) gcode = GCode(list(open(sys.argv[1])))
gcode.measure() gcode.measure()
...@@ -219,6 +351,8 @@ def main(): ...@@ -219,6 +351,8 @@ def main():
print "\tY: %0.02f - %0.02f (%0.02f)" % (gcode.ymin,gcode.ymax,gcode.depth) print "\tY: %0.02f - %0.02f (%0.02f)" % (gcode.ymin,gcode.ymax,gcode.depth)
print "\tZ: %0.02f - %0.02f (%0.02f)" % (gcode.zmin,gcode.zmax,gcode.height) print "\tZ: %0.02f - %0.02f (%0.02f)" % (gcode.zmin,gcode.zmax,gcode.height)
print "Filament used: %0.02fmm" % gcode.filament_length() print "Filament used: %0.02fmm" % gcode.filament_length()
print "Number of layers: %d" % gcode.num_layers()
if __name__ == '__main__': if __name__ == '__main__':
main() main()
plater.png

2.04 KB

...@@ -222,6 +222,7 @@ class printcore(): ...@@ -222,6 +222,7 @@ class printcore():
def pause(self): def pause(self):
"""Pauses the print, saving the current position. """Pauses the print, saving the current position.
""" """
if not self.printing: return False
self.paused = True self.paused = True
self.printing = False self.printing = False
self.print_thread.join() self.print_thread.join()
...@@ -230,6 +231,7 @@ class printcore(): ...@@ -230,6 +231,7 @@ class printcore():
def resume(self): def resume(self):
"""Resumes a paused print. """Resumes a paused print.
""" """
if not self.paused: return False
self.paused = False self.paused = False
self.printing = True self.printing = True
self.print_thread = Thread(target = self._print) self.print_thread = Thread(target = self._print)
...@@ -287,6 +289,8 @@ class printcore(): ...@@ -287,6 +289,8 @@ class printcore():
self.sentlines = {} self.sentlines = {}
self.log = [] self.log = []
self.sent = [] self.sent = []
self.print_thread.join()
self.print_thread = None
if self.endcb: if self.endcb:
#callback for printing done #callback for printing done
try: self.endcb() try: self.endcb()
......
...@@ -223,7 +223,7 @@ class MainToolbar(wx.BoxSizer): ...@@ -223,7 +223,7 @@ class MainToolbar(wx.BoxSizer):
root.serialport = wx.ComboBox(root.panel, -1, root.serialport = wx.ComboBox(root.panel, -1,
choices = root.scanserial(), choices = root.scanserial(),
style = wx.CB_DROPDOWN, size = (100, 25)) style = wx.CB_DROPDOWN, size = (150, 25))
root.serialport.SetToolTip(wx.ToolTip("Select Port Printer is connected to")) root.serialport.SetToolTip(wx.ToolTip("Select Port Printer is connected to"))
root.rescanports() root.rescanports()
self.Add(root.serialport) self.Add(root.serialport)
......
This diff is collapsed.
This diff is collapsed.
function pronterfaceWebInterface_setup(){
pronterfaceWebInterface_attachAsync();
}
function pronterfaceWebInterface_attachAsync(){
var list = [];
if(document.getElementsByClassName){
list = document.getElementsByClassName('command');
}else if(document.getElementsByTagName){
list = document.getElementsByTagName('a');
list.concat( document.getElementsByTagName('area') );
//TODO filter list via checking the className attributes
}else{
console && console.error && console.error('unable to gather list of elements');
return false;
}
for(var i=0; i < list.length; i++){
list[i].addEventListener && list[i].addEventListener( 'click', function(e){return pronterfaceWebInterface_asyncCommand(null, e);}, true );
list[i].attachEvent && list[i].attachEvent( 'onclick', function(e){return pronterfaceWebInterface_asyncCommand(null, e);} );
}
return true;
}
function pronterfaceWebInterface_asyncCommand( urlOrElement, event ){
if( ! urlOrElement && event.target)
urlOrElement = event.target;
var url = null;
if( typeof urlOrElement == 'string' ){
url = urlOrElement;
}else{
url = urlOrElement&&urlOrElement.href;
}
if( typeof url != 'string' ){
console && console.error && console.error('url not a string', urlOrElement, url);
return true;
}
var httpRequest;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
httpRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE 8 and older
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
if( ! httpRequest ){
alert('no AJAX available?');
// follow link
return true;
}
//onreadystatechange
//onerror
httpRequest.open( 'GET', url, true);
httpRequest.send(null);
// don't follow link
if( event ){
event.stopImmediatePropagation && event.stopImmediatePropagation();
event.defaultPrevented = true;
event.preventDefault && event.preventDefault();
}
return false;
}
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", pronterfaceWebInterface_setup, false);
} else if (document.attachEvent) {
document.attachEvent("onreadystatechange", pronterfaceWebInterface_setup);
} else {
document.onload = pronterfaceWebInterface_setup;
}
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