Skip to content

Commit aa0bd74

Browse files
Expand FANUC milling, Macro B and cycle execution
1 parent 7ad5e45 commit aa0bd74

93 files changed

Lines changed: 7125 additions & 4866 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎CHANGELOG.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
11
# Changelog
22

3+
## 1.6.2 - 2026-09-23
4+
5+
- Added a machine-neutral cycle execution contract while preserving machine-specific expansion models. Milling canned cycles now return geometry, signals, modal updates and position updates as one atomic outcome built against temporary state; the existing turning expansion pipeline is connected through an adapter without rewriting G70-G76 semantics. Cycle implementations now live under canonical `turning/cycles` and `milling/cycles` packages, with historical import paths retained as aliases.
6+
- Added FANUC milling `G16/G15` polar-coordinate programming with `G17/G18/G19` plane selection, absolute/incremental radius-angle commands, WCS/local-origin and current-position pole selection, canned-cycle positioning, R-format circular interpolation, coordinate-transform integration and Python/native execution parity. Turning remains unchanged.
7+
- Added FANUC Macro B vacant-variable semantics for `#0` and omitted G65 arguments, indirect `#[expr]` assignment, and shared immutable variable snapshots that avoid duplicating unchanged macro state across execution steps.
8+
- Fixed milling `G10` under `G91` to increment existing L2/L20 work offsets instead of silently replacing them.
9+
- Fixed two-line turning `G76` so the packed tool-angle digits now produce FANUC single-edge flank infeed for the supported 0/29/30/55/60/80-degree set instead of being silently ignored; unsupported angles now fail explicitly.
10+
- Expanded modal conflict validation for milling tool-length compensation, scaling and rotation plus turning spindle modes, and added an explicit `UNSUPPORTED_G72_TYPE_II_SPANS` failure for ambiguous multi-span facing profiles.
11+
- Refactored kernel execution without intentional CNC semantic changes: milling now uses named evaluation/validation/state/flow/motion phases with a single block finalizer, while turning machine-specific operations are grouped behind one execution-semantics contract instead of a growing callback list.
12+
- Added a standalone `Tool List` CNC function that reuses resolved per-tool statistics to produce a CIMCO-style UTF-8 text report with program/file metadata, configured tool geometry and exact per-tool Z minimums.
13+
- Fixed turning `G53` fail-open behavior for arc modes. `G53 G2/G3` now reports `UNSUPPORTED_G53_MOTION` and skips the complete block instead of silently executing a WCS-relative arc.
14+
- Expanded the Tokens diagnostic window into `Tokens/Macro Variables` with a read-only Macro Variables inspector driven by execution-step snapshots. The inspector follows the current logical playback position, shows only variables that actually exist at that point, includes active G65 local-variable scopes and restored caller values after M99, updates during playback/step/slider navigation without re-executing the program, and works consistently for turning and milling Python/native execution paths.
15+
- Added a persistent CNC comment-style selector under `Options -> CNC / Execution`. Parenthesized comments remain the default, while semicolon comments can now be selected consistently for editor lexing, generated statistics and every text export mode; existing source programs using either syntax remain readable.
16+
- Improved export failure reporting with an always-visible, copyable diagnostics field containing severity, diagnostic code, source line, explanation and the offending G-code block, so incomplete or invalid executions no longer require opening Tokens or relying on the temporary status-bar message.
17+
- Fixed `MILL FULL PROGRAM` export so the Delimiter option is also applied to retained controller blocks such as compact `G0G91G28Z0`, producing `G0 G91 G28 Z0` consistently with generated motion blocks.
18+
- Localized the dynamic Recent Files menu, including its empty state and clear-list action, for the Russian interface.
19+
- Fixed the Windows complexity-check script failing in project paths containing Cyrillic characters by decoding Ruff's JSON output explicitly as UTF-8.
20+
321
## 1.6.1 - 2026-09-22
422

523
- Fixed milling `G84` tapping so withdrawal from depth is emitted as synchronized feed motion instead of rapid motion.

‎FAQ.md‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Easy G-Code Plot is a desktop editor, analyzer, simulator and trace exporter for
2929

