300 import xml.etree.ElementTree as ET |
300 import xml.etree.ElementTree as ET |
301 from svg2gcode import shapes as shapes_pkg |
301 from svg2gcode import shapes as shapes_pkg |
302 from svg2gcode.shapes import point_generator |
302 from svg2gcode.shapes import point_generator |
303 from svg2gcode import simplepath, cspsubdiv, cubicsuperpath, simpletransform |
303 from svg2gcode import simplepath, cspsubdiv, cubicsuperpath, simpletransform |
304 |
304 |
305 bed_max_x = self.settings.lc_svg_width |
305 bed_max_x = float(self.settings.lc_svg_width) |
306 bed_max_y = self.settings.lc_svg_height |
306 bed_max_y = float(self.settings.lc_svg_height) |
307 |
307 |
308 self.log("Generating paths from SVG (outlines only)...") |
308 self.log("Generating paths from SVG (outlines only)...") |
309 svg_shapes = set(['rect', 'circle', 'ellipse', 'line', 'polyline', 'polygon', 'path']) |
309 svg_shapes = set(['rect', 'circle', 'ellipse', 'line', 'polyline', 'polygon', 'path']) |
310 tree = ET.parse(filename) |
310 tree = ET.parse(filename) |
311 root = tree.getroot() |
311 root = tree.getroot() |
366 ofs_y = y |
366 ofs_y = y |
367 if x > max_x: |
367 if x > max_x: |
368 max_x = x |
368 max_x = x |
369 if y > max_y: |
369 if y > max_y: |
370 max_y = y |
370 max_y = y |
371 #ofs_x = 0 |
371 |
372 #ofs_y = 0 |
372 if self.settings.lc_svg_offset: |
373 |
373 ofs_x *= -1 |
374 ofs_x *= -1 |
374 ofs_y *= -1 |
375 ofs_y *= -1 |
375 max_x += ofs_x |
376 max_x += ofs_x |
376 max_y += ofs_y |
377 max_y += ofs_y |
377 self.log("Calculated Offset to 0,0 is %f,%f" % (ofs_x, ofs_y)) |
378 self.log("Calculated Offset to 0,0 is %f,%f" % (ofs_x, ofs_y)) |
378 else: |
|
379 ofs_x = 0 |
|
380 ofs_y = 0 |
379 |
381 |
380 """ |
382 """ |
381 self.log("Calculated Dimension is %f,%f" % (max_x, max_y)) |
383 self.log("Calculated Dimension is %f,%f" % (max_x, max_y)) |
382 width = max_x |
384 width = max_x |
383 height = max_y |
385 height = max_y |
384 """ |
386 """ |
385 |
387 |
386 if self.settings.lc_svg_scalemode == "scale": |
388 if self.settings.lc_svg_scalemode == "original": |
387 scale_x = scale_y = min(bed_max_x, bed_max_y) / max(width, height) |
389 scale_x = 1.0 |
|
390 scale_y = 1.0 |
|
391 elif self.settings.lc_svg_scalemode == "scale": |
|
392 scale_x = bed_max_x / width |
|
393 scale_y = bed_max_y / height |
|
394 if (scale_x * height) > bed_max_y: |
|
395 # use y scale |
|
396 scale_x = scale_y |
|
397 elif (scale_y * width) > bed_max_x: |
|
398 # use x scale |
|
399 scale_y = scale_x |
|
400 # double-check |
|
401 if (scale_x * width > bed_max_x) or (scale_y * height > bed_max_y): |
|
402 scale_x = scale_y = min(bed_max_x, bed_max_y) / max(width, height) |
388 else: |
403 else: |
389 scale_x = bed_max_x / width |
404 scale_x = bed_max_x / width |
390 scale_y = bed_max_y / height |
405 scale_y = bed_max_y / height |
391 |
406 |
392 self.log("Scaling factor: %.2f, %.2f" % (scale_x,scale_y)) |
407 self.log("Scaling factor: %.2f, %.2f" % (scale_x,scale_y)) |