⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 axis.py

📁 CNC 的开放码,EMC2 V2.2.8版
💻 PY
📖 第 1 页 / 共 5 页
字号:
    if do_poll: s.poll()    return s.task_mode == emc.MODE_AUTO and s.interp_state != emc.INTERP_IDLEdef manual_ok(do_poll=True):    if do_poll: s.poll()    if s.task_state != emc.STATE_ON: return False    return s.interp_state == emc.INTERP_IDLE# If emc is not already in one of the modes given, switch it to the first# modedef ensure_mode(m, *p):    s.poll()    if s.task_mode == m or s.task_mode in p: return True    if running(do_poll=False): return False    c.wait_complete()    c.mode(m)    c.wait_complete()    return Trueclass DummyProgress:    def update(self, count): pass    def nextphase(self, count): pass    def done(self): passclass Progress:    def __init__(self, phases, total):        self.num_phases = phases        self.phase = 0        self.total = total or 1        self.lastcount = 0        self.text = None        self.old_focus = root_window.tk.call("focus", "-lastfor", ".")        root_window.tk.call("canvas", ".info.progress",                    "-width", 1, "-height", 1,                    "-highlightthickness", 0,                    "-borderwidth", 2, "-relief", "sunken",                    "-cursor", "watch")        root_window.configure(cursor="watch")        root_window.tk.call(".menu", "configure", "-cursor", "watch")        t.configure(cursor="watch")        root_window.tk.call("bind", ".info.progress", "<Key>", "break")        root_window.tk.call("pack", ".info.progress", "-side", "left",                                "-fill", "both", "-expand", "1")        root_window.tk.call(".info.progress", "create", "rectangle",                                (-10, -10, -10, -10),                                "-fill", "blue", "-outline", "blue")        root_window.update_idletasks()        root_window.tk.call("focus", "-force", ".info.progress")        root_window.tk.call("patient_grab", ".info.progress")    def update(self, count, force=0):        if force or count - self.lastcount > 400:            fraction = (self.phase + count * 1. / self.total) / self.num_phases            self.lastcount = count            try:                width = int(t.tk.call("winfo", "width", ".info.progress"))            except Tkinter.TclError, detail:                print detail                return            height = int(t.tk.call("winfo", "height", ".info.progress"))            t.tk.call(".info.progress", "coords", "1",                (0, 0, int(fraction * width), height))            t.tk.call("update", "idletasks")    def nextphase(self, total):        self.phase += 1        self.total = total or 1        self.lastcount = -100    def done(self):        root_window.tk.call("destroy", ".info.progress")        root_window.tk.call("grab", "release", ".info.progress")        root_window.tk.call("focus", self.old_focus)        root_window.configure(cursor="")        root_window.tk.call(".menu", "configure", "-cursor", "")        t.configure(cursor="xterm")    def __del__(self):        if root_window.tk.call("winfo", "exists", ".info.progress"):            self.done()    def set_text(self, text):        if self.text is None:            self.text = root_window.tk.call(".info.progress", "create", "text",                (1, 1), "-text", text, "-anchor", "nw")        else:            root_window.tk.call(".info.progress", "itemconfigure", text,                "-text", text)class AxisCanon(GLCanon):    def __init__(self, widget, text, linecount, progress):        GLCanon.__init__(self, widget, text)        self.linecount = linecount        self.progress = progress        self.aborted = False        root_window.bind_class(".info.progress", "<Escape>", self.do_cancel)    def comment(self, arg):        if arg.startswith("AXIS,"):            parts = arg.split(",")            command = parts[1]            if command == "stop": self.aborted = True            if command == "hide": self.suppress += 1            if command == "show": self.suppress -= 1    def do_cancel(self, event):        self.aborted = True    def check_abort(self):        root_window.update()        if self.aborted: raise KeyboardInterrupt    def draw_lines(self, lines, for_selection, j=0):        return draw_lines(lines, for_selection)    def draw_dwells(self, dwells, for_selection, j0=0):        delta = .015625        if for_selection == 0:            glBegin(GL_LINES)        for j, (l,c,x,y,z,axis) in enumerate(dwells):            self.progress.update(j+j0)            glColor3f(*c)            if for_selection == 1:                glLoadName(l)                glBegin(GL_LINES)            if axis == 0:                glVertex3f(x-delta,y-delta,z)                glVertex3f(x+delta,y+delta,z)                glVertex3f(x-delta,y+delta,z)                glVertex3f(x+delta,y-delta,z)                glVertex3f(x+delta,y+delta,z)                glVertex3f(x-delta,y-delta,z)                glVertex3f(x+delta,y-delta,z)                glVertex3f(x-delta,y+delta,z)            elif axis == 1:                glVertex3f(x-delta,y,z-delta)                glVertex3f(x+delta,y,z+delta)                glVertex3f(x-delta,y,z+delta)                glVertex3f(x+delta,y,z-delta)                glVertex3f(x+delta,y,z+delta)                glVertex3f(x-delta,y,z-delta)                glVertex3f(x+delta,y,z-delta)                glVertex3f(x-delta,y,z+delta)            else:                glVertex3f(x,y-delta,z-delta)                glVertex3f(x,y+delta,z+delta)                glVertex3f(x,y+delta,z-delta)                glVertex3f(x,y-delta,z+delta)                glVertex3f(x,y+delta,z+delta)                glVertex3f(x,y-delta,z-delta)                glVertex3f(x,y-delta,z+delta)                glVertex3f(x,y+delta,z-delta)            if for_selection == 1:                glEnd()        if for_selection == 0:            glEnd()    def draw(self, for_selection=0):        self.progress.nextphase(len(self.traverse) + len(self.feed) + len(self.dwells) + len(self.arcfeed))        glEnable(GL_LINE_STIPPLE)        glColor3f(*self.colors['traverse'])        self.draw_lines(self.traverse, for_selection)        glDisable(GL_LINE_STIPPLE)        glColor3f(*self.colors['straight_feed'])        self.draw_lines(self.feed, for_selection, len(self.traverse))        glColor3f(*self.colors['arc_feed'])        self.draw_lines(self.arcfeed, for_selection, len(self.traverse) + len(self.feed))        glLineWidth(2)        self.draw_dwells(self.dwells, for_selection, len(self.traverse) + len(self.feed) + len(self.arcfeed))        glLineWidth(1)    def next_line(self, st):        self.state = st        lineno = self.lineno = st.sequence_number        self.progress.update(lineno)    def get_tool(self, tool):        for t in s.tool_table:            if t[0] == tool:                return tuple(t)        return tool,0.,0.,0.,0.,0.,0    def get_external_angular_units(self):        return s.angular_units or 1.0    def get_external_length_units(self):        return s.linear_units or 1.0    def get_axis_mask(self):        return s.axis_maskprogress_re = re.compile("^FILTER_PROGRESS=(\\d*)$")def filter_program(program_filter, infilename, outfilename):    import subprocess    outfile = open(outfilename, "w")    env = dict(os.environ)    env['AXIS_PROGRESS_BAR'] = '1'    p = subprocess.Popen([program_filter, infilename], stdin=subprocess.PIPE,                        stdout=outfile, stderr=subprocess.PIPE, env=env)    p.stdin.close()  # No input for you    progress = Progress(1, 100)    progress.set_text(_("Filtering..."))    stderr_text = []    try:        while p.poll() is None: # XXX add checking for abort            t.update()            r,w,x = select.select([p.stderr], [], [], 0.100)            if r:                stderr_line = p.stderr.readline()                m = progress_re.match(stderr_line)                if m:                    progress.update(int(m.group(1)), 1)                else:                    stderr_text.append(stderr_line)                    sys.stderr.write(stderr_line)        # .. might be something left on stderr        for line in p.stderr:            m = progress_re.match(line)            if not m:                stderr_text.append(line)                sys.stderr.write(line)        return p.returncode, "".join(stderr_text)    finally:        progress.done()def get_filter(filename):    ext = os.path.splitext(filename)[1]    if ext:        return inifile.find("FILTER", ext[1:])    else:        return Noneloaded_file = Nonedef open_file_guts(f, filtered = False):    if not filtered:        global loaded_file        loaded_file = f        program_filter = get_filter(f)        if program_filter:            tempfile = os.path.join(tempdir, os.path.basename(f))            exitcode, stderr = filter_program(program_filter, f, tempfile)            if exitcode:                root_window.tk.call("nf_dialog", (".error", "-ext", stderr),                        _("Filter failed"),                        _("The program %r exited with code %d.  "                        "Any error messages it produced are shown below:")                            % (program_filter, exitcode),                        "error",0,_("OK"))                return            return open_file_guts(tempfile, True)    set_first_line(0)    t0 = time.time()    canon = None    try:        # be sure to switch modes to cause an interp synch, which        # writes out the var file.  there was a reset here, and that        # causes a var file write, but nukes important settings like        # TLO.        ensure_mode(emc.MODE_MDI)        ensure_mode(emc.MODE_AUTO)        c.wait_complete()        c.program_open(f)        lines = open(f).readlines()        progress = Progress(4, len(lines))         t.configure(state="normal")        t.tk.call("delete_all", t)        code = []        i = 0        for i, l in enumerate(lines):            l = l.expandtabs().replace("\r", "")            #t.insert("end", "%6d: " % (i+1), "lineno", l)            code.extend(["%6d: " % (i+1), "lineno", l, ""])            if i % 1000 == 0:                t.insert("end", *code)                del code[:]                progress.update(i)        if code:            t.insert("end", *code)        progress.nextphase(len(lines))        f = os.path.abspath(f)        o.g = canon = AxisCanon(o, widgets.text, i, progress)        parameter = inifile.find("RS274NGC", "PARAMETER_FILE")        temp_parameter = os.path.join(tempdir, os.path.basename(parameter))        shutil.copy(parameter, temp_parameter)        canon.parameter_file = temp_parameter        initcode = inifile.find("EMC", "RS274NGC_STARTUP_CODE") or ""        unitcode = "G%d" % (20 + (s.linear_units == 1))        try:            result, seq = gcode.parse(f, canon, unitcode, initcode)        except KeyboardInterrupt:            result, seq = 0, 0        # According to the documentation, MIN_ERROR is the largest value that is        # not an error.  Crazy though that sounds...        if result > gcode.MIN_ERROR:            error_str = r_(gcode.strerror(result))            root_window.tk.call("nf_dialog", ".error",                    _("G-Code error in %s") % os.path.basename(f),                    _("Near line %d of %s:\n%s") % (seq, f, error_str),                    "error",0,_("OK"))        t.configure(state="disabled")        canon.calc_extents()        canon.calc_notool_extents()        make_main_list(canon)        make_selection_list(canon)    finally:        # Before unbusying, I update again, so that any keystroke events        # that reached the program while it was busy are sent to the        # label, not to another window in the application.  If this        # update call is removed, the events are only handled after that        # widget is destroyed and focus has passed to some other widget,        # which will handle the keystrokes instead, leading to the        # R-while-loading bug.        #print "load_time", time.time() - t0        root_window.update()        root_window.tk.call("destroy", ".info.progress")        root_window.tk.call("grab", "release", ".info.progress")        if canon:            canon.progress = DummyProgress()        try:            progress.done()        except UnboundLocalError:            pass        o.tkRedraw()        root_window.tk.call("set_mode_from_tab")tabs_mdi = str(root_window.tk.call("set", "_tabs_mdi"))tabs_manual = str(root_window.tk.call("set", "_tabs_manual"))pane_top = str(root_window.tk.call("set", "pane_top"))pane_bottom = str(root_window.tk.call("set", "pane_bottom"))widgets = nf.Widgets(root_window,     ("help_window", Toplevel, ".keys"),    ("about_window", Toplevel, ".about"),    ("text", Text, pane_bottom + ".t.text"),    ("preview_frame", Frame, pane_top + ".preview"),    ("mdi_history", Listbox, tabs_mdi + ".history"),    ("mdi_command", Entry, tabs_mdi + ".command"),    ("code_text", Text, tabs_mdi + ".gcodes"),    ("axis_x", Radiobutton, tabs_manual + ".axes.axisx"),    ("axis_y", Radiobutton, tabs_manual + ".axes.axisy"),    ("axis_z", Radiobutton, tabs_manual + ".axes.axisz"),    ("axis_a", Radiobutton, tabs_manual + ".axes.axisa"),    ("axis_b", Radiobutton, tabs_manual + ".axes.axisb"),    ("axis_c", Radiobutton, tabs_manual + ".axes.axisc"),    ("axis_u", Radiobutton, tabs_manual + ".axes.axisu"),    ("axis_v", Radiobutton, tabs_manual + ".axes.axisv"),    ("axis_w", Radiobutton, tabs_manual + ".axes.axisw"),    ("jogincr", Entry, tabs_manual + ".jogf.jog.jogincr

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -