# Probe Basic Lathe (Database Tool Table)

This is the database-backed sibling of the `probe_basic_lathe` config. Both
are supported indefinitely -- pick whichever matches how you want to manage
tooling:

- `probe_basic_lathe`    -- classic LinuxCNC `.tbl` file + Fusion 360 JSON
                            tool library
- `probe_basic_lathe_db` (this one) -- single SQLite database, editable
                            live from the tool table UI, with typed
                            extras/custom columns and no external Fusion
                            library required

They are separate, self-contained folders on purpose -- nothing in here
depends on files in the other one. Copy whichever one matches your machine
as your starting point.


## Files specific to this config

- `probe_basic_lathe_db.ini` -- the machine config. Differs from the
  classic one in three places: `[EMCIO] DB_PROGRAM = ./tool_db.sh` instead
  of `TOOL_TABLE = lathe.tbl`, `CONFIG_FILE = custom_config_db.yml`, and
  the `[RS274NGC] REMAP=M6` line (see "Tool change" below).
- `tool_table.db` -- the actual tool data (SQLite). Ships pre-seeded with
  the same 23 reference tools as the classic config's `lathe.tbl`, so the
  two start out equivalent. Edit tools live from the tool table widget --
  there's nothing to hand-edit in the database file itself.
- `custom_config_db.yml` -- qtpyvcp widget/screen config for this variant.
- `tool_db.sh` -- the `DB_PROGRAM` wrapper LinuxCNC's `iocontrol` shells out
  to for tool data. Resolves `tool_table.db` relative to its own location,
  so it works if you copy this whole folder somewhere else.


## Tool change

`[RS274NGC] REMAP=M6` points at `subroutines/toolchange_manual.ngc` by
default. That file does nothing but fall through to LinuxCNC's own built-in
tool-change handling (prompt-and-wait) -- it exists purely so
`change_prolog`/`change_epilog` in `python/stdglue.py` run around every tool
change and publish the loaded tool's data as G-code parameters (see below).
**This is the correct default for manual tool change, which is most
machines.**

If you have a real automatic tool changer (turret/carousel), change the
`REMAP=M6 ... ngc=` target to `toolchange` instead
(`subroutines/toolchange.ngc`) -- that file actually indexes/rotates/clamps
hardware. Don't point a manual machine at it.

Either way, the parameter publishing below happens automatically. You don't
need to build a remap just to get it.


## Reading tool data from G-code

Every tool change (manual or ATC) writes the *currently loaded* tool's
numeric extras/custom columns to `#<_current_tool_*>` parameters --
e.g. `#<_current_tool_nose_radius>`. This always describes whatever tool is
actually in the spindle right now, not "tool N" by number -- there's no
by-tool-number lookup from G-code, only the loaded tool's data.

To see the exact parameter name for any column: right-click its header in
the tool table UI and pick "Parameter Names" -- it lists the live
`#<_current_tool_*>` name for every numeric extras/custom column on that
row, generated from whatever columns actually exist in your database (core
columns like X/Z offset aren't included there since G-code already has
native access to those via the standard tool-table words).

Text columns (holder style, notes, etc.) aren't published -- RS274NGC has no
string parameter type.


## Adding custom columns

Use the "Add Column" button in the tool table UI. Pick a type (int / float
/ bool / text) -- the editor enforces it, so you can't put a non-numeric
value in a numeric column. Numeric custom columns automatically get a
`#<_current_tool_*>` parameter the same way the built-in extras columns do;
text columns are UI/reference-only.


## Starting your own tool set from scratch

`tool_table.db` ships with the 23 reference tools for the sim machine. To
wipe those and start empty (or reseed from a `.tbl` file), see
`~/dev/scratch/qtpyvcp/tests/seed_db_from_tbl.py` -- or just delete every
row from the tool table UI and add your own.
