Added more svg options to settings

Sat, 04 Jun 2016 14:27:06 +0200

author
mbayer
date
Sat, 04 Jun 2016 14:27:06 +0200
changeset 25
0e3e7fbf0bc6
parent 24
620f9cd7ee9d
child 26
5c98c7e24b02

Added more svg options to settings

printrun-src/printrun/laser.py file | annotate | diff | comparison | revisions
printrun-src/printrun/pronterface.py file | annotate | diff | comparison | revisions
--- a/printrun-src/printrun/laser.py	Sat Jun 04 13:07:59 2016 +0200
+++ b/printrun-src/printrun/laser.py	Sat Jun 04 14:27:06 2016 +0200
@@ -63,6 +63,11 @@
 
         # SVG:
         self.lc_svg_speed_factor = 1.0
+        self.lc_svg_smoothness = 0.2
+        self.lc_svg_width = 50
+        self.lc_svg_height = 50
+        self.lc_svg_scalemode = "scale"
+
 
 class Lasercutter:
     """
@@ -285,14 +290,13 @@
             self.log("")        
             self.pronterwindow.load_gcode_async(filename + '.g')
 
-    def svg2gcode(self, filename, bed_max_x = 50, bed_max_y = 50, smoothness = 0.2):
+    def svg2gcode(self, filename):
         # Imports for SVG
         import xml.etree.ElementTree as ET
         from svg2gcode import shapes as shapes_pkg
         from svg2gcode.shapes import point_generator
 
-        self.log("Generating paths from SVG, alternative lib (outlines only)...")        
-        if smoothness < 0.1: smoothness = 0.1
+        self.log("Generating paths from SVG (outlines only)...")        
         svg_shapes = set(['rect', 'circle', 'ellipse', 'line', 'polyline', 'polygon', 'path'])
         tree = ET.parse(filename)
         root = tree.getroot()
@@ -310,9 +314,17 @@
 
         width = float(width.replace("px", "").replace("pt", ""))
         height = float(height.replace("px", "").replace("pt", ""))
+        smoothness = self.settings.lc_svg_smoothness
+        if smoothness < 0.1: smoothness = 0.1
 
-        scale_x = bed_max_x / max(width, height)
-        scale_y = bed_max_y / max(width, height)
+        bed_max_x = self.settings.lc_svg_width
+        bed_max_y = self.settings.lc_svg_height
+
+        if self.settings.lc_svg_scalemode == "scale":
+            scale_x = scale_y = min(bed_max_x, bed_max_y) / max(width, height)
+        else:
+            scale_x = bed_max_x / max(width, height)
+            scale_y = bed_max_y / max(width, height)
         
         self.log("Scaling factor: %.2f, %.2f" % (scale_x,scale_y))
 
--- a/printrun-src/printrun/pronterface.py	Sat Jun 04 13:07:59 2016 +0200
+++ b/printrun-src/printrun/pronterface.py	Sat Jun 04 14:27:06 2016 +0200
@@ -868,6 +868,10 @@
 
         self.settings._add(StaticTextSetting("separator_lc_svg", "SVG processing", "", group = "Laser"))
         self.settings._add(FloatSpinSetting("lc_svg_speed_factor", 1.0, 0.1, 2.0, "Engrave speed factor", "", "Laser"), self.update_lc_settings)
+        self.settings._add(FloatSpinSetting("lc_svg_smoothness", 0.2, 0.1, 10.0, "Smoothness", "Smoothness of curves (smaller value = smoother curve)", "Laser"), self.update_lc_settings)
+        self.settings._add(SpinSetting("lc_svg_width", 50, 1, 200, "Width (mm)", "Image width", "Laser"), self.update_lc_settings)
+        self.settings._add(SpinSetting("lc_svg_height", 50, 1, 200, "Height (mm)", "Image height", "Laser"), self.update_lc_settings)
+        self.settings._add(ComboSetting("lc_svg_scalemode", "scale", ["scale", "stretch"], "Scaling mode", "scale to dimensions / stretch to dimensions", "Laser"), self.update_lc_settings)
 
 
         self.settings._add(BooleanSetting("monitor", True, _("Monitor printer status"), _("Regularly monitor printer temperatures (required to have functional temperature graph or gauges)"), "Printer"), self.update_monitor)

mercurial