printrun-src/printrun/laser.py

changeset 36
f4730ef55ca8
parent 35
72c4cbf64211
child 37
926424f97c8e
--- a/printrun-src/printrun/laser.py	Sat Sep 23 13:07:51 2017 +0200
+++ b/printrun-src/printrun/laser.py	Tue Sep 26 19:08:02 2017 +0200
@@ -302,8 +302,8 @@
         from svg2gcode.shapes import point_generator
         from svg2gcode import simplepath, cspsubdiv, cubicsuperpath, simpletransform
 
-        bed_max_x = self.settings.lc_svg_width
-        bed_max_y = self.settings.lc_svg_height
+        bed_max_x = float(self.settings.lc_svg_width)
+        bed_max_y = float(self.settings.lc_svg_height)
 
         self.log("Generating paths from SVG (outlines only)...")        
         svg_shapes = set(['rect', 'circle', 'ellipse', 'line', 'polyline', 'polygon', 'path'])
@@ -368,14 +368,16 @@
                             max_x = x
                         if y > max_y:
                             max_y = y
-        #ofs_x = 0
-        #ofs_y = 0
-
-        ofs_x *= -1
-        ofs_y *= -1
-        max_x += ofs_x
-        max_y += ofs_y
-        self.log("Calculated Offset to 0,0 is %f,%f" % (ofs_x, ofs_y))
+        
+        if self.settings.lc_svg_offset:
+            ofs_x *= -1
+            ofs_y *= -1
+            max_x += ofs_x
+            max_y += ofs_y
+            self.log("Calculated Offset to 0,0 is %f,%f" % (ofs_x, ofs_y))
+        else:
+            ofs_x = 0
+            ofs_y = 0
 
         """
         self.log("Calculated Dimension is %f,%f" % (max_x, max_y))
@@ -383,8 +385,21 @@
         height = max_y
         """
 
-        if self.settings.lc_svg_scalemode == "scale":
-            scale_x = scale_y = min(bed_max_x, bed_max_y) / max(width, height)
+        if self.settings.lc_svg_scalemode == "original":
+            scale_x = 1.0
+            scale_y = 1.0
+        elif self.settings.lc_svg_scalemode == "scale":
+            scale_x = bed_max_x / width
+            scale_y = bed_max_y / height
+            if (scale_x * height) > bed_max_y:
+                # use y scale
+                scale_x = scale_y
+            elif (scale_y * width) > bed_max_x:
+                # use x scale
+                scale_y = scale_x
+            # double-check
+            if (scale_x * width > bed_max_x) or (scale_y * height > bed_max_y):
+                scale_x = scale_y = min(bed_max_x, bed_max_y) / max(width, height)
         else:
             scale_x = bed_max_x / width
             scale_y = bed_max_y / height

mercurial