示例#1
0
 def support_coord_buttons(self):
     try:
         self.stat = linuxcnc.stat()
         self.stat.poll()
         has_x = False
         for axno in range(0,9):
             axname = 'XYZABCUVW'[axno]
             if self.label_to_btn.has_key(axname):
                 b = self.label_to_btn[axname]
                 if bool(self.stat.axis_mask & (1 << axno)):
                     b.show()
                     if axno == 0: has_x = True
                 else:
                     b.hide()
         bdiam = None
         if self.label_to_btn.has_key('D'):
             bdiam = self.label_to_btn['D']
         if bdiam and has_x:
             bdiam.show()
         elif bdiam:
             bdiam.hide()
     except linuxcnc.error,msg:
         self.stat = None
         if self.coord_buttons is not None:
             self.coord_buttons.hide()
             print "linuxcnc must be running to use coordinate keys"
示例#2
0
 def __init__(self, halcomp,widgets,paths):
     self.hal = halcomp
     self.w = widgets
     self.stat = linuxcnc.stat()
     self.cmnd = linuxcnc.command()
     self.error = linuxcnc.error_channel()
     self.PATHS = paths
     self.IMAGE_PATH = paths.IMAGEDIR
示例#3
0
 def __init__(self, bind='localhost', port=22617, verbose=False):
     self.server = None
     self.bind = bind
     self.port = port
     self.verbose = verbose
     
     self.s = linuxcnc.stat()
     self.c = linuxcnc.command()
示例#4
0
 def __init__(self):
     try:
         # emcIniFile = linuxcnc.ini(os.environ['INI_FILE_NAME'])
         # linuxcnc.nmlfile = os.path.join(os.path.dirname(os.environ['INI_FILE_NAME']), emcIniFile.find("EMC", "NML_FILE"))
         self.s = linuxcnc.stat();
         self.c = linuxcnc.command()
     except Exception, msg:
         print "cant initialize EmcInterface: %s - EMC not running?" %(msg)
示例#5
0
 def __init__(self, stat = None):
     gobject.GObject.__init__(self)
     self.stat = stat or linuxcnc.stat()
     self.old = {}
     try:
         self.stat.poll()
         self.merge()
     except:
         pass
     gobject.timeout_add(100, self.update)
示例#6
0
    def __init__(self, halcomp,builder,useropts):

	self.linuxcnc = linuxcnc.command()
	self.stat = linuxcnc.stat()
        self.halcomp = halcomp
        self.builder = builder
        
	
        
	self.vely = self.builder.get_object('hal_hscale1')
	self.velx = self.builder.get_object('hal_hscale2')
示例#7
0
 def set_line(self, w, l):
     linuxcncstat = linuxcnc.stat()
     linuxcncstat.poll()
     self.selected_line = l
     line = self.buf.get_iter_at_line(l)
     if not self.mark:
         self.mark = self.buf.create_source_mark('motion', 'motion', line)
         self.mark.set_visible(True)
     else:
         self.buf.move_mark(self.mark, line)
     self.scroll_to_mark(self.mark, 0, True, 0, 0.5)
示例#8
0
 def __init__(self, stat = None):
     gobject.GObject.__init__(self)
     self.stat = stat or linuxcnc.stat()
     self.cmd = linuxcnc.command()
     self.old = {}
     try:
         self.stat.poll()
         self.merge()
     except:
         pass
     gobject.timeout_add(100, self.update)
     self._current_jog_rate = 15
     self._is_all_homed = False
示例#9
0
    def __init__(self,toolfile=None, *a, **kw):
        super(ToolEdit, self).__init__()
        self.emcstat = linuxcnc.stat()
        self.hash_check = None 
        self.toolfile = toolfile
        self.num_of_col = 1
        self.font="sans 12"
        self.toolinfo_num = 0
        self.toolinfo = []
        self.wTree = gtk.Builder()
        self.wTree.set_translation_domain("linuxcnc") # for locale translations
        self.wTree.add_from_file(os.path.join(datadir, "tooledit_gtk.glade") )
        # connect the signals from Glade
        dic = {
            "on_delete_clicked" : self.delete,
            "on_add_clicked" : self.add,
            "on_reload_clicked" : self.reload,
            "on_save_clicked" : self.save,
            "cell_toggled" : self.toggled
            }
        self.wTree.connect_signals( dic )
        renderer = self.wTree.get_object("cell_toggle")
        renderer.set_property('activatable', True)
        # list of the columns
        self.objectlist = "s","t","p","x","y","z","a","b","c","u","v","w","d","i","j","q",";"
        # these signals include column data so must be made here instead of in Glade
        # for view 2
        self.cell_list = "cell_toggle","cell_tool#","cell_pos","cell_x","cell_y","cell_z","cell_a","cell_b",\
                            "cell_c","cell_u","cell_v","cell_w","cell_d",\
                            "cell_front","cell_back","cell_orient","cell_comments"
        for col,name in enumerate(self.cell_list):
            if col == 0:continue
            temp = self.wTree.get_object(name)
            temp.connect( 'edited', self.col_editted, col )
            temp.set_property('font', self.font)

        # global references
        self.model = self.wTree.get_object("liststore1")
        self.all_window = self.wTree.get_object("all_window")
        self.view2 = self.wTree.get_object("treeview2")
        self.view2.connect( 'button_press_event', self.on_treeview2_button_press_event )
        self.apply = self.wTree.get_object("apply")
        self.buttonbox = self.wTree.get_object("buttonbox")
        # reparent tooledit box from Glades tp level window to tooledit's VBox
        window = self.wTree.get_object("tooledit_box")
        window.reparent(self)
        # If the toolfile was specified when tooledit was created load it
        if toolfile:
            self.reload(None)
        # check linuxcnc status every second
        gobject.timeout_add(1000, self.periodic_check)
示例#10
0
    def __init__(self, command=None, status=None, error=None):
        """init docs"""
        self.command = command
        self.status = status
        self.error = error

        if not self.command:
            self.command = linuxcnc.command()

        if not self.status:
            self.status = linuxcnc.stat()

        if not self.error:
            self.error = linuxcnc.error_channel()
示例#11
0
    def __init__(self, inifile):
        self.inifile = linuxcnc.ini(inifile)
        [self.INI_FILE_PATH, x] = os.path.split( inifile )
        self.select_primed = None

        temp = self.inifile.find("DISPLAY", "LATHE")
        self.lathe_option = bool(temp == "1" or temp == "True" or temp == "true" )

        rs274.glcanon.GlCanonDraw.__init__(self, linuxcnc.stat(), None)
	live_axis_count = 0
	for i,j in enumerate("XYZABCUVW"):
	    if self.stat.axis_mask & (1<<i) == 0: continue
	    live_axis_count += 1
	self.num_joints = int(self.inifile.find("TRAJ", "JOINTS") or live_axis_count)
示例#12
0
def pre_home_jog():
	with open(pos_file) as fh:
		pos = pickle.load(fh)

	logging.info("last known pos l=%f r=%f" % (pos['l'], pos['r']))
	logging.info("safe home pos  l=%f r=%f" % (safe_home_pos['l'], safe_home_pos['r']))
	l_jog = safe_home_pos['l'] - pos['l']
	r_jog = safe_home_pos['r'] - pos['r'] 
	logging.info("jogging l=%f r=%f" % (l_jog, r_jog))
	com = linuxcnc.command()
	sta = linuxcnc.stat()
	velocity = 20
	com.jog(linuxcnc.JOG_INCREMENT, 0, velocity, l_jog)
	com.jog(linuxcnc.JOG_INCREMENT, 1, velocity, r_jog)
	com.wait_complete() 
示例#13
0
    def poll_linuxcnc(self):
        # FIXME: poll regularly but don't spam logs unlike now
        try:
            self.stat = linuxcnc.stat()
            self.stat.poll()
        except linuxcnc.error as e:
            self.error('Unable to poll linuxcnc, is it running?')
            self.error('Error message: {}'.format(e))
            return

        #self.stat.poll()
        inps = self.stat.interp_state

        if inps != self.last_interp_state:
            self.debug('Interpreter stage changed to {}'.format(INTERP_STATES[self.stat.interp_state]))
            self.last_interp_state = inps

        if self.state == 'BUSY' and self.stat.interp_state == linuxcnc.INTERP_IDLE:
            log.msg('now idle again')
            self.state = 'IDLE'

            self.serial = self.stat.echo_serial_number
            log.msg('Serial {}'.format(self.serial))

            cmd = self.ack_queue.get_nowait()
            if cmd.line <= self.serial:
                cmd.result = 'ok'
                if cmd.text.startswith('G38.2'):
                    if self.stat.probe_tripped:
                        cmd.result = 'Z: {}'.format(self.stat.probed_position[2])
                    else:
                        self.error('Probe not tripped')
                        cmd.result = 'error'

                reactor.callLater(0, cmd.d.callback, cmd)
                log.msg('acked cmd: {}'.format(cmd.text))
                self.try_tx()
            else:
                log.msg('not reached cmd: {}'.format(cmd.line))
                self.ack_queue.put(cmd)

        error = self.error_channel.poll()
        if error:
            kind, text = error
            if kind in (linuxcnc.NML_ERROR, linuxcnc.OPERATOR_ERROR):
                self.error(text)
            else:
                self.info(text)
示例#14
0
    def __init__(self, parent=None):
        super(OriginOffsetView, self).__init__(parent)
        self.setAlternatingRowColors(True)

        self.filename = INFO.PARAMETER_FILE
        self.axisletters = ["x", "y", "z", "a", "b", "c", "u", "v", "w"]
        self.linuxcnc = linuxcnc
        self.status = linuxcnc.stat()
        self.IS_RUNNING = False
        self.current_system = None
        self.current_tool = 0
        self.metric_display = False
        self.mm_text_template = '%10.3f'
        self.imperial_text_template = '%9.4f'
        self.setEnabled(False)
        self.table = self.createTable()
示例#15
0
 def __init__(self, master):
     global DBG_state
     DBG_state = master._dbg
     self.emc = linuxcnc
     self.emcstat = linuxcnc.stat()
     self.emccommand = linuxcnc.command()
     self.return_to_mode = -1 # if not -1 return to the mode specified
     self.sb = 0;
     self.jog_velocity = 100.0/60.0
     self.angular_jog_velocity = 3600/60
     self._mdi = 0
     self.isjogging = [0,0,0,0,0,0,0,0,0]
     self.restart_line_number = self.restart_reset_line = 0
     try:
         handlers,self.handler_module,self.handler_instance = \
         load_handlers([CONFIGDIR], self.emcstat, self.emccommand,self, master)
     except Exception, e:
         print e
    def __init__(self,filename=None, *a, **kw):
        super(OffsetPage, self).__init__()
        self.filename = filename
        self.status = linuxcnc.stat()
        self.display_units_mm=0
        self.machine_units_mm=0
        self.unit_convert=[1]*9
        self.font="sans 12"
        self.hidejointslist = []
        self.hidecollist = []
        self.wTree = gtk.Builder()
        self.wTree.add_from_file(os.path.join(datadir, "offsetpage.glade") )

        # global references
        self.model = self.wTree.get_object("liststore2")
        self.all_window = self.wTree.get_object("all_window")
        self.view2 = self.wTree.get_object("treeview2")

        # reparent tooledit box from Glades top level window to widgets VBox
        window = self.wTree.get_object("offsetpage_box")
        window.reparent(self)

        # check the ini file if UNITS are set to mm
        # first check the global settings
        # else then the X axis units
        try:
            self.inifile = self.emc.ini(INIPATH)
            units=self.inifile.find("TRAJ","LINEAR_UNITS")
            if units==None:
                units=self.inifile.find("AXIS_0","UNITS")
        except:
            units = "inch"

        # now setup the conversion array depending on the machine native units
        if units=="mm" or units=="metric" or units == "1.0":
            self.machine_units_mm=1
            self.conversion=[1.0/25.4]*3+[1]*3+[1.0/25.4]*3
        else:
            self.machine_units_mm=0
            self.conversion=[25.4]*3+[1]*3+[25.4]*3

        # check linuxcnc status every half second
        gobject.timeout_add(500, self.periodic_check)
示例#17
0
    def __init__(self, stat = None):
        gobject.GObject.__init__(self)
        self.stat = stat or linuxcnc.stat()
        self.cmd = linuxcnc.command()
        self.old = {}
        try:
            self.stat.poll()
            self.merge()
        except:
            pass

        self.current_jog_rate = 15
        self.current_angular_jog_rate = 360
        self.current_jog_distance = 0
        self.current_jog_distance_text =''
        self.current_jog_distance_angular= 0
        self.current_jog_distance_angular_text =''
        self.selected_axis = -1
        self._is_all_homed = False
        self.set_timer()
示例#18
0
    def __init__(self, halcomp,widgets,paths):
        self.hal = halcomp
        self.w = widgets
        self.stat = linuxcnc.stat()
        self.cmnd = linuxcnc.command()
        self.error = linuxcnc.error_channel()
        self.jog_velocity = 10.0
        self.PATH = paths.CONFIGPATH
        self.IMAGE_PATH = paths.IMAGEDIR
        #print paths.CONFIGPATH
        # connect to GStat to catch linuxcnc events
        STATUS.connect('state-estop', self.say_estop)
        STATUS.connect('state-on', self.on_state_on)
        STATUS.connect('state-off', self.on_state_off)
        STATUS.connect('jograte-changed', self.on_jograte_changed)
        STATUS.connect('periodic', self.on_periodic)

        # Read user preferences
        self.desktop_notify = PREFS.getpref('desktop_notify', True, bool)
        self.shutdown_check = PREFS.getpref('shutdown_check', True, bool)
示例#19
0
    def init_linuxcnc(self):
        self.stat = linuxcnc.stat()
        self.command = linuxcnc.command()
        self.error_channel = linuxcnc.error_channel()

        try:
            self.stat.poll()
        except linuxcnc.error as e:
            self.error('Unable to poll linuxcnc, is it running?')
            self.error('Error message: {}'.format(e))
            return

        self.serial = self.stat.echo_serial_number
        self.cmd_serial = self.serial + 1
        self.error_channel.poll()

        self.last_interp_state = self.stat.interp_state

        self.poll_task = task.LoopingCall(self.poll_linuxcnc)
        self.poll_task.start(0.1)
        self.state = 'READY'
示例#20
0
    def __init__(self, halcomp,builder,useropts):
        self.halcomp = halcomp
        self.builder = builder

        (directory,filename) = os.path.split(__file__)
        (basename,extension) = os.path.splitext(filename)
        self.ini_filename = os.path.join(directory,basename + '.ini')
        self.defaults = {  IniFile.vars: { },
                           IniFile.widgets: widget_defaults(select_widgets(self.builder.get_objects(),
                                                                           hal_only=True,output_only = True)),
                                                                           }
        self.ini = IniFile(self.ini_filename,self.defaults, self.builder)
        self.ini.restore_state(self)

        self.c = linuxcnc.command()
        self.e = linuxcnc.error_channel()
        self.s = linuxcnc.stat()

        self.state = hal_glib.GPin(halcomp.newpin('state', hal.HAL_S32, hal.HAL_IN))
        self.state.connect('value-changed', self._on_state_changed)

        self.motion_type  = hal_glib.GPin(halcomp.newpin('motion_type', hal.HAL_S32, hal.HAL_IN))
        self.motion_type.connect('value-changed', self._on_motion_type_changed)
示例#21
0
 def __init__(self):
     self.c = linuxcnc.command()
     self.e = linuxcnc.error_channel()
     self.s = linuxcnc.stat()
