svg2gcode/svg2gcode.py

Sat, 07 Nov 2015 20:31:30 +0100

author
mbayer
date
Sat, 07 Nov 2015 20:31:30 +0100
changeset 9
89d724cfd8c3
parent 8
86f90bddac0f
child 10
92835c3f171a
permissions
-rwxr-xr-x

code refactoring - more cleanup

4
234ad2069fdd initial untested svg to gcode script
mbayer
parents:
diff changeset
1 #!/usr/bin/env python
5
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
2 # -*- coding: utf-8 -*-
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
3
4
234ad2069fdd initial untested svg to gcode script
mbayer
parents:
diff changeset
4 import svg, sys
234ad2069fdd initial untested svg to gcode script
mbayer
parents:
diff changeset
5 from gcode import Gcode
234ad2069fdd initial untested svg to gcode script
mbayer
parents:
diff changeset
6 from optparse import OptionParser
6
ff679c15cb0e infill only on Polygon or Path which have fill style attribute
mbayer
parents: 5
diff changeset
7 from tinycss import CSS21Parser
4
234ad2069fdd initial untested svg to gcode script
mbayer
parents:
diff changeset
8
8
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
9 from shapely.geometry import box, MultiLineString, Polygon
5
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
10 from shapely.affinity import rotate
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
11 from shapely import speedups
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
12 from math import sqrt
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
13
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
14 # enable Shapely speedups, if possible
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
15 if speedups.available:
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
16 speedups.enable()
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
17
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
18 def hatchbox(rect, angle, spacing):
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
19 """
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
20 returns a Shapely geometry (MULTILINESTRING, or more rarely,
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
21 GEOMETRYCOLLECTION) for a simple hatched rectangle.
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
22
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
23 args:
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
24 rect - a Shapely geometry for the outer boundary of the hatch
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
25 Likely most useful if it really is a rectangle
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
26
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
27 angle - angle of hatch lines, conventional anticlockwise -ve
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
28
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
29 spacing - spacing between hatch lines
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
30
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
31 GEOMETRYCOLLECTION case occurs when a hatch line intersects with
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
32 the corner of the clipping rectangle, which produces a point
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
33 along with the usual lines.
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
34 """
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
35
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
36 (llx, lly, urx, ury) = rect.bounds
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
37 centre_x = (urx + llx) / 2
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
38 centre_y = (ury + lly) / 2
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
39 diagonal_length = sqrt((urx - llx) ** 2 + (ury - lly) ** 2)
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
40 number_of_lines = 2 + int(diagonal_length / spacing)
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
41 hatch_length = spacing * (number_of_lines - 1)
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
42
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
43 # build a square (of side hatch_length) horizontal lines
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
44 # centred on centroid of the bounding box, 'spacing' units apart
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
45 coords = []
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
46 for i in range(number_of_lines):
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
47 # alternate lines l2r and r2l to keep HP-7470A plotter happy ☺
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
48 if i % 2:
8
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
49 coords.extend([((
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
50 centre_x - hatch_length / 2, \
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
51 centre_y - hatch_length / 2 + i * spacing), (
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
52 centre_x + hatch_length / 2, \
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
53 centre_y - hatch_length / 2 + i * spacing))])
5
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
54 else:
8
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
55 coords.extend([(( \
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
56 centre_x + hatch_length / 2, \
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
57 centre_y - hatch_length / 2 + i * spacing), (
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
58 centre_x - hatch_length / 2, \
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
59 centre_y - hatch_length / 2 + i * spacing))])
5
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
60 # turn array into Shapely object
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
61 lines = MultiLineString(coords)
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
62 # Rotate by angle around box centre
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
63 lines = rotate(lines, angle, origin='centroid', use_radians=False)
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
64 # return clipped array
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
65 return rect.intersection(lines)
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
66
6
ff679c15cb0e infill only on Polygon or Path which have fill style attribute
mbayer
parents: 5
diff changeset
67 def parse_style(stylestr):
ff679c15cb0e infill only on Polygon or Path which have fill style attribute
mbayer
parents: 5
diff changeset
68 if stylestr.strip() == '':
ff679c15cb0e infill only on Polygon or Path which have fill style attribute
mbayer
parents: 5
diff changeset
69 return None
ff679c15cb0e infill only on Polygon or Path which have fill style attribute
mbayer
parents: 5
diff changeset
70 parser = CSS21Parser()
ff679c15cb0e infill only on Polygon or Path which have fill style attribute
mbayer
parents: 5
diff changeset
71 style = parser.parse_style_attr(stylestr)
ff679c15cb0e infill only on Polygon or Path which have fill style attribute
mbayer
parents: 5
diff changeset
72 kv = {}
ff679c15cb0e infill only on Polygon or Path which have fill style attribute
mbayer
parents: 5
diff changeset
73 for obj in style[0]:
ff679c15cb0e infill only on Polygon or Path which have fill style attribute
mbayer
parents: 5
diff changeset
74 kv[obj.name] = obj.value[0].value
ff679c15cb0e infill only on Polygon or Path which have fill style attribute
mbayer
parents: 5
diff changeset
75 return kv
ff679c15cb0e infill only on Polygon or Path which have fill style attribute
mbayer
parents: 5
diff changeset
76
9
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
77 class Image(object):
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
78 def __init__(self, filename, options, gcoder):
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
79 self.gcoder = gcoder
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
80 self.options = options
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
81 self.svg = svg.parse(filename)
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
82 self.bb1, self.bb2 = self.svg.bbox()
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
83 self.width, self.height = self.bb2.coord()
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
84 self.infill = None
8
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
85
9
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
86 self._check_dimensions()
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
87 self._generate_infill()
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
88
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
89 def _check_dimensions(self):
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
90 msg = "Original dimension: %.2f x %.2f" % (self.width, self.height)
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
91 print msg
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
92 self.gcoder.comment(msg)
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
93 width = self.width * self.gcoder.mm_pixel * self.options.scale
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
94 height = self.height * self.gcoder.mm_pixel * self.options.scale
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
95 msg = "Print dimension: %.2fmm x %.2fmm" % (width, height)
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
96 print msg
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
97 self.gcoder.comment(msg)
8
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
98
9
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
99 def _generate_infill(self):
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
100 b1x, b1y = self.bb1.coord()
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
101 b2x, b2y = self.bb2.coord()
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
102 page = box(b1x, b1y, b2x, b2y)
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
103 # TODO: Infill spacing needs to be calculated with proper scaling and gcode MM dimensions
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
104 # TODO: Make infill angle 0, 45 or 90 degrees configurable to options parser (0° = X, 90° = Y, 45° = X and Y but half the speed/accel needed!)
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
105 self.infill = hatchbox(page, 0, 2)
4
234ad2069fdd initial untested svg to gcode script
mbayer
parents:
diff changeset
106
9
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
107 def normalize(self, coord):
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
108 c_x = coord[0]
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
109 c_y = coord[1]
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
110 # flip y
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
111 c_y = (self.height - c_y)
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
112 return (c_x, c_y)
4
234ad2069fdd initial untested svg to gcode script
mbayer
parents:
diff changeset
113
9
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
114 def get_drawings(self):
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
115 """
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
116 Returns a list of all svg drawings with segments attribute
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
117 """
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
118 data = []
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
119 for dwg in self.svg.flatten():
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
120 if hasattr(dwg, "segments"):
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
121 data.append(dwg)
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
122 return data
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
123
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
124 def svg2gcode(options, gcoder):
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
125 image = Image(options.filename, options, gcoder)
8
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
126
9
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
127 for dwg in image.get_drawings():
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
128 for l in dwg.segments(1):
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
129 # THE OUTLINE
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
130 coord = image.normalize(l[0].coord())
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
131 gcoder.move(coord[0], coord[1])
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
132 for pt in l[1:]:
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
133 coord = image.normalize(pt.coord())
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
134 gcoder.engrave(coord[0], coord[1])
8
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
135
9
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
136 if options.outline:
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
137 continue
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
138
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
139 if isinstance(dwg, svg.Polygon) or isinstance(dwg, svg.Path):
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
140 #check if we should infill?
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
141 style = parse_style(dwg.style)
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
142 if not style:
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
143 continue
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
144 if not 'fill' in style.keys():
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
145 continue
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
146 if style['fill'] == 'none':
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
147 continue
6
ff679c15cb0e infill only on Polygon or Path which have fill style attribute
mbayer
parents: 5
diff changeset
148
9
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
149 # try to generate the infill poly complex
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
150 poly = None
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
151 for l in dwg.segments(1):
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
152 segments = []
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
153 for pnt in l:
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
154 segments.append(pnt.coord())
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
155 shape = Polygon(segments)
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
156 if shape.is_valid:
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
157 if not poly:
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
158 poly = shape
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
159 else:
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
160 if shape.within(poly):
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
161 poly = poly.difference(shape)
8
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
162 else:
9
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
163 poly = poly.union(shape)
8
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
164
9
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
165 lines = poly.intersection(image.infill)
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
166 if lines:
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
167 # THE INFILL
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
168 for line in lines:
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
169 # TODO: swap start/end to nearest move!
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
170 start = image.normalize((line.coords[0][0], line.coords[0][1]))
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
171 end = image.normalize((line.coords[1][0], line.coords[1][1]))
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
172 gcoder.move(start[0], start[1])
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
173 gcoder.engrave(end[0], end[1])
6
ff679c15cb0e infill only on Polygon or Path which have fill style attribute
mbayer
parents: 5
diff changeset
174
9
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
175 def init_options():
8
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
176 parser = OptionParser()
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
177 parser.add_option("-f", "--file", dest="filename", default=None,
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
178 help="Load SVG file", metavar="FILE")
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
179 parser.add_option("-s", "--scale",
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
180 dest="scale", type="float", default=1.0,
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
181 help="set scale factor (default 1.0)")
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
182 parser.add_option("-e", "",
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
183 dest="engrave_speed", type="float", default=20,
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
184 help="engrave speed mm/sec (default 20)")
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
185 parser.add_option("-t", "",
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
186 dest="travel_speed", type="float", default=130,
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
187 help="travel speed mm/sec (default 130)")
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
188 parser.add_option("-o", "--outline", action="store_true",
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
189 dest="outline", default=False,
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
190 help="no infill, only outlines")
9
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
191 return parser.parse_args()
7
421aae29d9d9 finished poly infill
mbayer
parents: 6
diff changeset
192
9
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
193 if __name__ == "__main__":
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
194 (OPTIONS, ARGS) = init_options()
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
195 if not OPTIONS.filename:
8
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
196 print "no filename given!"
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
197 sys.exit(1)
5
b41cdab37aab added generic infill support, alpha stage
mbayer
parents: 4
diff changeset
198
8
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
199 # initialize gcode worker
9
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
200 GCODER = Gcode(scale=OPTIONS.scale, travel_speed=OPTIONS.travel_speed, engrave_speed=OPTIONS.engrave_speed)
8
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
201
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
202 # processing
9
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
203 svg2gcode(OPTIONS, GCODER)
8
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
204
86f90bddac0f code refactoring
mbayer
parents: 7
diff changeset
205 # write gcode file
9
89d724cfd8c3 code refactoring - more cleanup
mbayer
parents: 8
diff changeset
206 GCODER.write(OPTIONS.filename + ".g")

mercurial