nc-gcode-interpreter 0.4.0__tar.gz → 0.4.2__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.0 → nc_gcode_interpreter-0.4.2}/CHANGELOG.md +63 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/Cargo.lock +1 -1
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/Cargo.toml +1 -1
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/PKG-INFO +1 -1
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/README.md +2 -2
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/nc_gcode_interpreter/__init__.py +29 -4
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/nc_gcode_interpreter/_internal.pyi +2 -1
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/tests/test_batch_variables.py +1 -1
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/tests/test_bspline_pl.py +54 -4
- nc_gcode_interpreter-0.4.2/python/tests/test_frame_columns.py +115 -0
- nc_gcode_interpreter-0.4.2/python/tests/test_frame_scale_mirror.py +244 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/tests/test_frames.py +3 -3
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/tests/test_g_groups.py +2 -2
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/tests/test_start_inputs.py +2 -2
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/tests/test_unsupported.py +18 -9
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/src/flatten.rs +32 -9
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/src/frame.rs +95 -21
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/src/grammar.pest +3 -2
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/src/interpret_rules.rs +230 -78
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/src/lib.rs +7 -1
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/src/line_driver.rs +5 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/src/main.rs +1 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/src/output.rs +29 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/src/start.rs +26 -21
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/src/state.rs +135 -39
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/src/subprogram.rs +4 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/src/vm.rs +4 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/tests/syntax_compatibility.rs +25 -1
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/.github/workflows/benchmark.yml +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/.github/workflows/build-and-release.yml +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/.gitignore +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/CONTRIBUTING.md +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/Development.md +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/LICENSE +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/TODO.md +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/benches/extensions.rs +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/benches/fixtures.rs +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/benches/workloads.rs +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/build.rs +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/build_backend/nc_build_backend.py +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/docs/resumable-interpretation-design.md +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/docs/sinumerik-execution-model.md +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/actual_position.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/actual_position.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/arc.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/arc.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/arrays.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/arrays.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/axis_index_assignment.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/axis_index_assignment.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/basic_math.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/basic_math.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/case.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/case.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/case_insensitive_variables.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/case_insensitive_variables.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/custom_vars.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/custom_vars.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/def_string.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/def_string.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/defaults.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/defaults.def +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/defaults.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/defaults_start.json +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/edge_cases.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/edge_cases.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/flattening/flatten_demo.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/flattening/flatten_demo_flattened.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/flattening/flatten_demo_raw.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/for_loop.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/for_loop.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/function_calls.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/function_calls.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/goto.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/goto.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/if_statement.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/if_statement.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/increment.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/increment.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/logic_operators.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/logic_operators.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/loop.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/loop.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/multiple_m_codes.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/multiple_m_codes.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/precedence.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/precedence.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/r_param.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/r_param.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/repeat.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/repeat.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/rot.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/rot.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/simple.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/simple.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/spline.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/spline.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/tool.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/tool.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/trans.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/trans.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/trans2.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/trans2.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/trans_ic.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/trans_ic.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/trans_reset.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/trans_reset.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/trig.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/trig.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/variables.csv +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/examples/variables.mpf +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/ggroups/generate_g_commands.py +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/pyproject.toml +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/example/minimal.py +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/example/streaming.py +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/nc_gcode_interpreter/cli.py +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/nc_gcode_interpreter/ggroups.json +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/nc_gcode_interpreter/py.typed +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/nc_gcode_interpreter/viz.py +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/tests/nc_source.py +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/tests/test_arithmetic_functions.py +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/tests/test_batches.py +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/tests/test_build_backend.py +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/tests/test_compare_benchmarks.py +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/tests/test_diagnostics.py +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/tests/test_expected_output.py +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/tests/test_feed_check.py +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/tests/test_feed_group.py +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/tests/test_field_defects.py +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/tests/test_flags.py +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/tests/test_flatten.py +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/tests/test_g_group_enum.py +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/tests/test_g_vocabulary.py +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/tests/test_jumps.py +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/tests/test_preset.py +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/tests/test_real_comparisons.py +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/tests/test_stage1.py +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/tests/test_streaming.py +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/tests/test_string_operations.py +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/tests/test_structured_errors.py +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/tests/test_subprograms.py +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/rustfmt.toml +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/scripts/benchmark.py +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/scripts/compare_benchmarks.py +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/src/errors.rs +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/src/interpreter.rs +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/src/line_driver/experiments.rs +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/src/modal_groups.rs +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/src/structure_scan.rs +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/src/types.rs +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/tests/cli.rs +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/tests/performance_contract.rs +0 -0
- {nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/uv.lock +0 -0
|
@@ -4,6 +4,69 @@ 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.2] - 2026-11-28
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- Numeric literals accept the Siemens exponent notation `<mantissa>EX<exponent>`
|
|
12
|
+
(#117), for example `X=-.1EX-3`, `R1=1.874EX8` and `8.2EX-3`, in every place
|
|
13
|
+
a literal is accepted. A plain `E` exponent stays an error.
|
|
14
|
+
- `SCALE`/`ASCALE` and `MIRROR`/`AMIRROR` with arguments are interpreted for
|
|
15
|
+
the geometry axes X, Y, Z (#134). They chain onto the programmable frame as
|
|
16
|
+
machine XYZ = R * S * M * local XYZ + t, so an `ATRANS` after a scale is
|
|
17
|
+
scaled and an `AMIRROR` of a mirrored axis switches the mirror off (the
|
|
18
|
+
toggle behaviour of MD10612 = 0). The `rotation` in the final state and the
|
|
19
|
+
`frame_r11` to `frame_r33` columns hold the rotation with the scale and
|
|
20
|
+
mirror factors folded in. A circular arc is accepted under a frame that
|
|
21
|
+
keeps it a circle with the same direction (its `I`/`J`/`K` and `CR` are
|
|
22
|
+
scaled); an in-plane mirror or unequal in-plane factors under an arc raise
|
|
23
|
+
an error, as does a rotation chained after unequal scale factors.
|
|
24
|
+
- `SCALE`/`ASCALE` also scale every other configured axis, such as an
|
|
25
|
+
extruder axis `E` (#134; manual 3.12.2.6 scales all path, synchronized and
|
|
26
|
+
positioning axes): machine = factor * local + t, `ASCALE` multiplies the
|
|
27
|
+
factor, an `ATRANS` after it is scaled and an absolute frame instruction
|
|
28
|
+
resets it. The factors are in the final state as `axis_scale`, which
|
|
29
|
+
`start` accepts.
|
|
30
|
+
- `ROTS`/`AROTS`/`CROTS` with one solid angle, which is the same rotation as
|
|
31
|
+
`ROT`/`AROT` about that axis (#134). Two solid angles still raise an error,
|
|
32
|
+
because the manuals describe that form in two ways that give different
|
|
33
|
+
rotations.
|
|
34
|
+
- `start['rotation']` accepts a rotation with scale and mirror factors, so a
|
|
35
|
+
final state with an active `SCALE` or `MIRROR` can be resumed.
|
|
36
|
+
|
|
37
|
+
### Changed
|
|
38
|
+
|
|
39
|
+
- `TOFRAME`, `TOROT` (with their `X`/`Y`/`Z` variants) and `PAROT` raise an
|
|
40
|
+
"unsupported statement" error (#134). They were accepted without effect
|
|
41
|
+
before, so the blocks after them were read in the wrong frame without a
|
|
42
|
+
warning. `TOROTOF` and `PAROTOF` are still accepted.
|
|
43
|
+
|
|
44
|
+
## [v0.4.1] - 2026-11-24
|
|
45
|
+
|
|
46
|
+
### Added
|
|
47
|
+
|
|
48
|
+
- `include_frame` on `nc_to_dataframe` and `nc_to_batches` (#130). When set,
|
|
49
|
+
every row carries the programmable frame that is active on it: the rotation
|
|
50
|
+
`R` as `frame_r11` to `frame_r33` (row by row) and the translation `t` as
|
|
51
|
+
`frame_tx`, `frame_ty`, `frame_tz`, in machine XYZ = R * local XYZ + t. The
|
|
52
|
+
values are written on the first row and on the first row after a change and
|
|
53
|
+
forward-filled like the axis columns. The interpreter does not rotate
|
|
54
|
+
programmed A/B/C values, so a consumer that needs the orientation in the
|
|
55
|
+
basic system can apply `R` itself. The columns are absent by default.
|
|
56
|
+
|
|
57
|
+
### Fixed
|
|
58
|
+
|
|
59
|
+
- `BSPLINE` flattening accepts `PL=0` as a knot distance of zero, a repeated
|
|
60
|
+
knot (#129). Before, any `PL=0` on a control-point block made the whole
|
|
61
|
+
spline fall back to uniform knots with a warning, unless that block happened
|
|
62
|
+
to repeat the previous position and was dropped, so the same `PL` values gave
|
|
63
|
+
different knots depending on where the spline started. A `PL=0` on a block
|
|
64
|
+
whose `PL` is not used (the first and last block of a cubic) no longer has an
|
|
65
|
+
effect. Two cases still warn and use uniform knots, because they would split
|
|
66
|
+
the curve and are not measured on a control: `PL=0` as often in succession as
|
|
67
|
+
the spline degree, and `PL=0` on the first or last knot span. A negative `PL`
|
|
68
|
+
warns as before.
|
|
69
|
+
|
|
7
70
|
## [v0.4.0] - 2026-11-23
|
|
8
71
|
|
|
9
72
|
### Changed
|
|
@@ -11,7 +11,7 @@ The **NC-GCode-Interpreter** offers a streamlined and efficient solution for int
|
|
|
11
11
|
### Supported G-code Features
|
|
12
12
|
|
|
13
13
|
- **G Group Commands**: Recognizes G-code groups and modal G-code commands.
|
|
14
|
-
- **Programmable frames**: `TRANS`/`ATRANS` work offsets
|
|
14
|
+
- **Programmable frames**: `TRANS`/`ATRANS` work offsets, `ROT`/`AROT` rotations (`X.. Y.. Z..` RPY angles or `RPL=` in the active plane), `SCALE`/`ASCALE` factors for every configured axis, and `MIRROR`/`AMIRROR` for the geometry axes X, Y, Z; output coordinates are machine coordinates with the frame applied, and the final state reports the `translation`, the `rotation` (with the X, Y, Z scale and mirror folded in) and the `axis_scale` of the other axes. `ROTS`/`AROTS`/`CROTS` take one solid angle; two solid angles, `TOFRAME`, `TOROT` and `PAROT` raise an error.
|
|
15
15
|
- **Looping Constructs**: Handles loops using `WHILE`, `FOR`, `REPEAT ... UNTIL` and `LOOP ... ENDLOOP` statements.
|
|
16
16
|
- **Variable Handling**: Supports definition and manipulation of local variables.
|
|
17
17
|
- **Conditional Logic**: Implements conditional execution with `IF`, `ELSE`, and `ENDIF`.
|
|
@@ -26,7 +26,7 @@ The **NC-GCode-Interpreter** offers a streamlined and efficient solution for int
|
|
|
26
26
|
|
|
27
27
|
- **Streaming interpretation**: `nc_to_rows(program)` yields `(line_no, row)` tuples lazily while the interpreter runs on a background thread — bounded output buffering, early exit by dropping the iterator (breaking out of a `for` loop over an anonymous iterator does this; a stored iterator keeps the run alive until it is deleted or garbage-collected), and source-line numbers for mapping trace rows back to the program. With `include_variables=True` it yields `(line_no, row, variables)` instead, exposing every variable assignment (`R1=R1+1`, `DEF`, FOR counters) as it happens — including blocks that only assign variables, which are invisible in the batch DataFrame.
|
|
28
28
|
|
|
29
|
-
- **Curve flattening**: pass `flatten_tolerance` (Python) or `--flatten-tolerance` (CLI) to convert curved motions — `G2`/`G3` arcs (`I`/`J`/`K` centre offsets or `CR=` radius form, `G17`/`G18`/`G19` planes, helical third axis with `TURN=` multi-turn support, full circles) and `ASPLINE`/`BSPLINE`/`CSPLINE` splines (including `PW` weights and `SD` degree) — into runs of plain `G1` rows in the same table format. `CIP`/`CT`/`POLY`/thread/involute blocks pass through unchanged with a warning; spline start/end conditions (`BAUTO`/`BNAT`/... ) are approximated by natural (CSPLINE) / Akima (ASPLINE) boundaries — see the `flatten` module docs for the full list of checked approximations. A `BSPLINE` whose control-point blocks all carry a `PL` is built on those knot distances (cubic and quadratic, mapping measured on a SINUMERIK ONE). Without `PL` it is built on uniform knots, which is an approximation: the control's knots in that case are not uniform and the rule is not identified. A `PL` on only some of the blocks is ignored with a warning. The single tolerance is the maximum deviation between the emitted polyline and the true curve, in path units: arcs use the exact sagitta bound, splines adaptive subdivision. The interpolation addresses (`I`/`J`/`K`/`CR`/`PW`/`SD`/`PL`) are consumed and do not appear in the output; sampled rows keep the source block's line number, and its other cells (`F`, `M`, comments, ...) ride on the first sample so modal behavior is preserved. Generated samples carry a `flattened = 1` marker column (never forward-filled); programmed positions stay null there, so filtering on null recovers the original toolpath points.
|
|
29
|
+
- **Curve flattening**: pass `flatten_tolerance` (Python) or `--flatten-tolerance` (CLI) to convert curved motions — `G2`/`G3` arcs (`I`/`J`/`K` centre offsets or `CR=` radius form, `G17`/`G18`/`G19` planes, helical third axis with `TURN=` multi-turn support, full circles) and `ASPLINE`/`BSPLINE`/`CSPLINE` splines (including `PW` weights and `SD` degree) — into runs of plain `G1` rows in the same table format. `CIP`/`CT`/`POLY`/thread/involute blocks pass through unchanged with a warning; spline start/end conditions (`BAUTO`/`BNAT`/... ) are approximated by natural (CSPLINE) / Akima (ASPLINE) boundaries — see the `flatten` module docs for the full list of checked approximations. A `BSPLINE` whose control-point blocks all carry a `PL` is built on those knot distances (cubic and quadratic, mapping measured on a SINUMERIK ONE). Without `PL` it is built on uniform knots, which is an approximation: the control's knots in that case are not uniform and the rule is not identified. A `PL` on only some of the blocks is ignored with a warning. `PL=0` repeats a knot; as often in succession as the spline degree, or on the first or last knot span, it is ignored with a warning. The single tolerance is the maximum deviation between the emitted polyline and the true curve, in path units: arcs use the exact sagitta bound, splines adaptive subdivision. The interpolation addresses (`I`/`J`/`K`/`CR`/`PW`/`SD`/`PL`) are consumed and do not appear in the output; sampled rows keep the source block's line number, and its other cells (`F`, `M`, comments, ...) ride on the first sample so modal behavior is preserved. Generated samples carry a `flattened = 1` marker column (never forward-filled); programmed positions stay null there, so filtering on null recovers the original toolpath points.
|
|
30
30
|
- **Toolpath visualization** (optional): with the `viz` extra (`pip install 'nc-gcode-interpreter[viz]'`), `nc_gcode_interpreter.viz.view_toolpath(df)` renders an interpreted toolpath in [threejs-viewer](https://pypi.org/project/threejs-viewer/) as an extruded bead tube with a draw-range animation replaying the program at feed-rate-proportional speed. Combined with `flatten_tolerance`, programmed points render orange and flattener-generated samples blue. The extra also installs the `nc-view` command: `nc-view part.mpf` interprets, flattens (default tolerance 0.1, `--no-flatten` to skip) and opens the animated toolpath in the browser; `--speed` sets the time-lapse factor (default 60 = one machine-minute per second).
|
|
31
31
|
- **Custom Axes**: Allows users to define additional axes beyond the standard `X`, `Y`, `Z`.
|
|
32
32
|
- **Definitions, variables and start state**: `definitions` takes the definition files a control loads (GUD/MGUD/UGUD `.DEF`: DEF and REDEF statements, assignments, comments; M17/M30/M2 ends a file), `variables` takes variable values checked against their declared type, and `start` takes the machine state at program start in the shape of the returned `state` dict (axes, frame, variables, modal G groups, feed, tool, transformation, FGROUP and FGREF radii). The G groups, feed, tool, transformation, FGROUP and FGREF fill the first output row; seeded G groups have the same `pl.Enum` dtype as the rest of the column. They are applied in that order, before the main program. In a definition file `CHANDATA(1)` is ignored, another channel is an error, `TRAFOOF` sets the start transformation to off (a later `start["transformation"]` wins), M0 and M1 are ignored, a subprogram call is an error, and assigning to an undeclared name is an error unless it is an R parameter or `allow_undefined_variables` is set.
|
{nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/nc_gcode_interpreter/__init__.py
RENAMED
|
@@ -107,6 +107,11 @@ def _definition_texts(
|
|
|
107
107
|
return texts
|
|
108
108
|
|
|
109
109
|
|
|
110
|
+
_FRAME_COLUMNS = frozenset(
|
|
111
|
+
[f"frame_r{row}{column}" for row in (1, 2, 3) for column in (1, 2, 3)] + ["frame_tx", "frame_ty", "frame_tz"]
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
|
|
110
115
|
def _subprogram_texts(subprograms: "Mapping[str, str] | None") -> dict[str, str] | None:
|
|
111
116
|
return None if subprograms is None else dict(subprograms)
|
|
112
117
|
|
|
@@ -129,6 +134,7 @@ def nc_to_dataframe(
|
|
|
129
134
|
m_function_subprograms: "Mapping[int, str] | None" = None,
|
|
130
135
|
required_subprograms: "Iterable[str] | None" = None,
|
|
131
136
|
stop_on_setal: bool = False,
|
|
137
|
+
include_frame: bool = False,
|
|
132
138
|
) -> tuple[pl.DataFrame, dict]:
|
|
133
139
|
"""
|
|
134
140
|
Parses Sinumerik-flavored NC G-code and converts it into a Polars DataFrame along with the final state.
|
|
@@ -161,7 +167,8 @@ def nc_to_dataframe(
|
|
|
161
167
|
start: Mapping | None, optional
|
|
162
168
|
The machine state at program start, in the shape of the returned state
|
|
163
169
|
dict, so a returned state can be passed back. Keys: ``axes`` and
|
|
164
|
-
``translation`` (dict[str, float]), ``rotation`` (3x3), ``
|
|
170
|
+
``translation`` (dict[str, float]), ``rotation`` (3x3), ``axis_scale``
|
|
171
|
+
(SCALE factor per non-geometry axis, dict[str, float]), ``symbol_table``
|
|
165
172
|
(dict[str, float]), ``string_table`` (dict[str, str]), ``g_groups``
|
|
166
173
|
(modal G group column to code, e.g. ``{"gg01_motion": "G1"}``),
|
|
167
174
|
``feed`` (float; pass the control's default feed SD42110
|
|
@@ -200,6 +207,19 @@ def nc_to_dataframe(
|
|
|
200
207
|
across a jump, matching the streaming `nc_to_rows`. Never
|
|
201
208
|
forward-filled; `dataframe_to_nc` ignores it. Default False (column
|
|
202
209
|
absent, output schema unchanged).
|
|
210
|
+
include_frame: bool, optional
|
|
211
|
+
If True, add the programmable frame (TRANS, ROT, SCALE, MIRROR and
|
|
212
|
+
their additive forms) that is active on each row as twelve Float64
|
|
213
|
+
columns: `frame_r11` to `frame_r33`, the linear part R row by row, and
|
|
214
|
+
`frame_tx`, `frame_ty`, `frame_tz`, the translation t, in machine XYZ
|
|
215
|
+
= R * local XYZ + t. R is the rotation with the scale and mirror
|
|
216
|
+
factors folded in, so it is a pure rotation only while no SCALE or
|
|
217
|
+
MIRROR is active.
|
|
218
|
+
The values are written on the first row and on the first row after
|
|
219
|
+
each change, and forward-filled like the axis columns; with
|
|
220
|
+
`disable_forward_fill` the other rows are null. Programmed A/B/C
|
|
221
|
+
values are not rotated by the interpreter, so a consumer can apply R
|
|
222
|
+
to them. Default False (columns absent).
|
|
203
223
|
|
|
204
224
|
Returns:
|
|
205
225
|
--------
|
|
@@ -258,6 +278,7 @@ def nc_to_dataframe(
|
|
|
258
278
|
stop_on_setal,
|
|
259
279
|
# No row is read before the run ends, so a provider call need not wait for one.
|
|
260
280
|
defer_rows=True,
|
|
281
|
+
include_frame=include_frame,
|
|
261
282
|
)
|
|
262
283
|
# pl.DataFrame wraps each Arrow record batch via __arrow_c_array__ (polars
|
|
263
284
|
# >= 1.3), no pyarrow needed. Exhaust the iterator before reading .state.
|
|
@@ -391,6 +412,8 @@ def sanitize_dataframe(
|
|
|
391
412
|
# dataframe_to_nc.
|
|
392
413
|
if "line_no" in df.columns:
|
|
393
414
|
df = df.drop("line_no")
|
|
415
|
+
# The `frame_*` columns (include_frame=True) report the frame; they are not NC words.
|
|
416
|
+
df = df.drop([name for name in df.columns if name in _FRAME_COLUMNS])
|
|
394
417
|
|
|
395
418
|
modal = [g["short_name"] for g in GGroups.g_groups if g["effectiveness"] == "modal"]
|
|
396
419
|
non_modal = [g["short_name"] for g in GGroups.g_groups if g["effectiveness"] != "modal"]
|
|
@@ -584,8 +607,8 @@ def nc_to_rows(
|
|
|
584
607
|
|
|
585
608
|
Errors raise ``ValueError`` from ``next()`` when reached. After the
|
|
586
609
|
iterator is exhausted, its ``state`` attribute holds the final
|
|
587
|
-
interpreter state (axes, symbol_table, translation, rotation,
|
|
588
|
-
g_groups, feed, tool, transformation, fgroup, fgref).
|
|
610
|
+
interpreter state (axes, symbol_table, translation, rotation, axis_scale,
|
|
611
|
+
string_table, g_groups, feed, tool, transformation, fgroup, fgref).
|
|
589
612
|
|
|
590
613
|
Example:
|
|
591
614
|
--------
|
|
@@ -626,7 +649,7 @@ class _BatchIterator:
|
|
|
626
649
|
no Python list of primitives materialized. ``pl.DataFrame`` wraps that
|
|
627
650
|
capsule directly (polars >= 1.3), so no ``pyarrow`` is involved. After
|
|
628
651
|
exhaustion its ``state`` attribute holds the final interpreter state (axes,
|
|
629
|
-
symbol_table, translation, rotation, string_table, g_groups, feed, tool,
|
|
652
|
+
symbol_table, translation, rotation, axis_scale, string_table, g_groups, feed, tool,
|
|
630
653
|
transformation, fgroup, fgref), like
|
|
631
654
|
the iterator returned by :func:`nc_to_rows`.
|
|
632
655
|
"""
|
|
@@ -688,6 +711,7 @@ def nc_to_batches(
|
|
|
688
711
|
m_function_subprograms: "Mapping[int, str] | None" = None,
|
|
689
712
|
required_subprograms: "Iterable[str] | None" = None,
|
|
690
713
|
stop_on_setal: bool = False,
|
|
714
|
+
include_frame: bool = False,
|
|
691
715
|
) -> _BatchIterator:
|
|
692
716
|
"""Interpret an NC program into a stream of columnar polars DataFrames.
|
|
693
717
|
|
|
@@ -755,5 +779,6 @@ def nc_to_batches(
|
|
|
755
779
|
None if m_function_subprograms is None else dict(m_function_subprograms),
|
|
756
780
|
None if required_subprograms is None else list(required_subprograms),
|
|
757
781
|
stop_on_setal,
|
|
782
|
+
include_frame=include_frame,
|
|
758
783
|
)
|
|
759
784
|
return _BatchIterator(inner)
|
{nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/nc_gcode_interpreter/_internal.pyi
RENAMED
|
@@ -61,11 +61,12 @@ def nc_to_batches(
|
|
|
61
61
|
required_subprograms: list[str] | None = None,
|
|
62
62
|
stop_on_setal: bool = False,
|
|
63
63
|
defer_rows: bool = False,
|
|
64
|
+
include_frame: bool = False,
|
|
64
65
|
) -> Any:
|
|
65
66
|
"""Interpret an NC program into an iterator of columnar polars DataFrames.
|
|
66
67
|
|
|
67
68
|
The returned iterator exposes ``state`` (dict with ``axes``,
|
|
68
|
-
``symbol_table``, ``translation``, ``rotation``, ``string_table``,
|
|
69
|
+
``symbol_table``, ``translation``, ``rotation``, ``axis_scale``, ``string_table``,
|
|
69
70
|
``g_groups``, ``feed``, ``tool``, ``transformation``, ``fgroup`` and
|
|
70
71
|
``fgref``) once
|
|
71
72
|
exhausted, and
|
{nc_gcode_interpreter-0.4.0 → nc_gcode_interpreter-0.4.2}/python/tests/test_batch_variables.py
RENAMED
|
@@ -139,7 +139,7 @@ def test_string_table_round_trips_through_state_dict():
|
|
|
139
139
|
assert state["string_table"] == {"MSG": "HELLO WORLD", "TAG": "ABC"}
|
|
140
140
|
# The existing numeric sub-tables are untouched by the new key.
|
|
141
141
|
assert set(state) == {
|
|
142
|
-
"axes", "symbol_table", "translation", "rotation", "string_table", "g_groups", "feed",
|
|
142
|
+
"axes", "symbol_table", "translation", "rotation", "axis_scale", "string_table", "g_groups", "feed",
|
|
143
143
|
"tool", "transformation", "fgroup", "fgref",
|
|
144
144
|
}
|
|
145
145
|
# The string variable never leaks into the numeric symbol table.
|
|
@@ -72,7 +72,8 @@ def de_boor(ctrl, knots, degree, t):
|
|
|
72
72
|
for r in range(1, degree + 1):
|
|
73
73
|
for j in range(degree, r - 1, -1):
|
|
74
74
|
i = j + k - degree
|
|
75
|
-
|
|
75
|
+
width = knots[i + degree + 1 - r] - knots[i]
|
|
76
|
+
alpha = 0.0 if width == 0 else (t - knots[i]) / width
|
|
76
77
|
d[j] = [(1 - alpha) * a + alpha * b for a, b in zip(d[j - 1], d[j], strict=True)]
|
|
77
78
|
x, y, w = d[degree]
|
|
78
79
|
return x / w, y / w
|
|
@@ -206,10 +207,50 @@ def test_pl_with_other_degree_warns_and_uses_uniform_knots(capfd, degree):
|
|
|
206
207
|
assert_frame_equal(with_pl, without)
|
|
207
208
|
|
|
208
209
|
|
|
209
|
-
def
|
|
210
|
+
def test_negative_pl_warns_and_uses_uniform_knots(capfd):
|
|
210
211
|
without = flatten(program(pl_of=lambda i, value: None))
|
|
211
|
-
|
|
212
|
-
assert "not a
|
|
212
|
+
with_negative = flatten(program(pl_of=lambda i, value: -1 if i == 4 else value))
|
|
213
|
+
assert "negative or not a number" in capfd.readouterr().err
|
|
214
|
+
assert_frame_equal(with_negative, without)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
@pytest.mark.parametrize(("degree", "zero_blocks"), [(3, (4,)), (3, (4, 5)), (2, (4,))])
|
|
218
|
+
def test_zero_pl_repeats_a_knot(capfd, degree, zero_blocks):
|
|
219
|
+
"""PL=0 is a node distance of zero (#129)."""
|
|
220
|
+
text = program(degree=degree, pl_of=lambda i, value: 0 if i in zero_blocks else value)
|
|
221
|
+
points = curve_points(flatten(text))
|
|
222
|
+
assert capfd.readouterr().err == ""
|
|
223
|
+
used = BLOCKS[1:8] if degree == 3 else BLOCKS[0:8]
|
|
224
|
+
first = 2 if degree == 3 else 1
|
|
225
|
+
spans = [0 if i in zero_blocks else value for i, (_, _, value) in enumerate(used, start=first)]
|
|
226
|
+
assert Reference(CONTROL, spans, degree).max_distance(points) < 1e-6
|
|
227
|
+
assert points[-1] == CONTROL[-1]
|
|
228
|
+
# No sample is emitted twice for the empty span.
|
|
229
|
+
assert all(a != b for a, b in itertools.pairwise(points))
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def test_zero_pl_on_an_unused_cubic_block_is_accepted(capfd):
|
|
233
|
+
"""The same PL values give the same knots wherever the spline starts (#129)."""
|
|
234
|
+
zero_first = program(pl_of=lambda i, value: 0 if i in (1, 9) else value)
|
|
235
|
+
assert_frame_equal(flatten(zero_first), flatten(program()))
|
|
236
|
+
assert capfd.readouterr().err == ""
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
@pytest.mark.parametrize(
|
|
240
|
+
("degree", "zero_blocks", "reason"),
|
|
241
|
+
[
|
|
242
|
+
(3, (4, 5, 6), "as often in succession as the spline degree"),
|
|
243
|
+
(2, (4, 5), "as often in succession as the spline degree"),
|
|
244
|
+
(3, (2,), "first or last knot span"),
|
|
245
|
+
(3, (8,), "first or last knot span"),
|
|
246
|
+
(2, (1,), "first or last knot span"),
|
|
247
|
+
],
|
|
248
|
+
)
|
|
249
|
+
def test_zero_pl_that_would_split_the_curve_warns(capfd, degree, zero_blocks, reason):
|
|
250
|
+
without = flatten(program(degree=degree, pl_of=lambda i, value: None))
|
|
251
|
+
text = program(degree=degree, pl_of=lambda i, value: 0 if i in zero_blocks else value)
|
|
252
|
+
with_zero = flatten(text)
|
|
253
|
+
assert reason in capfd.readouterr().err
|
|
213
254
|
assert_frame_equal(with_zero, without)
|
|
214
255
|
|
|
215
256
|
|
|
@@ -291,3 +332,12 @@ def test_huge_pl_values_do_not_overflow():
|
|
|
291
332
|
small = flatten(program(degree=2))
|
|
292
333
|
huge = flatten(program(degree=2, pl_of=lambda i, value: f"{value}{'0' * 306}"))
|
|
293
334
|
assert flat(curve_points(huge)) == pytest.approx(flat(curve_points(small)), abs=1e-9)
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
def test_zero_pl_on_the_only_span_left_after_a_repeat_warns(capfd):
|
|
338
|
+
"""Dropping a repeated point must not skip the end-span check (review of #131)."""
|
|
339
|
+
body = "X10 Y10{}\nX10 Y10{}\nX20 Y0{}\nG1 X30\n"
|
|
340
|
+
head = "G1 X0 Y0 F100\nBSPLINE SD=2\n"
|
|
341
|
+
with_zero = flatten(head + body.format(" PL=0", " PL=1", " PL=2"), tolerance=0.1)
|
|
342
|
+
assert "first or last knot span" in capfd.readouterr().err
|
|
343
|
+
assert_frame_equal(with_zero, flatten(head + body.format("", "", ""), tolerance=0.1))
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""The programmable frame per row, `include_frame` (#130)."""
|
|
2
|
+
|
|
3
|
+
import math
|
|
4
|
+
|
|
5
|
+
import polars as pl
|
|
6
|
+
import pytest
|
|
7
|
+
from nc_gcode_interpreter import dataframe_to_nc, nc_to_batches, nc_to_dataframe
|
|
8
|
+
|
|
9
|
+
ROTATION = [f"frame_r{row}{column}" for row in (1, 2, 3) for column in (1, 2, 3)]
|
|
10
|
+
TRANSLATION = ["frame_tx", "frame_ty", "frame_tz"]
|
|
11
|
+
IDENTITY = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@pytest.fixture(params=["0", "1"])
|
|
15
|
+
def stage1(request, monkeypatch):
|
|
16
|
+
monkeypatch.setenv("NC_STAGE1", request.param)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def frames(text, **options):
|
|
20
|
+
df, state = nc_to_dataframe(text, include_frame=True, **options)
|
|
21
|
+
return df, state
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def rotation(df, row):
|
|
25
|
+
return [df[name][row] for name in ROTATION]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def translation(df, row):
|
|
29
|
+
return [df[name][row] for name in TRANSLATION]
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_columns_are_absent_by_default(stage1):
|
|
33
|
+
df, _ = nc_to_dataframe("AROT Z30\nG1 X1 Y0 Z0 F1000\n")
|
|
34
|
+
assert not [name for name in df.columns if name.startswith("frame_")]
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def test_issue_example_reports_the_evaluated_rotation(stage1):
|
|
38
|
+
text = "G18\nR1=10\nAROT RPL=R1*3\nG1 X1 Y0 Z0 F1000\n"
|
|
39
|
+
df, state = frames(text)
|
|
40
|
+
row = df.height - 1
|
|
41
|
+
assert rotation(df, row) == pytest.approx([v for line in state["rotation"] for v in line])
|
|
42
|
+
# Machine XYZ of the row is R * local XYZ.
|
|
43
|
+
r = rotation(df, row)
|
|
44
|
+
assert [df["X"][row], df["Y"][row], df["Z"][row]] == pytest.approx([r[0], r[3], r[6]])
|
|
45
|
+
assert r[0] == pytest.approx(math.cos(math.radians(30)))
|
|
46
|
+
assert r[4] == pytest.approx(1.0)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_every_row_carries_the_frame_active_on_it(stage1):
|
|
50
|
+
text = "G1 X1 Y0 Z0 F1000\nX2\nTRANS X10 Y20 Z30\nAROT Z90\nX1\nX2\nATRANS X1\nX3\nROT\nX4\nTRANS\nX5\n"
|
|
51
|
+
df, _ = frames(text)
|
|
52
|
+
quarter = [0.0, -1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0]
|
|
53
|
+
# ATRANS X1 is added in the rotated frame; ROT deletes the whole frame.
|
|
54
|
+
expected = [
|
|
55
|
+
(IDENTITY, [0, 0, 0]),
|
|
56
|
+
(IDENTITY, [0, 0, 0]),
|
|
57
|
+
(quarter, [10, 20, 30]),
|
|
58
|
+
(quarter, [10, 20, 30]),
|
|
59
|
+
(quarter, [10, 21, 30]),
|
|
60
|
+
(IDENTITY, [0, 0, 0]),
|
|
61
|
+
(IDENTITY, [0, 0, 0]),
|
|
62
|
+
]
|
|
63
|
+
assert df.height == len(expected)
|
|
64
|
+
for row, (r, t) in enumerate(expected):
|
|
65
|
+
assert rotation(df, row) == pytest.approx(r, abs=1e-12), row
|
|
66
|
+
assert translation(df, row) == pytest.approx(t, abs=1e-12), row
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def test_frame_from_a_loop_and_a_branch(stage1):
|
|
70
|
+
text = "G1 X1 Y0 Z0 F1000\nR1=0\nWHILE R1<3\nAROT Z10\nX1\nR1=R1+1\nENDWHILE\nIF R1==3\nROT Z90\nENDIF\nX1\n"
|
|
71
|
+
df, state = frames(text)
|
|
72
|
+
angles = [math.degrees(math.atan2(df["frame_r21"][row], df["frame_r11"][row])) for row in range(df.height)]
|
|
73
|
+
assert angles == pytest.approx([0, 10, 20, 30, 90])
|
|
74
|
+
assert rotation(df, df.height - 1) == pytest.approx([v for line in state["rotation"] for v in line])
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def test_only_changes_are_written_without_forward_fill(stage1):
|
|
78
|
+
df, _ = frames("G1 X1 Y0 Z0 F1000\nX2\nAROT Z90\nX3\nX4\n", disable_forward_fill=True)
|
|
79
|
+
assert df["frame_r11"].is_not_null().to_list() == [True, False, True, False]
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def test_flattened_arc_rows_carry_the_frame(stage1):
|
|
83
|
+
pytest.importorskip("numpy")
|
|
84
|
+
text = "G1 X0 Y0 Z0 F1000\nAROT Z90\nG2 X10 Y0 I5 J0\nG1 X20\n"
|
|
85
|
+
df, _ = frames(text, flatten_tolerance=0.01)
|
|
86
|
+
assert df.height > 4
|
|
87
|
+
assert df["frame_r21"].to_list() == pytest.approx([0.0] + [1.0] * (df.height - 1))
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def test_batches_fill_the_frame_across_batch_borders(stage1):
|
|
91
|
+
text = "G1 X0 Y0 Z0 F1000\nTRANS X5\n" + "".join(f"X{i}\n" for i in range(1, 10))
|
|
92
|
+
whole, _ = frames(text)
|
|
93
|
+
batches = pl.concat(list(nc_to_batches(text, batch_size=3, include_frame=True)))
|
|
94
|
+
assert batches.select(ROTATION + TRANSLATION).equals(whole.select(ROTATION + TRANSLATION))
|
|
95
|
+
assert batches["frame_tx"].to_list() == [0.0] + [5.0] * 9
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def test_a_frame_block_that_gives_a_row_carries_its_own_frame(stage1):
|
|
99
|
+
df, _ = frames("G0 X0\nTRANS X10 ; offset\nN30 ATRANS X5\nG0 X0\n")
|
|
100
|
+
assert df["frame_tx"].to_list() == [0.0, 10.0, 15.0, 15.0]
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def test_comment_only_program_has_the_columns(stage1):
|
|
104
|
+
df, _ = frames("; only a comment\n")
|
|
105
|
+
assert df.select(ROTATION + TRANSLATION).row(0) == (*IDENTITY, 0.0, 0.0, 0.0)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def test_export_ignores_the_frame_columns(stage1, tmp_path):
|
|
109
|
+
text = "G0 X0\nTRANS X10\nG0 X1\n"
|
|
110
|
+
plain, _ = nc_to_dataframe(text)
|
|
111
|
+
with_frame, _ = frames(text)
|
|
112
|
+
dataframe_to_nc(plain, tmp_path / "plain.mpf")
|
|
113
|
+
dataframe_to_nc(with_frame, tmp_path / "frame.mpf")
|
|
114
|
+
assert (tmp_path / "frame.mpf").read_text() == (tmp_path / "plain.mpf").read_text()
|
|
115
|
+
assert "frame_" not in (tmp_path / "frame.mpf").read_text()
|