Mach Modules Documentation
Lua Module API Documentation
Loading...
Searching...
No Matches
GCACaller.lua File Reference

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.

Function Documentation

◆ AdaptFiles()

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:

  1. Loads GCAdapter settings from the profile config file (creates defaults if missing)
  2. If Path is nil, opens a file browser for the operator to select a G-code file
  3. Builds the adapted output path via GCACaller.BuildAdaptedPath()
  4. Checks if the file contains the TRIGGER string or an already-adapted version exists; if so and ConvertIfAlreadyConverted is "NO", loads the existing adapted file directly
  5. If the selected file is an already-adapted file, searches recent directories for the original source file to re-adapt instead
  6. Creates a temporary directory, launches GCAdapter.lua as a subprocess, and polls NotFinished() while yielding to keep the UI responsive
  7. Writes the file path and directory to the Mach MRU INI entries
  8. Optionally loads the resulting adapted file into Mach via mc.mcCntlLoadGcodeFile
    Parameters
    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)
    Returns
    (string) Filename (name + extension) of the adapted output file
    (string) Full path to the adapted output file
    (string) Directory portion of the adapted output file path
    Warning
    This function blocks the calling coroutine while polling for subprocess completion. It yields via w.Yield(1) to prevent UI freezing.
    The machine's currently loaded G-code file is closed before adaptation begins.
    See also
    GCACaller.BuildAdaptedPath() for output path construction
    GCACaller.NotFinished() for subprocess completion polling
    GCACaller.AdaptFolder() for batch folder adaptation
    Note
    Documentation generated by AI on 2026-03-03

◆ 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().

Parameters
Path(string|nil) Full path to the folder to adapt. If nil, opens a directory browser dialog for the operator to select a folder
Warning
This function may take a long time for large folder trees. Each file adaptation spawns a subprocess and polls until complete before moving to the next file.
See also
GCACaller.AdaptFiles() for single-file adaptation
GCACaller.AdaptFolderTest() for folder adaptation with toolpath preview pause
Note
Documentation generated by AI on 2026-03-03

◆ AdaptFolderTest()

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.

Parameters
Path(string|nil) Full path to the folder to process. If nil, opens a directory browser dialog for the operator to select a folder
Warning
This function blocks the calling coroutine for the duration of all file adaptations. Each file adaptation itself spawns a subprocess and polls until complete.
See also
GCACaller.AdaptFolder() for batch adaptation without pause
GCACaller.AdaptFiles() for single-file adaptation
Note
Documentation generated by AI on 2026-03-03

◆ AddBlockComment()

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.

Parameters
PostTable(table) The currently loaded post processor table
post_name(string) The name of the post processor file to modify
Note
Documentation generated by AI on 2026-03-03

◆ AddBlockDelete()

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.

Parameters
PostTable(table) The currently loaded post processor table
post_name(string) The name of the post processor file to modify
Note
Documentation generated by AI on 2026-03-03

◆ AddCom()

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.

Parameters
PostTable(table) The currently loaded post processor table
post_name(string) The name of the post processor file to modify
Note
Documentation generated by AI on 2026-03-03

◆ AddDel()

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.

Parameters
PostTable(table) The currently loaded post processor table
post_name(string) The name of the post processor file to modify
Note
Documentation generated by AI on 2026-03-03

◆ AddMod()

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.

Parameters
PostTable(table) The currently loaded post processor table
post_name(string) The name of the post processor file to modify
Note
Documentation generated by AI on 2026-03-03

◆ AddNameAndDesc()

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.

Parameters
Name(string) The display label shown next to the setting control
Description(string) The tooltip text describing the setting's purpose
Returns
(table) Table with keys 'Name' (string) and 'Description' (string)
Note
Documentation generated by AI on 2026-03-03

◆ AddSetting()

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:

  • A custom DisplayFunction if defined in SettingsNames (e.g., dir picker, choice dropdown)
  • A checkbox for boolean values
  • A text control for string or numeric values Connects change event handlers to update the Settings table in real time. Increments CurrentSettingCount after each successfully added row.
    Parameters
    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
    Note
    Documentation generated by AI on 2026-03-03

References name().

◆ AddToPost()

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.

Parameters
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
Warning
This function overwrites the post processor file in place. Any syntax error in the mod string will corrupt the post file. Ensure mod is validated before calling.
Note
Documentation generated by AI on 2026-03-03

