#----------------------------------------------------------------------- # ngcgui.tcl is a front-end gui that reads one or more single function # gcode subroutine files, provides user prompts for parameters for an # arbitrary number of invocations, and creates a single output file # of gcode. # ngcgui can be run as a standalone application or its functionality # can be embedded in a parent tcl application including the axis gui. # Standalone Usage (typ) create link: # $ ln -s somewhere/ngcgui.tcl destination_in_path/ngcgui # # Usage: # ngcgui --help | -? # ngcgui [Options] -D nc_files_directory_name # ngcgui [Options] -i emc_inifile_name # ngcgui [Options] # # Options: # [-S subroutine_file] # [-p preamble_file] # [-P postamble_file] # [-o output_file] # [-a autosend_file] (autosend to axis default:auto.ngc) # [--noauto] (no autosend to axis) # [--font [big|small|fontspec]] (default: "Helvetica -10 bold") # [--horiz|--vert] (default: --horiz) # [--cwidth comment_width] (width of comment field) # [--vwidth varname_width] (width of varname field) # [--quiet] (fewer comments in outfile) # [--noiframe] (default: frame displays image) # #----------------------------------------------------------------------- # ngcgui developed on git-master version 2.4.0-pre # named "O" words available since: EMC 2.3.0, April 19, 2009 #----------------------------------------------------------------------- # Copyright: 2010-2011 # Author: Dewey Garrett # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #----------------------------------------------------------------------- # ngcgui allows a user to write subroutine files that contain # a single subroutine as described in # 3.7 Calling Files of the EMC ________ manual # and then use or test them with a gui frontend that simplifies # user entry of both calling arguments (positional parameters #1,#2,...) # and _global named parameters identified with a leading underscore like # (#<_global_named_parameter>) # see http://wiki.linuxcnc.org/cgi-bin/emcinfo.pl?Named_Parameters # If the subroutine includes lines to equate positional parameters # (#n) to named parameters (#) on special association lines like: # # # = #n (optional_comment_text) # # then the positional parameter will be supplemented with the more # descriptive # in the gui entry box and any optional_comment_text # will be included in the gui. Use of the descriptive # in # the body of the subroutine will make it more readable but is not # mandatory. # # When this format is used, the order of appearance of the positional # parameters must be monotonicly increasing with no omissions. This # helps to prevent user errors in assignment of parmnames to parameters. # # A default value can also be specified on the special association line like: # # = #n (=dvalue) # or # # = #n (=dvalue optional_comment_text) # All postional parameters must be entered -- an error occurs if an item # entry is missing when a feature is made with "Create Feature" # For _globals, additional information can be included on a special # association comment line: # ( #<_globalname> optional_comment_text ) # to include a default value: # ( #<_globalname> =dvalue optional_comment_text ) # (note a default dvalue may be superseded by settings in a preamble file) # As in many languages, avoid use of _globals is recommended # Entries for _globals may be omitted since they could be set through other # mechanisms. An error _will_ occur at runtime if a used _global is # undefined. # (i think there are some bugs in interpreter passing named globals to subs # (when they are set using mdi -- using an "immediate" preamble entry # (like :#_someglobal=1234) can be helpful) # To allow subroutines to return values as named _globals, _globals with # names that contain a colon (:) character are ignored in the creation of # entry boxes # example a subroutine called from a Subfile named o returns # results like: #<_line:theta>, $<_line:length> etc. # This feature can be used to hide globals from entry boxes for any purpose or # communication between routines # Workflow: # 1) The directory location for ngc gcode files used in emc2 # is specified in the ini file by: [DISPLAY]PROGRAM_PREFIX # 2) Candidate files for use with this utility should contain # a single subroutine as described in: # 3.7 Calling Files of the EMC ________ manual # 3) Optionally, user supplies a Preamble file of gcode # No substitutions are performed on this file # 4) User specifies a subroutine file (Subfile). # Entry boxes are created for each positional parameter and # each _global variable used within the Subfile. # 5) Optionally, user supplies a Postamble file of gcode # No substitutions are performed on this file # 6) "Create Feature" Button adds feature to queue for output file. # The gui will verify that all positional parameters are not # null but makes no checks on values. # A conflict would occur if a _global variable is set in both # the preamble file and a Subfile _global entry box. When # this situation is detected, the preamble file value is entered # in the entry box and the entry box is disabled from entry # The gui will verify that all _globals are not # null but makes no checks on values. # 7) "Finalize" button prompts for filename, and writes output file # with a terminating m2 # 8) After finalizing the file, the user may send the file to # the axis gui with the SendFileToAxis button. If axis is not running, # an error is displayed. User should verify axis state before # sending. Errors detected by axis are shown within the axis # application. # 9) to create a file with multiple sections from one or more # subroutine files: # a) enter values for Preamble, Subfile, Postamble # b) fill in _global and positional parameters # d) "Create Feature" number_1 # e) If this this the only feature, select "Finalize" to write # the file. Then select "SendFileToAxis" to send the file to axis # or "Create Feature" to start a new file # f) For multiple features, continue: # enter different parameter values # or # specify new values for Preamble, Subfile, Postamble # and fill in the new entry box values # g) "Create Feature" number_2 # h) Repeat f),g) for all features # i) "Finalize" the file (as above) # The Preamble and Postamble files are optional, for example one # might specify the Preamble only for the first subroutine and the # Postamble only for the last subroutine in making a output file # for a set of features with common parameters specified in a # single preamble file of features. # Options: # "Retain values on next Subfile read" # After opening a Subfile (and creating an output file) a second # Subfile (third,fourth, ...) may be opened while retaining values # for _globals and positional parameters where the names are # _matched_ in the subsequent file. This is useful when # testing new subroutines and may be useful when combining multiple # feature routines if they share parameters with common names like # "#<_zsafe>", "#", etc. # Values for _numbered_ positional parameters (#n) without a name # association are never retained. # "Expand subroutine" # When checked, subroutines are expanded in the # output file. This allows the axis_gui to highlight # gcode lines in the text window when paths are left-clicked in # the 3D window (and vice-vera) when subroutines are used. # In expanding subroutines, labels within are made unique # to avoid name collision with labels in other expansions or # other included subroutines. Only one level of subroutine # expansion is performed. If the interpreter detects an error, it # is sometimes unclear where it occurs when subroutines are called. # Expanding the Subfile and rerunning often gives a line number # as an aid in finding the problem. # # When not checked, subroutines are called and not expanded. # Button Shortcut bindings: # Preamble, Subfile, Postamble buttons # Instead of using the button and file selection dialog, enter # a new file name in the associated entry and to open # and read different file. When the filename differs from the # currently laoded file, the filename text changes color. # This shortcut is useful when you are debugging/editing one of the # input files -- enter a in the corresponding entry item # for the filename to reload the file. # Notes: # 0. ngcgui developed and tested under emc2-pre2.5 # 1. ngcgui supports subroutine files that contain a _single_ # subroutine in a file where the name of the subroutine # is the same as the name of the file. # ex: # $ cat rect.ngc # o sub # ... # o endsub # Only comments and empty lines may appear before sub or after endsub # 2. The parameters passed to a subroutine (Postional parameters) # are identified as "Numbered parameters" #1,#2,...,#n with # n <= 30 # ngcgui finds any instances of #1,...,#30 and identifies # each as a positional parameter for invocation of the subroutine. # So, if you have a subroutine with 3 parameters (#1,#2,#3), # it is not a good idea to use parameters like #4 or #30 in the # body of the routine since they will increase the number of # entry-box items in the ngcgui front-end and cause great confusion. # # In the manual: # "Parameters from #n+1 to #30 have the same value as # in the calling context" # If used, these _globals will cause the confusion mentioned above # so it would be better to use the "Named" format for _globals. # For example: #<_feedrate> # 3. EMC gcode supports labels for conditionals and subroutines # in both "Numbered" (ex: o100) and "Named" (ex: o) forms. # Support for the "Numbered" label format is included, but # it would be clearer to limit ngcgui support to: # Positional Parametrs --> #1, ..., #n 1<=n<=30 # Named Globals --> #<_global_name> # Named Labels --> o # This seems consistent with the trajectory of EMC gcode and # accomodation of earlier styles (numbered labels and _globals like # #n+1 to #30) is a small matter of editing:). # 4. If one inadvertenly codes a _global name in the special association # to positional parameters like this: # #<_aglobal> = #4 # and uses the same _global elsewhere, unexpected results may occur. # 5. If a file (subfile,preamble,postamble) is removed or modified by # another application (like an editor), the color for its name will # change to notify the ngcgui user that it should probably be reloaded. # 6. The preamble file is provided to support simple setup actions # like g20/g21,g40 etc. Similarly, the postamble file supports # terminating actions as required like m5. # The preamble and postamble file can be more complex even # including subroutines. Such inclusion requires care # by the user if multiple files are used to make a single output # file with ngcgui because if a file containing subroutines # is included more than once, a multiple definition error is # flagged. The user can avoid this by carefully selecting/deselecting # preamble/postamble files but a better course is to avoid # subroutines in these files and rely on a library of "subroutine-only" # files in the [DISPLAY]PROGRAM_PREFIX directory. # 7. ngcgui inserts a special global variable named #<_feature> that begins # with a value of 0 and is incremented for each added feature. This # _global can be tested in subroutines; no entry box is created for it. # 8. entry boxes for _global and postional parameters include a key bindings # keys x,y,z,a,b,c,u,v,w,d. When embedded in axis, typing these keys # cause the current value (emc_rel_act_pos) to be entered into the # entry box. This function makes it simple to enter current coordinate # values. The d key will enter the 2*x for the diameter on a lathe) # # (If there is a global ::entrykeybinding proc, it will # be used instead for these key bindings so that other embedding # applications can handle thse keys -- see the source for the parameters # passed to the proc.) # 9. lines before the o<>sub line and after the o<>endsub line must # be comments (enclosed in parentheses) or begun with a semicolon (;) # 10. each time an output file is finished, ngcgui saves a copy in # /tmp/ngcgui_bak/ just in case you want to see it or reuse it later # The /tmp directory is normally purged at restart or after # a number of days determined by the variable TMPTIME in # the system file /etc/default/rcS (ubuntu for example) # 11. key bindings # Escape return to Preview page (only if embed_in_axis) # Ctrl-a Toggle autosend # Ctrl-c Clear entries # Ctrl-d Set entries to default values # Ctrl-e Open editor specified by $VISUAL on last outfile # Ctrl-f Create feature # Ctrl-F Finalize # Ctrl-k Show key bindings # Ctrl-n Restart (cancel pending) # Ctrl-p (re)Read Preamble # Ctrl-P (re)Read Postamble # Ctrl-r (re)Read Subfile # Ctrl-s Show status # Ctrl-S Show full status (debug info) # Ctrl-u Open editor specified by $VISUAL on current subfile # Ctrl-U Open editor specified by $VISUAL on current preamble # 12. all entry boxes are checked for valid numbers and the entry is # turned red if invalid. # 13. Emc gcode (2.3 19apr09) allows a single semicolon use for comments. # This gui supports semicolon comments but the syntax for special # association lines requires the () forms: # # for positional parameters 1<=n<=30: # # = #n (=defaultvalue comment_text) # # for globals: # (#<_globalname> = value comment_text) # 14. Features requiring emc-2.4pre (that I can remember): # a) error detection when sending file to axis # 15. Some helper subroutine files that are included in the # [DISPLAY]PROGRAM_PREFIX directory may not be # suitable for use as a subfile. To indicate this to a # user, include a comment line: # (not_a_subfile) # Alternatively, these files can be placed in a different # directory specified in the ini file [WIZARD]WIZARD_ROOT # 16. using a launcher (like ubuntu gnome destop launcher) doesn't # make it easy to pass in environmental variables like VISUAL. # This works for a launcher: put ngcgui.tcl in a directory # such as /home/yourname/bin and create script such as # $ cat /home/yourname/bin/launch_ngc # #!/bin/sh # export VISUAL=gedit ;# your favorite editor # /home/yourname/bin/ngcgui.tcl -a auto -i your inifile # # make it executable: # $ chmod 755 /home/yourname/bin/launch_ngc # configure the launcher so the command is: # Command: /home/yourname/bin/launch_ngc # # 17. xembed support removed, internal embedding works better # # 18. If --vwidth 0 is used and a parameter has no comment, the variable # name is placed in the comment field # # 19. The proc embed_in_axis_tab will embed directly in an axis tab using # [DISPLAY]USER_COMMAND_FILE (or ~/.axisrc) # example: # w = widgets.right.insert("end", 'ngcgui', text='Ngcgui') # w.configure(borderwidth=1, highlightthickness=0) # f = Tkinter.Frame(w, container=0, borderwidth=0, highlightthickness=0) # f.pack(fill="both", expand=1, anchor="nw",side="top") # root_window.tk.call("source","somepath/ngcgui.tcl") # root_window.tk.call("::ngcgui::embed_in_axis_tab",f,"nameof_ngcgui_subfile") # # 20. The Preamble and Postamble entry fields may be used to insert # immediate gcode commands instead of reading files. The immediate # syntax is signaled by a leading colon (:), commands are separated by # semicolons (;). Example: # :t0m6;(debug, pausing);m0 (pause) # The commands are not validated by ngcgui but are added to the # output gcode file # # 21. When embedding in axis directly, multiple tabpagess can be specified. Each # can be used independently to add multiple features from the initial or # newly selected subfiles. If multiple tabpagess have created features, the # Finalize action will offer to finalize all tabpagess in left-to-right order. # Beware of this ordering. You may rearrange page order before finalizing. # # 22. Subfiles can optionally include a special comment: # (info: info_text) # The info text will be displayed (embed_in_axis only) # # 23. An optional image file (.png,.gif,.jpg,.pgm) can accompany a subfile. # The image file can help clarify the parameters; a window displaying # the image is popped up when the subfile is read. The image file # should be in the same directory as the subfile and have the same # name with an appropriate image suffix, e.g. the subfile iquad.ngc # should be accompanied by an image file iquad.png # # 24. when ngcgui pages are embedded in the axis gui, options can # be specified: # NGCGUI_OPTIONS = opt1 opt2 ... # opt items: # nonew -- disallow making new tab page # noremove -- disallow removing any tab page # noauto -- noautosend (makeFile, then manually send) # noiframe -- put image inside a toplevel instead of a frame # so all controls are available # # 25. when ngcgui pages are embedded in the axis gui and the user # is allowed to open new subroutines, the initial starting directroy # for subfiles is: # the first directory in [RS274NGC]SUBROUTINE_PATH if # [RS274NGC]SUBROUTINE_PATH is specified # or # the dir specified by [DISPLAY]PROGRAM_PREFIX if # [DISPLAY]PROGRAM_PREFIX is specified # otherwise # "." #-----------------------------------------------------------------------