printrun-src/printrun/pronterface.py

changeset 48
3c27b4ee6fec
parent 47
dcc64b767b64
equal deleted inserted replaced
47:dcc64b767b64 48:3c27b4ee6fec
1 # FILE MODIFIED BY NEOSOFT - MALTE DI DONATO
2 # Embed Lasercut functions from laser.py
3 from . import laser
4 try:
5 from . import module_watcher
6 mw = module_watcher.ModuleWatcher()
7 mw.watch_module('laser')
8 mw.start_watching()
9 except Exception, e:
10 print e
11 print "ModuleWatcher not loaded, skipping autoreloading of changed modules"
12
1 # This file is part of the Printrun suite. 13 # This file is part of the Printrun suite.
2 # 14 #
3 # Printrun is free software: you can redistribute it and/or modify 15 # Printrun is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by 16 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or 17 # the Free Software Foundation, either version 3 of the License, or
243 self.connect() 255 self.connect()
244 if self.filename is not None: 256 if self.filename is not None:
245 self.do_load(self.filename) 257 self.do_load(self.filename)
246 if self.settings.monitor: 258 if self.settings.monitor:
247 self.update_monitor() 259 self.update_monitor()
260
261 # --------------------------------------------------------------
262 # Lasercutter methods
263 # --------------------------------------------------------------
264
265 def on_lc_printfile(self, event):
266 # lc print button
267 self.log("Priming Z axis to initial focus")
268 line = self.precmd("G1 Z%.2f" % (self.settings.lc_z_focus + self.lc_material_thickness.GetValue()))
269 wx.CallAfter(self.onecmd, line)
270 self.lc_printing = True
271 wx.CallAfter(self.printfile, None)
272
273 def endcb_lasercut(self):
274 # LASERCUT: Now check if we should do another print pass?
275 self.log("event: endcb_lasercut")
276 if self.lc_printing:
277 self.log(" -> checking if something to do...")
278 pass_count = self.lc_pass_count.GetValue()
279 if pass_count > 1:
280 time.sleep(0.5)
281 if self.pass_current < pass_count:
282 self.pass_current += 1
283 self.log("Starting lasercut pass # %i of %i" % (self.pass_current, pass_count))
284 if self.lc_pass_zdiff.GetValue() != 0:
285 # move Z focus
286 new_z = self.settings.lc_z_focus + self.lc_material_thickness.GetValue() + (
287 self.lc_pass_zdiff.GetValue() * (self.pass_current - 1))
288 self.log("Re-Positioning laser focus by %.1f mm to %.1f" % (self.lc_pass_zdiff.GetValue(), new_z))
289 line = self.precmd("G1 Z%.2f" % (new_z))
290 self.onecmd(line)
291 time.sleep(0.5)
292
293 # "click" print button again
294 tmp = self.pass_current
295 self.printfile(None)
296 self.pass_current = tmp
297 else:
298 self.lc_printing = False
299 wx.CallAfter(self.lc_printbtn.Enable)
300 wx.CallAfter(self.lc_printbtn.SetLabel, _("Start cutting"))
301
302 self.log("Resetting Z axis to initial focus")
303 line = self.precmd("G1 Z%.2f" % (self.settings.lc_z_focus + self.lc_material_thickness.GetValue()))
304 self.onecmd(line)
305 else:
306 self.lc_printing = False
307 wx.CallAfter(self.lc_printbtn.Enable)
308 wx.CallAfter(self.lc_printbtn.SetLabel, _("Start cutting"))
309
310
311 def update_lc_settings(self, key, value):
312 return True
313
314 def _lc_add_settings(self, size):
315 # first add the lasercutter options
316 self.settings._add(StaticTextSetting("separator_lc_general", "General laser settings", "", group = "Laser"))
317 self.settings._add(BooleanSetting("lc_melzi_hack", False, "Use Melzi M571 Hack instead M3/M5", "no description :)", "Laser"), self.update_lc_settings)
318 self.settings._add(SpinSetting("lc_travel_speed", 120, 1, 300, "Travel speed in mm/s", "", "Laser"), self.update_lc_settings)
319 self.settings._add(SpinSetting("lc_engrave_speed", 10, 1, 300, "Engrave speed in mm/s", "", "Laser"), self.update_lc_settings)
320 self.settings._add(SpinSetting("lc_z_focus", 16, -80, 80, "Laser Z focus position", "", "Laser"), self.update_lc_settings)
321 self.settings._add(SpinSetting("lc_pass_count", 1, 0, 20, "Default Number of cutting passes", "", "Laser"), self.reload_ui)
322 self.settings._add(FloatSpinSetting("lc_pass_zdiff", -0.25, -2.0, 2.0, "Default Z movement after each cut", "", "Laser"), self.reload_ui)
323 self.settings._add(FloatSpinSetting("lc_material_thickness", 4.0, 0.0, 80.0, "Default Material Thickness", "", "Laser"), self.reload_ui)
324
325 self.settings._add(StaticTextSetting("separator_lc_bitmap", "PNG Bitmap processing", "", group = "Laser"))
326 self.settings._add(FloatSpinSetting("lc_bitmap_speed_factor", 1.0, 0.1, 2.0, "Engrave speed factor", "", "Laser"), self.update_lc_settings)
327 self.settings._add(SpinSetting("lc_dpi", 300, 25, 600, "Image DPI", "Image resolution for scaling", "Laser"), self.update_lc_settings)
328 self.settings._add(SpinSetting("lc_grey_threshold", 0, 0, 255, "Grey threshold value for RGB", "", "Laser"), self.update_lc_settings)
329 self.settings._add(BooleanSetting("lc_invert_cut", True, "PNG: Invert grey threshold", "Invert laser on/off logic", "Laser"), self.update_lc_settings)
330 self.settings._add(BooleanSetting("lc_change_dir", True, "PNG: Change direction", "Engrave in both directions on Y Axis", "Laser"), self.update_lc_settings)
331
332 self.settings._add(StaticTextSetting("separator_lc_hpgl", "HPGL processing", "", group = "Laser"))
333 self.settings._add(FloatSpinSetting("lc_hpgl_speed_factor", 1.0, 0.1, 2.0, "Engrave speed factor", "", "Laser"), self.update_lc_settings)
334
335 self.settings._add(StaticTextSetting("separator_lc_svg", "SVG processing", "", group = "Laser"))
336 self.settings._add(FloatSpinSetting("lc_svg_speed_factor", 1.0, 0.1, 2.0, "Engrave speed factor", "", "Laser"), self.update_lc_settings)
337 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)
338 self.settings._add(SpinSetting("lc_svg_width", 50, 1, 9999, "Width (mm)", "Image width", "Laser"), self.update_lc_settings)
339 self.settings._add(SpinSetting("lc_svg_height", 50, 1, 9999, "Height (mm)", "Image height", "Laser"), self.update_lc_settings)
340 self.settings._add(ComboSetting("lc_svg_scalemode", "original", ["original", "scale", "stretch"], "Scaling mode", "scale/stretch to above dimensions", "Laser"), self.update_lc_settings)
341 self.settings._add(BooleanSetting("lc_svg_offset", True, "Calculate offset to X=0, Y=0", "If enabled, move image to origin position", "Laser"), self.update_lc_settings)
342
248 343
249 # -------------------------------------------------------------- 344 # --------------------------------------------------------------
250 # Main interface handling 345 # Main interface handling
251 # -------------------------------------------------------------- 346 # --------------------------------------------------------------
252 347
942 Printrun. If not, see <http://www.gnu.org/licenses/>.""" 1037 Printrun. If not, see <http://www.gnu.org/licenses/>."""
943 1038
944 info.SetLicence(licence) 1039 info.SetLicence(licence)
945 info.AddDeveloper('Kliment Yanev') 1040 info.AddDeveloper('Kliment Yanev')
946 info.AddDeveloper('Guillaume Seguin') 1041 info.AddDeveloper('Guillaume Seguin')
1042 info.AddDeveloper('Malte Di Donato')
947 1043
948 wx.adv.AboutBox(info) 1044 wx.adv.AboutBox(info)
949 1045
950 # -------------------------------------------------------------- 1046 # --------------------------------------------------------------
951 # Settings & command line handling (including update callbacks) 1047 # Settings & command line handling (including update callbacks)
952 # -------------------------------------------------------------- 1048 # --------------------------------------------------------------
953 1049
954 def _add_settings(self, size): 1050 def _add_settings(self, size):
1051 self._lc_add_settings(size)
1052
955 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) 1053 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)
956 self.settings._add(StringSetting("simarrange_path", "", _("Simarrange command"), _("Path to the simarrange binary to use in the STL plater"), "External")) 1054 self.settings._add(StringSetting("simarrange_path", "", _("Simarrange command"), _("Path to the simarrange binary to use in the STL plater"), "External"))
957 self.settings._add(BooleanSetting("circular_bed", False, _("Circular build platform"), _("Draw a circular (or oval) build platform instead of a rectangular one"), "Printer"), self.update_bed_viz) 1055 self.settings._add(BooleanSetting("circular_bed", False, _("Circular build platform"), _("Draw a circular (or oval) build platform instead of a rectangular one"), "Printer"), self.update_bed_viz)
958 self.settings._add(SpinSetting("extruders", 0, 1, 5, _("Extruders count"), _("Number of extruders"), "Printer")) 1056 self.settings._add(SpinSetting("extruders", 0, 1, 5, _("Extruders count"), _("Number of extruders"), "Printer"))
959 self.settings._add(BooleanSetting("clamp_jogging", False, _("Clamp manual moves"), _("Prevent manual moves from leaving the specified build dimensions"), "Printer")) 1057 self.settings._add(BooleanSetting("clamp_jogging", False, _("Clamp manual moves"), _("Prevent manual moves from leaving the specified build dimensions"), "Printer"))
1484 except: 1582 except:
1485 pass 1583 pass
1486 dlg = None 1584 dlg = None
1487 if filename is None: 1585 if filename is None:
1488 dlg = wx.FileDialog(self, _("Open file to print"), basedir, style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) 1586 dlg = wx.FileDialog(self, _("Open file to print"), basedir, style = wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
1489 dlg.SetWildcard(_("OBJ, STL, and GCODE files (*.gcode;*.gco;*.g;*.stl;*.STL;*.obj;*.OBJ)|*.gcode;*.gco;*.g;*.stl;*.STL;*.obj;*.OBJ|GCODE files (*.gcode;*.gco;*.g)|*.gcode;*.gco;*.g|OBJ, STL files (*.stl;*.STL;*.obj;*.OBJ)|*.stl;*.STL;*.obj;*.OBJ|All Files (*.*)|*.*")) 1587 # add image files to GCODE file list
1588 dlg.SetWildcard(_("GCODE and Image files|*.gcode;*.gco;*.g;*.png;*.svg;*.hpgl;*.plt|OBJ, STL, and GCODE files (*.gcode;*.gco;*.g;*.stl;*.STL;*.obj;*.OBJ)|*.gcode;*.gco;*.g;*.stl;*.STL;*.obj;*.OBJ|GCODE files (*.gcode;*.gco;*.g)|*.gcode;*.gco;*.g|OBJ, STL files (*.stl;*.STL;*.obj;*.OBJ)|*.stl;*.STL;*.obj;*.OBJ|All Files (*.*)|*.*"))
1490 try: 1589 try:
1491 dlg.SetFilterIndex(self.settings.last_file_filter) 1590 dlg.SetFilterIndex(self.settings.last_file_filter)
1492 except: 1591 except:
1493 pass 1592 pass
1494 if filename or dlg.ShowModal() == wx.ID_OK: 1593 if filename or dlg.ShowModal() == wx.ID_OK:
1519 recent_files = recent_files[:5] 1618 recent_files = recent_files[:5]
1520 self.set("recentfiles", json.dumps(recent_files)) 1619 self.set("recentfiles", json.dumps(recent_files))
1521 except: 1620 except:
1522 self.logError(_("Could not update recent files list:") + 1621 self.logError(_("Could not update recent files list:") +
1523 "\n" + traceback.format_exc()) 1622 "\n" + traceback.format_exc())
1623
1624 # reload the library local so we dont have to restart the whole app when making code changes
1625 reload(laser)
1626
1524 if name.lower().endswith(".stl") or name.lower().endswith(".obj"): 1627 if name.lower().endswith(".stl") or name.lower().endswith(".obj"):
1525 self.slice(name) 1628 self.slice(name)
1629 elif name.lower().endswith(".png") or name.lower().endswith(".jpg") or name.lower().endswith(".gif"):
1630 # Generate GCODE from IMAGE
1631 lc = laser.Lasercutter(pronterwindow = self)
1632 lc.image2gcode(name)
1633 wx.CallAfter(self.endcb_lasercut)
1634 elif name.lower().endswith(".svg"):
1635 # Generate GCODE from SVG
1636 lc = laser.Lasercutter(pronterwindow = self)
1637 lc.svg2gcode(name)
1638 wx.CallAfter(self.endcb_lasercut)
1639 elif name.lower().endswith(".hpgl") or name.lower().endswith(".plt"):
1640 # Generate GCODE from HPGL
1641 lc = laser.Lasercutter(pronterwindow = self)
1642 lc.hpgl2gcode(name)
1643 wx.CallAfter(self.endcb_lasercut)
1526 else: 1644 else:
1527 self.load_gcode_async(name) 1645 self.load_gcode_async(name)
1528 else: 1646 else:
1529 dlg.Destroy() 1647 dlg.Destroy()
1530 1648
1735 printer_progress_string = "M117 Finished Print" 1853 printer_progress_string = "M117 Finished Print"
1736 self.p.send_now(printer_progress_string) 1854 self.p.send_now(printer_progress_string)
1737 wx.CallAfter(self.pausebtn.Disable) 1855 wx.CallAfter(self.pausebtn.Disable)
1738 wx.CallAfter(self.printbtn.SetLabel, _("&Print")) 1856 wx.CallAfter(self.printbtn.SetLabel, _("&Print"))
1739 wx.CallAfter(self.toolbarsizer.Layout) 1857 wx.CallAfter(self.toolbarsizer.Layout)
1858 wx.CallAfter(self.endcb_lasercut)
1740 1859
1741 def online(self): 1860 def online(self):
1742 """Callback when printer goes online""" 1861 """Callback when printer goes online"""
1743 self.log(_("Printer is now online.")) 1862 self.log(_("Printer is now online."))
1744 wx.CallAfter(self.online_gui) 1863 wx.CallAfter(self.online_gui)

mercurial