◆ Array()

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:

  1. Adds the single-part extent to the user-specified shift values
  2. Creates a temporary working directory
  3. Launches GCAdapter.lua in a subprocess via lua53.exe with the ARRAY operation ID
  4. Polls NotFinished() while yielding to keep the UI responsive
  5. Prepends an array header comment to the adapted output file
  6. Loads the resulting file into the Mach instance

The output file path is determined by GCACaller.BuildAdaptedPath() using the current GCAdapter settings (DefaultOutputDirectory, AdaptedFilenameAddition, AdaptedExtension).

Returns
(string|number) Full path to the adapted array G-code file on success, or -1 if no file is loaded or the operator cancels the array configuration dialog
Warning
This function blocks the calling coroutine while polling for subprocess completion. It yields via w.Yield(1) to prevent UI freezing.
The machine's currently loaded G-code file is closed (mc.mcCntlCloseGCodeFile) before adaptation begins and replaced with the arrayed output on completion.
See also
GCACaller.BuildAdaptedPath() for output path construction
GCACaller.NotFinished() for subprocess polling
GCACaller.WaitArray() for array UI wait loop
Note
Documentation generated by AI on 2026-03-03

◆ BuildAdaptedPath()

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:

  • AdaptedFilenameAddition is appended only if it is non-empty and not already present in the base name (prevents double-appending on repeated adaptation)
  • The file extension is replaced with Settings.AdaptedExtension if that setting is non-empty; otherwise the source file's original extension is preserved
    Parameters
    srcFullPath(string) Full path to the source G-code file to be adapted
    Returns
    (string) Full path to the adapted output file
    (string) Output directory path including trailing separator
    (string) Base name of the source file without extension
    (string) Effective file extension used for the output file
    Note
    Documentation generated by AI on 2026-03-03

◆ CheckComp()

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.

Returns
(number) 1 if Type C (SUV) compensation is active, 0 otherwise
Note
Documentation generated by AI on 2026-03-03

◆ ConfigSettings()

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.

Note
This function must be called from a screen chunk context where wxWidgets and the Mach UI event loop are available.
See also
GCACaller._ConfigSettings() for the full settings dialog implementation
GCACaller.CreateDefaultConfig() for default settings file creation
Note
Documentation generated by AI on 2026-03-03

◆ Create()

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()).

Returns
(table) A new GCACaller instance with GCACaller as its metatable
Note
Documentation generated by AI on 2026-03-03

◆ CreateDefaultConfig()

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:

  • DefaultPost: "GCAdapter_User_Default_Post"
  • DefaultExtentions: common file type filter string
  • AdaptedFilenameAddition: "_Adapted"
  • ValidComment: {";", "()"}
  • DefaultOutputDirectory: <MachDir>/GCodeFiles/
  • DefaultFloatingLength: "6"
  • ShowModifications: "NO"
  • MaxFileLength: "260000"
  • ConvertIfAlreadyConverted: "NO"
  • AdaptedExtension: ""

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.

Returns
(string) Full path to the newly created GCAdapterConfig.lua configuration file
Warning
This function overwrites any existing GCAdapterConfig.lua file in the profile directory. Existing custom settings will be lost.
Note
Documentation generated by AI on 2026-03-03

◆ CreatePreCannedCommands()

GCACaller CreatePreCannedCommands ( )

Register all GCACaller pre-canned Mach commands for GCode adaptation and transformation.

Creates and registers Mach commands for the following operations:

  • Adapt File: Opens file browser to select and adapt a single G-code file
  • GCAdapter Settings: Opens the GCAdapter configuration dialog
  • Adapt Folder: Opens folder browser to batch-adapt all G-code files in a directory
  • Adapt Folder Test: Same as Adapt Folder but pauses after each file load to display toolpath
  • Mirror X: Mirrors the currently loaded G-code across the Y-axis
  • Mirror Y: Mirrors the currently loaded G-code across the X-axis
  • Rotate 90 CW: Rotates the currently loaded G-code 90 degrees clockwise
  • Rotate 90 CCW: Rotates the currently loaded G-code 90 degrees counter-clockwise
  • Rotate 180: Rotates the currently loaded G-code 180 degrees
  • Array: Opens the array configuration dialog and generates an arrayed G-code file Each command is registered with a display label suitable for operator panel buttons.
    Note
    This function should be called once during screen initialization via GCACaller.ScreenLoad()
    See also
    GCACaller.ScreenLoad() for screen load wiring
    Note
    Documentation generated by AI on 2026-03-03

