📄 axis.py
字号:
#!/usr/bin/env python2# This is a component of AXIS, a front-end for emc# Copyright 2004, 2005, 2006 Jeff Epler <jepler@unpythonic.net> and# Chris Radek <chris@timeguy.com>## This program is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA# import pdbimport sys, osimport stringBASE = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), ".."))sys.path.insert(0, os.path.join(BASE, "lib", "python"))import gettext;gettext.install("axis", localedir=os.path.join(BASE, "share", "locale"), unicode=True)r_ = gettext.translation("rs274_err", localedir=os.path.join(BASE, "share", "locale"), fallback=True).ugettextimport array, time, atexit, tempfile, shutil, errno, thread, select, re# Print Tk errors to stdout. python.org/sf/639266import Tkinter OldTk = Tkinter.Tkclass Tk(OldTk): def __init__(self, *args, **kw): OldTk.__init__(self, *args, **kw) self.tk.createcommand('tkerror', self.tkerror) def tkerror(self, arg): print "TCL error in asynchronous code:" print self.tk.call("set", "errorInfo")Tkinter.Tk = Tkfrom Tkinter import *from minigl import *from rs274.OpenGLTk import *from rs274.glcanon import GLCanonfrom hershey import Hersheyfrom propertywindow import propertiesimport rs274.optionsimport nfimport gcodeimport localefrom math import hypot, atan2, sin, cos, pi, sqrtfrom rs274 import ArcsToSegmentsMixinimport emcimport halimport ConfigParsercp = ConfigParser.ConfigParserclass AxisPreferences(cp): def __init__(self): cp.__init__(self) self.fn = os.path.expanduser("~/.axis_preferences") self.read(self.fn) def getpref(self, option, default=False): try: o = self.getboolean("DEFAULT", option) except: self.set("DEFAULT", option, default) self.write(open(self.fn, "w")) o = default return o def putpref(self, option, value): self.set("DEFAULT", option, bool(value)) self.write(open(self.fn, "w"))ap = AxisPreferences()root_window = Tkinter.Tk(className="Axis")nf.start(root_window)nf.makecommand(root_window, "_", _)rs274.options.install(root_window)root_window.tk.call("set", "version", emc.version)try: nf.source_lib_tcl(root_window,"axis.tcl")except TclError: print root_window.tk.call("set", "errorInfo") raiseprogram_start_line = 0program_start_line_last = -1lathe = 0mdi_history_max_entries = 1000mdi_history_save_filename= "~/.axis_mdi_history"feedrate_blackout = 0spindlerate_blackout = 0jogincr_index_last = 1mdi_history_index= -1homeicon = array.array('B', [0x2, 0x00, 0x02, 0x00, 0x02, 0x00, 0x0f, 0x80, 0x1e, 0x40, 0x3e, 0x20, 0x3e, 0x20, 0x3e, 0x20, 0xff, 0xf8, 0x23, 0xe0, 0x23, 0xe0, 0x23, 0xe0, 0x13, 0xc0, 0x0f, 0x80, 0x02, 0x00, 0x02, 0x00])limiticon = array.array('B', [ 0, 0, 128, 0, 134, 0, 140, 0, 152, 0, 176, 0, 255, 255, 255, 255, 176, 0, 152, 0, 140, 0, 134, 0, 128, 0, 0, 0, 0, 0, 0, 0])help1 = [ ("F1", _("Emergency stop")), ("F2", _("Turn machine on")), ("", ""), ("X, `", _("Activate first axis")), ("Y, 1", _("Activate second axis")), ("Z, 2", _("Activate third axis")), ("A, 3", _("Activate fourth axis")), ("4..8", _("Activate fifth through ninth axis")), ("`, 1..9, 0", _("Set Feed Override from 0% to 100%")), (_(", and ."), _("Select jog speed")), (_("< and >"), _("Select angular jog speed")), (_("I, Shift-I"), _("Select jog increment")), ("C", _("Continuous jog")), (_("Home"), _("Send active axis home")), (_("Ctrl-Home"), _("Home all axes")), (_("Shift-Home"), _("Zero G54 offset for active axis")), (_("End"), _("Set G54 offset for active axis")), ("-, =", _("Jog active axis")), (_("Left, Right"), _("Jog first axis")), (_("Up, Down"), _("Jog second axis")), (_("Pg Up, Pg Dn"), _("Jog third axis")), ("[, ]", _("Jog fourth axis")), ("", ""), ("D", _("Toggle between Drag and Rotate mode")), (_("Left Button"), _("Pan, rotate or select line")), (_("Shift+Left Button"), _("Rotate or pan")), (_("Right Button"), _("Zoom view")), (_("Wheel Button"), _("Rotate view")), (_("Rotate Wheel"), _("Zoom view")), (_("Control+Left Button"), _("Zoom view")),]help2 = [ ("F3", _("Manual control")), ("F5", _("Code entry (MDI)")), (_("Control-M"), _("Clear MDI history")), (_("Control-H"), _("Copy selected MDI history elements")), ("", _("to clipboard")), (_("Control-Shift-H"), _("Paste clipboard to MDI history")), ("L", _("Override Limits")), ("", ""), ("O", _("Open program")), (_("Control-R"), _("Reload program")), (_("Control-S"), _("Save g-code as")), ("R", _("Run program")), ("T", _("Step program")), ("P", _("Pause program")), ("S", _("Resume program")), ("ESC", _("Stop running program, or")), ("", _("stop loading program preview")), ("", ""), ("F7", _("Toggle mist")), ("F8", _("Toggle flood")), ("", ""), ("B", _("Spindle brake off")), (_("Shift-B"), _("Spindle brake on")), ("F9", _("Turn spindle clockwise")), ("F10", _("Turn spindle counterclockwise")), ("F11", _("Turn spindle more slowly")), ("F12", _("Turn spindle more quickly")), ("", ""), (_("Control-K"), _("Clear live plot")), ("V", _("Cycle among preset views")),]def install_help(app): keys = nf.makewidget(app, Frame, '.keys.text') for i in range(len(help1)): a, b = help1[i] Label(keys, text=a, font="fixed", padx=4, pady=0, highlightthickness=0).grid(row=i, column=0, sticky="w") Label(keys, text=b, padx=4, pady=0, highlightthickness=0).grid(row=i, column=1, sticky="w") for i in range(len(help2)): a, b = help2[i] Label(keys, text=a, font="fixed", padx=4, pady=0, highlightthickness=0).grid(row=i, column=3, sticky="w") Label(keys, text=b, padx=4, pady=0, highlightthickness=0).grid(row=i, column=4, sticky="w") Label(keys, text=" ").grid(row=0, column=2)color_names = [ ('back', 'Background'), 'dwell', 'm1xx', 'straight_feed', 'arc_feed', 'traverse', 'backplotjog', 'backplotfeed', 'backplotarc', 'backplottraverse', 'backplottoolchange', 'backplotprobing', 'selected', 'tool_ambient', 'tool_diffuse', 'lathetool', 'overlay_foreground', ('overlay_background', 'Background'), 'label_ok', 'label_limit', 'small_origin', 'axis_x', 'axis_y', 'axis_z', 'cone',] def parse_color(c): if c == "": return (1,0,0) return tuple([i/65535. for i in root_window.winfo_rgb(c)])def to_internal_units(pos, unit=None): if unit is None: unit = s.linear_units lu = (unit or 1) * 25.4 lus = [lu, lu, lu, 1, 1, 1, lu, lu, lu] return [a/b for a, b in zip(pos, lus)]def to_internal_linear_unit(v, unit=None): if unit is None: unit = s.linear_units lu = (unit or 1) * 25.4 return v/ludef from_internal_units(pos, unit=None): if unit is None: unit = s.linear_units lu = (unit or 1) * 25.4 lus = [lu, lu, lu, 1, 1, 1, lu, lu, lu] return [a*b for a, b in zip(pos, lus)]def from_internal_linear_unit(v, unit=None): if unit is None: unit = s.linear_units lu = (unit or 1) * 25.4 return v*luclass MyOpengl(Opengl): def __init__(self, *args, **kw): self.after_id = None self.motion_after = None self.perspective = False Opengl.__init__(self, *args, **kw) self.bind('<Button-4>', self.zoomin) self.bind('<Button-5>', self.zoomout) self.bind('<MouseWheel>', self.zoomwheel) self.bind('<Button-1>', self.select_prime, add=True) self.bind('<ButtonRelease-1>', self.select_fire, add=True) self.bind('<Button1-Motion>', self.translate_or_rotate) self.bind('<Button1-Motion>', self.select_cancel, add=True) self.bind("<Control-Button-1>", self.start_zoom) self.bind("<Control-B1-Motion>", self.continue_zoom) self.bind("<Button-3>", self.start_zoom) self.bind("<B3-Motion>", self.continue_zoom) self.bind("<Shift-Button-1>", self.StartRotate) self.bind("<Shift-B1-Motion>", self.rotate_or_translate) self.bind("<B2-Motion>", self.rotate_or_translate) self.highlight_line = None self.select_event = None self.select_buffer_size = 100 self.select_primed = False self.last_position = None self.last_homed = None self.last_origin = None self.last_tool = None self.g = None self.set_eyepoint(5.) self.get_resources() def translate_or_rotate(self, event): if vars.rotate_mode.get(): self.tkRotate(event) else: self.tkTranslate(event) def rotate_or_translate(self, event): if not vars.rotate_mode.get(): self.tkRotate(event) else: self.tkTranslate(event) def basic_lighting(self): self.activate() glLightfv(GL_LIGHT0, GL_POSITION, (1, -1, 1, 0)) glLightfv(GL_LIGHT0, GL_AMBIENT, self.colors['tool_ambient'] + (0,)) glLightfv(GL_LIGHT0, GL_DIFFUSE, self.colors['tool_diffuse'] + (0,)) glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, (1,1,1,0)) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) glDepthFunc(GL_LESS) glEnable(GL_DEPTH_TEST) glMatrixMode(GL_MODELVIEW) glLoadIdentity() def start_zoom(self, event): self.y0 = event.y self.original_zoom = self.distance def continue_zoom(self, event): dy = event.y - self.y0 self.distance = self.original_zoom * pow(1.25, dy / 16.) self.tkRedraw() def get_resources(self): self.colors = {} for c in color_names: if isinstance(c, tuple): c, d = c else: d = "Foreground" self.colors[c] = parse_color(self.option_get(c, d)) self.colors['backplotjog_alpha'] = \ float(self.option_get("backplotjog_alpha", "Float")) self.colors['backplotfeed_alpha'] = \ float(self.option_get("backplotfeed_alpha", "Float")) self.colors['backplotarc_alpha'] = \ float(self.option_get("backplotarc_alpha", "Float")) self.colors['backplottraverse_alpha'] = \ float(self.option_get("backplottraverse_alpha", "Float")) self.colors['backplottoolchange_alpha'] = \ float(self.option_get("backplottoolchange_alpha", "Float")) self.colors['backplotprobing_alpha'] = \ float(self.option_get("backplotprobing_alpha", "Float")) self.colors['overlay_alpha'] = \ float(self.option_get("overlay_alpha", "Float")) x = float(self.option_get("tool_light_x", "Float")) y = float(self.option_get("tool_light_y", "Float")) z = float(self.option_get("tool_light_z", "Float")) dist = (x**2 + y**2 + z**2) ** .5 self.light_position = (x/dist, y/dist, z/dist, 0) self.colors['tool_alpha'] = \ float(self.option_get("tool_alpha", "Float")) self.colors['lathetool_alpha'] = \ float(self.option_get("lathetool_alpha", "Float")) def select_prime(self, event): self.select_primed = event def select_cancel(self, event): self.select_primed = False def select_fire(self, event): if self.select_primed: self.queue_select(event) def queue_select(self, event): self.select_event = event self.tkRedraw() def deselect(self, event): self.set_highlight_line(None) def select(self, event): if self.g is None: return pmatrix = glGetDoublev(GL_PROJECTION_MATRIX)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -