|
Mach Modules Documentation
Lua Module API Documentation
|
Go to the source code of this file.
Functions | |
| GCACaller | CreateDefaultConfig () |
| Create a default GCAdapter configuration file for the current Mach profile. | |
| GCACaller | Create () |
| Create and return a new GCACaller instance via metatable inheritance. | |
| GCACaller | ConfigSettings () |
| Open the GCAdapter settings dialog for the operator to configure adaptation options. | |
| AddNameAndDesc (Name, Description) | |
| Create a settings entry table with a display name and description. | |
| GetPostFiles (tbl, display) | |
| Filter post processor files to only user posts and strip template naming from display names. | |
| SaveOnClose (SettingsTbl, file) | |
| Serialize a settings table to a Lua file for persistent storage. | |
| PopulateSettings () | |
| Populate the Settings page UI with all settings from the loaded configuration. | |
| AddSetting (name, tbl, prefix) | |
| Add a single setting entry row to the settings grid bag sizer. | |
| PopulateModifications () | |
| Build and display the Modifications page UI for the GCAdapter settings dialog. | |
| PopulateModTables (tbl, post_table) | |
| Flatten a post processor three-field modification table into formatted strings and append to a list. | |
| PopulateTables (tbl, post_table) | |
| Flatten a post processor two-field table into formatted strings and append to a list. | |
| MakeString (tbl) | |
| Concatenate an array of strings into a single newline-delimited string. | |
| AddToPost (PostTable, mod, post_name, table_name) | |
| Append a modification entry to a post processor Lua file's named table. | |
| UpdateCtrl (ctrl, mod) | |
| Append a modification string to a text control label and scroll to the end. | |
| Validate (str, param) | |
| Validate a user-entered modification string for use in a post directive. | |
| UI | AddMod (PostTable, post_name) |
| Add a ModWord directive to the current post and update the display control. | |
| UI | AddDel (PostTable, post_name) |
| Add a DeleteWord directive to the current post and update the display control. | |
| FormatParams (par) | |
| Format a parameter string into a comma-separated quoted letter list. | |
| UI | AddCom (PostTable, post_name) |
| Add a CommentWord directive to the current post and update the display control. | |
| UI | AddBlockDelete (PostTable, post_name) |
| Add a DeleteBlock directive to the current post and update the display control. | |
| UI | AddBlockComment (PostTable, post_name) |
| Add a CommentBlock directive to the current post and update the display control. | |
| GCACaller | CreateTmpDir () |
| Create a new temporary working directory for GCAdapter subprocess output. | |
| GCACaller | DeleteTmpDir (path) |
| Delete a temporary directory and all files within it. | |
| GCACaller | NotFinished () |
| Poll the GCAdapter subprocess for completion, progress updates, and errors. | |
| GCACaller | WaitArray () |
| Poll whether the operator has confirmed the array configuration dialog. | |
| GCACaller | BuildAdaptedPath (srcFullPath) |
| Build the adapted output file path from a source G-code file path using current settings. | |
| GCACaller | CheckComp () |
| Check whether Type C cutter compensation (SUV) is currently selected. | |
| GCACaller | GetRecentDirectories (instance) |
| Retrieve the list of recently used G-code source directories from the Mach profile. | |
| GCACaller | AdaptFiles (Path, instance, show) |
| Adapt a single G-code file using GCAdapter and optionally load it into Mach. | |
| GCACaller DI | DestroyGauge () |
| Destroy the GCACaller progress bar dialog and release associated resources. | |
| GCACaller | AdaptFolder (Path) |
| Adapt all G-code files in a folder and its subdirectories recursively. | |
| GCACaller | AdaptFolderTest (Path) |
| Adapt all G-code files in a folder recursively, pausing after each file to display the toolpath. | |
| GCACaller | MirrorX () |
| Mirror the currently loaded G-code file across the Y-axis and reload it. | |
| GCACaller | MirrorY () |
| Mirror the currently loaded G-code file across the X-axis and reload it. | |
| GCACaller | Rotate (degree, shift) |
| Rotate the currently loaded G-code file by a specified degree and reload it. | |
| GCACaller | Array () |
| Generate an arrayed G-code file from the currently loaded G-code. | |
| GCACaller | ScreenLoad () |
| Register the GCACaller pre-canned command creator with the Mach command registrar. | |
| GCACaller | CreatePreCannedCommands () |
| Register all GCACaller pre-canned Mach commands for GCode adaptation and transformation. | |
| GCACaller AdaptFiles | ( | Path | , |
| instance | , | ||
| show | ) |
Adapt a single G-code file using GCAdapter and optionally load it into Mach.
The public entry point for single-file G-code adaptation. Wraps GCACaller._AdaptFiles() in a w.pcall() protected call and raises any errors via w.Error(). The inner implementation:
| Path | (string|nil) Full path to the G-code file to adapt. If nil, a file browser dialog is shown for the operator to select a file |
| instance | (number|nil) The Mach4 instance handle. If nil, uses mc.mcGetInstance() |
| show | (boolean|nil) If true or nil, loads the adapted file into Mach after adaptation. If false, adapts without loading (used by AdaptFolder) |
| GCACaller AdaptFolder | ( | Path | ) |
Adapt all G-code files in a folder and its subdirectories recursively.
Iterates over every entry in the specified folder. Files are passed to GCACaller.AdaptFiles() for adaptation (with show=false so files are not loaded into the Mach editor). Subdirectories are descended into recursively via a second call to GCACaller.AdaptFolder().
If Path is nil, a directory browser dialog is shown for the operator to select a folder. Settings are loaded from the GCAdapterConfig.lua profile file; if missing, a default config is created automatically. All errors are caught via w.pcall() and raised via w.Error().
| Path | (string|nil) Full path to the folder to adapt. If nil, opens a directory browser dialog for the operator to select a folder |
| GCACaller AdaptFolderTest | ( | Path | ) |
Adapt all G-code files in a folder recursively, pausing after each file to display the toolpath.
Same behavior as GCACaller.AdaptFolder() but inserts a 2-second pause after each file is loaded via w.PleaseWaitDialog() so the operator can inspect the rendered toolpath before the next file is processed. Recursively descends into subdirectories.
If Path is nil, a directory browser dialog is shown for the operator to select a folder. Settings are loaded from the GCAdapterConfig.lua profile file; if missing, a default config is created automatically.
| Path | (string|nil) Full path to the folder to process. If nil, opens a directory browser dialog for the operator to select a folder |
| UI AddBlockComment | ( | PostTable | , |
| post_name | ) |
Add a CommentBlock directive to the current post and update the display control.
Reads the block pattern from UI.m_comment2, validates it, converts it to uppercase, formats it as a CommentBlock directive string, appends it to the post file's BlocksToComment table via AddToPost(), and updates the display text control via UpdateCtrl(). If validation fails, a GMS notification warning is shown and no changes are made.
| PostTable | (table) The currently loaded post processor table |
| post_name | (string) The name of the post processor file to modify |
| UI AddBlockDelete | ( | PostTable | , |
| post_name | ) |
Add a DeleteBlock directive to the current post and update the display control.
Reads the block pattern from UI.m_delete2, validates it, converts it to uppercase, formats it as a DeleteBlock directive string, appends it to the post file's BlocksToDelete table via AddToPost(), and updates the display text control via UpdateCtrl(). If validation fails, a GMS notification warning is shown and no changes are made.
| PostTable | (table) The currently loaded post processor table |
| post_name | (string) The name of the post processor file to modify |
| UI AddCom | ( | PostTable | , |
| post_name | ) |
Add a CommentWord directive to the current post and update the display control.
Reads the word to comment from UI.m_comment1, validates it, converts it to uppercase, formats it as a CommentWord directive string, appends it to the post file's WordsToComment table via AddToPost(), and updates the display text control via UpdateCtrl(). If validation fails, a GMS notification warning is shown and no changes are made.
| PostTable | (table) The currently loaded post processor table |
| post_name | (string) The name of the post processor file to modify |
| UI AddDel | ( | PostTable | , |
| post_name | ) |
Add a DeleteWord directive to the current post and update the display control.
Reads the word to delete from UI.m_delete1 and optional axis parameters from UI.m_params, validates both, then formats and appends a DeleteWord directive to the post file's WordsToDelete table via AddToPost(). Updates the display text control via UpdateCtrl(). If parameters are provided, they are formatted via FormatParams() into a quoted axis list. If validation of either input fails, a GMS notification warning is shown and no changes are made.
| PostTable | (table) The currently loaded post processor table |
| post_name | (string) The name of the post processor file to modify |
| UI AddMod | ( | PostTable | , |
| post_name | ) |
Add a ModWord directive to the current post and update the display control.
Reads the find text from UI.m_orig1 and replace text from UI.m_modified1, validates both, converts them to uppercase, formats a ModWord directive string, and appends it to the post file's WordsToReplace table via AddToPost(). Updates the display text control via UpdateCtrl(). Both the original and modified text are cleared after reading. If either validation fails, a GMS notification warning is shown and no changes are made.
| PostTable | (table) The currently loaded post processor table |
| post_name | (string) The name of the post processor file to modify |
| AddNameAndDesc | ( | Name | , |
| Description | ) |
Create a settings entry table with a display name and description.
Constructs and returns a simple table with "Name" and "Description" keys. Used to populate the SettingsNames lookup table that drives label text and tooltip content for each setting row in the GCAdapter settings dialog.
| Name | (string) The display label shown next to the setting control |
| Description | (string) The tooltip text describing the setting's purpose |
| AddSetting | ( | name | , |
| tbl | , | ||
| prefix | ) |
Add a single setting entry row to the settings grid bag sizer.
Looks up the setting's display name and description from the SettingsNames table, optionally traversing nested prefix keys. Adds a static text label and an appropriate input control to UI.gbSizer1 at the current row. The input control type is determined by:
| name | (string) The settings key name to add |
| tbl | (table) The settings sub-table containing the value for this key |
| prefix | (table) Array of parent key names for nested settings traversal |
References name().
| AddToPost | ( | PostTable | , |
| mod | , | ||
| post_name | , | ||
| table_name | ) |
Append a modification entry to a post processor Lua file's named table.
Reads the user post file at the given path, locates the named table (e.g., WordsToReplace, WordsToDelete) by searching for its identifier and the opening brace, inserts the new modification string as the first entry in that table, then writes the modified content back to the same file.
| PostTable | (table) The currently loaded post processor table (unused directly, present for context) |
| mod | (string) The formatted directive string to insert (e.g., '{"ModWord","G0","G1"}') |
| post_name | (string) The base name of the post processor file (without path or extension) |
| table_name | (string) The name of the table within the post file to insert the entry into |
| GCACaller Array | ( | ) |
Generate an arrayed G-code file from the currently loaded G-code.
Opens an array configuration dialog for the operator to specify rows, columns, and X/Y separation distances. If the current file already has an array header comment, the header is parsed to pre-populate the dialog with the previous array settings and single-part extents are derived from the current path length registers.
After the operator confirms the configuration, the function:
The output file path is determined by GCACaller.BuildAdaptedPath() using the current GCAdapter settings (DefaultOutputDirectory, AdaptedFilenameAddition, AdaptedExtension).
| GCACaller BuildAdaptedPath | ( | srcFullPath | ) |
Build the adapted output file path from a source G-code file path using current settings.
Constructs the full output path for an adapted G-code file based on the GCACaller.Settings configuration. The output directory is taken from Settings.DefaultOutputDirectory if set; otherwise the source file's own directory is used. The output directory is created automatically if it does not exist.
The output filename is built as: <OutputDir><BaseName>[<AdaptedFilenameAddition>].<ext>
Where:
| srcFullPath | (string) Full path to the source G-code file to be adapted |
| GCACaller CheckComp | ( | ) |
Check whether Type C cutter compensation (SUV) is currently selected.
Reads the PV_CCT machine parameter and tests the PV_CCT_BIT_SUV bit using w.GetParameterBitCached(). Initializes the mc.PV_CCT_BIT_SUV and mc.PV_CCT constants to their default values if they are not already defined.
| GCACaller ConfigSettings | ( | ) |
Open the GCAdapter settings dialog for the operator to configure adaptation options.
Public entry point for the GCAdapter configuration UI. Delegates immediately to GCACaller._ConfigSettings(), which builds and displays a modal wxWidgets frame containing two notebook pages: a Settings page for configuring post processor, output directory, filename additions, and other adapter options, and a Modifications page for adding ModWord, DeleteWord, CommentWord, DeleteBlock, and CommentBlock directives to the current default post processor file. Settings are loaded from the GCAdapterConfig.lua profile file and saved back on OK button click.
| GCACaller Create | ( | ) |
Create and return a new GCACaller instance via metatable inheritance.
Initializes the GCACaller metatable index to GCACaller itself and returns a new empty table with GCACaller set as its metatable. The returned object inherits all GCACaller methods and fields, allowing instance-style method calls using the colon syntax (e.g., obj:CreateTmpDir()).
| GCACaller CreateDefaultConfig | ( | ) |
Create a default GCAdapter configuration file for the current Mach profile.
Generates a GCAdapterConfig.lua settings file with default values in the profile-specific GCodeAdapterSettings directory. The following defaults are written:
If the GCodeAdapterSettings directory or DefaultOutputDirectory do not exist, they are created automatically before writing the file. Nested table settings are written as indexed sub-table assignments in the output Lua file.
| GCACaller CreatePreCannedCommands | ( | ) |
Register all GCACaller pre-canned Mach commands for GCode adaptation and transformation.
Creates and registers Mach commands for the following operations:
| GCACaller CreateTmpDir | ( | ) |
Create a new temporary working directory for GCAdapter subprocess output.
Public entry point for temporary directory creation. Wraps GCACaller._CreateTmpDir() in a w.pcall() protected call. If an error occurs, raises a GMS notification and a Lua error via w.Error(). The inner implementation:
| GCACaller DeleteTmpDir | ( | path | ) |
Delete a temporary directory and all files within it.
Public entry point for temporary directory deletion. Wraps GCACaller._DeleteTmpDir() in a w.pcall() protected call. If an error occurs during deletion, raises a GMS notification and a Lua error via w.Error(). Iterates through all files in the directory, removes each one, then removes the directory itself using lfs.rmdir().
| path | (string) Full path to the temporary directory to delete |
| GCACaller DI DestroyGauge | ( | ) |
Destroy the GCACaller progress bar dialog and release associated resources.
Destroy the GCACaller Array UI dialog and release associated resources.
Destroys the wxWidgets Dialog1 progress bar window used during the AdaptFiles G-code adaptation operation and sets GCACaller.DI to nil, releasing all resources. This function is stored as a closure on GCACaller.DI and is called automatically when the adaptation subprocess signals completion via the finished.txt sentinel file.
Destroys the wxWidgets Dialog1 progress bar window used during the MirrorX G-code adaptation operation and sets GCACaller.DI to nil, releasing all resources. This function is stored as a closure on GCACaller.DI and is called automatically when the adaptation process completes or is canceled by the operator.
Destroys the wxWidgets Dialog1 progress bar window used during the MirrorY G-code adaptation operation and sets GCACaller.DI to nil, releasing all resources. This function is stored as a closure on GCACaller.DI and is called automatically when the adaptation process completes or is canceled by the operator.
Destroys the wxWidgets Dialog1 progress bar window used during the Rotate G-code adaptation operation and sets GCACaller.DI to nil, releasing all resources. This function is stored as a closure on GCACaller.DI and is called automatically when the adaptation process completes or is canceled by the operator.
Destroys the wxWidgets Dialog1 progress bar window used during the Array G-code adaptation operation and sets GCACaller.DI to nil, releasing all resources. This function is stored as a closure on GCACaller.DI and is called automatically when the adaptation process completes or is canceled by the operator.
Destroys the wxWidgets ArrayDialog window and sets GCACaller.UI to nil, releasing all UI resources associated with the array configuration dialog. This function is stored as a closure on GCACaller.UI and should be called when the array dialog is no longer needed.
| FormatParams | ( | par | ) |
Format a parameter string into a comma-separated quoted letter list.
Strips spaces from the input string, wraps the first character in double quotes, then iterates over remaining alphabetic characters and appends each as a quoted, comma-separated entry. The resulting string is converted to uppercase. Used to format the optional axis parameter list for DeleteWord directives.
| par | (string) Raw parameter string containing axis letters (e.g., "XY" or "X Y") |
| GetPostFiles | ( | tbl | , |
| display | ) |
Filter post processor files to only user posts and strip template naming from display names.
Iterates over the provided file table starting at index 2 (skipping the placeholder entry), retains only files whose names contain "_User_", and optionally strips the "GCAdapter_User_" prefix and "_Post.lua" suffix for display purposes. The filtered entries are added to a wxArrayString, sorted alphabetically, and returned.
| tbl | (table) Array of file name strings to filter, with a placeholder at index 1 |
| display | (boolean) If true, strips template prefix and suffix from names for display |
| GCACaller GetRecentDirectories | ( | instance | ) |
Retrieve the list of recently used G-code source directories from the Mach profile.
Reads up to 9 recently used directory paths stored in the GCAdapter section of the Mach profile INI under keys "MRUDir1" through "MRUDir9". Entries are returned in the order they were stored (most recent first). Empty entries are skipped.
| instance | (number|nil) The Mach4 instance handle. If nil, uses mc.mcGetInstance() |
| MakeString | ( | tbl | ) |
Concatenate an array of strings into a single newline-delimited string.
Iterates over all entries in the provided table and concatenates them with newline separators. Used to format modification tables into display text for the modifications page text controls.
| tbl | (table) Array of strings to concatenate |
| GCACaller MirrorX | ( | ) |
Mirror the currently loaded G-code file across the Y-axis and reload it.
Mirrors all tool paths in the currently loaded G-code file across the Y-axis (negating X coordinates) using GCAdapter.lua launched as a subprocess via lua53.exe with the MIRRORX operation ID.
Processing steps:
| GCACaller MirrorY | ( | ) |
Mirror the currently loaded G-code file across the X-axis and reload it.
Mirrors all tool paths in the currently loaded G-code file across the X-axis (negating Y coordinates) using GCAdapter.lua launched as a subprocess via lua53.exe with the MIRRORY operation ID.
Processing steps:
| GCACaller NotFinished | ( | ) |
Poll the GCAdapter subprocess for completion, progress updates, and errors.
Checks three sentinel files written by the GCAdapter subprocess into the current temporary directory:
All file I/O and error handling is wrapped in w.pcall(). Errors from the subprocess are re-raised as GMS notifications and Lua errors. Results are stored in the module-level globals GCACaller.g_file, GCACaller.g_path, and GCACaller.g_dir.
| PopulateModifications | ( | ) |
Build and display the Modifications page UI for the GCAdapter settings dialog.
Populates the Modifications notebook page (UI.MyPage2) with five sections: Modify (word replacement), Delete (word deletion), Comment (word commenting), Delete Block, and Comment Block. For each section, loads existing modifications from the current default post processor file and displays them in a read-only text control. Provides text entry fields and Add buttons to insert new directives into the post file. Loads the post from GCACaller.Settings.DefaultPost; falls back to GCAdapter_User_Default_Post if the configured post fails to load.
| PopulateModTables | ( | tbl | , |
| post_table | ) |
Flatten a post processor three-field modification table into formatted strings and append to a list.
Iterates over the entries in post_table (each a three-element array), formats each as a "{field1,field2,field3}" string, and appends it to tbl. Used to collect ModWord entries (original, replacement, and type) from multiple post table sections (CommonWordsToReplace, MachineWordsToReplace, WordsToReplace) into a single display list.
| tbl | (table) Destination array to append formatted strings into |
| post_table | (table) Source array of three-element arrays from the post processor |
| PopulateSettings | ( | ) |
Populate the Settings page UI with all settings from the loaded configuration.
Iterates over SettingsNamesSorted (a sorted wxArrayString of setting keys) and calls AddSetting() for each entry to add a label and input control row to the settings grid. For nested table settings, delegates to the inner populatesettings() recursive function. Flat (non-table) settings are added directly via AddSetting().
| PopulateTables | ( | tbl | , |
| post_table | ) |
Flatten a post processor two-field table into formatted strings and append to a list.
Iterates over the entries in post_table (each a two-element array), formats each as a "{field1,field2}" string, and appends it to tbl. Used to collect DeleteWord, CommentWord, DeleteBlock, and CommentBlock entries from multiple post table sections into a single display list.
| tbl | (table) Destination array to append formatted strings into |
| post_table | (table) Source array of two-element arrays from the post processor |
| GCACaller Rotate | ( | degree | , |
| shift | ) |
Rotate the currently loaded G-code file by a specified degree and reload it.
Rotates all tool paths in the currently loaded G-code file by the given angle using GCAdapter.lua as a subprocess. When the shift parameter is true (default), the function calculates the bounding box transformation for the given rotation angle and computes X/Y shift values to keep the rotated part entirely in the positive quadrant.
The adapted output filename includes the rotation angle (e.g., "_GCRotate90.00"). If the current file already contains a rotation suffix, it is stripped before building the new output path to avoid accumulating rotation labels on repeated rotations.
Processing steps:
| degree | (number) The rotation angle in degrees. Positive values rotate counter-clockwise; negative values rotate clockwise (e.g., -90 for 90 CW) |
| shift | (boolean|nil) If true or nil, automatically calculate and apply XY shifts to keep the rotated part in the positive quadrant. If false, no shift is applied |
| SaveOnClose | ( | SettingsTbl | , |
| file | ) |
Serialize a settings table to a Lua file for persistent storage.
Converts the given settings table into a Lua source file that returns the table when executed. Handles nested tables recursively, and serializes string, number, and boolean value types. String values are wrapped in double quotes; numbers and booleans are written as literals. Applies special sanitization to AdaptedExtension values, stripping non-alphabetic characters. Writes the result to the specified file path.
| SettingsTbl | (table) The settings table to serialize and save |
| file | (string) Full path to the output Lua file to write |
| GCACaller ScreenLoad | ( | ) |
Register the GCACaller pre-canned command creator with the Mach command registrar.
Called automatically by Mach during screen load. Registers GCACaller.CreatePreCannedCommands with the global CommandRegistrar so that all GCAdapter Mach commands are available after screen initialization completes.
| UpdateCtrl | ( | ctrl | , |
| mod | ) |
Append a modification string to a text control label and scroll to the end.
Retrieves the current label text from the given control, strips double-quote characters from the new modification string, appends the modification followed by a newline, sets the updated label back on the control, and moves the insertion point to the end to keep the newest entry visible.
| ctrl | (userdata) The wxWidgets text control whose label will be updated |
| mod | (string) The modification directive string to append to the control |
| Validate | ( | str | , |
| param | ) |
Validate a user-entered modification string for use in a post directive.
Checks the input string against three rules:
| str | (string) The user-entered text to validate |
| param | (boolean|nil) If true, applies stricter param-only validation (no digits allowed) |
| GCACaller WaitArray | ( | ) |
Poll whether the operator has confirmed the array configuration dialog.
Checks GCACaller.wait to determine if the array UI dialog is still open. If both array_X and array_Y are non-zero and x_shift/y_shift are not yet numeric (i.e., the operator has not yet entered shift values), sets GCACaller.arr_valid to true. Used as the loop condition in the Array() wait loop: returns true while the dialog is still open, false once the operator has dismissed it.