nc-gcode-interpreter 0.4.2__tar.gz → 0.4.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/CHANGELOG.md +17 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/Cargo.lock +1 -1
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/Cargo.toml +1 -1
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/PKG-INFO +1 -1
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/nc_gcode_interpreter/__init__.py +48 -9
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/nc_gcode_interpreter/_internal.pyi +1 -0
- nc_gcode_interpreter-0.4.3/python/tests/test_work_offsets.py +183 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/src/flatten.rs +47 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/src/interpret_rules.rs +46 -7
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/src/lib.rs +32 -1
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/src/line_driver.rs +13 -3
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/src/output.rs +15 -1
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/src/start.rs +3 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/src/state.rs +167 -31
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/src/subprogram.rs +9 -1
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/src/vm.rs +3 -2
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/.github/workflows/benchmark.yml +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/.github/workflows/build-and-release.yml +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/.gitignore +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/CONTRIBUTING.md +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/Development.md +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/LICENSE +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/README.md +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/TODO.md +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/benches/extensions.rs +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/benches/fixtures.rs +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/benches/workloads.rs +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/build.rs +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/build_backend/nc_build_backend.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/docs/resumable-interpretation-design.md +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/docs/sinumerik-execution-model.md +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/actual_position.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/actual_position.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/arc.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/arc.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/arrays.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/arrays.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/axis_index_assignment.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/axis_index_assignment.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/basic_math.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/basic_math.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/case.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/case.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/case_insensitive_variables.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/case_insensitive_variables.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/custom_vars.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/custom_vars.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/def_string.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/def_string.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/defaults.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/defaults.def +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/defaults.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/defaults_start.json +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/edge_cases.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/edge_cases.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/flattening/flatten_demo.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/flattening/flatten_demo_flattened.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/flattening/flatten_demo_raw.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/for_loop.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/for_loop.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/function_calls.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/function_calls.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/goto.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/goto.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/if_statement.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/if_statement.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/increment.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/increment.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/logic_operators.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/logic_operators.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/loop.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/loop.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/multiple_m_codes.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/multiple_m_codes.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/precedence.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/precedence.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/r_param.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/r_param.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/repeat.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/repeat.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/rot.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/rot.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/simple.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/simple.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/spline.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/spline.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/tool.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/tool.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/trans.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/trans.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/trans2.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/trans2.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/trans_ic.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/trans_ic.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/trans_reset.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/trans_reset.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/trig.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/trig.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/variables.csv +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/examples/variables.mpf +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/ggroups/generate_g_commands.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/pyproject.toml +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/example/minimal.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/example/streaming.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/nc_gcode_interpreter/cli.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/nc_gcode_interpreter/ggroups.json +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/nc_gcode_interpreter/py.typed +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/nc_gcode_interpreter/viz.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/tests/nc_source.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/tests/test_arithmetic_functions.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/tests/test_batch_variables.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/tests/test_batches.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/tests/test_bspline_pl.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/tests/test_build_backend.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/tests/test_compare_benchmarks.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/tests/test_diagnostics.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/tests/test_expected_output.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/tests/test_feed_check.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/tests/test_feed_group.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/tests/test_field_defects.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/tests/test_flags.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/tests/test_flatten.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/tests/test_frame_columns.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/tests/test_frame_scale_mirror.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/tests/test_frames.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/tests/test_g_group_enum.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/tests/test_g_groups.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/tests/test_g_vocabulary.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/tests/test_jumps.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/tests/test_preset.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/tests/test_real_comparisons.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/tests/test_stage1.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/tests/test_start_inputs.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/tests/test_streaming.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/tests/test_string_operations.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/tests/test_structured_errors.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/tests/test_subprograms.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/tests/test_unsupported.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/rustfmt.toml +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/scripts/benchmark.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/scripts/compare_benchmarks.py +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/src/errors.rs +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/src/frame.rs +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/src/grammar.pest +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/src/interpreter.rs +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/src/line_driver/experiments.rs +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/src/main.rs +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/src/modal_groups.rs +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/src/structure_scan.rs +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/src/types.rs +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/tests/cli.rs +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/tests/performance_contract.rs +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/tests/syntax_compatibility.rs +0 -0
- {nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/uv.lock +0 -0
|
@@ -4,6 +4,23 @@ Notable changes to **nc-gcode-interpreter**. The format loosely follows
|
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/); versions are git tags,
|
|
5
5
|
released to PyPI.
|
|
6
6
|
|
|
7
|
+
## [v0.4.3] - 2026-12-05
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- `nc_to_dataframe` and `nc_to_batches` take a `work_offsets` table (#139)
|
|
12
|
+
that maps G54 to G57 and G505 to G599 to a pose in G500, and then report
|
|
13
|
+
X, Y, Z and the `frame_*` columns in G500. Selecting an offset holds the
|
|
14
|
+
machine position, so partial-axis moves, `IC` increments, programmable
|
|
15
|
+
frames and flattened arcs and helices follow the active offset. G53, G153,
|
|
16
|
+
SUPA, G74 and G75 suppress the offset and the programmable frame for their
|
|
17
|
+
block only. Selecting an offset the table does not define raises an error
|
|
18
|
+
naming the block. A Boolean `xyz_in_g500` column marks the resolved rows.
|
|
19
|
+
`nc_to_rows` and the command-line tools do not take the table.
|
|
20
|
+
- `dataframe_to_nc` writes a frame with `xyz_in_g500` as G500 and G90 moves,
|
|
21
|
+
so the exported program reproduces the same positions. It refuses curved
|
|
22
|
+
motions that were not flattened and any A, B or C column.
|
|
23
|
+
|
|
7
24
|
## [v0.4.2] - 2026-11-28
|
|
8
25
|
|
|
9
26
|
### Added
|
{nc_gcode_interpreter-0.4.2 → nc_gcode_interpreter-0.4.3}/python/nc_gcode_interpreter/__init__.py
RENAMED
|
@@ -135,6 +135,7 @@ def nc_to_dataframe(
|
|
|
135
135
|
required_subprograms: "Iterable[str] | None" = None,
|
|
136
136
|
stop_on_setal: bool = False,
|
|
137
137
|
include_frame: bool = False,
|
|
138
|
+
work_offsets: dict[str, list[float]] | None = None,
|
|
138
139
|
) -> tuple[pl.DataFrame, dict]:
|
|
139
140
|
"""
|
|
140
141
|
Parses Sinumerik-flavored NC G-code and converts it into a Polars DataFrame along with the final state.
|
|
@@ -207,6 +208,20 @@ def nc_to_dataframe(
|
|
|
207
208
|
across a jump, matching the streaming `nc_to_rows`. Never
|
|
208
209
|
forward-filled; `dataframe_to_nc` ignores it. Default False (column
|
|
209
210
|
absent, output schema unchanged).
|
|
211
|
+
work_offsets: dict, optional
|
|
212
|
+
Map settable work offsets (G54-G57, G505-G599) to [X, Y, Z, rot X,
|
|
213
|
+
rot Y, rot Z] in G500, in program length units and frame RPY degrees.
|
|
214
|
+
Supplying a table resolves XYZ and frame columns in G500. G500 is
|
|
215
|
+
identity and a non-zero G500 entry is refused; when the control's
|
|
216
|
+
$P_UIFR[0] carries values, pass inv(T_G500) @ T_Gn for each offset.
|
|
217
|
+
The translation is the sum of the coarse and fine parts (TR + FI);
|
|
218
|
+
settable SCALE and MIRROR are not represented. A program that writes
|
|
219
|
+
$P_UIFR does not change what the table selects. A selected offset
|
|
220
|
+
missing from the table raises an error. The Boolean column
|
|
221
|
+
``xyz_in_g500`` records the XYZ coordinate system while
|
|
222
|
+
``gg08_work_offset`` continues to report the selected offset.
|
|
223
|
+
``nc_to_dataframe`` and ``nc_to_batches`` take the table;
|
|
224
|
+
``nc_to_rows`` and the command-line tools do not.
|
|
210
225
|
include_frame: bool, optional
|
|
211
226
|
If True, add the programmable frame (TRANS, ROT, SCALE, MIRROR and
|
|
212
227
|
their additive forms) that is active on each row as twelve Float64
|
|
@@ -214,7 +229,8 @@ def nc_to_dataframe(
|
|
|
214
229
|
`frame_tx`, `frame_ty`, `frame_tz`, the translation t, in machine XYZ
|
|
215
230
|
= R * local XYZ + t. R is the rotation with the scale and mirror
|
|
216
231
|
factors folded in, so it is a pure rotation only while no SCALE or
|
|
217
|
-
MIRROR is active.
|
|
232
|
+
MIRROR is active. With ``work_offsets`` the columns hold the
|
|
233
|
+
selected offset times the programmable frame, in G500.
|
|
218
234
|
The values are written on the first row and on the first row after
|
|
219
235
|
each change, and forward-filled like the axis columns; with
|
|
220
236
|
`disable_forward_fill` the other rows are null. Programmed A/B/C
|
|
@@ -227,6 +243,9 @@ def nc_to_dataframe(
|
|
|
227
243
|
A tuple containing:
|
|
228
244
|
- A Polars DataFrame representing the parsed G-code.
|
|
229
245
|
- A nested dictionary representing the final state after execution.
|
|
246
|
+
With ``work_offsets`` its translation and rotation are the
|
|
247
|
+
programmable frame relative to the selected offset, as ``start``
|
|
248
|
+
expects.
|
|
230
249
|
|
|
231
250
|
Raises:
|
|
232
251
|
-------
|
|
@@ -279,10 +298,11 @@ def nc_to_dataframe(
|
|
|
279
298
|
# No row is read before the run ends, so a provider call need not wait for one.
|
|
280
299
|
defer_rows=True,
|
|
281
300
|
include_frame=include_frame,
|
|
301
|
+
work_offsets=work_offsets,
|
|
282
302
|
)
|
|
283
303
|
# pl.DataFrame wraps each Arrow record batch via __arrow_c_array__ (polars
|
|
284
304
|
# >= 1.3), no pyarrow needed. Exhaust the iterator before reading .state.
|
|
285
|
-
frames: list[pl.DataFrame] = [_batch_frame(batch) for batch in it]
|
|
305
|
+
frames: list[pl.DataFrame] = [_batch_frame(batch, work_offsets is not None) for batch in it]
|
|
286
306
|
state = it.state
|
|
287
307
|
if not frames:
|
|
288
308
|
# A program with no output rows (e.g. only variable assignments) yields
|
|
@@ -373,7 +393,7 @@ _G_GROUP_CATEGORIES: dict[str, pl.Series] = {
|
|
|
373
393
|
}
|
|
374
394
|
|
|
375
395
|
|
|
376
|
-
def _batch_frame(batch: Any) -> pl.DataFrame:
|
|
396
|
+
def _batch_frame(batch: Any, xyz_in_g500: bool) -> pl.DataFrame:
|
|
377
397
|
"""Wrap one Arrow batch from Rust, with every G-group column as its Enum.
|
|
378
398
|
|
|
379
399
|
Rust sends each G-group column as UInt8 indices into the group's commands
|
|
@@ -381,7 +401,9 @@ def _batch_frame(batch: Any) -> pl.DataFrame:
|
|
|
381
401
|
Enum, since polars 2 no longer casts integers to an Enum.
|
|
382
402
|
"""
|
|
383
403
|
frame = pl.DataFrame(batch)
|
|
384
|
-
columns = [_G_GROUP_CATEGORIES[name].gather(frame[name]) for name in frame.columns if name in _G_GROUP_CATEGORIES]
|
|
404
|
+
columns: list[pl.Series | pl.Expr] = [_G_GROUP_CATEGORIES[name].gather(frame[name]) for name in frame.columns if name in _G_GROUP_CATEGORIES]
|
|
405
|
+
if xyz_in_g500:
|
|
406
|
+
columns.append(pl.lit(True).alias("xyz_in_g500"))
|
|
385
407
|
return frame.with_columns(columns) if columns else frame
|
|
386
408
|
|
|
387
409
|
|
|
@@ -432,7 +454,7 @@ def sanitize_dataframe(
|
|
|
432
454
|
|
|
433
455
|
# Value columns: anything that is not a known string/list column.
|
|
434
456
|
value_columns = [
|
|
435
|
-
c for c in df.columns if c not in string_columns and c not in ("M", "N")
|
|
457
|
+
c for c in df.columns if c not in string_columns and c not in ("M", "N", "xyz_in_g500")
|
|
436
458
|
]
|
|
437
459
|
|
|
438
460
|
# Cast to the canonical dtypes.
|
|
@@ -456,6 +478,7 @@ def sanitize_dataframe(
|
|
|
456
478
|
*known_axes,
|
|
457
479
|
*sorted(c for c in value_columns if c not in known_axes and c not in block_addresses),
|
|
458
480
|
*block_addresses,
|
|
481
|
+
"xyz_in_g500",
|
|
459
482
|
"T",
|
|
460
483
|
"M",
|
|
461
484
|
"non_returning_function_call",
|
|
@@ -502,6 +525,16 @@ def dataframe_to_nc(df: pl.DataFrame, file_path: str | Path):
|
|
|
502
525
|
>>> df = pl.DataFrame({'X': [10, 20], 'Y': [0, 0], 'Z': [0, 0]})
|
|
503
526
|
>>> dataframe_to_nc(df, 'output.MPF')
|
|
504
527
|
"""
|
|
528
|
+
if "xyz_in_g500" in df.columns:
|
|
529
|
+
if df["xyz_in_g500"].null_count() or not df["xyz_in_g500"].all():
|
|
530
|
+
raise ValueError("Cannot export mixed XYZ coordinate systems")
|
|
531
|
+
if "gg01_motion" in df.columns and not df["gg01_motion"].drop_nulls().is_in(["G0", "G1"]).all():
|
|
532
|
+
raise ValueError("Flatten curved motions before exporting G500 coordinates")
|
|
533
|
+
if {"A", "B", "C"} & set(df.columns):
|
|
534
|
+
raise ValueError("G500 XYZ export requires orienting A/B/C in the output frame")
|
|
535
|
+
df = df.drop("xyz_in_g500", "flattened", strict=False).with_columns(
|
|
536
|
+
pl.lit("G500").alias("gg08_work_offset"), pl.lit("G90").alias("gg14_wp_measure_mode")
|
|
537
|
+
)
|
|
505
538
|
df = sanitize_dataframe(df)
|
|
506
539
|
# Python prototype of df to nc conversion code
|
|
507
540
|
float_cols = [col for col in df.columns if df[col].dtype == pl.Float64]
|
|
@@ -654,14 +687,15 @@ class _BatchIterator:
|
|
|
654
687
|
the iterator returned by :func:`nc_to_rows`.
|
|
655
688
|
"""
|
|
656
689
|
|
|
657
|
-
def __init__(self, inner: Any) -> None:
|
|
690
|
+
def __init__(self, inner: Any, xyz_in_g500: bool) -> None:
|
|
658
691
|
self._inner = inner
|
|
692
|
+
self._xyz_in_g500 = xyz_in_g500
|
|
659
693
|
|
|
660
694
|
def __iter__(self) -> "Iterator[pl.DataFrame]":
|
|
661
695
|
return self
|
|
662
696
|
|
|
663
697
|
def __next__(self) -> pl.DataFrame:
|
|
664
|
-
return _batch_frame(next(self._inner))
|
|
698
|
+
return _batch_frame(next(self._inner), self._xyz_in_g500)
|
|
665
699
|
|
|
666
700
|
@property
|
|
667
701
|
def state(self) -> dict | None:
|
|
@@ -712,6 +746,7 @@ def nc_to_batches(
|
|
|
712
746
|
required_subprograms: "Iterable[str] | None" = None,
|
|
713
747
|
stop_on_setal: bool = False,
|
|
714
748
|
include_frame: bool = False,
|
|
749
|
+
work_offsets: dict[str, list[float]] | None = None,
|
|
715
750
|
) -> _BatchIterator:
|
|
716
751
|
"""Interpret an NC program into a stream of columnar polars DataFrames.
|
|
717
752
|
|
|
@@ -729,7 +764,10 @@ def nc_to_batches(
|
|
|
729
764
|
with ``how="diagonal"`` and select the final column order.
|
|
730
765
|
|
|
731
766
|
The returned iterator exposes a ``state`` attribute holding the final
|
|
732
|
-
interpreter state once it is exhausted, like :func:`nc_to_rows`.
|
|
767
|
+
interpreter state once it is exhausted, like :func:`nc_to_rows`. With
|
|
768
|
+
``work_offsets`` its translation and rotation are the programmable frame
|
|
769
|
+
relative to the selected offset, while the ``frame_*`` columns hold the
|
|
770
|
+
offset times the programmable frame.
|
|
733
771
|
``definitions``, ``variables`` and ``start`` work as in
|
|
734
772
|
:func:`nc_to_dataframe`.
|
|
735
773
|
|
|
@@ -780,5 +818,6 @@ def nc_to_batches(
|
|
|
780
818
|
None if required_subprograms is None else list(required_subprograms),
|
|
781
819
|
stop_on_setal,
|
|
782
820
|
include_frame=include_frame,
|
|
821
|
+
work_offsets=work_offsets,
|
|
783
822
|
)
|
|
784
|
-
return _BatchIterator(inner)
|
|
823
|
+
return _BatchIterator(inner, work_offsets is not None)
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"""Settable and programmable frames under both interpreter paths."""
|
|
2
|
+
|
|
3
|
+
import itertools
|
|
4
|
+
import math
|
|
5
|
+
|
|
6
|
+
import polars as pl
|
|
7
|
+
import pytest
|
|
8
|
+
from nc_gcode_interpreter import (
|
|
9
|
+
NcError,
|
|
10
|
+
dataframe_to_nc,
|
|
11
|
+
nc_to_batches,
|
|
12
|
+
nc_to_dataframe,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
OFFSETS = {"G507": [10, 20, 0, 0, 0, 0], "G511": [100, 30, 0, 0, 0, 90]}
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@pytest.fixture(autouse=True, params=["0", "1"])
|
|
19
|
+
def decoding(request, monkeypatch):
|
|
20
|
+
monkeypatch.setenv("NC_STAGE1", request.param)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def run(text, **kw):
|
|
24
|
+
return nc_to_dataframe(text, work_offsets=OFFSETS, include_frame=True, **kw)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def xy(frame, row):
|
|
28
|
+
return frame.select("X", "Y").row(row)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def test_partial_move_after_switch_in_either_word_order():
|
|
32
|
+
frame, _ = run("G507 G0 X0 Y0 Z0\nG1 X10 F600\nX5 G511\nY=IC(5)\nG500\nX0")
|
|
33
|
+
for row, expected in enumerate(
|
|
34
|
+
[(10, 20), (20, 20), (20, 35), (15, 35), (15, 35), (0, 35)]
|
|
35
|
+
):
|
|
36
|
+
assert xy(frame, row) == pytest.approx(expected)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_programmable_frame_survives_selection_and_trans_only_resets_its_own_frame():
|
|
40
|
+
frame, state = run("G511\nTRANS X2\nG0 X0 Y0 Z0\nAROT Z90\nG507\nG1 X4 Y0 F100\n")
|
|
41
|
+
assert xy(frame, -1) == pytest.approx((12, 24))
|
|
42
|
+
resumed, _ = run("X=IC(1)\nG511\nTRANS\nG1 X0 Y0", start=state)
|
|
43
|
+
assert xy(resumed, 0) == pytest.approx((12, 25))
|
|
44
|
+
assert xy(resumed, -1) == pytest.approx((100, 30))
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@pytest.mark.parametrize("word", ["G53", "G153", "SUPA"])
|
|
48
|
+
def test_block_suppression_then_return_to_the_held_physical_position(word):
|
|
49
|
+
frame, _ = run(f"G511\nTRANS X2\nG0 X0 Y0 Z0\nX8 Y9 {word}\nX=IC(3)")
|
|
50
|
+
assert xy(frame, -3) == pytest.approx((100, 32))
|
|
51
|
+
assert xy(frame, -2) == pytest.approx((8, 9))
|
|
52
|
+
assert xy(frame, -1) == pytest.approx((8, 12))
|
|
53
|
+
assert frame["frame_r11"][-2] == pytest.approx(1)
|
|
54
|
+
assert frame["frame_r11"][-1] == pytest.approx(0)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def test_executed_subprogram_save_and_missing_frame():
|
|
58
|
+
frame, _ = run(
|
|
59
|
+
"G507 G0 X0 Y0 Z0\nFOO\nX=IC(2)\n",
|
|
60
|
+
subprograms={"FOO": "PROC FOO SAVE\nG511 G0 X0 Y0\nM17\n"},
|
|
61
|
+
)
|
|
62
|
+
assert xy(frame, -1) == pytest.approx((102, 30))
|
|
63
|
+
with pytest.raises(NcError, match="G512 is not defined"):
|
|
64
|
+
run("G507 G0 X0\nG512 G1 X2 F100")
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def test_arc_flattens_in_the_rotated_work_offset():
|
|
68
|
+
frame, _ = run("G511 G0 X1 Y0 Z0\nG3 X0 Y1 I-1 J0 F600\n", flatten_tolerance=0.01)
|
|
69
|
+
assert frame.height > 4
|
|
70
|
+
assert xy(frame, -1) == pytest.approx((99, 30))
|
|
71
|
+
for x, y in frame.select("X", "Y").drop_nulls().iter_rows():
|
|
72
|
+
assert (x - 100) ** 2 + (y - 30) ** 2 == pytest.approx(1)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_tilted_helical_arc_uses_the_programmed_plane():
|
|
76
|
+
table = {"G507": [12, 30, 7, 0, 0, 0], "G511": [10, 30, 7, 90, 0, 0]}
|
|
77
|
+
frame, _ = nc_to_dataframe(
|
|
78
|
+
"G507 G0 X0 Y0 Z0\nG511 G0 X1 Y0 Z0\nG3 X0 Y1 Z2 I-1 J0 F600\nG1 X=IC(1)",
|
|
79
|
+
work_offsets=table,
|
|
80
|
+
flatten_tolerance=0.01,
|
|
81
|
+
)
|
|
82
|
+
arc = frame.select("X", "Y", "Z").rows()[2:-1]
|
|
83
|
+
assert len(arc) > 4
|
|
84
|
+
for x, y, z in arc:
|
|
85
|
+
assert (x - 10) ** 2 + (z - 7) ** 2 == pytest.approx(1)
|
|
86
|
+
assert 28 - 1e-8 <= y <= 30 + 1e-8
|
|
87
|
+
assert arc[-1] == pytest.approx((10, 28, 8))
|
|
88
|
+
assert frame.select("X", "Y", "Z").row(-1) == pytest.approx((11, 28, 8))
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
# Images of local X1, Y1, Z1 under Rz(30) Ry(20) Rx(10), the Z Y' X'' order of MD10600 = 1.
|
|
92
|
+
TILTED = {"G508": [0, 0, 0, 10, 20, 30]}
|
|
93
|
+
TILTED_AXES = [
|
|
94
|
+
(0.81380, 0.46985, -0.34202),
|
|
95
|
+
(-0.44097, 0.88256, 0.16318),
|
|
96
|
+
(0.37852, 0.01803, 0.92542),
|
|
97
|
+
]
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def test_offset_rotated_about_two_axes_turns_z_then_y_then_x():
|
|
101
|
+
frame, _ = nc_to_dataframe("G508 G0 X1 Y0 Z0\nX0 Y1\nY0 Z1", work_offsets=TILTED)
|
|
102
|
+
for row, expected in enumerate(TILTED_AXES):
|
|
103
|
+
assert frame.select("X", "Y", "Z").row(row) == pytest.approx(expected, abs=1e-5)
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def test_arc_flattens_in_an_offset_rotated_about_two_axes():
|
|
107
|
+
frame, _ = nc_to_dataframe(
|
|
108
|
+
"G508 G0 X1 Y0 Z0\nG2 X0 Y-1 I-1 J0 F600", work_offsets=TILTED, flatten_tolerance=0.01
|
|
109
|
+
)
|
|
110
|
+
points = frame.select("X", "Y", "Z").rows()
|
|
111
|
+
assert len(points) > 4
|
|
112
|
+
local = [
|
|
113
|
+
tuple(sum(a * p for a, p in zip(axis, point, strict=True)) for axis in TILTED_AXES)
|
|
114
|
+
for point in points
|
|
115
|
+
]
|
|
116
|
+
angles = [math.atan2(y, x) for x, y, _ in local]
|
|
117
|
+
for x, y, z in local:
|
|
118
|
+
assert x**2 + y**2 == pytest.approx(1, abs=1e-4)
|
|
119
|
+
assert z == pytest.approx(0, abs=1e-4)
|
|
120
|
+
assert all(later < earlier for earlier, later in itertools.pairwise(angles))
|
|
121
|
+
assert points[-1] == pytest.approx(tuple(-v for v in TILTED_AXES[1]), abs=1e-5)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
@pytest.mark.parametrize(
|
|
125
|
+
"table, message",
|
|
126
|
+
[
|
|
127
|
+
({"G53": [0] * 6}, "G53 is not a settable work offset"),
|
|
128
|
+
({"G54": [0, 0, float("nan"), 0, 0, 0]}, "G54 has a value that is not finite"),
|
|
129
|
+
({"G500": [1, 0, 0, 0, 0, 0]}, "G500 must be all zeros"),
|
|
130
|
+
({"G54": [0] * 6, "g54": [0] * 6}, "(?i)g54 names an offset that another key already names"),
|
|
131
|
+
],
|
|
132
|
+
)
|
|
133
|
+
def test_invalid_table_entry_names_the_rule(table, message):
|
|
134
|
+
with pytest.raises(ValueError, match=message):
|
|
135
|
+
nc_to_dataframe("G0 X0", work_offsets=table)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def test_save_restores_implicit_g500():
|
|
139
|
+
frame, _ = run(
|
|
140
|
+
"G0 X0 Y0 Z0\nFOO\nX=IC(3)\n",
|
|
141
|
+
subprograms={"FOO": "PROC FOO SAVE\nG511 G0 X0 Y0\nM17\n"},
|
|
142
|
+
)
|
|
143
|
+
assert xy(frame, -1) == pytest.approx((103, 30))
|
|
144
|
+
|
|
145
|
+
@pytest.mark.parametrize("streaming", [False, True])
|
|
146
|
+
def test_export_resolved_xyz_in_g500(tmp_path, streaming):
|
|
147
|
+
program = "G507 G0 X0 Y0 Z0\nG511 G1 X2 Y3 F600\nG91 Y1"
|
|
148
|
+
if streaming:
|
|
149
|
+
frame = pl.concat(nc_to_batches(program, batch_size=1, work_offsets=OFFSETS), how="diagonal")
|
|
150
|
+
else:
|
|
151
|
+
frame, _ = run(program)
|
|
152
|
+
output = tmp_path / "roundtrip.mpf"
|
|
153
|
+
dataframe_to_nc(frame, output)
|
|
154
|
+
assert "G500" in output.read_text()
|
|
155
|
+
assert "G511" not in output.read_text()
|
|
156
|
+
reparsed, _ = run(output)
|
|
157
|
+
assert reparsed.select("X", "Y", "Z").rows() == frame.select("X", "Y", "Z").rows()
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def test_export_requires_resolved_curve_and_orientation(tmp_path):
|
|
161
|
+
output = tmp_path / "roundtrip.mpf"
|
|
162
|
+
arc, _ = run("G511 G0 X1 Y0 Z0\nG3 X0 Y1 I-1 J0 F600")
|
|
163
|
+
with pytest.raises(ValueError, match="Flatten curved motions"):
|
|
164
|
+
dataframe_to_nc(arc, output)
|
|
165
|
+
tilted, _ = run("G511 G0 X0 Y0 Z0 A30")
|
|
166
|
+
with pytest.raises(ValueError, match="orienting A/B/C"):
|
|
167
|
+
dataframe_to_nc(tilted, output)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def test_rotated_offset_requires_each_coupled_geometry_axis():
|
|
171
|
+
with pytest.raises(NcError, match="axis Y, which is not a configured axis"):
|
|
172
|
+
run("G511 G0 X4", axis_identifiers=["X"])
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
@pytest.mark.parametrize("last_frame", ["G54", "G500"])
|
|
176
|
+
def test_restart_with_reduced_axes(last_frame):
|
|
177
|
+
options = {"axis_identifiers": ["X"], "work_offsets": {"G54": [20, 30, 40, 0, 0, 0]}}
|
|
178
|
+
program = f"G54 G0 X1\nTRANS X2\nX4\n{last_frame}"
|
|
179
|
+
expected, _ = nc_to_dataframe(program + "\nX=IC(1)", **options)
|
|
180
|
+
_, state = nc_to_dataframe(program, **options)
|
|
181
|
+
assert set(state["translation"]) == {"X"}
|
|
182
|
+
resumed, _ = nc_to_dataframe("X=IC(1)", start=state, **options)
|
|
183
|
+
assert resumed["X"][-1] == pytest.approx(expected["X"][-1])
|
|
@@ -350,6 +350,53 @@ impl Flattener {
|
|
|
350
350
|
// Arcs
|
|
351
351
|
// ------------------------------------------------------------------
|
|
352
352
|
|
|
353
|
+
/// Sample a tilted circle or helix in its programmed plane, then return XYZ to machine axes.
|
|
354
|
+
pub fn push_framed_arc(
|
|
355
|
+
&mut self,
|
|
356
|
+
mut row: Row,
|
|
357
|
+
out: &mut Vec<Row>,
|
|
358
|
+
rotation: crate::frame::Matrix3,
|
|
359
|
+
) -> Result<(), ParsingError> {
|
|
360
|
+
use crate::frame::{apply, AXIS_NAMES};
|
|
361
|
+
let line = row.line_no;
|
|
362
|
+
let error = |message| ParsingError::with_context(line, "", "tilted arc", message);
|
|
363
|
+
let [Some(x), Some(y), Some(z)] = AXIS_NAMES.map(|k| self.axis_slot(k)) else {
|
|
364
|
+
return Err(error("A tilted arc needs XYZ axes"));
|
|
365
|
+
};
|
|
366
|
+
let slots = [x, y, z];
|
|
367
|
+
let [Some(x), Some(y), Some(z)] = slots.map(|s| self.positions[s]) else {
|
|
368
|
+
return Err(error("A tilted arc needs a known starting XYZ"));
|
|
369
|
+
};
|
|
370
|
+
if self.buffering_spline() {
|
|
371
|
+
self.flush_spline(out);
|
|
372
|
+
}
|
|
373
|
+
let start = [x, y, z];
|
|
374
|
+
let end = std::array::from_fn(|i| cell_float(&row, AXIS_NAMES[i]).unwrap_or(start[i]));
|
|
375
|
+
let inverse = std::array::from_fn(|i| std::array::from_fn(|j| rotation[j][i]));
|
|
376
|
+
let local_start = apply(&inverse, start);
|
|
377
|
+
let local_end = apply(&inverse, end);
|
|
378
|
+
for i in 0..3 {
|
|
379
|
+
self.positions[slots[i]] = Some(local_start[i]);
|
|
380
|
+
row.cells.insert(AXIS_NAMES[i], Value::Float(local_end[i]));
|
|
381
|
+
}
|
|
382
|
+
let begin = out.len();
|
|
383
|
+
self.push(row, out);
|
|
384
|
+
let samples = &mut out[begin..];
|
|
385
|
+
if !matches!(samples.first().and_then(|r| r.cells.get("gg01_motion")), Some(Value::Str(code)) if code=="G1") {
|
|
386
|
+
return Err(error("Could not flatten the arc in its programmed plane"));
|
|
387
|
+
}
|
|
388
|
+
for sample in samples.iter_mut() {
|
|
389
|
+
let local = std::array::from_fn(|i| cell_float(sample, AXIS_NAMES[i]).unwrap_or(local_start[i]));
|
|
390
|
+
for (key, value) in AXIS_NAMES.into_iter().zip(apply(&rotation, local)) {
|
|
391
|
+
sample.cells.insert(key, Value::Float(value));
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
for (slot, value) in slots.into_iter().zip(end) {
|
|
395
|
+
self.positions[slot] = Some(value);
|
|
396
|
+
}
|
|
397
|
+
Ok(())
|
|
398
|
+
}
|
|
399
|
+
|
|
353
400
|
fn flatten_arc(&mut self, row: Row, cw: bool, out: &mut Vec<Row>) {
|
|
354
401
|
let plane = self.plane;
|
|
355
402
|
let u_axis = intern_column(plane.axes[0]);
|
|
@@ -1288,7 +1288,7 @@ fn run_subprogram(
|
|
|
1288
1288
|
// The rest of the calling block gets a row of its own, after the body's rows.
|
|
1289
1289
|
output.start_row(call_line)?;
|
|
1290
1290
|
if let Some(saved) = saved_g_functions {
|
|
1291
|
-
restore_g_functions(name, saved, output, state)
|
|
1291
|
+
restore_g_functions(name, saved, output, state, call_line)?;
|
|
1292
1292
|
}
|
|
1293
1293
|
Ok(())
|
|
1294
1294
|
}
|
|
@@ -1408,7 +1408,13 @@ fn run_subprogram_pass(
|
|
|
1408
1408
|
|
|
1409
1409
|
/// PROC ... SAVE: the modal G functions active before the call are active
|
|
1410
1410
|
/// again after it (manual 4.2.2.4). They go on the row after the body's rows.
|
|
1411
|
-
fn restore_g_functions(
|
|
1411
|
+
fn restore_g_functions(
|
|
1412
|
+
name: &str,
|
|
1413
|
+
saved: HashMap<&'static str, String>,
|
|
1414
|
+
output: &mut Output,
|
|
1415
|
+
state: &mut State,
|
|
1416
|
+
line_no: usize,
|
|
1417
|
+
) -> Result<(), ParsingError> {
|
|
1412
1418
|
let changed: Vec<(&'static str, String)> = state
|
|
1413
1419
|
.ext
|
|
1414
1420
|
.modal_g
|
|
@@ -1421,6 +1427,8 @@ fn restore_g_functions(name: &str, saved: HashMap<&'static str, String>, output:
|
|
|
1421
1427
|
Some(before) => {
|
|
1422
1428
|
if group == "gg06_plane_select" {
|
|
1423
1429
|
state.set_plane(before);
|
|
1430
|
+
} else if group == "gg08_work_offset" {
|
|
1431
|
+
state.select_work_offset(before, line_no, false)?;
|
|
1424
1432
|
}
|
|
1425
1433
|
if let Some(row) = output.last_mut() {
|
|
1426
1434
|
row.insert(group, Value::Str(before.clone()));
|
|
@@ -1434,6 +1442,7 @@ fn restore_g_functions(name: &str, saved: HashMap<&'static str, String>, output:
|
|
|
1434
1442
|
)),
|
|
1435
1443
|
}
|
|
1436
1444
|
}
|
|
1445
|
+
Ok(())
|
|
1437
1446
|
}
|
|
1438
1447
|
|
|
1439
1448
|
/// Bind a VAR parameter to the caller's variable named by `argument`.
|
|
@@ -4153,8 +4162,11 @@ fn interpret_frame_op(element: Pair<Rule>, state: &mut State) -> Result<(), Pars
|
|
|
4153
4162
|
// programmed frames"; 3.12.2.4 example 1 relies on a TRANS after
|
|
4154
4163
|
// AROT dropping the rotation). Bare TRANS is therefore just the reset.
|
|
4155
4164
|
state.reset_frame();
|
|
4156
|
-
|
|
4157
|
-
|
|
4165
|
+
let offsets = frame_assignments(assignments, state)?;
|
|
4166
|
+
for (index, (key, value)) in offsets.iter().enumerate() {
|
|
4167
|
+
if !offsets[index + 1..].iter().any(|(later, _)| later == key) {
|
|
4168
|
+
state.add_translation(key, *value, line_no, &preview)?;
|
|
4169
|
+
}
|
|
4158
4170
|
}
|
|
4159
4171
|
Ok(())
|
|
4160
4172
|
}
|
|
@@ -4237,6 +4249,32 @@ fn annotate_error(pair: &Pair<Rule>, context: &str, message: String, state: &Sta
|
|
|
4237
4249
|
ParsingError::with_context(line_no, preview, context.to_string(), message)
|
|
4238
4250
|
}
|
|
4239
4251
|
|
|
4252
|
+
fn begin_offset_block(
|
|
4253
|
+
block: &Pair<Rule>,
|
|
4254
|
+
state: &mut State,
|
|
4255
|
+
line_no: usize,
|
|
4256
|
+
) -> Result<Option<crate::state::SuppressedFrame>, ParsingError> {
|
|
4257
|
+
if state.ext.work_offsets.is_none() {
|
|
4258
|
+
return Ok(None);
|
|
4259
|
+
}
|
|
4260
|
+
// A G word applies to axes anywhere on its block, including axes before it.
|
|
4261
|
+
state.begin_offset_block(
|
|
4262
|
+
block
|
|
4263
|
+
.clone()
|
|
4264
|
+
.into_inner()
|
|
4265
|
+
.filter(|p| p.as_rule() == Rule::statement)
|
|
4266
|
+
.filter_map(|p| p.into_inner().next())
|
|
4267
|
+
.filter(|p| {
|
|
4268
|
+
matches!(
|
|
4269
|
+
p.as_rule(),
|
|
4270
|
+
Rule::g_command | Rule::g_command_numbered | Rule::non_returning_function_call
|
|
4271
|
+
)
|
|
4272
|
+
})
|
|
4273
|
+
.map(|p| p.as_str()),
|
|
4274
|
+
line_no,
|
|
4275
|
+
)
|
|
4276
|
+
}
|
|
4277
|
+
|
|
4240
4278
|
pub(crate) fn interpret_block(
|
|
4241
4279
|
element: Pair<Rule>,
|
|
4242
4280
|
output: &mut Output,
|
|
@@ -4247,6 +4285,7 @@ pub(crate) fn interpret_block(
|
|
|
4247
4285
|
// Start this block's output row, flushing the previous one.
|
|
4248
4286
|
let line_no = element.line_col().0;
|
|
4249
4287
|
reject_second_call(&element, state)?;
|
|
4288
|
+
let suppressed = begin_offset_block(&element, state, line_no)?;
|
|
4250
4289
|
output.start_row(line_no)?;
|
|
4251
4290
|
|
|
4252
4291
|
let mut flow = BlockFlow::Continue;
|
|
@@ -4292,10 +4331,10 @@ pub(crate) fn interpret_block(
|
|
|
4292
4331
|
}
|
|
4293
4332
|
if had_statements {
|
|
4294
4333
|
output.seed_assumed_starts(&mut state.assumed_starts);
|
|
4295
|
-
|
|
4296
|
-
state.
|
|
4334
|
+
output.finish_block_frame(state, line_no)?;
|
|
4335
|
+
state.end_offset_block(suppressed)?;
|
|
4297
4336
|
if !state.ext.m_functions.is_empty() {
|
|
4298
|
-
let m_codes = match
|
|
4337
|
+
let m_codes = match output.last_mut().expect("row started").get("M") {
|
|
4299
4338
|
Some(Value::StrList(codes)) => codes.clone(),
|
|
4300
4339
|
_ => Vec::new(),
|
|
4301
4340
|
};
|
|
@@ -495,6 +495,7 @@ mod python_bindings {
|
|
|
495
495
|
stop_on_setal: bool,
|
|
496
496
|
defer_rows: bool,
|
|
497
497
|
include_frame: bool,
|
|
498
|
+
work_offsets: Option<HashMap<String, [f64; 6]>>,
|
|
498
499
|
) -> PyResult<(
|
|
499
500
|
mpsc::Receiver<WorkerMessage>,
|
|
500
501
|
mpsc::Receiver<Result<FinalState, ErrInfo>>,
|
|
@@ -511,7 +512,35 @@ mod python_bindings {
|
|
|
511
512
|
});
|
|
512
513
|
(names, provider)
|
|
513
514
|
});
|
|
515
|
+
let work_offsets = work_offsets
|
|
516
|
+
.map(|rows| {
|
|
517
|
+
let mut table = HashMap::new();
|
|
518
|
+
for (key, pose) in rows {
|
|
519
|
+
let code = crate::modal_groups::normalize_g_command(&key.to_uppercase());
|
|
520
|
+
let problem = if !matches!(
|
|
521
|
+
crate::modal_groups::classify_g_command(&code),
|
|
522
|
+
Some(("gg08_work_offset", _))
|
|
523
|
+
) {
|
|
524
|
+
Some("is not a settable work offset (G500, G54-G57, G505-G599)")
|
|
525
|
+
} else if pose.iter().any(|v| !v.is_finite()) {
|
|
526
|
+
Some("has a value that is not finite")
|
|
527
|
+
} else if code == "G500" && pose != [0.0; 6] {
|
|
528
|
+
Some("must be all zeros, because G500 is the reference frame")
|
|
529
|
+
} else if table.contains_key(&code) {
|
|
530
|
+
Some("names an offset that another key already names")
|
|
531
|
+
} else {
|
|
532
|
+
None
|
|
533
|
+
};
|
|
534
|
+
if let Some(problem) = problem {
|
|
535
|
+
return Err(PyValueError::new_err(format!("work_offsets entry {key} {problem}")));
|
|
536
|
+
}
|
|
537
|
+
table.insert(code, pose);
|
|
538
|
+
}
|
|
539
|
+
Ok(table)
|
|
540
|
+
})
|
|
541
|
+
.transpose()?;
|
|
514
542
|
let extensions = Extensions {
|
|
543
|
+
work_offsets,
|
|
515
544
|
subprograms,
|
|
516
545
|
external,
|
|
517
546
|
m_functions,
|
|
@@ -1134,7 +1163,7 @@ mod python_bindings {
|
|
|
1134
1163
|
/// thread. Wrapping each with `pl.DataFrame` and concatenating reconstructs
|
|
1135
1164
|
/// `nc_to_dataframe`.
|
|
1136
1165
|
#[pyfunction]
|
|
1137
|
-
#[pyo3(signature = (input, batch_size = 500_000, definitions = None, variables = None, start = None, axis_identifiers = None, extra_axes = None, iteration_limit = 10000, disable_forward_fill = false, axis_index_map = None, allow_undefined_variables = false, input_is_path = false, flatten_tolerance = None, include_line_numbers = false, include_variables = false, subprograms = None, external_variables = None, m_function_subprograms = None, required_subprograms = None, stop_on_setal = false, defer_rows = false, include_frame = false))]
|
|
1166
|
+
#[pyo3(signature = (input, batch_size = 500_000, definitions = None, variables = None, start = None, axis_identifiers = None, extra_axes = None, iteration_limit = 10000, disable_forward_fill = false, axis_index_map = None, allow_undefined_variables = false, input_is_path = false, flatten_tolerance = None, include_line_numbers = false, include_variables = false, subprograms = None, external_variables = None, m_function_subprograms = None, required_subprograms = None, stop_on_setal = false, defer_rows = false, include_frame = false, work_offsets = None))]
|
|
1138
1167
|
#[allow(clippy::too_many_arguments)]
|
|
1139
1168
|
fn nc_to_batches(
|
|
1140
1169
|
input: PyBackedStr,
|
|
@@ -1159,6 +1188,7 @@ mod python_bindings {
|
|
|
1159
1188
|
stop_on_setal: bool,
|
|
1160
1189
|
defer_rows: bool,
|
|
1161
1190
|
include_frame: bool,
|
|
1191
|
+
work_offsets: Option<HashMap<String, [f64; 6]>>,
|
|
1162
1192
|
py: Python<'_>,
|
|
1163
1193
|
) -> PyResult<NcBatchIterator> {
|
|
1164
1194
|
// The provider declares the variable names it serves.
|
|
@@ -1192,6 +1222,7 @@ mod python_bindings {
|
|
|
1192
1222
|
stop_on_setal,
|
|
1193
1223
|
defer_rows,
|
|
1194
1224
|
include_frame,
|
|
1225
|
+
work_offsets,
|
|
1195
1226
|
)?;
|
|
1196
1227
|
|
|
1197
1228
|
Ok(NcBatchIterator {
|
|
@@ -644,6 +644,17 @@ fn execute_decoded(
|
|
|
644
644
|
}
|
|
645
645
|
output.start_row(line.line_no)?;
|
|
646
646
|
let mut flow = BlockFlow::Continue;
|
|
647
|
+
let suppressed = if state.ext.work_offsets.is_some() {
|
|
648
|
+
state.begin_offset_block(
|
|
649
|
+
arena[line.words.clone()].iter().filter_map(|word| match word {
|
|
650
|
+
Word::GCommand(_, raw) => Some(*raw),
|
|
651
|
+
_ => None,
|
|
652
|
+
}),
|
|
653
|
+
line.line_no,
|
|
654
|
+
)?
|
|
655
|
+
} else {
|
|
656
|
+
None
|
|
657
|
+
};
|
|
647
658
|
// Split borrows: row insertion vs axis-state updates.
|
|
648
659
|
for word in &arena[line.words.clone()] {
|
|
649
660
|
match word {
|
|
@@ -803,13 +814,12 @@ fn execute_decoded(
|
|
|
803
814
|
}
|
|
804
815
|
}
|
|
805
816
|
}
|
|
806
|
-
|
|
807
|
-
// Same end-of-block frame hook as interpret_block (arc words under a rotation).
|
|
808
|
-
state.finish_block_frame(last, line.line_no)?;
|
|
817
|
+
output.finish_block_frame(state, line.line_no)?;
|
|
809
818
|
output.seed_assumed_starts(&mut state.assumed_starts);
|
|
810
819
|
if let Some(frame) = state.take_frame_change() {
|
|
811
820
|
output.seed_frame(frame);
|
|
812
821
|
}
|
|
822
|
+
state.end_offset_block(suppressed)?;
|
|
813
823
|
let last = output.last_mut().expect("row was just pushed");
|
|
814
824
|
if let Some(n) = line.n {
|
|
815
825
|
last.insert("N", Value::Str(n.to_string()));
|