示例#22
0
    def __init__(self, joint_number=0):
        super(Combi_DRO, self).__init__()

        # we have to distinguish this, as we use the joints number to check homing
        # and we do need the axis to check for the positions
        # this is needed if non trivial kinematics are used or just a lathe,
        # as the lathe has only two joints, but Z will be the third value in position feedback
        self.axis_no = self.joint_number = joint_number

        # get the necessary connections to linuxcnc
        self.linuxcnc = linuxcnc
        self.status = linuxcnc.stat()
        self.gstat = GStat()
        # set some default values'
        self._ORDER = ["Rel", "Abs", "DTG"]
        self.system = "Rel"
        self.homed = False
        self.homed_color = "#00FF00"
        self.unhomed_color = "#FF0000"
        self.abs_color = "#0000FF"
        self.rel_color = "#000000"
        self.dtg_color = "#FFFF00"
        self.mm_text_template = "%10.3f"
        self.imperial_text_template = "%9.4f"
        self.font_size = 25
        self.metric_units = True
        self.machine_units = _MM
        self.unit_convert = 1
        self._auto_units = True
        self.toggle_readout = True
        self.cycle_time = 150
        self.diameter = False
        self.actual = True
        self.dtg = 0
        self.abs_pos = 0
        self.rel_pos = 0

        self.widgets = {}  # will hold all our widgets we need to style

        # Make the GUI and connect signals

        self.css_text = """
                        .background  {background-color: #000000;}
                        .labelcolor  {color: #FF0000;}
                        .size_big    {font-size: 25px;font-weight: bold;}
                        .size_small  {font-size: 10px;font-weight: bold;}
                        """

        self.css = Gtk.CssProvider()
        self.css.load_from_data(bytes(self.css_text, 'utf-8'))

        eventbox = Gtk.EventBox()
        eventbox.get_style_context().add_provider(
            self.css, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
        eventbox.get_style_context().add_class('background')
        self.add(eventbox)
        vbox_main = Gtk.VBox(homogeneous=False, spacing=0)
        eventbox.add(vbox_main)
        hbox_up = Gtk.HBox(homogeneous=False, spacing=5)
        vbox_main.pack_start(hbox_up, True, True, 0)
        self.widgets["eventbox"] = eventbox

        lbl_axisletter = Gtk.Label(label=_AXISLETTERS[self.axis_no])
        lbl_axisletter.get_style_context().add_provider(
            self.css, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
        lbl_axisletter.get_style_context().add_class('background')
        lbl_axisletter.get_style_context().add_class('labelcolor')
        lbl_axisletter.get_style_context().add_class('size_big')
        hbox_up.pack_start(lbl_axisletter, False, False, 0)
        self.widgets["lbl_axisletter"] = lbl_axisletter

        vbox_ref_type = Gtk.VBox(homogeneous=False, spacing=0)
        hbox_up.pack_start(vbox_ref_type, False, False, 0)
        # This label is needed to press the main index (rel,Abs;Dtg) to the upper part
        lbl_space = Gtk.Label(label="")
        vbox_ref_type.pack_start(lbl_space, True, True, 0)

        lbl_sys_main = Gtk.Label(label=self.system)
        lbl_sys_main.get_style_context().add_provider(
            self.css, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
        lbl_sys_main.get_style_context().add_class('background')
        lbl_sys_main.get_style_context().add_class('labelcolor')
        lbl_sys_main.get_style_context().add_class("size_small")
        vbox_ref_type.pack_start(lbl_sys_main, False, False, 0)
        self.widgets["lbl_sys_main"] = lbl_sys_main

        main_dro = Gtk.Label(label="9999.999")
        main_dro.get_style_context().add_provider(
            self.css, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
        main_dro.get_style_context().add_class('background')
        main_dro.get_style_context().add_class('labelcolor')
        main_dro.get_style_context().add_class("size_big")
        main_dro.set_xalign(1.0)
        hbox_up.pack_start(main_dro, True, True, 0)
        self.widgets["main_dro"] = main_dro

        hbox_down = Gtk.HBox(homogeneous=True, spacing=5)
        vbox_main.pack_start(hbox_down, False, False, 0)

        lbl_sys_left = Gtk.Label(label="Abs")
        lbl_sys_left.set_xalign(0.0)
        lbl_sys_left.get_style_context().add_provider(
            self.css, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
        lbl_sys_left.get_style_context().add_class('background')
        lbl_sys_left.get_style_context().add_class('labelcolor')
        lbl_sys_left.get_style_context().add_class('size_small')
        hbox_down.pack_start(lbl_sys_left, True, True, 0)
        self.widgets["lbl_sys_left"] = lbl_sys_left

        dro_left = Gtk.Label(label="-11.111")
        dro_left.get_style_context().add_provider(
            self.css, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
        dro_left.get_style_context().add_class('background')
        dro_left.get_style_context().add_class('labelcolor')
        dro_left.get_style_context().add_class('size_small')
        dro_left.set_xalign(1.0)
        hbox_down.pack_start(dro_left, True, True, 0)
        self.widgets["dro_left"] = dro_left

        lbl_sys_right = Gtk.Label(label="DTG")
        lbl_sys_right.set_xalign(0.0)
        lbl_sys_right.get_style_context().add_provider(
            self.css, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
        lbl_sys_right.get_style_context().add_class('background')
        lbl_sys_right.get_style_context().add_class('labelcolor')
        lbl_sys_right.get_style_context().add_class('size_small')
        hbox_down.pack_start(lbl_sys_right, False, False, 0)
        self.widgets["lbl_sys_right"] = lbl_sys_right

        dro_right = Gtk.Label(label="22.222")
        dro_right.get_style_context().add_provider(
            self.css, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
        dro_right.get_style_context().add_class('background')
        dro_right.get_style_context().add_class('labelcolor')
        dro_right.get_style_context().add_class('size_small')
        dro_right.set_xalign(1.0)
        hbox_down.pack_start(dro_right, True, True, 0)
        self.widgets["dro_right"] = dro_right

        eventbox.connect("button_press_event", self._on_eventbox_clicked)

        self.show_all()

        self.gstat.connect('not-all-homed', self._not_all_homed)
        self.gstat.connect('all-homed', self._all_homed)
        self.gstat.connect('homed', self._homed)
        self.gstat.connect('current-position', self._position)

        # This try is only needed because while working with glade
        # linuxcnc may not be working
        try:
            self.inifile = self.linuxcnc.ini(INIPATH)
            # check the ini file if UNITS are set to mm"
            # first check the global settings
            units = self.inifile.find("TRAJ", "LINEAR_UNITS")
            if units == None:
                # else then the X axis units
                units = self.inifile.find("AXIS_0", "UNITS")
        except:
            units = "inch"

        if units == "mm" or units == "metric" or units == "1.0":
            self.machine_units = _MM
        else:
            self.machine_units = _INCH
示例#23
0
 def __init__(self):
     self.c = linuxcnc.command()
     self.e = linuxcnc.error_channel()
     self.s = linuxcnc.stat()
示例#24
0
 def __init__(self):
     self.i = linuxcnc.ini(os.environ['INI_FILE_NAME'])
     self.c = linuxcnc.command()
     self.s = linuxcnc.stat()
     self.gui = self.i.find('DISPLAY', 'DISPLAY').lower()
     self.configFile = '{}_wizards.cfg'.format(self.i.find('EMC', 'MACHINE').lower())
示例#25
0
    def periodic_radiobuttons(self):
        self.radiobutton_mask = 1
        s = linuxcnc.stat()
        s.poll()
        # Show effect of external override inputs
        self.fo_val = s.feedrate * 100
        self.so_val = s.spindlerate * 100
        self.mv_val = s.max_velocity * 60
        am = s.axis_mask
        if not self.resized_wheelbuttons:
            at = self.wTree.get_widget("axis_table")
            for i in range(9):
                b = [
                    "wheelx", "wheely", "wheelz", "wheela", "wheelb", "wheelc",
                    "wheelu", "wheelv", "wheelw"
                ][i]
                w = self.wTree.get_widget(b)
                if not (am & (1 << i)):
                    at.remove(w)
            if (am & 0700) == 0:
                at.resize(3, 2)
                if (am & 070) == 0:
                    at.resize(3, 1)
                    self.wTree.get_widget("wheel_hbox").set_homogeneous(1)
            self.resized_wheelbuttons = 1

        self.wTree.get_widget("scrolling").set_sensitive(self.tab == 3)
        if self.tab != 3 and self.wheel == "scrolling":
            self.jogsettings_activate(0)
            self.wheel = "fo"

        set_active(self.wTree.get_widget("wheelx"), self.wheelxyz == 0)
        set_active(self.wTree.get_widget("wheely"), self.wheelxyz == 1)
        set_active(self.wTree.get_widget("wheelz"), self.wheelxyz == 2)
        set_active(self.wTree.get_widget("wheela"), self.wheelxyz == 3)
        set_active(self.wTree.get_widget("wheelb"), self.wheelxyz == 4)
        set_active(self.wTree.get_widget("wheelc"), self.wheelxyz == 5)
        set_active(self.wTree.get_widget("wheelu"), self.wheelxyz == 6)
        set_active(self.wTree.get_widget("wheelv"), self.wheelxyz == 7)
        set_active(self.wTree.get_widget("wheelw"), self.wheelxyz == 8)
        set_active(self.wTree.get_widget("wheelinc1"), self.wheelinc == 0)
        set_active(self.wTree.get_widget("wheelinc2"), self.wheelinc == 1)
        set_active(self.wTree.get_widget("wheelinc3"), self.wheelinc == 2)
        set_active(self.wTree.get_widget("fo"), self.wheel == "fo")
        set_active(self.wTree.get_widget("so"), self.wheel == "so")
        set_active(self.wTree.get_widget("mv"), self.wheel == "mv")
        set_active(self.wTree.get_widget("jogging"), self.wheel == "jogging")
        set_active(self.wTree.get_widget("scrolling"),
                   self.wheel == "scrolling")
        set_active(self.wTree.get_widget("pointer_show"),
                   not self.invisible_cursor)
        set_active(self.wTree.get_widget("pointer_hide"),
                   self.invisible_cursor)
        set_active(self.wTree.get_widget("toolset_workpiece"), not self.g10l11)
        set_active(self.wTree.get_widget("toolset_fixture"), self.g10l11)
        self.radiobutton_mask = 0

        if self.wheel == "jogging":
            self.hal.jogaxis(self.wheelxyz)
        else:
            # disable all
            self.hal.jogaxis(-1)

        if self.wheel == "scrolling":
            incs = ["100", "10", "1"]
        elif self.wheelxyz == 3 or self.wheelxyz == 4 or self.wheelxyz == 5:
            incs = ["1.0", "0.1", "0.01"]
        elif self.machine_units_mm:
            incs = ["0.1", "0.01", "0.001"]
        else:
            incs = ["0.01", "0.001", "0.0001"]

        set_label(self.wTree.get_widget("wheelinc1").child, incs[0])
        set_label(self.wTree.get_widget("wheelinc2").child, incs[1])
        set_label(self.wTree.get_widget("wheelinc3").child, incs[2])

        self.hal.jogincrement(self.wheelinc, map(float, incs))

        d = self.hal.wheel()
        if self.wheel == "fo":
            self.fo_val += d
            if self.fo_val < 0: self.fo_val = 0
            if d != 0: self.linuxcnc.feed_override(self.fo_val)

        if self.wheel == "so":
            self.so_val += d
            if self.so_val < 0: self.so_val = 0
            if d != 0: self.linuxcnc.spindle_override(self.so_val)

        if self.wheel == "mv":
            if self.machine_units_mm:
                self.mv_val += 20 * d
            else:
                self.mv_val += d
            if self.mv_val < 0: self.mv_val = 0
            if d != 0:
                self.linuxcnc.max_velocity(self.mv_val)
                self.linuxcnc.continuous_jog_velocity(self.mv_val)

        if self.wheel == "scrolling":
            d0 = d * 10**(2 - self.wheelinc)
            if d != 0: self.listing.next(None, d0)
        set_label(self.wTree.get_widget("fo").child, "FO: %d%%" % self.fo_val)
        set_label(self.wTree.get_widget("so").child, "SO: %d%%" % self.so_val)
        set_label(self.wTree.get_widget("mv").child, "MV: %d" % self.mv_val)

        return True
示例#26
0
    def __init__(self, *a, **kw):
        self.linuxcnc = linuxcnc.command()
        self.stat = linuxcnc.stat()
        settings = gtk.settings_get_default()
        settings.props.gtk_button_images = True

        opt, optl = "U:c:x:i:t", ["catalog=", "ini="]
        optlist, args = getopt.getopt(sys.argv[1:], opt, optl)
        optlist = dict(optlist)
        if "-U" in optlist:
            optlist_, args = getopt.getopt(optlist["-U"].split(), opt, optl)
            optlist.update(optlist_)
        self.catalog_src = "catalogs/mill.xml"

        if "-t" in optlist:
            # get translations and exit
            self.get_translations()
            sys.exit()

        if "--catalog" in optlist:
            self.catalog_src = optlist["--catalog"]
        ini = os.getenv("INI_FILE_NAME")
        if "-i" in optlist:
            ini = optlist["-i"]
        if "--ini" in optlist:
            ini = optlist["--ini"]

        global SUBROUTINES_PATH
        global PROGRAM_PREFIX
        SUBROUTINES_PATH = ""
        PROGRAM_PREFIX = ""
        try:
            inifile = linuxcnc.ini(ini)
            try:
                SUBROUTINES_PATH = inifile.find("RS274NGC", "SUBROUTINE_PATH") or ""
            except:
                print _("Warning! There's no SUBROUTINES_PATH in ini file!")

            try:
                PROGRAM_PREFIX = inifile.find("DISPLAY", "PROGRAM_PREFIX") or ""
                # Support relative paths based on the ini file location
                if not os.path.isabs(PROGRAM_PREFIX):
                    PROGRAM_PREFIX = os.path.normpath(os.path.join(ini, PROGRAM_PREFIX))
            except:
                print _("Warning! There's no PROGRAM_PREFIX in ini file!")
        except:
            print _("Warning! Problem while loading ini file!")

        self.config_src = ""
        if ini != "" and ini != None:
            self.config_src = os.path.dirname(ini)
        self.config_src += "/features.conf"

        self.config = ConfigParser.ConfigParser()
        self.config.read(self.config_src)

        if len(SUBROUTINES_PATH) > 0 and SUBROUTINES_PATH[-1] != ":":
            SUBROUTINES_PATH += ":"
        SUBROUTINES_PATH += os.path.abspath(os.path.dirname(__file__)) + "/subroutines:"
        self.file_dialogs_folder = SUBROUTINES_PATH.split(":")[0]

        gtk.VBox.__init__(self, *a, **kw)
        self.undo_list = []
        self.undo_pointer = 0

        self.glade = gtk.Builder()
        self.glade.add_from_file(os.path.join(os.path.abspath(os.path.dirname(__file__)), "features.glade"))
        self.main_box = self.glade.get_object("FeaturesBox")
        self.glade.connect_signals(self)
        self.timeout = None
        # create features catalog
        if search_path(SUBROUTINES_PATH, self.catalog_src) == None:
            print _("Error! Fatal! Cannot find features catalog %(src)s at %(path)s!") % {
                "src": self.catalog_src,
                "path": SUBROUTINES_PATH,
            }
            sys.exit()
        self.catalog_src = search_path(SUBROUTINES_PATH, self.catalog_src)
        xml = etree.parse(self.catalog_src)

        self.catalog = xml.getroot()
        self.catalog_path = self.catalog

        self.add_iconview = gtk.IconView()
        self.icon_store = gtk.ListStore(gtk.gdk.Pixbuf, str, str, str, int)
        self.add_iconview.set_model(self.icon_store)
        self.add_iconview.set_pixbuf_column(0)
        self.add_iconview.set_text_column(2)
        self.add_iconview.connect("item-activated", self.catalog_activate)

        self.update_catalog(xml=self.catalog_path)
        parent = self.main_box.get_toplevel()
        self.add_dialog = gtk.Dialog(
            _("Add feature"), parent, gtk.RESPONSE_CANCEL or gtk.DIALOG_MODAL, (gtk.STOCK_CLOSE, gtk.RESPONSE_REJECT)
        )

        self.add_dialog.set_transient_for(parent)
        scroll = gtk.ScrolledWindow()
        scroll.add_with_viewport(self.add_iconview)
        self.add_dialog.vbox.pack_start(scroll)

        hbox = gtk.HBox()
        button = gtk.Button(_("Catalog root"))
        button.connect("clicked", self.update_catalog, self.catalog)
        hbox.pack_start(button)
        button = gtk.Button(_("Upper level"))
        button.connect("clicked", self.update_catalog, "parent")
        hbox.pack_start(button)
        self.add_dialog.vbox.pack_start(hbox, False)

        self.add_dialog.show_all()
        self.add_dialog.set_size_request(700, 500)
        self.add_dialog.hide()

        self.get_features()

        # setup topfeatures toolbar
        try:
            topfeatures = self.config.get("VAR", "topfeatures", raw=True)
        except:
            topfeatures = ""
        self.ini = {"top-features": 3, "last-features": 10}

        for i in self.ini:
            try:
                s = self.config.get("FEATURES", i.lower(), raw=True)
                self.ini[i] = int(s)
            except:
                pass
        topfeatures = topfeatures.split("\n")
        self.topfeatures_dict = {}
        for s in topfeatures:
            s = s.split("\t")
            if len(s) == 3:
                self.topfeatures_dict[s[0]] = [int(s[1]), float(s[2])]

        feature_list = [s.get("src") for s in self.catalog.findall(".//sub") if "src" in s.keys()]
        self.topfeatures_toolbar = self.glade.get_object("topfeatures")
        self.block_toptoolbar = False
        # self.topfeatures_toolbar.connect("expose-event", self.block_expose)
        self.topfeatures = {}
        self.topfeatures_buttons = {}
        self.topfeatures_topbuttons = {}

        for src in feature_list:
            try:
                f = Feature(src)
                icon = gtk.Image()  # icon widget
                icon.set_from_pixbuf(f.get_icon())
                button = gtk.ToolButton(icon, label=_(f.get_attr("name")))
                button.set_tooltip_markup(_(f.get_attr("name")))
                button.connect("clicked", self.topfeatures_click, src)
                self.topfeatures_buttons[src] = button

                icon = gtk.Image()  # icon widget
                icon.set_from_pixbuf(f.get_icon())
                button1 = gtk.ToolButton(icon, label=_(f.get_attr("name")))
                button1.set_tooltip_markup(_(f.get_attr("name")))
                button1.connect("clicked", self.topfeatures_click, src)
                self.topfeatures_topbuttons[src] = button1

                self.topfeatures[src] = [button, button1, 0, 0]
                if src in self.topfeatures_dict:
                    self.topfeatures[src][2:] = self.topfeatures_dict[src]
            except:
                pass
        self.topfeatures_update()

        self.help_viewport = self.glade.get_object("help_viewport")
        self.help_image = self.glade.get_object("feature_image")
        self.help_text = self.glade.get_object("feature_help")

        # self.add_container = self.glade.get_object("add_feature_container")
        # self.add_container.add_with_viewport(self.add_iconview)

        # create treeview
        self.treeview = self.glade.get_object("treeview1")
        self.treestore = gtk.TreeStore(object, str)
        self.treeview.set_model(self.treestore)
        self.treeview.set_tooltip_column(1)

        self.cols = {}
        col = gtk.TreeViewColumn(_("Name"))
        # icons
        cell = gtk.CellRendererPixbuf()
        col.pack_start(cell, expand=False)
        col.set_cell_data_func(cell, self.get_col_icon)
        # name
        cell = gtk.CellRendererText()
        col.pack_start(cell, expand=False)
        col.set_cell_data_func(cell, self.get_col_name)
        col.set_resizable(True)
        self.treeview.append_column(col)
        self.cols["name"] = col

        # value
        col = gtk.TreeViewColumn(_("Value"))
        cell = gtk.CellRendererText()
        cell.set_property("editable", True)
        cell.connect("edited", self.edit_value)
        col.pack_start(cell, expand=False)
        col.set_cell_data_func(cell, self.get_col_value, ["string", "float", "int", "bool"])
        self.cell_value = cell
        self.col_value = col

        col.set_resizable(True)
        self.treeview.append_column(col)
        self.cols["value"] = col

        self.treeview.connect("cursor-changed", self.show_help, self.treeview)
        self.treeview.connect("key_press_event", self.treeview_keypress)
        self.treeview.connect("key-release-event", self.treeview_release)

        button = self.glade.get_object("save")
        button.connect("clicked", self.save)
        button = self.glade.get_object("open")
        button.connect("clicked", self.load)
        button = self.glade.get_object("import")
        button.connect("clicked", self.import_file)

        button = self.glade.get_object("to_file")
        button.connect("clicked", self.to_file)
        button = self.glade.get_object("undo")
        button.connect("clicked", self.undo)
        button = self.glade.get_object("redo")
        button.connect("clicked", self.redo)
        button = self.glade.get_object("add")
        button.connect("clicked", self.add)
        button = self.glade.get_object("remove")
        button.connect("clicked", self.remove)
        button = self.glade.get_object("refresh")
        button.connect("clicked", self.refresh)

        button = self.glade.get_object("copy")
        button.connect("clicked", self.copy)
        button = self.glade.get_object("up")
        button.connect("clicked", self.move, -1)
        button = self.glade.get_object("down")
        button.connect("clicked", self.move, 2)
        button = self.glade.get_object("indent")
        button.connect("clicked", self.indent)
        button = self.glade.get_object("unindent")
        button.connect("clicked", self.unindent)

        self.main_box.reparent(self)
        self.main_box.show_all()

        self.autorefresh = self.glade.get_object("autorefresh")
        self.autorefresh_timeout = self.glade.get_object("autorefresh_timeout")
        if self.autorefresh_timeout.get_value() == 0:
            self.autorefresh_timeout.set_value(1)  # hack to glade default value=0 bug
        paned = self.glade.get_object("vpaned2")
        w, h = paned.get_size_request()
        paned.set_size_request(w, 500)
        w, h = paned.get_size_request()
        paned.set_position(max(300, h - 200))

        w, h = self.treeview.get_size_request()
        self.treeview.set_size_request(w, 200)
        w, h = self.help_viewport.get_size_request()
        self.help_viewport.set_size_request(w, 100)

        if search_path(SUBROUTINES_PATH, "defaults.ngc") != None:
            self.defaults = open(search_path(SUBROUTINES_PATH, "defaults.ngc")).read()
        else:
            print _("Warning defaults.ngc was not found in path %s!") % SUBROUTINES_PATH
        self.load(filename=search_path(SUBROUTINES_PATH, "template.xml"))

        self.treeview.connect("destroy", self.delete)
 def __init__(self):
     try:
         self.s = linuxcnc.stat();
         self.c = linuxcnc.command()
     except Exception, msg:
         print "cant initialize EmcInterface: %s - EMC not running?" %(msg)
示例#28
0
    def __init__(self, joint_number=0):
        super(Combi_DRO, self).__init__()

        # get the necesarry connextions to linuxcnc
        self.joint_number = joint_number
        self.linuxcnc = linuxcnc
        self.status = linuxcnc.stat()

        # set some default values'
        self._ORDER = ["Rel", "Abs", "DTG"]
        self.system = "Rel"
        self.homed = False
        self.homed_color = gtk.gdk.Color("green")
        self.unhomed_color = gtk.gdk.Color("red")
        self.abs_color = gtk.gdk.Color("blue")
        self.rel_color = gtk.gdk.Color("black")
        self.dtg_color = gtk.gdk.Color("yellow")
        self.mm_text_template = "%10.3f"
        self.imperial_text_template = "%9.4f"
        self.font_size = 25
        self.metric_units = True
        self.machine_units = _MM
        self.unit_convert = 1
        self._auto_units = True

        # Make the GUI and connect signals
        self.eventbox = gtk.EventBox()
        self.eventbox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse("black"))
        self.add(self.eventbox)
        vbox_main = gtk.VBox(False, 0)
        self.eventbox.add(vbox_main)
        hbox_up = gtk.HBox(False, 0)
        vbox_main.pack_start(hbox_up)
        attr = self._set_attributes((0, 0, 0), (65535, 0, 0),
                                    (self.font_size * 1000, 0, -1),
                                    (600, 0, -1))
        self.lbl_axisletter = gtk.Label(_AXISLETTERS[self.joint_number])
        self.lbl_axisletter.set_attributes(attr)
        hbox_up.pack_start(self.lbl_axisletter, False, False)
        vbox_ref_type = gtk.VBox(False, 0)
        hbox_up.pack_start(vbox_ref_type, False, False)
        lbl_space = gtk.Label("")
        vbox_ref_type.pack_start(lbl_space)
        attr = self._set_attributes((0, 0, 0), (65535, 0, 0),
                                    (int(self.font_size * 1000 / 2.5), 0, -1),
                                    (600, 0, -1))
        self.lbl_sys_main = gtk.Label(self.system)
        vbox_ref_type.pack_start(self.lbl_sys_main, False, False)
        self.lbl_sys_main.set_attributes(attr)
        self.main_dro = gtk.Label("9999.999")
        hbox_up.pack_start(self.main_dro)
        self.main_dro.set_alignment(1.0, 0.5)
        attr = self._set_attributes((0, 0, 0), (65535, 0, 0),
                                    (self.font_size, 0, -1), (600, 0, -1))
        self.main_dro.set_attributes(attr)
        hbox_down = gtk.HBox(False, 5)
        vbox_main.pack_start(hbox_down)
        self.lbl_sys_left = gtk.Label("Abs")
        hbox_down.pack_start(self.lbl_sys_left)
        attr = self._set_attributes((0, 0, 0), (65535, 0, 0),
                                    (int(self.font_size * 1000 / 2.5), 0, -1),
                                    (600, 0, -1))
        self.lbl_sys_left.set_attributes(attr)
        self.dro_left = gtk.Label("-11.111")
        hbox_down.pack_start(self.dro_left)
        self.dro_left.set_alignment(1.0, 0.5)
        self.dro_left.set_attributes(attr)
        self.lbl_sys_right = gtk.Label("DTG")
        hbox_down.pack_start(self.lbl_sys_right)
        self.lbl_sys_right.set_attributes(attr)
        self.dro_right = gtk.Label("22.222")
        hbox_down.pack_start(self.dro_right)
        self.dro_right.set_alignment(1.0, 0.5)
        self.dro_right.set_attributes(attr)

        self.eventbox.connect("button_press_event", self._on_eventbox_clicked)

        self.show_all()

        # add the timer at a period of 100 ms
        gobject.timeout_add(100, self._periodic)

        # This try is only needed because while working with glade
        # linuxcnc may not be working
        try:
            self.inifile = self.linuxcnc.ini(INIPATH)
            # check the ini file if UNITS are set to mm"
            # first check the global settings
            units = self.inifile.find("TRAJ", "LINEAR_UNITS")
            if units == None:
                # else then the X axis units
                units = self.inifile.find("AXIS_0", "UNITS")
        except:
            units = "inch"

        if units == "mm" or units == "metric" or units == "1.0":
            self.machine_units = _MM
        else:
            self.machine_units = _INCH
示例#29
0
def g733(self, **words):
    """ remap code G73.3 """
    p = int(words['p'])    
    q = int(words['q'])
    offset = float(words['k'])
    
    if words.has_key('s'):
        sspeed = int(words['s'])
        self.execute("S%d" % (sspeed))
    if words.has_key('l'): #только int ???
        offset_StartZ = int(words['l']) 
    only_finishing_cut = 0    
    if words.has_key('j'):
        only_finishing_cut = int(words['j'])
    quantity = 1    
    if words.has_key('i'):
        quantity = int(words['i'])
    if words.has_key('t'):
        R_Fanuc = float(words['t'])
    if words.has_key('f'):    
        fr = float(words['f'])
    if words.has_key('d'):
        d = float(words['d'])        

           
    s = linuxcnc.stat() 
    s.poll()
    filename = s.file
    f = open(filename, "r")
    lines = f.readlines()
    pr = []
    
    x=0
    while x < len(lines):
        # находим начальную точку цикла по X 
        if re.search(".*\s*G73.3", lines[x], re.I) and not re.search(".*\s*[(]", lines[x], re.I):
            t_Sx = x
            while not re.search(".*\s*X", lines[t_Sx], re.I) and t_Sx > 0:
                t_Sx -= 1
            ST_COORDx0 = float(re.search("X\s*([-0-9.]+)",lines[t_Sx], re.I).group(1))
            
        # находим начальную точку цикла по Z 
        if re.search(".*\s*G73.3", lines[x], re.I) and not re.search(".*\s*[(]", lines[x], re.I):
            t_Sz = x
            while not re.search(".*\s*Z", lines[t_Sz], re.I) and t_Sz > 0:
                t_Sz -= 1
            ST_COORDz0 = float(re.search("Z\s*([-0-9.]+)",lines[t_Sz], re.I).group(1))    
        x+=1    
    
    self.execute("G21 G18 G49 G40 G90 G61 G7 F1000")
    name_file = "./fgcode.ngc" 
    fgcode = open(name_file, "w") 
    string = 'G21 G18 G49 G40 G90 G61 G7 F1000 \n'
    string += 'T1 M6\n'
    string += 'G1 X-30 Z30\n'
    string += 'G1 X-25 Z35\n'#XXX
    if float(words['d'])<0 :
        string += 'G41\n' 
    else:
        string += 'G42\n'                            
    f.close()
    
    c_line2 = 0               
    for w in lines:
        if  re.search("^\s*[(]\s*N\d", w.upper()):
            if not re.search("[^\(\)\.\-\+NGZXRIKSF\d\s]", w.upper()):
                num2 = int(re.findall("^\s*\d*",(re.split('N',w.upper())[1]))[0])                
                if num2 == p: 
                    c_line2 = 1
        if c_line2:
            try: 
                contour=re.split('\)',(re.split('\(',w.upper())[1]))[0]
                string += contour
                string += '\n'
            except :
                print 'G700_error'
                return INTERP_ERROR
            if re.search("Z\s*([-0-9.]+)",w, re.I):
                end_cont_Z = float(re.search("Z\s*([-0-9.]+)",w, re.I).group(1))
            if re.search("X\s*([-0-9.]+)",w, re.I):   
                end_cont_X = float(re.search("X\s*([-0-9.]+)",w, re.I).group(1)) 
        if  re.search("^\s*[(]\s*N\d", w.upper()):
            if not re.search("[^\(\)\.\-\+NGZXRIKSF\d\s]", w.upper()):
                num2 = int(re.findall("^\s*\d*",(re.split('N',w.upper())[1]))[0])
                if num2 == q: 
                    c_line2 = 0    
    
    string += 'G40\n'
    self.execute("G40")
    string += 'M30\n'
    fgcode.write(string)
    outfilename  = "./RS274_temp.txt"
    outfile = open(outfilename, "w")    
    fgcode.close() 
    offset = offset/12.7
    offset_mem = offset
#============================================================================    
    for i in range(quantity):
        tfile  = "./rs.tbl"
        setline = open(tfile ,"w")
        offs = ' '.join(['\n','T1','P1','X0','Z0','D%s' % (str(offset_mem))])
        setline.write(offs)
        setline.close()
     
        p = subprocess.Popen(["sh", "-c", (' '.join(['./rs274','-t',tfile,'-g',name_file,outfilename]))],
                          stdin=None,
                          stdout=None,
                          stderr=None )
        p.wait()                
        outfile.close()                      
        
        f1 = open(outfilename, "r")
        ln = f1.readlines()
        old_posX = 0
        old_posZ = 0   
        for w in ln:
            if  re.search("STRAIGHT_TRAVERSE", w.upper()):
                numbers = re.split('\(',w.upper())
                number = re.split('\,',numbers[1].upper())
                prog(pr,0,number[0],number[2])
                old_posX = float(number[0])
                old_posZ = float(number[2])             
            elif  re.search("STRAIGHT_FEED", w.upper()):
                numbers = re.split('\(',w.upper())
                number = re.split('\,',numbers[1].upper())
                x1=float(number[0])*2
                z1=float(number[2])
                prog(pr,1,x1,z1)
                old_posX = float(number[0])
                old_posZ = float(number[2])

            elif  re.search("ARC_FEED", w.upper()):
                numbers = re.split('\(',w.upper())
                number = re.split('\,',numbers[1].upper())
                if float(number[4])>0:
                    g=3
                elif float(number[4])<0:
                    g=2 
                x_arc=float(number[1])*2
                z_arc=float(number[0])
                arc_I = float(number[3]) - old_posX
                arc_K = float(number[2]) - old_posZ
                radius = round(hip(arc_I,arc_K),6)
                prog(pr,g,x_arc,z_arc,arc_I,arc_K)            
                old_posX = float(number[1])
                old_posZ = float(number[0])        
        f1.close() 
        
        explicit = 'ngc/explicit.ngc'
        expcode = open(explicit, "r")
        exp_lines = expcode.readlines()
        exp_string=''
        if len(exp_lines):
            for el in exp_lines:
                exp_string += el
            es1=exp_string.split('M02')[0]
            expcode = open(explicit, "w")
            expcode.write(es1)
            expcode = open(explicit, "a")
        else:
            expcode = open(explicit, "w")
        expcode.write("G21 G18 G49  G90 G61 G7\n")
        if words.has_key('f'):    
            fr = float(words['f'])
            expcode.write("F%f\n" % fr)        

        bounce_x = 0.5
        bounce_z = 0.5 
              
        print 'pr=', pr 
        print 'ST_COORDz0  G73=', ST_COORDz0 
        self.execute("G0  Z%f" % (ST_COORDz0))
        expcode.write("G0  Z%f\n" % (ST_COORDz0))
        for w in range(2,len(pr)):
            try:  
                self.execute(pr[w])
                expcode.write(pr[w])
                expcode.write("\n")
            except:
                print 'G733_error'
                return INTERP_ERROR     
        offset_mem -= offset/quantity
        pr = []
        
        #  завершающий отход (в зависимости : OD или ID)
        if words.has_key('d'):
            d = float(words['d'])
            if d<0:
                self.execute("G91")
                expcode.write("G91\n")
                self.execute("G0 X%f Z%f" % (-bounce_x,0.1))
                expcode.write("G0 X%f Z%f\n" % (-bounce_x,0.1))
                self.execute("G90")
                expcode.write("G90\n")
                self.execute("G0  Z0")
                expcode.write("G0 Z0\n")
            else:
                self.execute("G91")
                expcode.write("G91\n")                
                self.execute("G0 X%f Z%f" % (bounce_x,0.1))
                expcode.write("G0 X%f Z%f\n" % (bounce_x,0.1))
                self.execute("G90")
                expcode.write("G90\n")
                self.execute("G0  Z0")
                expcode.write("G0 Z0\n")
        expcode.write("M02\n")                
        expcode.close()   
    return INTERP_OK 
示例#30
0
def g720(self, **words):
    """ remap code G71.2 """
    p = int(words['p'])    
    q = int(words['q'])
    d = float(words['d'])
    offset = float(words['k'])
    
    if words.has_key('s'):
        sspeed = int(words['s'])
        self.execute("S%d" % (sspeed))
    if words.has_key('l'): #только int ???
        offset_StartZ = int(words['l']) 
    only_finishing_cut = 0    
    if words.has_key('j'):
        only_finishing_cut = int(words['j'])
    quantity = 1    
    if words.has_key('i'):
        quantity = int(words['i'])
    if words.has_key('t'):
        R_Fanuc = float(words['t'])

    if words.has_key('f'):    
        fr = float(words['f'])
        
    tfile  = "./rs.tbl"
    setline = open(tfile ,"w")
    offs = ' '.join(['\n','T1','P1','X0','Z0','D%s' % (str(offset/12.7))])
    setline.write(offs)
    setline.close() 
           
    s = linuxcnc.stat() 
    s.poll()
    filename = s.file
    f = open(filename, "r")
    lines = f.readlines()
    
    x=0
    c_line = 0
    while x < len(lines):
        # находим начальную точку цикла по X 
        if re.search(".*\s*G72", lines[x], re.I) and not re.search(".*\s*[(]", lines[x], re.I):
            t_Sx = x
            while not re.search(".*\s*X", lines[t_Sx], re.I) and t_Sx > 0:
                t_Sx -= 1
            ST_COORDx0 = float(re.search("X\s*([-0-9.]+)",lines[t_Sx], re.I).group(1))
            
        # находим начальную точку цикла по Z 
        if re.search(".*\s*G72", lines[x], re.I) and not re.search(".*\s*[(]", lines[x], re.I):
            t_Sz = x
            while not re.search(".*\s*Z", lines[t_Sz], re.I) and t_Sz > 0:
                t_Sz -= 1
            ST_COORDz0 = float(re.search("Z\s*([-0-9.]+)",lines[t_Sz], re.I).group(1))    
        x+=1

    self.execute("G21 G18 G49 G40 G90 G61 G7 F1000")
    name_file = "./fgcode.ngc" 
    fgcode = open(name_file, "w") 
    string = 'G21 G18 G49 G40 G90 G61 G7 F1000 \n'
    string += 'T1 M6\n'

    
    # добавляем в  контур "начальный отрезок"(обязательно), и "конечный"(опционально)
    for w in lines:
        if  re.search("^\s*[(]\s*N\d", w.upper()):
            if not re.search("[^\(\)\.\-\+NGZXRIK\d\s]", w.upper()):
                num2 = int(re.findall("^\s*\d*",(re.split('N',w.upper())[1]))[0])
                if num2 == p :
                    if re.search("X\s*([-0-9.]+)",w, re.I):
                        st_cont_X = float(re.search("X\s*([-0-9.]+)",w, re.I).group(1))
                if num2 >= p and num2 <= q:
                    if re.search("Z\s*([-0-9.]+)",w, re.I):
                        end_cont_Z = float(re.search("Z\s*([-0-9.]+)",w, re.I).group(1))

    string += 'G1 X-30 Z30\n'
    string += 'G1 X-25 Z35\n'
    string += 'G42\n'    
                     
    for w in lines:
        if  re.search("^\s*[(]\s*N\d", w.upper()):
            if not re.search("[^\(\)\.\-\+NGZXRIK\d\s]", w.upper()):
                num2 = int(re.findall("^\s*\d*",(re.split('N',w.upper())[1]))[0])
                if num2 >= p and num2 <= q:
                    try: 
                        contour=re.split('\)',(re.split('\(',w.upper())[1]))[0]
                        string += contour
                        string += '\n'
                    except:
                        return INTERP_ERROR                             
    f.close()

    string += 'G40\n'
    self.execute("G40")
    string += 'M30\n'
    fgcode.write(string)
    outfilename  = "./RS274_temp.txt"
    outfile = open(outfilename, "w")
    
    fgcode.close() 
    p = subprocess.Popen(["sh", "-c", (' '.join(['./rs274','-t',tfile,'-g',name_file,outfilename]))],
                      stdin=None,
                      stdout=outfile,
                      stderr=None )
    p.wait()                 
    outfile.close()
    P = []                      
    pr = []    
    f1 = open(outfilename, "r")
    ln = f1.readlines()
    old_posX = 0
    old_posZ = 0 
    i=-1   
    for w in ln:
        if  re.search("STRAIGHT_TRAVERSE", w.upper()):
            numbers = re.split('\(',w.upper())
            number = re.split('\,',numbers[1].upper())
            x1=float(number[0])*2
            z1=float(number[2])
            prog(pr,0,x1,z1)
            i+=1
            papp(i,0,x1,z1,old_posX,old_posZ,P)
            old_posX = float(number[0])
            old_posZ = float(number[2])            
        elif  re.search("STRAIGHT_FEED", w.upper()):
            numbers = re.split('\(',w.upper())
            number = re.split('\,',numbers[1].upper())
            x1=float(number[0])*2
            z1=float(number[2])
            prog(pr,1,x1,z1)
            i+=1
            papp(i,1,x1,z1,old_posX,old_posZ,P)
            old_posX = float(number[0])
            old_posZ = float(number[2])

        elif  re.search("ARC_FEED", w.upper()):
            numbers = re.split('\(',w.upper())
            number = re.split('\,',numbers[1].upper())
            if float(number[4])>0:
                g=3
            elif float(number[4])<0:
                g=2 
            x_arc=float(number[1])*2
            z_arc=float(number[0])
            arc_I = float(number[3]) - old_posX
            arc_K = float(number[2]) - old_posZ
            radius = round(hip(arc_I,arc_K),6)
            prog(pr,g,x_arc,z_arc,arc_I,arc_K)            
            i+=1
            papp(i,g,x_arc,z_arc,old_posX,old_posZ,P,radius,arc_I,arc_K)
            old_posX = float(number[1])
            old_posZ = float(number[0])

    # начало контура
    tmp1=[]
    tmp2=[] 
    for p in P: #XXX если дуга - добавлять точку максимума по X
       tmp1.append(p[1])
       tmp2.append(p[4])
                
    z_minim = min(tmp2)
    z_maxim = 5
    print 'z_minim=',z_minim,'z_maxim=',z_maxim
    A=[]
    bounce_x = 0.5
    bounce_z = 0.5
    #---------------------------------------------------ищем все точки пересечения
    
    h1=0
    while h1>=z_minim :
        for i in range(len(P)):          
            if i>2 and P[i][0]==1 :
                par=in_line_line_G72( P[i][3], P[i][4], P[i][1], P[i][2],   0 ,h1, 1000 ,h1,A)
            if i>2 and P[i][0]>1 :
                intersect_vertic(P[i][2],P[i][4],P[i][1],P[i][3],h1,P[i][7],P[i][6],P[i][5],A)    
        h1 = h1-(1*d)
        
    print 'P =', P ,'\n'
    print 'A =', A ,'\n'
    
    explicit = 'ngc/explicit.ngc'
    expcode = open(explicit, "r")
    exp_lines = expcode.readlines()
    exp_string=''
    if len(exp_lines):
        for el in exp_lines:
            exp_string += el
        es1=exp_string.split('M02')[0]
        expcode = open(explicit, "w")
        expcode.write(es1)
        expcode = open(explicit, "a")
    else:
        expcode = open(explicit, "w")
    expcode.write("G21 G18 G49  G90 G61 G7\n")
    if words.has_key('f'):    
        fr = float(words['f'])
        expcode.write("F%f\n" % fr)
    
    self.execute("G1 F1000  X%f Z%f" % (ST_COORDx0,0))
    expcode.write("G1 F1000  X%f Z%f\n" % (ST_COORDx0,0))
    for i in range(len(A)) :
        self.execute("G1 F1000  Z%f" % (A[i][1]))
        expcode.write("G1 F1000  Z%f\n" % (A[i][1]))
        
        self.execute("G1 F1000  X%f Z%f" % (A[i][0],A[i][1])) 
        expcode.write("G1 F1000  X%f Z%f\n" % (A[i][0],A[i][1])) 
                       
        self.execute("G1 F1000  X%f" % (ST_COORDx0))
        expcode.write("G1 F1000  X%f\n" % (ST_COORDx0))
        
    self.execute("G1 F1000  X%f" % (ST_COORDx0)) 
    expcode.write("G1 F1000  X%f\n" % (ST_COORDx0)) 
       
    self.execute("G0   Z0")
    expcode.write("G0   Z0\n")
    #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++GO            
    print 'pr=', pr 
    for w in range(2,len(pr)):
        try:  
            self.execute(pr[w])
            expcode.write(pr[w])
            expcode.write("\n")
        except :
            return INTERP_ERROR 
    
    self.execute("G1 F1000  X%f " % (ST_COORDx0))
    expcode.write("G1 F1000  X%f\n " % (ST_COORDx0))    
    self.execute("G0   Z0")
    expcode.write("G0   Z0\n") 
    expcode.write("M02\n")                             
    expcode.close()   
    return INTERP_OK 
示例#31
0
    def __init__(self, inifile):

        self.xwindow_id = None

        #self.set_has_alpha(True)
        #'set_has_stencil_buffer',
        glutInit()
        glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH)

        self.add_attribute(GLX.GLX_RGBA, True)
        self.add_attribute(GLX.GLX_RED_SIZE, 1)
        self.add_attribute(GLX.GLX_GREEN_SIZE, 1)
        self.add_attribute(GLX.GLX_BLUE_SIZE, 1)
        self.add_attribute(GLX.GLX_DOUBLEBUFFER, 1)

        xvinfo = GLX.glXChooseVisual(self.xdisplay,
                                     self.display.get_default_screen(),
                                     self.get_attributes())
        configs = GLX.glXChooseFBConfig(self.xdisplay, 0, None, byref(c_int()))
        self.context = GLX.glXCreateContext(self.xdisplay, xvinfo, None, True)

        #class Gremlin(gtk.gtkgl.widget.DrawingArea, glnav.GlNavBase,
        #              rs274.glcanon.GlCanonDraw):
        #    rotation_vectors = [(1.,0.,0.), (0., 0., 1.)]

        #    def __init__(self, inifile):
        #
        #        display_mode = ( gtk.gdkgl.MODE_RGB | gtk.gdkgl.MODE_DEPTH |
        #                         gtk.gdkgl.MODE_DOUBLE )
        #        glconfig = gtk.gdkgl.Config(mode=display_mode)

        #        gtk.gtkgl.widget.DrawingArea.__init__(self, glconfig)
        glnav.GlNavBase.__init__(self)

        def C(s):
            a = self.colors[s + "_alpha"]
            s = self.colors[s]
            return [int(x * 255) for x in s + (a, )]

        self.inifile = inifile
        self.logger = linuxcnc.positionlogger(linuxcnc.stat(),
                                              C('backplotjog'),
                                              C('backplottraverse'),
                                              C('backplotfeed'),
                                              C('backplotarc'),
                                              C('backplottoolchange'),
                                              C('backplotprobing'),
                                              self.get_geometry())
        _thread.start_new_thread(self.logger.start, (.01, ))

        rs274.glcanon.GlCanonDraw.__init__(self, linuxcnc.stat(), self.logger)

        self.current_view = 'z'

        self.select_primed = None

        self.connect_after('realize', self.realize)
        self.connect('configure_event', self.reshape)
        self.connect('map_event', self.map)
        self.connect('draw', self.expose)  # expose_event was deprecated
        self.connect('motion-notify-event', self.motion)
        self.connect('button-press-event', self.pressed)
        self.connect('button-release-event', self.select_fire)
        self.connect('scroll-event', self.scroll)

        self.add_events(Gdk.EventMask.POINTER_MOTION_MASK)
        self.add_events(Gdk.EventMask.POINTER_MOTION_HINT_MASK)
        #self.add_events(gdk.BUTTON_MOTION_MASK)
        #self.add_events(gdk.EventMask.BUTTON_PRESS_MASK)
        #self.add_events(gdk.BUTTON_RELEASE_MASK)
        self.add_events(Gdk.EventMask.BUTTON_MOTION_MASK)
        self.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)
        self.add_events(Gdk.EventMask.BUTTON_RELEASE_MASK)
        self.add_events(Gdk.EventMask.SCROLL_MASK)

        self.fingerprint = ()

        self.lat = 0
        self.minlat = -90
        self.maxlat = 90

        self.highlight_line = None
        self.program_alpha = False
        self.use_joints_mode = False
        self.use_commanded = True
        self.show_limits = True
        self.show_extents_option = True
        self.show_live_plot = True
        self.show_velocity = True
        self.metric_units = True
        self.show_program = True
        self.show_rapids = True
        self.use_relative = True
        self.show_tool = True
        self.show_dtg = True
        self.grid_size = 0.0
        temp = inifile.find("DISPLAY", "LATHE")
        self.lathe_option = bool(temp == "1" or temp == "True"
                                 or temp == "true")
        self.foam_option = bool(inifile.find("DISPLAY", "FOAM"))
        self.show_offsets = False
        self.use_default_controls = True
        self.mouse_btn_mode = 0

        self.a_axis_wrapped = inifile.find("AXIS_A", "WRAPPED_ROTARY")
        self.b_axis_wrapped = inifile.find("AXIS_B", "WRAPPED_ROTARY")
        self.c_axis_wrapped = inifile.find("AXIS_C", "WRAPPED_ROTARY")

        live_axis_count = 0
        for i, j in enumerate("XYZABCUVW"):
            if self.stat.axis_mask & (1 << i) == 0: continue
            live_axis_count += 1
        self.num_joints = int(
            inifile.find("KINS", "JOINTS") or live_axis_count)
        glDrawBuffer(GL_BACK)
        glDisable(GL_CULL_FACE)
        glLineStipple(2, 0x5555)
        glDisable(GL_LIGHTING)
        glClearColor(0, 0, 0, 0)
        glPixelStorei(GL_UNPACK_ALIGNMENT, 1)
示例#32
0
 def __init__(self, stat = None):
     gobject.GObject.__init__(self)
     self.stat = stat or linuxcnc.stat()
     self.old = {}
     gobject.timeout_add(100, self.update)
示例#33
0
 def __init__(self, timeout=2):
     self.c = linuxcnc.command()
     self.e = linuxcnc.error_channel()
     self.s = linuxcnc.stat()
     self.timeout = timeout
示例#34
0
import sys, os
import linuxcnc, time
import rs274.options

import gettext

BASE = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), ".."))
gettext.install("linuxcnc", localedir=os.path.join(BASE, "share", "locale"), unicode=True)

if len(sys.argv) > 1 and sys.argv[1] == "-ini":
    ini = linuxcnc.ini(sys.argv[2])
    linuxcnc.nmlfile = ini.find("EMC", "NML_FILE") or linuxcnc.nmlfile
    del sys.argv[1:3]

s = linuxcnc.stat()
s.poll()


def show_mcodes(l):
    return " ".join(["M%g" % i for i in l[1:] if i != -1])


def show_gcodes(l):
    return " ".join(["G%g" % (i / 10.0) for i in l[1:] if i != -1])


position = " ".join(["%-8.4f"] * s.axes)


def show_position(p):
示例#35
0
        def periodic_radiobuttons(self):
                self.radiobutton_mask = 1
                s = linuxcnc.stat()
                s.poll()
                am = s.axis_mask
                if not self.resized_wheelbuttons:
                        at = self.wTree.get_widget("axis_table")
                        for i in range(9):
                                b = ["wheelx", "wheely", "wheelz",
                                     "wheela", "wheelb", "wheelc",
                                     "wheelu", "wheelv", "wheelw"][i]
                                w = self.wTree.get_widget(b)
                                if not (am & (1<<i)):
                                        at.remove(w)
                        if (am & 0700) == 0:
                                at.resize(3, 2)
                                if (am & 070) == 0:
                                        at.resize(3, 1)
                                        self.wTree.get_widget("wheel_hbox").set_homogeneous(1)
                        self.resized_wheelbuttons = 1
                
                self.wTree.get_widget("scrolling").set_sensitive(self.tab == 3)
                if self.tab != 3 and self.wheel == "scrolling":
                        self.jogsettings_activate(0)
                        self.wheel = "fo"

                set_active(self.wTree.get_widget("wheelx"), self.wheelxyz == 0)
                set_active(self.wTree.get_widget("wheely"), self.wheelxyz == 1)
                set_active(self.wTree.get_widget("wheelz"), self.wheelxyz == 2)
                set_active(self.wTree.get_widget("wheela"), self.wheelxyz == 3)
                set_active(self.wTree.get_widget("wheelb"), self.wheelxyz == 4)
                set_active(self.wTree.get_widget("wheelc"), self.wheelxyz == 5)
                set_active(self.wTree.get_widget("wheelu"), self.wheelxyz == 6)
                set_active(self.wTree.get_widget("wheelv"), self.wheelxyz == 7)
                set_active(self.wTree.get_widget("wheelw"), self.wheelxyz == 8)
                set_active(self.wTree.get_widget("wheelinc1"), self.wheelinc == 0)
                set_active(self.wTree.get_widget("wheelinc2"), self.wheelinc == 1)
                set_active(self.wTree.get_widget("wheelinc3"), self.wheelinc == 2)
                set_active(self.wTree.get_widget("fo"), self.wheel == "fo")
                set_active(self.wTree.get_widget("so"), self.wheel == "so")
                set_active(self.wTree.get_widget("mv"), self.wheel == "mv")
                set_active(self.wTree.get_widget("jogging"), self.wheel == "jogging")
                set_active(self.wTree.get_widget("scrolling"), self.wheel == "scrolling")
                set_active(self.wTree.get_widget("pointer_show"), not self.invisible_cursor)
                set_active(self.wTree.get_widget("pointer_hide"), self.invisible_cursor)
                set_active(self.wTree.get_widget("toolset_workpiece"), not self.g10l11)
                set_active(self.wTree.get_widget("toolset_fixture"), self.g10l11)
                self.radiobutton_mask = 0

                if self.wheel == "jogging":
                        self.hal.jogaxis(self.wheelxyz)
                else:
                        # disable all
                        self.hal.jogaxis(-1)

                if self.wheel == "scrolling":
                        incs = ["100", "10", "1"]
                elif self.wheelxyz == 3 or self.wheelxyz == 4 or self.wheelxyz == 5:
                        incs = ["1.0", "0.1", "0.01"]
                elif self.machine_units_mm:
                        incs = ["0.1", "0.01", "0.001"]
                else:
                        incs = ["0.01", "0.001", "0.0001"]

                set_label(self.wTree.get_widget("wheelinc1").child, incs[0])
                set_label(self.wTree.get_widget("wheelinc2").child, incs[1])
                set_label(self.wTree.get_widget("wheelinc3").child, incs[2])

                self.hal.jogincrement(self.wheelinc, map(float,incs))

                d = self.hal.wheel()
                if self.wheel == "fo":
                        self.fo_val += d
                        if self.fo_val < 0: self.fo_val = 0
                        if d != 0: self.linuxcnc.feed_override(self.fo_val)

                if self.wheel == "so":
                        self.so_val += d
                        if self.so_val < 0: self.so_val = 0
                        if d != 0: self.linuxcnc.spindle_override(self.so_val)

                if self.wheel == "mv":
                        if self.machine_units_mm:
                                self.mv_val += 20 * d
                        else:
                                self.mv_val += d
                        if self.mv_val < 0: self.mv_val = 0
                        if d != 0:
                                self.linuxcnc.max_velocity(self.mv_val)
                                self.linuxcnc.continuous_jog_velocity(self.mv_val)
                        
		if self.wheel == "scrolling":
			d0 = d * 10 ** (2-self.wheelinc)
			if d != 0: self.listing.next(None, d0)

                set_label(self.wTree.get_widget("fo").child, "FO: %d%%" % self.fo_val)
                set_label(self.wTree.get_widget("so").child, "SO: %d%%" % self.so_val)
                set_label(self.wTree.get_widget("mv").child, "MV: %d" % self.mv_val)

                        
                return True
示例#36
0
 def __init__(self,timeout=2):
     self.c = linuxcnc.command()
     self.e = linuxcnc.error_channel()
     self.s = linuxcnc.stat()
     self.timeout = timeout
示例#37
0
def g700(self, **words):
    """ remap code G70 """
    p = int(words['p'])    
    q = int(words['q'])
    
    if words.has_key('f'):
        fr = float(words['f'])
        self.execute("F%f" % (fr))
    if words.has_key('d'):
        d = float(words['d'])
   
    s = linuxcnc.stat() 
    s.poll()

    filename = s.file
    f = open(filename, "r")
    lines = f.readlines()
    
    bounce_x = 0.5
    bounce_z = 0.5 
    
    explicit = 'ngc/explicit.ngc'
    expcode = open(explicit, "r")
    exp_lines = expcode.readlines()
    exp_string=''
    if len(exp_lines):
        for el in exp_lines:
            exp_string += el
        es1=exp_string.split('M02')[0]
        expcode = open(explicit, "w")
        expcode.write(es1)
        expcode = open(explicit, "a")
    else:
        expcode = open(explicit, "w")
    expcode.write("G21 G18 G49  G90 G61 G7\n")
    if words.has_key('f'):    
        fr = float(words['f'])
        expcode.write("F%f\n" % fr)   
##################################################### 

    c_line2 = 0               
    for w in lines:
        if  re.search("^\s*[(]\s*N\d", w.upper()):
            if not re.search("[^\(\)\.\-\+NGZXRIKSF\d\s]", w.upper()):
                num2 = int(re.findall("^\s*\d*",(re.split('N',w.upper())[1]))[0])                
                if num2 == p: 
                    c_line2 = 1
        if c_line2:
            try: 
                contour=re.split('\)',(re.split('\(',w.upper())[1]))[0]
                self.execute(contour)
                expcode.write(contour)
                expcode.write("\n")
            except :
                print 'G700_error'
                return INTERP_ERROR
            if re.search("Z\s*([-0-9.]+)",w, re.I):
                end_cont_Z = float(re.search("Z\s*([-0-9.]+)",w, re.I).group(1))
            if re.search("X\s*([-0-9.]+)",w, re.I):   
                end_cont_X = float(re.search("X\s*([-0-9.]+)",w, re.I).group(1)) 
        if  re.search("^\s*[(]\s*N\d", w.upper()):
            if not re.search("[^\(\)\.\-\+NGZXRIKSF\d\s]", w.upper()):
                num2 = int(re.findall("^\s*\d*",(re.split('N',w.upper())[1]))[0])
                if num2 == q: 
                    c_line2 = 0
                              
#  завершающий отход (в зависимости : OD или ID)
    if words.has_key('d'):
        if d<0:
            self.execute("G0 X%f Z%f" % (float(end_cont_X)-bounce_x,float(end_cont_Z)+0.1))
            expcode.write("G0 X%f Z%f\n" % (float(end_cont_X)-bounce_x,float(end_cont_Z)+0.1))
        else:
            self.execute("G0 X%f Z%f" % (float(end_cont_X)+bounce_x,float(end_cont_Z)+0.1))
            expcode.write("G0 X%f Z%f\n" % (float(end_cont_X)+bounce_x,float(end_cont_Z)+0.1))  
                                
    f.close()
    expcode.write("M02\n")                
    expcode.close()
    return INTERP_OK           
示例#38
0
def g710(self, **words):
    """ remap code G71.2 """
    p = int(words['p'])    
    q = int(words['q'])
    d = abs(float(words['d']))
    offset = float(words['k'])
    
    if words.has_key('s'):
        sspeed = int(words['s'])
        self.execute("S%d" % (sspeed))
    if words.has_key('l'): #только int ???
        offset_StartZ = int(words['l']) 
    only_finishing_cut = 0    
    if words.has_key('j'):
        only_finishing_cut = int(words['j'])
    quantity = 1    
    if words.has_key('i'):
        quantity = int(words['i'])
    if words.has_key('t'):
        R_Fanuc = float(words['t'])

    if words.has_key('f'):    
        fr = float(words['f'])
        self.execute("F%f" % (fr))
    tfile  = "./rs.tbl"
    setline = open(tfile ,"w")
    offs = ' '.join(['\n','T1','P1','X0','Z0','D%s' % (str(offset/12.7))])
    setline.write(offs)
    setline.close() 
           
    s = linuxcnc.stat() 
    s.poll()
    filename = s.file
    f = open(filename, "r")
    lines = f.readlines()
    
    x=0
    c_line = 0
    while x < len(lines):
        # находим начальную точку цикла по X 
        if re.search(".*\s*G71", lines[x], re.I) and not re.search(".*\s*[(]", lines[x], re.I):
            t_Sx = x
            while not re.search(".*\s*X", lines[t_Sx], re.I) and t_Sx > 0:
                t_Sx -= 1
            ST_COORDx0 = float(re.search("X\s*([-0-9.]+)",lines[t_Sx], re.I).group(1))
            
        # находим начальную точку цикла по Z 
        if re.search(".*\s*G71", lines[x], re.I) and not re.search(".*\s*[(]", lines[x], re.I):
            t_Sz = x
            while not re.search(".*\s*Z", lines[t_Sz], re.I) and t_Sz > 0:
                t_Sz -= 1
            ST_COORDz0 = float(re.search("Z\s*([-0-9.]+)",lines[t_Sz], re.I).group(1))    
        x+=1

    self.execute("G21 G18 G49 G40 G90 G61 G7 ")
    name_file = "./fgcode.ngc" 
    fgcode = open(name_file, "w") 
    string = 'G21 G18 G49 G40 G90 G61 G7 F1000 \n'
    string += 'T1 M6\n'
    
    # добавляем в  контур "начальный отрезок"(обязательно), и "конечный"(опционально)
    for x in range(len(lines)):
        if  re.search("^\s*[(]\s*N\d", lines[x].upper()):
            if not re.search("[^\(\)\.\-\+NGZXRIK\d\s]", lines[x].upper()):
                num2 = int(re.findall("^\s*\d*",(re.split('N',lines[x].upper())[1]))[0])
                if num2 == p :
                    c_line = 1
                    if re.search("X\s*([-0-9.]+)",lines[x], re.I):
                        st_cont_X = float(re.search("X\s*([-0-9.]+)",lines[x], re.I).group(1))
        if c_line:
            if re.search("Z\s*([-0-9.]+)",lines[x], re.I):
                end_cont_Z = float(re.search("Z\s*([-0-9.]+)",lines[x], re.I).group(1))
            if re.search("X\s*([-0-9.]+)",lines[x], re.I):   
                end_cont_X = float(re.search("X\s*([-0-9.]+)",lines[x], re.I).group(1))
        if  re.search("^\s*[(]\s*N\d", lines[x].upper()):
            if not re.search("[^\(\)\.\-\+NGZXRIK\d\s]", lines[x].upper()):
                num2 = int(re.findall("^\s*\d*",(re.split('N',lines[x].upper())[1]))[0])
                if num2 == q :
                    c_line = 0                  
                
                

    if float(words['d'])<0 : # если расточка(d со знаком минус)  
        if ST_COORDx0 - end_cont_X > d :
            print 'error cycle start point '
            self.execute("(AXIS,notify, %s)" % ("error cycle start point"))
            return
    
    string += 'G1 X-30 Z30\n'
    string += 'G1 X-25 Z35\n'
    if float(words['d'])>=0 : # если НЕ расточка(d НЕ со знаком минус)
        string += 'G0 X%f Z%f\n' % (ST_COORDx0,ST_COORDz0)
        string += 'G0 X%f Z%f\n' % (st_cont_X+d,ST_COORDz0)
    if float(words['d'])<0 :
        string += 'G41\n' 
    else:
        string += 'G42\n'  
                     
    for w in lines:
        if  re.search("^\s*[(]\s*N\d", w.upper()):
            if not re.search("[^\(\)\.\-\+NGZXRIK\d\s]", w.upper()):
                num2 = int(re.findall("^\s*\d*",(re.split('N',w.upper())[1]))[0])
                if num2 == p :
                    c_line = 1
        if c_line:    
            try: 
                contour=re.split('\)',(re.split('\(',w.upper())[1]))[0]
                string += contour
                string += '\n'
            except :
                print 'error_for w in lines'
                return INTERP_ERROR
        if  re.search("^\s*[(]\s*N\d", w.upper()):
            if not re.search("[^\(\)\.\-\+NGZXRIK\d\s]", w.upper()):
                num2 = int(re.findall("^\s*\d*",(re.split('N',w.upper())[1]))[0])
                if num2 == q :
                    c_line = 0                                                    
    f.close()
    
    string += 'G1 F100 Z%f\n' % (end_cont_Z-offset*2) #"конечный" отрезок
    string += 'G1 F100 X%f Z%f\n' % (ST_COORDx0,end_cont_Z-offset*2) #"конечный" отрезок
    string += 'G40\n'
    self.execute("G40")
    string += 'M30\n'
    fgcode.write(string)
    outfilename  = "./RS274_temp.txt"
    outfile = open(outfilename, "w")
    
    fgcode.close() 
    p = subprocess.Popen(["sh", "-c", (' '.join(['./rs274','-t',tfile,'-g',name_file,outfilename]))],
                      stdin=None,
                      stdout=outfile,
                      stderr=None )
    p.wait()                 
    outfile.close()
    P = []                      
    pr = []    
    f1 = open(outfilename, "r")
    ln = f1.readlines()
    old_posX = 0
    old_posZ = 0 
    i=-1   
    for w in ln:
        if  re.search("STRAIGHT_TRAVERSE", w.upper()):
            numbers = re.split('\(',w.upper())
            number = re.split('\,',numbers[1].upper())
            x1=float(number[0])*2
            z1=float(number[2])
            prog(pr,0,x1,z1)
            i+=1
            papp(i,0,x1,z1,old_posX,old_posZ,P)
            old_posX = float(number[0])
            old_posZ = float(number[2])            
        elif  re.search("STRAIGHT_FEED", w.upper()):
            numbers = re.split('\(',w.upper())
            number = re.split('\,',numbers[1].upper())
            x1=float(number[0])*2
            z1=float(number[2])
            prog(pr,1,x1,z1)
            i+=1
            papp(i,1,x1,z1,old_posX,old_posZ,P)
            old_posX = float(number[0])
            old_posZ = float(number[2])

        elif  re.search("ARC_FEED", w.upper()):
            numbers = re.split('\(',w.upper())
            number = re.split('\,',numbers[1].upper())
            if float(number[4])>0:
                g=3
            elif float(number[4])<0:
                g=2 
            x_arc=float(number[1])*2
            z_arc=float(number[0])
            arc_I = float(number[3]) - old_posX
            arc_K = float(number[2]) - old_posZ
            radius = round(hip(arc_I,arc_K),6)
            prog(pr,g,x_arc,z_arc,arc_I,arc_K)            
            i+=1
            papp(i,g,x_arc,z_arc,old_posX,old_posZ,P,radius,arc_I,arc_K)
            old_posX = float(number[1])
            old_posZ = float(number[0])

    # начало контура
    tmp1=[]
    tmp2=[] 
    for p in P: #XXX если дуга - добавлять точку максимума по X
       tmp1.append(p[1])
       tmp2.append(p[4])
                
    z_minim = min(tmp2)
    z_maxim = 50  #XXX вынести в INI ??

    A=[]    
    bounce_x = 0.5
    bounce_z = 0.5
    h1=max(tmp1)*0.5 - 0.1 #XXX разобраться с точностью вычислений 
                
    kh1= 0.0    
    while num(P,d,h1):
        kh1 = kh1 + 0.01
        d = d - kh1  #XXX может быть нужно изменять (и) h1
        print 'd=',d 
    #---------------------------------------------------ищем все точки пересечения    
    h1=max(tmp1)*0.5 - 0.1 
    while h1>=0:
        for i in reversed(range(len(P))):            
            if i>2 and P[i][0]<=1 :
                par=intersection_line_line( P[i][3], P[i][4], P[i][1], P[i][2],  h1, z_minim,h1, z_maxim,A)
            if i>2 and P[i][0]>1 :
                o=en_line_arc(P[i][0],P[i][2],P[i][4],P[i][1],P[i][3],z_minim,h1,z_maxim,h1,P[i][7],P[i][6],P[i][5],A)    
        h1 = h1-(1*d)
        
    print 'P =', P ,'\n'
    print 'A =', A ,'\n'
    
    explicit = 'ngc/explicit.ngc'
    expcode = open(explicit, "r")
    exp_lines = expcode.readlines()
    exp_string=''
    if len(exp_lines):
        for el in exp_lines:
            exp_string += el
        es1=exp_string.split('M02')[0]
        expcode = open(explicit, "w")
        expcode.write(es1)
        expcode = open(explicit, "a")
    else:
        expcode = open(explicit, "w")
    expcode.write("G21 G18 G49  G90 G61 G7\n")
    if words.has_key('f'):    
        fr = float(words['f'])
        expcode.write("F%f\n" % fr)
        
    #------------------------------------------------------------------ID
    if float(words['d'])<0 : # если расточка(d со знаком минус)
        for i in reversed(range(len(A))) : 
            self.execute("G1 F1000  X%f" % (A[i][1]))
            expcode.write("G1 F1000  X%f\n" % (A[i][1]))                          
            self.execute("G1 F1000  Z%f" % (A[i][0]))
            expcode.write("G1 F1000  Z%f\n" % (A[i][0]))
            self.execute("G0 X%f Z%f" % (float(A[i][1]) - d + bounce_x,float(A[i][0])+bounce_z))
            expcode.write("G0 X%f Z%f\n" % (float(A[i][1]) - d + bounce_x,float(A[i][0])+bounce_z))
            self.execute("G0 Z%f" % (ST_COORDz0))
            expcode.write("G0 Z%f\n" % (ST_COORDz0))

        for w in range(2,len(pr)):
            try:  
                self.execute(pr[w])
                expcode.write(pr[w])
                expcode.write("\n")
            except: 
                return INTERP_ERROR 
        self.execute("G0 Z%f" % (ST_COORDz0))
        
        return    
    
    #находим X всех горизонталей
    L=[]
    nn=0                            
    for a in range(len(A)):
        try:
            if A[a][1]!=nn:
                ns=A[a][1]
                L.append(A[a][1])
                nn= ns  
        except:
            return INTERP_ERROR
    L.append(0)



    D=[]              
    R=[0]
    go(self,A,L,D,R,expcode)            
    self.execute("G0  X%f" % (max(tmp1)+5))#XXX 
    expcode.write("G0 X%f\n" % (max(tmp1)+5))
                   
    print 'pr=', pr 
    for w in range(2,len(pr)):
        try:  
            self.execute(pr[w])
            expcode.write(pr[w])
            expcode.write("\n")
        except: 
            return INTERP_ERROR 
    self.execute("G0 X%f " % (max(tmp1)+0))#XXX 
    expcode.write("G0 X%f\n" % (max(tmp1)+0)) 
    self.execute("G0 Z%f " % (ST_COORDz0))#XXX
    expcode.write("G0 Z%f\n" % (ST_COORDz0))     
    expcode.write("M02\n") 
    expcode.close()
    return INTERP_OK 
示例#39
0
timeout = 1.0

#
# set up pins
# shell out to halcmd to net our pins to where they need to go
#

h = hal.component("python-ui")
h.ready()

#
# connect to LinuxCNC
#

c = linuxcnc.command()
s = linuxcnc.stat()
e = linuxcnc.error_channel()

l = linuxcnc_util.LinuxCNC(command=c, status=s, error=e)

c.state(linuxcnc.STATE_ESTOP_RESET)
c.state(linuxcnc.STATE_ON)
c.home(0)
c.home(1)
c.home(2)

l.wait_for_home([1, 1, 1, 0, 0, 0, 0, 0, 0])

c.mode(linuxcnc.MODE_MDI)

c.mdi("O<obug> call [0]")
示例#40
0
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

import sys, os
import linuxcnc, time
import rs274.options

import gettext
BASE = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), ".."))
gettext.install("linuxcnc", localedir=os.path.join(BASE, "share", "locale"), unicode=True)

