From f428938bd77403d16e66252a14d86f12ca463b31 Mon Sep 17 00:00:00 2001 From: zz912 Date: Sat, 17 May 2025 20:43:36 +0200 Subject: [PATCH 1/2] Gmoccapy-integration halui MDI commands --- configs/sim/gmoccapy/gmoccapy.ini | 6 +++- src/emc/usr_intf/gmoccapy/gmoccapy.py | 41 +++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/configs/sim/gmoccapy/gmoccapy.ini b/configs/sim/gmoccapy/gmoccapy.ini index 9aa8a90074e..edc432101f1 100644 --- a/configs/sim/gmoccapy/gmoccapy.ini +++ b/configs/sim/gmoccapy/gmoccapy.ini @@ -96,7 +96,11 @@ HALUI = halui # Trajectory planner section -------------------------------------------------- [HALUI] -#No Content +MDI_COMMAND = M6 T1 +MDI_COMMAND = M6 T2 +MDI_COMMAND = M61 Q1 +MDI_COMMAND = M61 Q2 +MDI_COMMAND = M6 T3 G4 P10 [TRAJ] COORDINATES = X Y Z diff --git a/src/emc/usr_intf/gmoccapy/gmoccapy.py b/src/emc/usr_intf/gmoccapy/gmoccapy.py index 950476bb6aa..f61bc8e3344 100644 --- a/src/emc/usr_intf/gmoccapy/gmoccapy.py +++ b/src/emc/usr_intf/gmoccapy/gmoccapy.py @@ -213,6 +213,17 @@ def __init__(self, argv): self.jog_increments = [] # This holds the increment values self.unlock = False # this value will be set using the hal pin unlock settings + # if halui MDI commands are not defined in the INI file, the pin halui.halui-mdi-is-running will not be created. + try: + hal.get_value("halui.halui-mdi-is-running") + # this pin prevents mode switching during execution of halui MDI commands + self.halui_cmd_exist = True + # this value will allow reading the halui.halui-mdi-is-running pin only if it exists + LOG.debug("halui MDI commands are used") + except Exception: + self.halui_cmd_exist = False + LOG.debug("halui MDI commands are NOT used") + # needed to display the labels self.system_list = ("0", "G54", "G55", "G56", "G57", "G58", "G59", "G59.1", "G59.2", "G59.3") self.dro_size = 28 # The size of the DRO, user may want them bigger on bigger screen @@ -2520,16 +2531,31 @@ def on_tbtn_on_toggled(self, widget, data=None): # The mode buttons def on_rbt_manual_pressed(self, widget, data=None): + if self.halui_cmd_exist: + if hal.get_value("halui.halui-mdi-is-running"): + LOG.error(_("It is not possible to change to manual Mode at the moment")) + LOG.error(_("halui MDI command is running")) + return LOG.debug("mode Manual") self.command.mode(linuxcnc.MODE_MANUAL) self.command.wait_complete() def on_rbt_mdi_pressed(self, widget, data=None): + if self.halui_cmd_exist: + if hal.get_value("halui.halui-mdi-is-running"): + LOG.error(_("It is not possible to change to MDI Mode at the moment")) + LOG.error(_("halui MDI command is running")) + return LOG.debug("mode MDI") self.command.mode(linuxcnc.MODE_MDI) self.command.wait_complete() def on_rbt_auto_pressed(self, widget, data=None): + if self.halui_cmd_exist: + if hal.get_value("halui.halui-mdi-is-running"): + LOG.error(_("It is not possible to change to Auto Mode at the moment")) + LOG.error(_("halui MDI command is running")) + return LOG.debug("mode Auto") self.command.mode(linuxcnc.MODE_AUTO) self.command.wait_complete() @@ -2775,6 +2801,11 @@ def on_hal_status_limits_tripped(self, object, state, lst_limits): self.widgets.chk_ignore_limits.set_active(False) def on_hal_status_mode_manual(self, widget): + if self.halui_cmd_exist: + if hal.get_value("halui.halui-mdi-is-running"): + LOG.debug("switch to Manual page is ignored, because halui MDI command is running") + return + LOG.debug("MANUAL Mode") self.widgets.rbt_manual.set_active(True) # if setup page is activated, we must leave here, otherwise the pages will be reset @@ -2797,6 +2828,11 @@ def on_hal_status_mode_manual(self, widget): self.last_key_event = None, 0 def on_hal_status_mode_mdi(self, widget): + if self.halui_cmd_exist: + if hal.get_value("halui.halui-mdi-is-running"): + LOG.debug("switch to MDI page is ignored, because halui MDI command is running") + return + LOG.debug("MDI Mode, tool_change = {0}".format(self.tool_change)) # if the edit offsets button is active, we do not want to change @@ -2845,6 +2881,11 @@ def on_hal_status_mode_mdi(self, widget): self.last_key_event = None, 0 def on_hal_status_mode_auto(self, widget): + if self.halui_cmd_exist: + if hal.get_value("halui.halui-mdi-is-running"): + LOG.debug("switch to Auto page is ignored, because halui MDI command is running") + return + LOG.debug("AUTO Mode") # if Auto button is not sensitive, we are not ready for AUTO commands # so we have to abort external commands and get back to manual mode From fb61cb3b5b7daa392abe5a04e6711d9a9b314b96 Mon Sep 17 00:00:00 2001 From: Hans Unzner Date: Fri, 25 Sep 2026 18:45:01 +0200 Subject: [PATCH 2/2] gmoccapy: don't switch modes in GUI for halui MDI command; show abort button during command execution --- src/emc/usr_intf/gmoccapy/gmoccapy.py | 86 +++++++++++++++------------ 1 file changed, 47 insertions(+), 39 deletions(-) diff --git a/src/emc/usr_intf/gmoccapy/gmoccapy.py b/src/emc/usr_intf/gmoccapy/gmoccapy.py index f61bc8e3344..bcbdf453ab0 100644 --- a/src/emc/usr_intf/gmoccapy/gmoccapy.py +++ b/src/emc/usr_intf/gmoccapy/gmoccapy.py @@ -213,17 +213,6 @@ def __init__(self, argv): self.jog_increments = [] # This holds the increment values self.unlock = False # this value will be set using the hal pin unlock settings - # if halui MDI commands are not defined in the INI file, the pin halui.halui-mdi-is-running will not be created. - try: - hal.get_value("halui.halui-mdi-is-running") - # this pin prevents mode switching during execution of halui MDI commands - self.halui_cmd_exist = True - # this value will allow reading the halui.halui-mdi-is-running pin only if it exists - LOG.debug("halui MDI commands are used") - except Exception: - self.halui_cmd_exist = False - LOG.debug("halui MDI commands are NOT used") - # needed to display the labels self.system_list = ("0", "G54", "G55", "G56", "G57", "G58", "G59", "G59.1", "G59.2", "G59.3") self.dro_size = 28 # The size of the DRO, user may want them bigger on bigger screen @@ -2531,31 +2520,16 @@ def on_tbtn_on_toggled(self, widget, data=None): # The mode buttons def on_rbt_manual_pressed(self, widget, data=None): - if self.halui_cmd_exist: - if hal.get_value("halui.halui-mdi-is-running"): - LOG.error(_("It is not possible to change to manual Mode at the moment")) - LOG.error(_("halui MDI command is running")) - return LOG.debug("mode Manual") self.command.mode(linuxcnc.MODE_MANUAL) self.command.wait_complete() def on_rbt_mdi_pressed(self, widget, data=None): - if self.halui_cmd_exist: - if hal.get_value("halui.halui-mdi-is-running"): - LOG.error(_("It is not possible to change to MDI Mode at the moment")) - LOG.error(_("halui MDI command is running")) - return LOG.debug("mode MDI") self.command.mode(linuxcnc.MODE_MDI) self.command.wait_complete() def on_rbt_auto_pressed(self, widget, data=None): - if self.halui_cmd_exist: - if hal.get_value("halui.halui-mdi-is-running"): - LOG.error(_("It is not possible to change to Auto Mode at the moment")) - LOG.error(_("halui MDI command is running")) - return LOG.debug("mode Auto") self.command.mode(linuxcnc.MODE_AUTO) self.command.wait_complete() @@ -2681,7 +2655,8 @@ def on_hal_status_interp_idle(self, widget): else: self._change_kbd_image("img_macro_menu_stop") self.macro_dic["keyboard"].set_sensitive(False) - + + self._hide_abort_button() self.widgets.btn_run.set_sensitive(True) self.widgets.btn_stop.set_sensitive(False) @@ -2711,9 +2686,50 @@ def on_hal_status_interp_run(self, widget): self.widgets.btn_stop.set_sensitive(True) self._change_kbd_image("img_macro_menu_stop") + + self._show_abort_button() # Show only in MDI mode? self.macro_dic["keyboard"].set_sensitive(True) self.elapsed_time_run = 0 + # Goes through all buttonboxes in "ntb_button" and replaces the last button by an mdi abort button. + # It stores the removes buttons in a dict to be restored later. + def _show_abort_button(self): + self.saved_buttons = {} + for page_num in range(self.widgets.ntb_button.get_n_pages()): + buttonbox = self.widgets.ntb_button.get_nth_page(page_num) + buttons = buttonbox.get_children() + # Some buttonboxes does not contain buttons; don't replace for auto mode and mdi + if buttons and Gtk.Buildable.get_name(buttonbox) not in ["hbtb_auto", "hbtb_MDI"]: + button = buttons[-1] + self.saved_buttons[page_num] = button + buttonbox.remove(button) + # Copy image to pixbuf because one image cannot be used twice + pixbuf = self.widgets.img_macro_menu_stop.get_pixbuf() + image_abort = Gtk.Image.new_from_pixbuf(pixbuf) + button_abort = self._new_button_with_predefined_image(name="img_macro_menu_stop", + size=_DEFAULT_BB_SIZE, image=image_abort) + # TBD: add function. Also refactor self._change_kbd_image() + # new_button.connect("clicked", self._on_abort_mdi_clicked) + self.macro_dic["keyboard"].set_image(Gtk.Image.new_from_pixbuf(pixbuf)) + button_abort.show() + buttonbox.add(button_abort) + + # Goes through all buttonboxes in "ntb_button" and replaces the last button by the saved button from the dict. + def _hide_abort_button(self): + # Try block here because self.saved_buttons is first created in _show_abort_button() + try: + for page_num in range(self.widgets.ntb_button.get_n_pages()): + buttonbox = self.widgets.ntb_button.get_nth_page(page_num) + buttons = buttonbox.get_children() + # Some buttonboxes does not contain buttons; don't replace for auto mode and mdi + if buttons and Gtk.Buildable.get_name(buttonbox) not in ["hbtb_auto", "hbtb_MDI"]: + buttonbox.remove(buttons[-1]) + saved_button = self.saved_buttons[page_num] + buttonbox.add(saved_button) + saved_button.show() + except: + pass + def on_hal_status_tool_in_spindle_changed(self, object, new_tool_no): LOG.debug("hal signal tool changed") # need to save the tool in spindle as preference, to be able to reload it on startup @@ -2801,11 +2817,6 @@ def on_hal_status_limits_tripped(self, object, state, lst_limits): self.widgets.chk_ignore_limits.set_active(False) def on_hal_status_mode_manual(self, widget): - if self.halui_cmd_exist: - if hal.get_value("halui.halui-mdi-is-running"): - LOG.debug("switch to Manual page is ignored, because halui MDI command is running") - return - LOG.debug("MANUAL Mode") self.widgets.rbt_manual.set_active(True) # if setup page is activated, we must leave here, otherwise the pages will be reset @@ -2828,10 +2839,12 @@ def on_hal_status_mode_manual(self, widget): self.last_key_event = None, 0 def on_hal_status_mode_mdi(self, widget): - if self.halui_cmd_exist: + try: if hal.get_value("halui.halui-mdi-is-running"): - LOG.debug("switch to MDI page is ignored, because halui MDI command is running") + LOG.debug("switch to MDI page is ignored, because halui MDI-command is running") return + except: + pass LOG.debug("MDI Mode, tool_change = {0}".format(self.tool_change)) @@ -2881,11 +2894,6 @@ def on_hal_status_mode_mdi(self, widget): self.last_key_event = None, 0 def on_hal_status_mode_auto(self, widget): - if self.halui_cmd_exist: - if hal.get_value("halui.halui-mdi-is-running"): - LOG.debug("switch to Auto page is ignored, because halui MDI command is running") - return - LOG.debug("AUTO Mode") # if Auto button is not sensitive, we are not ready for AUTO commands # so we have to abort external commands and get back to manual mode