svg2gcode/svg2gcode.py

changeset 13
e2fd4d7b3cb6
parent 12
a90b8113be25
equal deleted inserted replaced
12:a90b8113be25 13:e2fd4d7b3cb6
77 return None 77 return None
78 parser = CSS21Parser() 78 parser = CSS21Parser()
79 style = parser.parse_style_attr(stylestr) 79 style = parser.parse_style_attr(stylestr)
80 data = {} 80 data = {}
81 for obj in style[0]: 81 for obj in style[0]:
82 data[obj.name] = obj.value[0].value 82 val = obj.value[0]
83 if hasattr(val, 'value'):
84 data[obj.name] = val.value
83 return data 85 return data
84 86
85 class Image(object): 87 class Image(object):
86 """ 88 """
87 SVG Image handler class 89 SVG Image handler class
116 Generates infill pattern image for later use 118 Generates infill pattern image for later use
117 """ 119 """
118 b1x, b1y = self.bb1.coord() 120 b1x, b1y = self.bb1.coord()
119 b2x, b2y = self.bb2.coord() 121 b2x, b2y = self.bb2.coord()
120 page = box(b1x, b1y, b2x, b2y) 122 page = box(b1x, b1y, b2x, b2y)
121 # TODO: Infill spacing needs to be calculated with proper scaling and gcode MM dimensions 123 # TODO: Infill spacing needs to be calculated with proper scaling and gcode MM dimensions, when set to 0 (auto)
122 # 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!) 124 # 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!)
123 self.infill = hatchbox(page, 0, 2) 125 self.infill = hatchbox(page, self.options.infill_angle, self.options.infill_spacing)
124 126
125 def normalize(self, coord): 127 def normalize(self, coord):
126 """ 128 """
127 Normalize X / Y Axis of coordinates 129 Normalize X / Y Axis of coordinates
128 At the moment only Y gets flipped to match Reprap coordinate system (0,0 is bottom left instead top left on SVG) 130 At the moment only Y gets flipped to match Reprap coordinate system (0,0 is bottom left instead top left on SVG)
297 dest="travel_speed", type="float", default=130, 299 dest="travel_speed", type="float", default=130,
298 help="travel speed mm/sec (default 130)") 300 help="travel speed mm/sec (default 130)")
299 parser.add_option("-o", "--outline", action="store_true", 301 parser.add_option("-o", "--outline", action="store_true",
300 dest="outline", default=False, 302 dest="outline", default=False,
301 help="no infill, only outlines") 303 help="no infill, only outlines")
304 parser.add_option("", "--infill-angle",
305 dest="infill_angle", type="int", default=45,
306 help="infill angle: 0 = X, 90 = Y (default 45)")
307 parser.add_option("", "--infill-spacing",
308 dest="infill_spacing", type="float", default=1.5,
309 help="infill spacing in SVG units (default 1.5)")
302 return parser.parse_args() 310 return parser.parse_args()
303 311
304 if __name__ == "__main__": 312 if __name__ == "__main__":
305 (OPTIONS, ARGS) = init_options() 313 (OPTIONS, ARGS) = init_options()
306 if not OPTIONS.filename: 314 if not OPTIONS.filename:

mercurial