>From 7c78a7718f0cae22ace2871bbe7aa49959f175c6 Mon Sep 17 00:00:00 2001
From: Frank Tkalcevic <frankt@cncrouter.(none)>
Date: Mon, 31 Oct 2011 08:51:46 +1100
Subject: [PATCH 2/2] Add AUTO_WORLD_AFTER_HOMEALL to DISPLAY section of .ini file.

This automatically switches from joint mode to world mode after doing a home-all.

Also removes the $ hotkey assignment for mode toggle.

Still a bit wonky - sometime you need to home/unhome all twice to get it to work.
---
 src/emc/usr_intf/axis/scripts/axis.py |   30 +++++++++++++++++++++++++++---
 1 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/src/emc/usr_intf/axis/scripts/axis.py b/src/emc/usr_intf/axis/scripts/axis.py
index 89cf90f..f8b6951 100755
--- a/src/emc/usr_intf/axis/scripts/axis.py
+++ b/src/emc/usr_intf/axis/scripts/axis.py
@@ -132,7 +132,8 @@ lathe = 0
 mdi_history_max_entries = 1000
 mdi_history_save_filename =\
     inifile.find('DISPLAY', 'MDI_HISTORY_FILE') or "~/.axis_mdi_history"
-
+auto_world_after_homeall =\
+    inifile.find('DISPLAY', 'AUTO_WORLD_AFTER_HOMEALL') or 0
 
 feedrate_blackout = 0
 spindlerate_blackout = 0
@@ -2241,12 +2242,18 @@ class TclCommands(nf.TclCommands):
         doHoming=True
         if isHomed:
             doHoming=prompt_areyousure(_("Warning"),_("Axis is already homed, are you sure you want to re-home?"))
+        if auto_world_after_homeall:
+            vars.joint_mode.set(0)
+            commands.set_joint_mode()
         if doHoming:
             c.home(-1)
 
     def unhome_all_axes(event=None):
         if not manual_ok(): return
         ensure_mode(emc.MODE_MANUAL)
+        if auto_world_after_homeall:
+            vars.joint_mode.set(0)
+            commands.set_joint_mode()
         c.unhome(-1)
 
     def home_axis(event=None):
@@ -2557,9 +2564,25 @@ vars.dro_large_font.set(ap.getpref("dro_large_font", False))
 vars.block_delete.set(ap.getpref("block_delete", True))
 vars.optional_stop.set(ap.getpref("optional_stop", True))
 
+def all_homed():
+    isHomed=True
+    for i,h in enumerate(s.homed):
+        if s.axis_mask & (1<<i):
+            isHomed=isHomed and h
+    return isHomed
+
+def DoAutoWorldMode():
+    # watch for home-all to complete, and switch to world mode
+    # joint_mode=1 means world mode
+    if not vars.joint_mode.get():
+        if all_homed():
+            vars.joint_mode.set(1)
+            commands.set_joint_mode()
+
 # placeholder function for LivePlotter.update():
 def user_live_update():
-    pass
+    if auto_world_after_homeall:
+        DoAutoWorldMode()
 
 vars.touch_off_system.set("P1  G54")
 
@@ -2628,7 +2651,8 @@ root_window.bind("I", lambda event: jogspeed_incremental(-1))
 root_window.bind("!", "set metric [expr {!$metric}]; redraw")
 root_window.bind("@", commands.toggle_display_type)
 root_window.bind("#", commands.toggle_coord_type)
-root_window.bind("$", commands.toggle_joint_mode)
+if not auto_world_after_homeall:
+    root_window.bind("$", commands.toggle_joint_mode)
 
 root_window.bind("<Home>", commands.home_axis)
 root_window.bind("<KP_Home>", kp_wrap(commands.home_axis, "KeyPress"))
-- 
1.7.0.4