◆ CreateTmpDir()

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:

  1. Generates a unique temp filename using os.tmpname()
  2. Deletes any leftover temp directories from previous crashed sessions
  3. Creates a new directory under Modules\GCAdapter\tmp_dir\ and stores the path in GCACaller.temp_dir
    Returns
    (string) The path to the newly created temporary directory
    Warning
    Any existing temporary directories found under the GCAdapter tmp_dir folder will be deleted before the new directory is created, to clean up from any previous crashes.
    Note
    Documentation generated by AI on 2026-03-03

◆ DeleteTmpDir()

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().

Parameters
path(string) Full path to the temporary directory to delete
Returns
(string) Status message from the protected call result
Warning
This function permanently deletes all files in the specified directory and then removes the directory itself. This operation cannot be undone.
Note
Documentation generated by AI on 2026-03-03

◆ DestroyGauge()

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.

Warning
After this function is called, GCACaller.DI will be nil. Do not attempt to access gauge or dialog elements after calling this function.
Note
Documentation generated by AI on 2026-03-03

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.

Warning
After this function is called, GCACaller.DI will be nil. Do not attempt to access gauge or dialog elements after calling this function.
Note
Documentation generated by AI on 2026-03-03

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.

Warning
After this function is called, GCACaller.DI will be nil. Do not attempt to access gauge or dialog elements after calling this function.
Note
Documentation generated by AI on 2026-03-03

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.

Warning
After this function is called, GCACaller.DI will be nil. Do not attempt to access gauge or dialog elements after calling this function.
Note
Documentation generated by AI on 2026-03-03

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.

Warning
After this function is called, GCACaller.DI will be nil. Do not attempt to access gauge or dialog elements after calling this function.
Note
Documentation generated by AI on 2026-03-03

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.

Warning
After this function is called, GCACaller.UI will be nil. Do not attempt to access any UI elements after calling this function.
Note
Documentation generated by AI on 2026-03-03

◆ FormatParams()

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.

Parameters
par(string) Raw parameter string containing axis letters (e.g., "XY" or "X Y")
Returns
(string) Formatted uppercase quoted parameter list (e.g., "\"X\",\"Y\"")
Note
Documentation generated by AI on 2026-03-03

◆ GetPostFiles()

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.

Parameters
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
Returns
(userdata) Sorted wxArrayString containing only the matching user post file names
Note
Documentation generated by AI on 2026-03-03

◆ GetRecentDirectories()

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.

Parameters
instance(number|nil) The Mach4 instance handle. If nil, uses mc.mcGetInstance()
Returns
(table) Array of directory path strings, most recent first. May be empty if no directories have been recorded yet
Note
Documentation generated by AI on 2026-03-03

◆ MakeString()

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.

Parameters
tbl(table) Array of strings to concatenate
Returns
(string) All table entries joined with newline characters, or empty string if table is empty
Note
Documentation generated by AI on 2026-03-03

◆ MirrorX()

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:

  1. Creates a progress bar dialog
  2. Retrieves the currently loaded G-code filename from the Mach instance
  3. Loads GCAdapter settings from the profile config file
  4. Builds the adapted output path via GCACaller.BuildAdaptedPath()
  5. Creates a temporary directory and launches GCAdapter.lua
  6. Polls NotFinished() while yielding to keep the UI responsive
  7. Loads the resulting file into the Mach instance
    Returns
    (string|number) Full path to the adapted mirrored G-code file on success, or -1 if no G-code file is currently loaded
    Warning
    This function blocks the calling coroutine while polling for subprocess completion. It yields via w.Yield(1) to prevent UI freezing.
    The machine's currently loaded G-code file is closed before adaptation begins and replaced with the mirrored output on completion.
    See also
    GCACaller.MirrorY() for mirroring across the X-axis
    GCACaller.BuildAdaptedPath() for output path construction
    Note
    Documentation generated by AI on 2026-03-03

◆ MirrorY()

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:

  1. Creates a progress bar dialog
  2. Retrieves the currently loaded G-code filename from the Mach instance
  3. Loads GCAdapter settings from the profile config file
  4. Builds the adapted output path via GCACaller.BuildAdaptedPath()
  5. Creates a temporary directory and launches GCAdapter.lua
  6. Polls NotFinished() while yielding to keep the UI responsive
  7. Loads the resulting file into the Mach instance
    Returns
    (string|number) Full path to the adapted mirrored G-code file on success, or -1 if no G-code file is currently loaded
    Warning
    This function blocks the calling coroutine while polling for subprocess completion. It yields via w.Yield(1) to prevent UI freezing.
    The machine's currently loaded G-code file is closed before adaptation begins and replaced with the mirrored output on completion.
    See also
    GCACaller.MirrorX() for mirroring across the Y-axis
    GCACaller.BuildAdaptedPath() for output path construction
    Note
    Documentation generated by AI on 2026-03-03

