Final bugfixes, SVG working like a charm now

Sat, 23 Sep 2017 13:07:51 +0200

author
mdd
date
Sat, 23 Sep 2017 13:07:51 +0200
changeset 35
72c4cbf64211
parent 34
654a41b13258
child 36
f4730ef55ca8

Final bugfixes, SVG working like a charm now

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 Sep 23 10:27:49 2017 +0200
+++ b/printrun-src/printrun/laser.py	Sat Sep 23 13:07:51 2017 +0200
@@ -30,7 +30,7 @@
 M209 S0 ; disable firmware retraction, we dont want to burn holes...
 M302 ; Allow cold extrudes - doesnt matter because we hack the extruder physically off with the M571 E mod
 M571 S1 E1 ; Activate Laser output on extrusion, but block real motor movement!
-M85 S0 ; Disable idle hold timeout
+;M85 S0 ; Disable idle hold timeout (BUG!)
 M84 ; enable motors
 
 """
@@ -38,9 +38,9 @@
 GCODE_FOOT = """
 M400 ; Wait for all moves to finish
 M42 P28 S0 ; Force laser off!
-M85 S30 ; re-enable idle hold timeout
+;M85 S30 ; re-enable idle hold timeout (BUG!)
 G0 X0 Y0 F%.4f ; Move back to origin
-; M571 S0 E0 ; disable extruder firmware hack
+M571 S0 E0 ; disable extruder firmware hack
 ; M501 ; undo all settings made
 """ % (100*60)
 
@@ -300,7 +300,10 @@
         import xml.etree.ElementTree as ET
         from svg2gcode import shapes as shapes_pkg
         from svg2gcode.shapes import point_generator
-        from svg2gcode import simplepath, cspsubdiv, cubicsuperpath
+        from svg2gcode import simplepath, cspsubdiv, cubicsuperpath, simpletransform
+
+        bed_max_x = self.settings.lc_svg_width
+        bed_max_y = self.settings.lc_svg_height
 
         self.log("Generating paths from SVG (outlines only)...")        
         svg_shapes = set(['rect', 'circle', 'ellipse', 'line', 'polyline', 'polygon', 'path'])
@@ -313,7 +316,16 @@
         # if width == None or height == None:
         viewbox = root.get('viewBox')
         if viewbox:
-            _, _, width, height = viewbox.split()                
+            _, _, width, height = viewbox.split()
+        else:
+            # no viewbox element, try to get from svg root element
+            try:
+                width = root.attrib["width"]
+                height = root.attrib["height"]
+                self.log("No ViewBox, got dimensions from root element)")
+            except:
+                width = None
+                height = None
 
         if width == None or height == None:
             self.log("Unable to get width and height for the svg!")
@@ -356,6 +368,9 @@
                             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
@@ -368,9 +383,6 @@
         height = max_y
         """
 
-        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:
@@ -386,6 +398,7 @@
         travel_speed = self.settings.lc_travel_speed * 60
         engrave_speed = self.settings.lc_engrave_speed * 60 * self.settings.lc_svg_speed_factor
 
+        errors = 0
 
         for elem in root.iter():
             try:
@@ -453,18 +466,20 @@
                                 if xo == xs and yo == ys: continue
 
                                 #self.log(" Point " + repr(end_pt))
+                                e_distance = math.hypot(xs - xo, ys - yo)
+                                xo = xs
+                                yo = ys                                
+                                E = E + (e_distance)
 
                                 if xs >= 0 and xs <= bed_max_x+0.1 and ys >= 0 and ys <= bed_max_y+0.1:
-                                    e_distance = math.hypot(xs - xo, ys - yo)
-                                    xo = xs
-                                    yo = ys                                
-                                    E = E + (e_distance)
                                     fo.write("G1 X%0.4f Y%0.4f E%.4f F%.4f\n" % (
                                         xs, ys, E * E_FACTOR, engrave_speed))
-
                                 else:
-                                    self.log("Position outside print dimension: %d, %d" % (xs, ys)) 
-
+                                    fo.write("G0 X%0.4f Y%0.4f F%.4f\n" % (
+                                        xs, ys, travel_speed))
+                                    errors += 1
+                                    if errors < 10:
+                                        self.log("Position outside print dimension: %d, %d" % (xs, ys)) 
 
                                 #print "   Point: ", end_pt[0], end_pt[1], pen
                             #self.log("Laser OFF at: " + repr(sp[-1][-1]))