if len(sys.argv) > 1 and sys.argv[1] == '-ini':
    ini = linuxcnc.ini(sys.argv[2])
    linuxcnc.nmlfile = ini.find("EMC", "NML_FILE") or linuxcnc.nmlfile
    del sys.argv[1:3]

s = linuxcnc.stat(); s.poll()

def show_mcodes(l):
    return " ".join(["M%g" % i for i in l[1:] if i != -1])
def show_gcodes(l):
    return " ".join(["G%g" % (i/10.) for i in l[1:] if i != -1])
position = " ".join(["%-8.4f"] * s.axes)
def show_position(p):
    return position % p[:s.axes]
peraxis = " ".join(["%s"] * s.axes)
def show_peraxis(p):
    return peraxis % p[:s.axes]
def show_float(p): return "%-8.4f" % p

maps = {
'exec_state': {linuxcnc.EXEC_ERROR: 'error',
示例#41
0
    def __init__(self, inifile):

        display_mode = ( gtk.gdkgl.MODE_RGB | gtk.gdkgl.MODE_DEPTH |
                         gtk.gdkgl.MODE_DOUBLE )
        glconfig = gtk.gdkgl.Config(mode=display_mode)

        gtk.gtkgl.widget.DrawingArea.__init__(self, glconfig)
        glnav.GlNavBase.__init__(self)
        def C(s):
            a = self.colors[s + "_alpha"]
            s = self.colors[s]
            return [int(x * 255) for x in s + (a,)]
        self.inifile = inifile
        self.logger = linuxcnc.positionlogger(linuxcnc.stat(),
            C('backplotjog'),
            C('backplottraverse'),
            C('backplotfeed'),
            C('backplotarc'),
            C('backplottoolchange'),
            C('backplotprobing'),
            self.get_geometry()
        )
        thread.start_new_thread(self.logger.start, (.01,))

        rs274.glcanon.GlCanonDraw.__init__(self, linuxcnc.stat(), self.logger)

        self.current_view = 'z'

        self.select_primed = None

        self.connect_after('realize', self.realize)
        self.connect('configure_event', self.reshape)
        self.connect('map_event', self.map)
        self.connect('expose_event', self.expose)
        self.connect('motion-notify-event', self.motion)
        self.connect('button-press-event', self.pressed)
        self.connect('button-release-event', self.select_fire)
        self.connect('scroll-event', self.scroll)

        self.add_events(gtk.gdk.POINTER_MOTION_MASK)
        self.add_events(gtk.gdk.POINTER_MOTION_HINT_MASK)
        self.add_events(gtk.gdk.BUTTON_MOTION_MASK)
        self.add_events(gtk.gdk.BUTTON_PRESS_MASK)
        self.add_events(gtk.gdk.BUTTON_RELEASE_MASK)

        self.fingerprint = ()

        self.lat = 0
        self.minlat = -90
        self.maxlat = 90

        self.highlight_line = None
        self.program_alpha = False
        self.use_joints_mode = False
        self.use_commanded = True
        self.show_limits = True
        self.show_extents_option = True
        self.show_live_plot = True
        self.show_velocity = True
        self.metric_units = True
        self.show_program = True
        self.show_rapids = True
        self.use_relative = True
        self.show_tool = True
        self.show_dtg = True
        self.grid_size = 0.0
        temp = inifile.find("DISPLAY", "LATHE")
        self.lathe_option = bool(temp == "1" or temp == "True" or temp == "true" )
        self.foam_option = bool(inifile.find("DISPLAY", "FOAM"))
        self.show_offsets = False
        self.use_default_controls = True
        self.mouse_btn_mode = 0

        self.a_axis_wrapped = inifile.find("AXIS_A", "WRAPPED_ROTARY")
        self.b_axis_wrapped = inifile.find("AXIS_B", "WRAPPED_ROTARY")
        self.c_axis_wrapped = inifile.find("AXIS_C", "WRAPPED_ROTARY")

        live_axis_count = 0
        for i,j in enumerate("XYZABCUVW"):
            if self.stat.axis_mask & (1<<i) == 0: continue
            live_axis_count += 1
        self.num_joints = int(inifile.find("KINS", "JOINTS") or live_axis_count)
示例#42
0
    def __init__(self, inifile):
        gobject.GObject.__init__(self)

        display_mode = ( gtk.gdkgl.MODE_RGB | gtk.gdkgl.MODE_DEPTH |
                         gtk.gdkgl.MODE_DOUBLE )
        glconfig = gtk.gdkgl.Config(mode=display_mode)

        gtk.gtkgl.widget.DrawingArea.__init__(self, glconfig)
        glnav.GlNavBase.__init__(self)
        def C(s):
            a = self.colors[s + "_alpha"]
            s = self.colors[s]
            return [int(x * 255) for x in s + (a,)]
        self.inifile = inifile
        self.logger = linuxcnc.positionlogger(linuxcnc.stat(),
            C('backplotjog'),
            C('backplottraverse'),
            C('backplotfeed'),
            C('backplotarc'),
            C('backplottoolchange'),
            C('backplotprobing'),
            self.get_geometry()
        )
        thread.start_new_thread(self.logger.start, (.01,))

        rs274.glcanon.GlCanonDraw.__init__(self, linuxcnc.stat(), self.logger)

        self.current_view = 'z'

        self.select_primed = None

        self.connect_after('realize', self.realize)
        self.connect('configure_event', self.reshape)
        self.connect('map_event', self.map)
        self.connect('expose_event', self.expose)
        self.connect('motion-notify-event', self.motion)
        self.connect('button-press-event', self.pressed)
        self.connect('button-release-event', self.select_fire)
        self.connect('scroll-event', self.scroll)

        self.add_events(gtk.gdk.POINTER_MOTION_MASK)
        self.add_events(gtk.gdk.POINTER_MOTION_HINT_MASK)
        self.add_events(gtk.gdk.BUTTON_MOTION_MASK)
        self.add_events(gtk.gdk.BUTTON_PRESS_MASK)
        self.add_events(gtk.gdk.BUTTON_RELEASE_MASK)

        self.fingerprint = ()

        self.lat = 0
        self.minlat = -90
        self.maxlat = 90

        self.highlight_line = None
        self.material_buttom_left = (0.0,0.0)
        self.material_buttom_right = (0.0,0.0)
        self.material_top_left = (0.0,0.0)
        self.material_top_right = (0.0,0.0)
        self.draw_material_state = False
        self.program_alpha = False
        self.use_joints_mode = False
        self.use_commanded = True
        self.show_limits = True
        self.show_extents_option = True
        self.show_live_plot = True
        self.show_velocity = True
        self.metric_units = True
        self.show_program = True
        self.show_rapids = True
        self.use_relative = True
        self.show_tool = True
        self.show_dtg = True
        self.grid_size = 0.0
        temp = inifile.find("DISPLAY", "LATHE")
        self.lathe_option = bool(temp == "1" or temp == "True" or temp == "true" )
        self.foam_option = bool(inifile.find("DISPLAY", "FOAM"))
        self.show_offsets = False
        self.use_default_controls = True
        self.mouse_btn_mode = 0

        self.a_axis_wrapped = inifile.find("AXIS_3", "WRAPPED_ROTARY")
        self.b_axis_wrapped = inifile.find("AXIS_4", "WRAPPED_ROTARY")
        self.c_axis_wrapped = inifile.find("AXIS_5", "WRAPPED_ROTARY")

        live_axis_count = 0
        for i,j in enumerate("XYZABCUVW"):
            if self.stat.axis_mask & (1<<i) == 0: continue
            live_axis_count += 1
        self.num_joints = int(inifile.find("TRAJ", "JOINTS") or live_axis_count)
        self.highlight_mode = 'line'
        self.highlight_mode = inifile.find("DISPLAY", "HIGHLIGHT_MODE")
示例#43
0
 def __init__(self, stat=None):
     gobject.GObject.__init__(self)
     self.stat = stat or linuxcnc.stat()
     self.old = {}
     gobject.timeout_add(100, self.update)
示例#44
0
#!/usr/bin/python

import sys
import linuxcnc
try:
    s = linuxcnc.stat(dtg) # create a connection to the status channel
    s.poll() # get current values
except linuxcnc.error, detail:
    print "error", detail
    sys.exit(1)
for x in dir(s):
    if not x.startswith('_'):
        print x, getattr(s,x)
示例#45
0
    def __init__(self, toolfile=None, *a, **kw):
        super(ToolEdit, self).__init__()
        self.emcstat = linuxcnc.stat()
        self.hash_check = None
        self.lathe_display_type = True
        self.toolfile = toolfile
        self.num_of_col = 1
        self.font = "sans 12"
        self.hide_columns = ''
        self.toolinfo_num = 0
        self.toolinfo = []
        self.wTree = gtk.Builder()
        self.wTree.set_translation_domain(
            "linuxcnc")  # for locale translations
        self.wTree.add_from_file(os.path.join(datadir, "tooledit_gtk.glade"))
        # connect the signals from Glade
        dic = {
            "on_delete_clicked": self.delete,
            "on_add_clicked": self.add,
            "on_reload_clicked": self.reload,
            "on_save_clicked": self.save,
            "cell_toggled": self.toggled
        }
        self.wTree.connect_signals(dic)

        self.treeview1 = self.wTree.get_object("treeview1")
        self.treeview1.connect("key-release-event",
                               self.on_tree_navigate_key_press, None)

        # for raw view 1:

        # toggle button useable
        renderer = self.wTree.get_object("cell_toggle1")
        renderer.set_property('activatable', True)
        # make colums editable
        self.tool_cell_list = "cell_tool#","cell_pos","cell_x","cell_y","cell_z","cell_a","cell_b","cell_c","cell_u","cell_v","cell_w","cell_d", \
                "cell_front","cell_back","cell_orient","cell_comments"
        for col, name in enumerate(self.tool_cell_list):
            #print name,col
            renderer = self.wTree.get_object(name + '1')
            renderer.connect('edited', self.col_editted, col + 1, None)
            renderer.props.editable = True
        self.all_label = self.wTree.get_object("all_label")

        # for lathe wear view2:

        # make columns editable
        temp =[ ("cell_x2",3),("cell_z2",5),("cell_front2",13),("cell_back2",14), \
                ("cell_orient2",15), ("cell_comments2",16)]
        for name, col in temp:
            renderer = self.wTree.get_object(name)
            renderer.connect('edited', self.col_editted, col, 'wear')
            renderer.props.editable = True
        # Hide columns we don't want to see
        self.set_col_visible(list='spyabcuvwdijq', bool=False, tab='2')
        self.wear_label = self.wTree.get_object("wear_label")

        # for tool offsets view 3:

        # make columns editable
        temp =[ ("cell_x3",3),("cell_z3",5),("cell_front3",13),("cell_back3",14), \
                ("cell_orient3",15), ("cell_comments3",16)]
        for name, col in temp:
            renderer = self.wTree.get_object(name)
            renderer.connect('edited', self.col_editted, col, 'tool')
            renderer.props.editable = True
        # Hide columns we don't want to see
        self.set_col_visible(list='spyabcuvwdij', bool=False, tab='3')
        self.tool_label = self.wTree.get_object("tool_label")

        # global references
        self.model = self.wTree.get_object("liststore1")
        self.notebook = self.wTree.get_object("tool_offset_notebook")
        self.all_window = self.wTree.get_object("all_window")
        self.wear_window = self.wTree.get_object("wear_window")
        self.tool_window = self.wTree.get_object("tool_window")
        self.view1 = self.wTree.get_object("treeview1")
        self.view2 = self.wTree.get_object("treeview2")

        # sort routine for tool diameter
        def compare(model, row1, row2, user_data=None):
            sort_column, _ = model.get_sort_column_id()
            value1 = model.get_value(row1, sort_column)
            value2 = model.get_value(row2, sort_column)
            return cmp(value1, value2)

        model = self.view1.get_model()
        model.set_sort_func(12, compare)
        #self.view2.connect('button_press_event', self.on_treeview2_button_press_event)
        self.view2.connect("key-release-event",
                           self.on_tree_navigate_key_press, 'wear')
        self.selection = self.view2.get_selection()
        self.selection.set_mode(gtk.SELECTION_SINGLE)
        self.view3 = self.wTree.get_object("treeview3")
        #self.view3.connect('button_press_event', self.on_treeview2_button_press_event)
        self.view3.connect("key-release-event",
                           self.on_tree_navigate_key_press, 'tool')
        self.apply = self.wTree.get_object("apply")
        self.buttonbox = self.wTree.get_object("buttonbox")
        self.tool_filter = self.wTree.get_object("tool_modelfilter")
        self.tool_filter.set_visible_func(self.match_type, False)
        self.wear_filter = self.wTree.get_object("wear_modelfilter")
        self.wear_filter.set_visible_func(self.match_type, True)
        # reparent tooledit box from Glades tp level window to tooledit's VBox
        window = self.wTree.get_object("tooledit_box")
        window.reparent(self)
        # If the toolfile was specified when tooledit was created load it
        if toolfile:
            self.reload(None)
        # check the ini file if display-type: LATHE is set
        try:
            self.inifile = linuxcnc.ini(INIPATH)
            test = self.inifile.find("DISPLAY", "LATHE")
            if test == '1' or test == 'True':
                self.lathe_display_type = True
                self.set_lathe_display(True)
            else:
                self.lathe_display_type = False
                self.set_lathe_display(False)
        except:
            pass

        # check linuxcnc status every second
        gobject.timeout_add(1000, self.periodic_check)