◆ NotFinished()

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:

  • error.txt: If present, reads the error table, destroys the progress gauge, raises a GMS notification and a Lua error via w.Error()
  • progress.txt: If present, reads the progress table and updates the gauge title, range, and current value in the GCACaller.DI dialog
  • finished.txt: If present, marks completion, reads the output file/path/dir from the table, cleans up the temporary directory, and destroys the progress gauge

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.

Returns
(boolean) True if the subprocess has not yet finished, false when the finished.txt sentinel file is detected and output globals have been populated
Warning
This function is intended to be called in a polling loop with w.Yield(1) between calls to prevent UI freezing. Do not call from a blocking context without yielding.
See also
GCACaller.g_file, GCACaller.g_path, GCACaller.g_dir for output results
Note
Documentation generated by AI on 2026-03-03

◆ PopulateModifications()

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.

Note
This function defines and uses several inner functions: PopulateModTables, PopulateTables, MakeString, AddToPost, UpdateCtrl, Validate, and the UI.Add* button handlers.
Documentation generated by AI on 2026-03-03

◆ PopulateModTables()

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.

Parameters
tbl(table) Destination array to append formatted strings into
post_table(table) Source array of three-element arrays from the post processor
Note
Documentation generated by AI on 2026-03-03

◆ PopulateSettings()

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().

Note
This function must be called after SettingsNamesSorted is built and the UI grid sizer (UI.gbSizer1) has been created. It defines the inner AddSetting() and populatesettings() functions used during population.
Documentation generated by AI on 2026-03-03

◆ PopulateTables()

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.

Parameters
tbl(table) Destination array to append formatted strings into
post_table(table) Source array of two-element arrays from the post processor
Note
Documentation generated by AI on 2026-03-03

◆ Rotate()

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:

  1. Creates a progress bar dialog
  2. Optionally computes bounding box shift from PathXlength/PathYlength registers
  3. Loads GCAdapter settings from the profile config file
  4. Builds the adapted output path with the rotation angle in the filename
  5. Creates a temporary directory and launches GCAdapter.lua via lua53.exe
  6. Polls NotFinished() while yielding to keep the UI responsive
  7. Loads the resulting file into the Mach instance
    Parameters
    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
    Returns
    (string|number) Full path to the adapted rotated G-code file on success, or -1 if no G-code file is currently loaded
    Warning
    This function blocks the calling coroutine while polling for subprocess completion. It yields via w.Yield(1) to prevent UI freezing.
    The machine's currently loaded G-code file is closed before adaptation begins and replaced with the rotated output on completion.
    See also
    GCACaller.BuildAdaptedPath() for output path construction
    GCACaller.NotFinished() for subprocess polling
    Note
    Documentation generated by AI on 2026-03-03

◆ SaveOnClose()

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.

Parameters
SettingsTbl(table) The settings table to serialize and save
file(string) Full path to the output Lua file to write
Warning
This function overwrites the specified file completely. Any existing content will be lost. Ensure the path is correct before calling.
Note
Documentation generated by AI on 2026-03-03

◆ ScreenLoad()

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.

Note
This function must be connected to the Mach screen load event to ensure commands are available before the operator interacts with the screen.
See also
GCACaller.CreatePreCannedCommands() for the full list of registered commands
Note
Documentation generated by AI on 2026-03-03

◆ UpdateCtrl()

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.

Parameters
ctrl(userdata) The wxWidgets text control whose label will be updated
mod(string) The modification directive string to append to the control
Note
Documentation generated by AI on 2026-03-03

◆ Validate()

Validate ( str ,
param  )

Validate a user-entered modification string for use in a post directive.

Checks the input string against three rules:

  1. No invalid characters: only letters, digits, periods, and spaces are allowed
  2. Must contain at least one letter (pure numeric strings are rejected)
  3. If param is true, must not contain any digits (parameter fields are letters only) Additionally, if param is not true, a blank string is considered invalid.
    Parameters
    str(string) The user-entered text to validate
    param(boolean|nil) If true, applies stricter param-only validation (no digits allowed)
    Returns
    (boolean) True if the string is invalid, false if it passes validation
    (string) Error message describing the validation failure(s), or empty string if valid
    Note
    Documentation generated by AI on 2026-03-03

◆ WaitArray()

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.

Returns
(boolean) True if the array dialog is still open and waiting for input, false if the operator has confirmed or canceled the dialog
Note
Documentation generated by AI on 2026-03-03