Skip to content

Commit

Permalink
library examples converted to lsa format
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Hechenberger committed Jun 6, 2014
1 parent 613828f commit cdf99ef
Show file tree
Hide file tree
Showing 20 changed files with 70 additions and 1,617 deletions.
4 changes: 2 additions & 2 deletions backend/filereaders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def read_dxf(dxf_string, tolerance, optimize=True):
def read_ngc(ngc_string, tolerance, optimize=True):
ngcReader = NGCReader(tolerance)
parse_results = ngcReader.parse(ngc_string)
if optimize:
optimize_all(parse_results['boundarys'], tolerance)
# if optimize:
# optimize_all(parse_results['boundarys'], tolerance)
return parse_results

59 changes: 59 additions & 0 deletions backend/filereaders/ngc_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import math
import sys
import re
import os.path
import StringIO

Expand All @@ -29,6 +30,64 @@ def __init__(self, tolerance):


def parse(self, ngcstring):
"""This is a total super quick HACK!!!!
Pretty much only parses the old example files.
"""

paths = []
current_path = []
re_findall_attribs = re.compile('(S|F|X|Y|Z)(-?[0-9]+\.?[0-9]*(?:e-?[0-9]*)?)').findall

intensity = 0.0
feedrate = 1000.0
target = [0.0, 0.0, 0.0]
prev_motion_was_seek = True


lines = ngcstring.split('\n')
for line in lines:
line = line.replace(' ', '')
if line.startswith('G0'):
attribs = re_findall_attribs(line[2:])
for attr in attribs:
if attr[0] == 'X':
target[0] = float(attr[1])
prev_motion_was_seek = True
elif attr[0] == 'Y':
target[1] = float(attr[1])
prev_motion_was_seek = True
elif attr[0] == 'Z':
target[2] = float(attr[1])
prev_motion_was_seek = True
elif line.startswith('G1'):
if prev_motion_was_seek:
# new path
paths.append([[target[0], target[1], target[2]]])
current_path = paths[-1]
prev_motion_was_seek = False
# new target
attribs = re_findall_attribs(line[2:])
for attr in attribs:
if attr[0] == 'X':
target[0] = float(attr[1])
elif attr[0] == 'Y':
target[1] = float(attr[1])
elif attr[0] == 'Z':
target[2] = float(attr[1])
elif attr[0] == 'S':
intensity = float(attr[1])
elif attr[0] == 'F':
feedrate = float(attr[1])
current_path.append([target[0], target[1], target[2]])
elif line.startswith('S'):
attribs = re_findall_attribs(line)
for attr in attribs:
if attr[0] == 'S':
intensity = float(attr[1])
else:
print "Warning: Unsupported Gcode"

print "Done!"
self.boundarys = {'#000000':paths}
pass_ = ['1', feedrate, '', intensity, '', '#000000']
return {'boundarys':self.boundarys}
17 changes: 0 additions & 17 deletions library/Four Quadrant Test

This file was deleted.

1 change: 1 addition & 0 deletions library/Four Quadrant Test.lsa
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"passes":[{"colors":["#000000"],"feedrate":"1000","intensity":"20"}],"paths_by_color":{"#000000":[[[0,0],[0,0]],[[100,100],[105,100]],[[100,500],[105,500]],[[1100,500],[1105,500]],[[1100,100],[1105,100]]]}}
186 changes: 0 additions & 186 deletions library/Lasersaur

This file was deleted.

1 change: 1 addition & 0 deletions library/Lasersaur.lsa
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"passes":[{"colors":["#000000"],"feedrate":"2000","intensity":"50"}],"paths_by_color":{"#000000":[[[0,0],[0,0]],[[118.032,8.486],[116.43,8.641],[113.708,9.719],[111.841,11.177],[110.933,12.172],[110.096,13.547],[108.931,17.198],[108.037,21.231],[106.926,24.67],[106.135,25.86],[105.149,26.732],[102.655,27.988],[99.453,28.569],[95.53,28.449],[93.294,28.118],[90.879,27.483],[86.2225703314408,25.66155476564305],[85.467,25.366],[80.77220317668392,23.645859660440095],[79.135,23.046],[74.25217628108282,21.96988080122141],[73.681,21.844],[69.668,21.561],[67.541,21.627],[62.766,22.113],[57.85801938374431,23.06784358428932],[53.483,23.919],[48.688691357459064,25.338367690225937],[44.971,26.439],[40.29805070544943,28.21763568235861],[37.725,29.197],[34.733,30.517],[30.229012150953807,32.68819631900118],[28.852,33.352],[24.507745624582938,35.82736945155055],[20.163491249165872,38.302738903101115],[19.712,38.56],[15.715089470487142,41.56411488113709],[14.43,42.53],[12.296,44.628],[11.383,45.754],[9.943,48.18],[8.714,51.874],[8.486,54.082],[8.688,56.113],[9.945,59.827],[11.6,62.562],[12.719,63.96],[13.743,65.031],[16.357,67.172],[19.675,69.148],[23.638,70.76],[25.843,71.368],[27.959,71.799],[31.404,72.127],[35.447,71.541],[38.049,70.636],[39.97,69.735],[43.57,67.249],[44.875,65.953],[46.066,64.18],[46.77,61.805],[46.868,61.411],[47.322,62.24],[48.164,63.212],[49.834,63.566],[51.666,63.537],[53.466,63.521],[54.065,63.528],[53.944,62.647],[52.884,61.53],[52.089,60.573],[51.869,59.653],[51.851,55.721],[51.948,53.094],[52.243,51.178],[53.024,49.244],[53.183,49.037],[58.1825559483841,49.10363571847856],[58.51,49.108],[63.507602393433324,48.95317649677938],[66.483,48.861],[71.44610260574365,48.254689415513226],[74.636,47.865],[79.59825083902635,47.25175729879409],[80.276,47.168],[80.737,47.218],[81.638,47.936],[82.909,50.16],[84.5455623709014,54.88458078628671],[84.969,56.107],[85.815,58.88],[86.862,62.082],[87.455,63.431],[89.769,63.672],[93.012,63.581],[92.843,62.728],[91.712,61.589],[91.107,60.855],[90.985,59.882],[91.048,55.122],[91.318,52.318],[91.901,48.938],[92.448,46.235],[92.827,45.609],[93.082,45.545],[94.361,45.346],[98.39,44.352],[101.196,43.358],[103.8,42.129],[107.88471556717619,39.24540870869874],[108.374,38.9],[111.8477532566452,35.303746628510886],[111.947,35.201],[114.334,31.701],[115.025,30.234],[115.79,27.993],[116.497,24.354],[116.206,20.223],[115.66,17.746],[115.693,17.212],[116.604,16.748],[118.214,16.583],[120.007,16.106],[120.81,15.559],[121.058,15.262],[121.181,15.056],[120.805,14.598],[118.472,13.765],[117.918,13.618],[119.505,13.773],[121.833,13.689],[122.704,12.219],[123.139,10.69],[121.964,9.565],[119.745,8.637],[118.412,8.503],[118.225,8.492],[118.032,8.486]],[[118.976,9.632],[119.325,9.787],[119.47,10.161],[119.325,10.536],[118.976,10.691],[118.627,10.536],[118.482,10.161],[118.627,9.787],[118.976,9.632]],[[35.526,44.716],[36.571,44.748],[37.414,44.91],[38.807,45.408],[40.756,46.527],[42.465,49.085],[43.482,51.824],[45.087,56.339],[45.272,57.575],[44.3,56.875],[42.504,56.04],[40.915,55.868],[39.54,56.251],[37.896,57.634],[36.527,60.425],[36.214,61.984],[37.222,60.846],[38.97,59.222],[40.574,58.696],[42.29,59.546],[43.27,60.573],[43.685,61.341],[43.482,63.038],[42.2,64.836],[40.197,66.596],[39.037,67.417],[37.619,68.303],[34.944,69.605],[32.437,70.287],[30.046,70.359],[28.877,70.169],[26.95,69.528],[23.078,67.172],[19.726,63.835],[17.543,60.058],[17.094,58.174],[16.984,56.757],[17.139,54.364],[17.985,52.341],[19.749,50.426],[21.045,49.426],[22.389,48.595],[25.913,46.995],[29.97,45.671],[33.861,44.858],[35.526,44.716]]]}}
10 changes: 0 additions & 10 deletions library/Pulse Far X-Axis

This file was deleted.

1 change: 1 addition & 0 deletions library/Pulse Far X-Axis.lsa
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"passes":[{"colors":["#000000"],"feedrate":"400","intensity":"15"}],"paths_by_color":{"#000000":[[[0,0],[0,0]],[[100,520],[105,520]]]}}
10 changes: 0 additions & 10 deletions library/Pulse Far Y-Axis

This file was deleted.

1 change: 1 addition & 0 deletions library/Pulse Far Y-Axis.lsa
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"passes":[{"colors":["#000000"],"feedrate":"400","intensity":"20"}],"paths_by_color":{"#000000":[[[0,0],[0,0]],[[1100,300],[1105,300]]]}}
10 changes: 0 additions & 10 deletions library/Pulse Near X-Axis

This file was deleted.

1 change: 1 addition & 0 deletions library/Pulse Near X-Axis.lsa
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"passes":[{"colors":["#000000"],"feedrate":"400","intensity":"12"}],"paths_by_color":{"#000000":[[[0,0],[0,0]],[[100,100],[105,100]]]}}
10 changes: 0 additions & 10 deletions library/Pulse Near Y-Axis

This file was deleted.

1 change: 1 addition & 0 deletions library/Pulse Near Y-Axis.lsa
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"passes":[{"colors":["#000000"],"feedrate":"400","intensity":"15"}],"paths_by_color":{"#000000":[[[0,0],[0,0]],[[100,300],[105,300]]]}}
25 changes: 0 additions & 25 deletions library/Tangram

This file was deleted.

1 change: 1 addition & 0 deletions library/Tangram.lsa
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"passes":[],"paths_by_color":{"#000000":[[[0,0],[0,0]],[[60,120],[56.46446609406726,116.46446609406726],[52.928932188134524,112.92893218813452],[49.39339828220179,109.39339828220179],[45.85786437626905,105.85786437626905],[42.32233047033631,102.32233047033631],[40,100]],[[20,120],[23.535533905932738,116.46446609406726],[27.071067811865476,112.92893218813452],[30.606601717798213,109.39339828220179],[34.14213562373095,105.85786437626905],[37.67766952966369,102.32233047033631],[41.21320343559643,98.78679656440359],[44.74873734152916,95.25126265847085],[48.284271247461895,91.7157287525381],[51.81980515339464,88.18019484660536],[55.35533905932738,84.64466094067262],[58.890872965260115,81.10912703473988],[62.42640687119286,77.57359312880715],[65.96194077712559,74.03805922287441],[69.49747468305833,70.50252531694166],[73.03300858899107,66.96699141100892],[76.56854249492382,63.43145750507619],[80.10407640085656,59.895923599143444],[83.6396103067893,56.360389693210706],[87.17514421272203,52.82485578727797],[90.71067811865478,49.289321881345224],[94.2462120245875,45.753787975412486],[97.78174593052026,42.218254069479755],[100,40]],[[100,80],[96.46446609406726,83.53553390593274],[92.92893218813452,87.07106781186548],[89.3933982822018,90.60660171779821],[85.85786437626905,94.14213562373095],[82.32233047033631,97.67766952966369],[78.78679656440357,101.21320343559643],[75.25126265847084,104.74873734152916],[71.7157287525381,108.2842712474619],[68.18019484660536,111.81980515339464],[64.64466094067262,115.35533905932738],[61.10912703473988,118.89087296526012],[60,120]],[[60,80],[56.46446609406726,76.46446609406726],[52.928932188134524,72.92893218813452],[49.393398282201794,69.39339828220179],[45.85786437626905,65.85786437626905],[42.32233047033631,62.32233047033631],[38.78679656440357,58.78679656440357],[35.251262658470836,55.251262658470836],[31.715728752538105,51.7157287525381],[28.180194846605364,48.18019484660536],[24.644660940672622,44.64466094067262],[21.10912703473988,41.109127034739885],[20,40]],[[20,40],[25,40],[30,40],[35,40],[40,40],[45,40],[50,40],[55,40],[60,40],[65,40],[70,40],[75,40],[80,40],[85,40],[90,40],[95,40],[100,40],[100,45],[100,50],[100,55],[100,60],[100,65],[100,70],[100,75],[100,80],[100,85],[100,90],[100,95],[100,100],[100,105],[100,110],[100,115],[100,120],[95,120],[90,120],[85,120],[80,120],[75,120],[70,120],[65,120],[60,120],[55,120],[50,120],[45,120],[40,120],[35,120],[30,120],[25,120],[20,120],[20,115],[20,110],[20,105],[20,100],[20,95],[20,90],[20,85],[20,80],[20,75],[20,70],[20,65],[20,60],[20,55],[20,50],[20,45],[20,40]],[[60,80],[63.53553390593274,83.53553390593274],[67.07106781186548,87.07106781186548],[70.60660171779821,90.60660171779821],[74.14213562373095,94.14213562373095],[77.67766952966369,97.67766952966369],[80,100],[80,95],[80,90],[80,85],[80,80],[80,75],[80,70],[80,65],[80,60]]]}}
Loading

0 comments on commit cdf99ef

Please sign in to comment.