Hi!
I am quite new to EMC developing, and not really good with tcl and 
python. Actually, I started this morning. However, I managed to add a 
new menu-item to axis' File menu.
It is called "Filter", you choose an executable program, and after 
pressing ok, the executeable is called with one parameter being the 
currently opened gcode.
The program can do whatever with this code, e.g. remove all comments, 
center it, modify it, and is expected to finally output some new gcode 
to its output stream.
This stream is written to a temporary file , and reread as new gcode-file.

[The temporary file is named "filter.ngc", which is stupid, it should be 
random. I don't know how to do this.]

This is functionally different from the filters is the open-file dialog, 
as they have no access to the currently opened gcode.
The directory of the filters can currently be specified in the ini-file 
of the machine, as entry EMC->FILTER_DIRECTORY = ....

Maybe there are better ways of accomplishing this, but I believe that 
the basic functionallity is actually good.
Examples of filters that one could program and execute by this:
Center Gcode, MirrorX, MirrorY, ExchangeXwithY, Optimize paths, 
FixIntendation, ....
Or a program that for a "schleppmesser" (sorry, don't know the English 
name, a knife that is in the lathe, axially rotate-able, cutting a 
fraction behind the actual position) includes the initial direction 
moves and respects the delayed cutting.

Some of this codes I have already programed (flipping, N* removal), and 
currently I use them from the shell.

Below is a difference between a git download I did yesterday and my 
current code. The ini file changes are obviously just for testing.

So, what do you guys think, is this something that should be part of axis?
greetings,
  Bernhard Kubicek, Vienna, Austria

-------------------
diff --git a/configs/Sherline3Axis/Sherline3Axis_mm.ini 
b/configs/Sherline3Axis/Sherline3Axis_mm.ini
index 580791d..3032c57 100644
--- a/configs/Sherline3Axis/Sherline3Axis_mm.ini
+++ b/configs/Sherline3Axis/Sherline3Axis_mm.ini
@@ -22,7 +22,7 @@ MACHINE =               EMC-HAL-STEP-MM
  DEBUG = 0
  # DEBUG =               0x00000007
  # DEBUG =               0x7FFFFFFF
-
+FILTER_DIRECTORY = /hobe/bkubicek/bin/
  
###############################################################################
  # Sections for display options
  
###############################################################################

diff --git a/share/axis/tcl/axis.tcl b/share/axis/tcl/axis.tcl
index 24f0174..ca99be5 100644
--- a/share/axis/tcl/axis.tcl
+++ b/share/axis/tcl/axis.tcl
@@ -60,6 +60,11 @@ setup_menu_accel .menu.file end [_ "_Edit..."]
  setup_menu_accel .menu.file end [_ "_Reload"]

  .menu.file add command \
+-accelerator [_ "Ctrl-F"] \
+-command do_filter
+setup_menu_accel .menu.file end [_ "_Filter..."]
+
+.menu.file add command \
          -accelerator [_ "Ctrl-S"] \
          -command save_gcode
  setup_menu_accel .menu.file end [_ "_Save gcode as..."]
diff --git a/src/emc/usr_intf/axis/scripts/axis.py 
b/src/emc/usr_intf/axis/scripts/axis.py
index edabbf1..1302ec2 100755
--- a/src/emc/usr_intf/axis/scripts/axis.py
+++ b/src/emc/usr_intf/axis/scripts/axis.py
@@ -1828,6 +1828,28 @@ class TclCommands(nf.TclCommands):
          f = str(f)
          open_directory = os.path.dirname(f)
          commands.open_file_name(f)
+    def do_filter(*event):
+        if running(): return
+        global open_directory
+        global filter_directory
+        global loaded_file
+        if not filter_directory: filter_directory=open_directory
+        types = ((_("All files"), "*"),)
+        f = root_window.tk.call("tk_getOpenFile", "-initialdir", 
filter_directory,
+            "-filetypes", types)
+        if not f: return
+        o.set_highlight_line(None)
+        f = str(f)
+        tempfile = os.path.join(tempdir, "filter.ngc")
+        exitcode, stderr = filter_program(f, loaded_file, tempfile)
+        if exitcode:
+         root_window.tk.call("nf_dialog", (".error", "-ext", 
stderr),_("Filter failed"),
+                            _("The program %(program)r exited with code 
%(code)d.  "
+                            "Any error messages it produced are shown 
below:")
+                                    % {'program': program_filter, 
'code': exitcode},
+                            "error",0,_("OK"))
+         return
+        return open_file_guts(tempfile, True, False)

      def remote (cmd,arg=""):
          if cmd == "clear_live_plot":
@@ -2689,6 +2711,7 @@ vars.emcini.set(sys.argv[2])
  open_directory = inifile.find("DISPLAY", "PROGRAM_PREFIX")
  vars.machine.set(inifile.find("EMC", "MACHINE"))
  extensions = inifile.findall("FILTER", "PROGRAM_EXTENSION")
+filter_directory = inifile.find("EMC", "FILTER_DIRECTORY")
  extensions = [e.split(None, 1) for e in extensions]
  extensions = tuple([(v, tuple(k.split(","))) for k, v in extensions])
  postgui_halfile = inifile.find("HAL", "POSTGUI_HALFILE")




------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Emc-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to