3030
The simplest Windows installation is the standalone executable from [GitHub Releases](https://github.com/MaestroFusion360/easy_gcode_plot/releases). It does not require a separate Python installation.
3131

32-
To run from source, install Python 3.11+ and [uv](https://docs.astral.sh/uv/), then run:
32+
To run from source, install Python 3.11+, [uv](https://docs.astral.sh/uv/) and a C compiler (Visual Studio Build Tools with **Desktop development with C++** on Windows, or the platform compiler and Python development headers on Linux/macOS), then run:
3333

3434
```bash
3535
git clone https://github.com/MaestroFusion360/easy_gcode_plot.git
@@ -272,6 +272,12 @@ Yes. When exporting an R-format full circle, Expanded Execution emits two exact
272272
- Configured milling tools and cutter-radius compensation.
273273
- G52 local coordinate shifts, G68/G69 coordinate rotation and G51/G50 coordinate scaling.
274274

275+
### How does FANUC milling polar-coordinate programming work?
276+
277+
`G16` enables radius/angle endpoint programming and `G15` returns to ordinary Cartesian coordinates. `G17`, `G18` and `G19` select the polar plane; its first axis is the radius and its second axis is the angle in degrees. `G90` uses the active work/local origin as the pole and absolute radius/angle values, while `G91 G16` captures the current position as the pole and later `G91` words increment the modal radius or angle. Omitted polar components retain their previous values.
278+
279+
Polar programming is milling-only. Polar `G2/G3` follows the supported FANUC contract and requires an `R` arc radius; I/J/K center programming in `G16` mode is rejected instead of guessed. `G12.1/G13.1` polar interpolation is not implemented.
280+
275281
### FANUC turning
276282

277283
- X/Z and U/W motion with diameter/radius handling.
@@ -312,9 +318,13 @@ Select `Inches` at the bottom-left of the window to convert every displayed leng
312318

313319
One or more motions lack a trustworthy physical feed rate. A common cause is feed-per-revolution execution without a known spindle RPM. The application reports unknown time instead of treating that feed as millimetres per minute.
314320

315-
### What is the Tokens window for?
321+
### What is the Tokens/Macro Variables window for?
322+
323+
**Settings → Tokens/Macro Variables** has two read-only diagnostic tabs. **Tokens** shows parser words, evaluated values, source position, execution status and diagnostics. Suspicious or unsupported rows are highlighted and can be copied or exported as CSV.
324+
325+
**Macro Variables** shows the Macro B variable state captured at the current logical playback position. Only variables that exist at that execution point are shown. G65 local variables follow the active macro-call scope and are restored after M99. Moving Play, Step or the slider updates the inspector from the existing execution snapshots without re-executing the CNC program. If the current source is stale relative to the displayed execution result, Macro Variables are not shown until the toolpath is updated.
316326

317-
**Settings → Tokens** shows parser words, evaluated values, source position, execution status and diagnostics. Suspicious or unsupported rows are highlighted and can be copied or exported as CSV.
327+
Macro variable `#0` is permanently vacant and cannot be assigned. Omitted G65 local arguments are also vacant, so standard tests such as `IF[#1 EQ #0]` work. Assigning `#0` to another variable clears that variable, while indirect assignment such as `#[#1]=5` resolves the destination variable number at runtime.
318328

319329
### Which export types are available?
320330

@@ -323,6 +333,7 @@ One or more motions lack a trustworthy physical feed rate. A common cause is fee
323333
- Expanded Execution.
324334
- Plot Data.
325335
- DXF trajectory.
336+
- Tool List text report from **CNC Functions → Tool List**.
326337

327338
Expanded Execution follows actual occurrence order, including subprogram calls and generated cycle motions. It preserves relevant WCS, home returns, threading, dwell, spindle and coolant events.
328339

@@ -411,7 +422,7 @@ Use `--encoding cp1251` for Windows-1251 input. Export modes include `program` a
411422

412423
### How is the project organized?
413424

414-
- `app/gcode/kernel/` owns deterministic CNC parsing and execution. Its implementation is split into `api/` (public execution facade and result types), `frontend/` (lexing, parsing, AST/model and NC input), `geometry/` (analytical/profile geometry and coordinate systems), `lathe_cycles/` (turning-cycle motion builders), `compensation/` (turning and milling compensation), `runtime/` (control flow, cycle expansion, interpreter, events/signals and trace construction) and `milling/` (milling state, motion and canned-cycle execution).
425+
- `app/gcode/kernel/` owns deterministic CNC parsing and execution. Its implementation is split into `api/` (public execution facade and result types), `frontend/` (lexing, parsing, AST/model and NC input), `geometry/` (analytical/profile geometry and coordinate systems), `turning/cycles/` and `milling/cycles/` (machine-specific cycle implementations behind the shared runtime cycle contract), `compensation/` (turning and milling compensation), `runtime/` (control flow, cycle contracts/expansion, interpreter, events/signals and trace construction) and `milling/` (milling state and motion execution). Historical `lathe_cycles` and `milling.drilling` import paths remain compatibility aliases.
415426
- `app/gcode/export/` owns Full Program, Expanded Execution, Plot Data and DXF serialization. Exporters consume the authoritative kernel result/resolved trace and do not implement a second G-code interpreter.
416427
- `app/gcode/trace_tools.py` owns render sampling and statistics derived from the resolved trace.
417428
- `app/ui/` owns PyQt GUI behavior, grouped into `dialogs/` (dialogs and tool editors), `plot/` (OpenGL items, STL, overlays and playback), `windows/` (main-window mixins and the execution worker) and `support/` (editor lexer, units, numeric input and shared widgets).

‎LICENSE.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MIT License
22

3-
Copyright (c) 2025 MaestroFusion360
3+
Copyright (c) 2025-2026 MaestroFusion360
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

‎README.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ Easy G-Code Plot is a desktop editor, analyzer, simulator and trace exporter for
2626

2727
- FANUC turning and milling with Macro B expressions, conditions, loops, `G65` custom-macro calls and `M98/M99` subprograms.
2828
- Turning G70–G76 cycles, G32/G33/G92 threading, tool-nose compensation and direct A/C/corner-R programming.
29-
- Milling canned cycles, helical arcs, cutter-radius compensation and G10/G50/G51/G52/G54.1/G68/G69 coordinate operations.
29+
- Milling canned cycles, helical arcs, `G15/G16` polar-coordinate programming, cutter-radius compensation and G10/G50/G51/G52/G54.1/G68/G69 coordinate operations.
3030
- G-code editor with highlighting, line numbers, search, replace and cleanup tools.
3131
- Interactive OpenGL toolpath, logical-motion playback and source-line synchronization.
32+
- Toolpath statistics and CIMCO-style UTF-8 Tool List export from the resolved trace and configured tools.
3233
- Cutter-aware turning Stock Removal, including thread profiles.
3334
- ASCII and binary STL overlays with solid and feature-edge modes.
3435
- SQLite-backed turning and milling tool libraries.
@@ -67,7 +68,7 @@ uv run --no-dev python main.py
6768
2. Enable `Lathe Mode` for turning or leave it disabled for milling.
6869
3. Configure WCS, machine home and tools when required.
6970
4. Refresh and inspect the resolved toolpath.
70-
5. Use playback, Tokens and Statistics to inspect execution.
71+
5. Use playback, Tokens/Macro Variables and Statistics to inspect execution. The Macro Variables tab shows the actual Macro B state captured at the current logical playback step.
7172
6. Optionally import an STL reference model.
7273
7. Export the required program or trajectory representation.
7374

‎app/gcode/comments.py‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""Shared G-code comment syntax policy."""
2+
3+
from __future__ import annotations
4+
5+
import re
6+
7+
PARENTHESES = "parentheses"
8+
SEMICOLON = "semicolon"
9+
DEFAULT_COMMENT_STYLE = PARENTHESES
10+
COMMENT_STYLES = (PARENTHESES, SEMICOLON)
11+
12+
13+
def normalize_comment_style(value: object) -> str:
14+
"""Return a supported persisted comment style."""
15+
style = str(value or "").strip().lower()
16+
return style if style in COMMENT_STYLES else DEFAULT_COMMENT_STYLE
17+
18+
19+
def comment_markers(style: object = DEFAULT_COMMENT_STYLE) -> tuple[str, str]:
20+
"""Return the opening and closing text for *style*."""
21+
return (";", "") if normalize_comment_style(style) == SEMICOLON else ("(", ")")
22+
23+
24+
def format_comment(text: object, style: object = DEFAULT_COMMENT_STYLE) -> str:
25+
"""Format one comment using the selected project-wide syntax."""
26+
body = str(text).strip()
27+
if not body:
28+
return ""
29+
start, end = comment_markers(style)
30+
return f"{start}{body}{end}"
31+
32+
33+
def strip_comments(line: str, style: object | None = None) -> str:
34+
"""Remove comments from a source line.
35+
36+
With no explicit style both common CNC syntaxes are accepted for backwards
37+
compatibility by the parser. UI consumers pass the configured style.
38+
"""
39+
selected = normalize_comment_style(style) if style is not None else None
40+
out = line
41+
if selected in (None, PARENTHESES):
42+
out = re.sub(r"\([^()]*\)", "", out)
43+
if selected in (None, SEMICOLON):
44+
out = out.split(";", 1)[0]
45+
return out.strip()
46+
47+
48+
def extract_comments(line: str) -> list[str]:
49+
"""Extract comments from either supported input syntax."""
50+
comments = [match.group(1).strip() for match in re.finditer(r"\((.*?)\)", line) if match.group(1).strip()]
51+
_code, separator, comment = line.partition(";")
52+
if separator and comment.strip():
53+
comments.append(comment.strip())
54+
return comments

‎app/gcode/export/formatting.py‎

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import re
66

7+
from ..comments import DEFAULT_COMMENT_STYLE, extract_comments, format_comment, strip_comments
78
from ..core import format_gcode_number
89
from ..kernel import TraceMotion
910
from ..kernel.events import PROGRAM_END, SUBPROGRAM_END, SUBPROGRAM_START
@@ -13,8 +14,9 @@
1314
_TURN_CYCLE_G_CODES = {70, 71, 72, 73, 74, 75, 76, 83, 84, 90, 92, 94}
1415
_TURN_GEOMETRY_G_CODES = {0, 1, 2, 3, 28, 30, 32, 33, *_TURN_CYCLE_G_CODES}
1516
_MILL_CYCLE_G_CODES = {81, 82, 83, 84, 85, 86}
16-
_MILL_GEOMETRY_G_CODES = {0, 1, 2, 3, 28, *_MILL_CYCLE_G_CODES}
17+
_MILL_GEOMETRY_G_CODES = {0, 1, 2, 3, 15, 16, 28, *_MILL_CYCLE_G_CODES}
1718
_WORD_RE = re.compile(r"([A-Z])([+\-]?(?:\d+(?:\.\d*)?|\.\d+))", re.IGNORECASE)
19+
_ADDRESS_BOUNDARY_RE = re.compile(r"(?<=[0-9.\]#])(?=[A-Z](?=[+\-]?(?:\d|\.|#|\[)))", re.IGNORECASE)
1820

1921

2022
def _g(move: int, leading_zero: bool) -> str:
@@ -194,32 +196,16 @@ def _subprogram_label(event) -> str:
194196
return "UNKNOWN"
195197

196198

197-
def _format_comment(text: str) -> str:
198-
body = text.strip()
199-
return f"({body})" if body else ""
199+
def _format_comment(text: str, style: str = DEFAULT_COMMENT_STYLE) -> str:
200+
return format_comment(text, style)
200201

201202

202203
def _strip_comments(line: str) -> str:
203-
out = line
204-
while "(" in out and ")" in out:
205-
start = out.find("(")
206-
end = out.find(")", start + 1)
207-
if end < 0:
208-
break
209-
out = out[:start] + out[end + 1 :]
210-
if ";" in out:
211-
out = out.split(";", 1)[0]
212-
return out
204+
return strip_comments(line)
213205

214206

215207
def _extract_comments(line: str) -> list[str]:
216-
comments = [match.group(1).strip() for match in re.finditer(r"\((.*?)\)", line) if match.group(1).strip()]
217-
semi = line.find(";")
218-
if semi >= 0:
219-
text = line[semi + 1 :].strip()
220-
if text:
221-
comments.append(text)
222-
return comments
208+
return extract_comments(line)
223209

224210

225211
def _normalize_words_line(line: str) -> str:
@@ -327,8 +313,13 @@ def _number_full_program_lines(lines: list[str], options: ExportOptions) -> list
327313
spacer = " " if options.sequence_spacing or options.delimiter else ""
328314
for line in lines:
329315
stripped = line.strip()
330-
structural = not stripped or stripped == "%" or stripped.startswith("O") or stripped.startswith("(")
331-
output = line if options.delimiter or structural else line.replace(" ", "")
316+
structural = not stripped or stripped == "%" or stripped.startswith(("O", "(", ";"))
317+
if structural:
318+
output = line
319+
elif options.delimiter:
320+
output = _ADDRESS_BOUNDARY_RE.sub(" ", line)
321+
else:
322+
output = line.replace(" ", "")
332323
if not options.sequence_numbers or structural:
333324
numbered.append(output)
334325
continue

‎app/gcode/export/mill.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def export_full_mill_program(
102102
safety.append("G21")
103103

104104
lines: list[str] = ["%", _program_number(result, options), " ".join(safety)]
105-
lines.append(_format_comment("EXPANDED MILL PROGRAM"))
105+
lines.append(_format_comment("EXPANDED MILL PROGRAM", options.comment_style))
106106
program_start_blocks = event_blocks(result.events, PROGRAM_START)
107107
subprogram_target_blocks = {
108108
event.target_block
@@ -118,7 +118,7 @@ def export_full_mill_program(
118118
event_kinds = _event_kinds(step)
119119

120120
for comment in comments:
121-
lines.append(_format_comment(comment))
121+
lines.append(_format_comment(comment, options.comment_style))
122122

123123
if not clean or clean == "%":
124124
continue
@@ -162,7 +162,7 @@ def export_full_mill_program(
162162

163163
if any(motion.cycle_generated for motion in motions):
164164
source = clean or block.raw.strip()
165-
lines.append(_format_comment(f"EXPANDED MILL CYCLE: {source}"))
165+
lines.append(_format_comment(f"EXPANDED MILL CYCLE: {source}", options.comment_style))
166166

167167
_append_mill_motion_chunk(
168168
lines,

‎app/gcode/export/options.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from dataclasses import dataclass, replace
66

7+
from ..comments import DEFAULT_COMMENT_STYLE, normalize_comment_style
8+
79
TURN_FULL_PROGRAM_MODE = 0
810
MILL_FULL_PROGRAM_MODE = 1
911
EXPANDED_EXECUTION_MODE = 2
@@ -30,6 +32,7 @@ class ExportOptions:
3032
analysis_banner: bool = True
3133
linearization_tolerance: float = 0.0005
3234
include_execution_events: bool = True
35+
comment_style: str = DEFAULT_COMMENT_STYLE
3336

3437

3538
def _turn_program_options(options: ExportOptions | None) -> ExportOptions:
@@ -68,4 +71,5 @@ def _window_export_options(window, *, arc_mode: int) -> ExportOptions:
6871
start_program=str(window.startPgmExp or ""),
6972
end_program=str(window.endPgmExp or ""),
7073
safety_line=bool(window.safLine),
74+
comment_style=normalize_comment_style(getattr(window, "commentStyle", DEFAULT_COMMENT_STYLE)),
7175
)

‎app/gcode/export/trace.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,13 @@ def _append_expanded_event(
8282
occurrence = call_counts[label]
8383
active_calls[event.call_depth] = (label, occurrence)
8484
_append_blank_line(lines)
85-
lines.append(_format_comment(f"SUBPROGRAM {label} START - CALL {occurrence}"))
85+
lines.append(_format_comment(f"SUBPROGRAM {label} START - CALL {occurrence}", options.comment_style))
8686
return
8787

8888
if event.kind == SUBPROGRAM_END:
8989
label = _subprogram_label(event)
9090
active_label, occurrence = active_calls.pop(event.call_depth, (label, call_counts.get(label, 1)))
91-
lines.append(_format_comment(f"SUBPROGRAM {active_label} END - CALL {occurrence}"))
91+
lines.append(_format_comment(f"SUBPROGRAM {active_label} END - CALL {occurrence}", options.comment_style))
9292
lines.append("")
9393
return
9494

@@ -158,7 +158,7 @@ def export_result(result: ExecutionResult, options: ExportOptions | None = None,
158158
if start_event is not None and start_event.code:
159159
lines.append(start_event.code.upper())
160160
if options.analysis_banner:
161-
lines.append("(EXPANDED FROM LOGICAL MOTION TRACE - ANALYSIS ONLY)")
161+
lines.append(_format_comment("EXPANDED FROM LOGICAL MOTION TRACE - ANALYSIS ONLY", options.comment_style))
162162
if options.safety_line:
163163
lines.append("G00 G17 G40 G49 G80 G90" if options.delimiter else "G00G17G40G49G80G90")
164164
turning = result.language == "fanuc_turn"

0 commit comments

Comments
 (0)