@@ -479,6 +494,9 @@
 
         fo.write(GCODE_FOOT)
         fo.close()
+
+        if errors > 0:
+            self.log("%i errors while generating gcode" % errors)
                      
         if self.pronterwindow:
             self.log("")        
--- a/printrun-src/printrun/pronterface.py	Sat Sep 23 10:27:49 2017 +0200
+++ b/printrun-src/printrun/pronterface.py	Sat Sep 23 13:07:51 2017 +0200
@@ -268,44 +268,47 @@
         # lc print button
         self.log("Priming Z axis to initial focus")
         line = self.precmd("G1 Z%.2f" % (self.settings.lc_z_focus + self.lc_material_thickness.GetValue()))
-        self.onecmd(line)
-
-        self.printfile(event)
+        wx.CallAfter(self.onecmd, line)
         self.lc_printing = True
-
+        wx.CallAfter(self.printfile, None)
 
     def endcb_lasercut(self):
         # LASERCUT: Now check if we should do another print pass?
-        if not self.lc_printing:
-            return
+        self.log("event: endcb_lasercut")
+        if self.lc_printing:
+            self.log(" -> checking if something to do...")
+            pass_count = self.lc_pass_count.GetValue()
+            if pass_count > 1:
+                time.sleep(0.5)
+                if self.pass_current < pass_count:
+                    self.pass_current += 1
+                    self.log("Starting lasercut pass # %i of %i" % (self.pass_current, pass_count))
+                    if self.lc_pass_zdiff.GetValue() != 0:
+                        # move Z focus
+                        new_z = self.settings.lc_z_focus + self.lc_material_thickness.GetValue() + (
+                            self.lc_pass_zdiff.GetValue() * (self.pass_current - 1))
+                        self.log("Re-Positioning laser focus by %.1f mm to %.1f" % (self.lc_pass_zdiff.GetValue(), new_z))
+                        line = self.precmd("G1 Z%.2f" % (new_z))
+                        self.onecmd(line)
+                        time.sleep(0.5)
 
-        pass_count = self.lc_pass_count.GetValue()
-        if pass_count > 1:
-            time.sleep(0.5)
-            if self.pass_current < pass_count:
-                self.pass_current += 1
-                self.log("Starting lasercut pass # %i of %i" % (self.pass_current, pass_count))
-                if self.lc_pass_zdiff.GetValue() != 0:
-                    # move Z focus
-                    new_z = self.settings.lc_z_focus + self.lc_material_thickness.GetValue() + (
-                        self.lc_pass_zdiff.GetValue() * (self.pass_current - 1))
-                    self.log("Re-Positioning laser focus by %.1f mm to %.1f" % (self.lc_pass_zdiff.GetValue(), new_z))
-                    line = self.precmd("G1 Z%.2f" % (new_z))
+                    # "click" print button again
+                    tmp = self.pass_current
+                    self.printfile(None)
+                    self.pass_current = tmp
+                else:
+                    self.lc_printing = False
+                    wx.CallAfter(self.lc_printbtn.Enable)
+                    wx.CallAfter(self.lc_printbtn.SetLabel, _("Start cutting"))
+
+                    self.log("Resetting Z axis to initial focus")
+                    line = self.precmd("G1 Z%.2f" % (self.settings.lc_z_focus + self.lc_material_thickness.GetValue()))
                     self.onecmd(line)
-                    time.sleep(0.5)
-
-                # "click" print button again
-                tmp = self.pass_current
-                self.printfile(None)
-                self.pass_current = tmp
             else:
                 self.lc_printing = False
                 wx.CallAfter(self.lc_printbtn.Enable)
                 wx.CallAfter(self.lc_printbtn.SetLabel, _("Start cutting"))
-
-                self.log("Resetting Z axis to initial focus")
-                line = self.precmd("G1 Z%.2f" % (self.settings.lc_z_focus + self.lc_material_thickness.GetValue()))
-                self.onecmd(line)
+                
 
     def update_lc_settings(self, key, value):
         return True
@@ -1657,7 +1660,6 @@
             wx.CallAfter(self.pausebtn.Disable)
             wx.CallAfter(self.printbtn.SetLabel, _("Print"))
             wx.CallAfter(self.toolbarsizer.Layout)
-
             wx.CallAfter(self.endcb_lasercut)
 
     def online(self):

mercurial