Skip to content

Commit a12cd0b

Browse files
Configurable arc sampling and G65 macros
1 parent 34d97b1 commit a12cd0b

40 files changed

Lines changed: 4594 additions & 3656 deletions

‎CHANGELOG.md‎

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

3+
## 1.6.0 - 2026-09-21
4+
5+
- Added FANUC `G65` custom-macro calls for turning and milling: `P` target selection, `L` repetition, Type I/II address-to-`#1..#33` argument binding, four macro-local nesting levels, local-variable restoration on `M99`, and shared execution/export events. `G65` argument words are isolated from normal motion, feed, spindle, M-code and tool-selection side effects; Python/Cython parsing and tool discovery follow the same rule. `G66/G67` remain intentionally out of scope for this release.
6+
- Removed the obsolete installation-directory `config.ini` and its first-run migration; `%APPDATA%/easy-gcode-plot/config.ini` is now the only settings file and clean-profile defaults come exclusively from code.
7+
- Added persistent arc-sampling presets and maximum radius, minimum radius and minimum chord length controls under `Options -> CNC / Execution`; GUI trace generation now applies them per arc to reduce unnecessary render points in large programs without changing CNC execution geometry.
8+
39
## 1.5.9 - 2026-09-20
410

511
- Localized every user-visible Toolpath Statistics report label for the Russian UI while preserving the existing English report text, values, units and statistics calculations.

‎FAQ.md‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ Type I roughing ends with one full pass along the roughing profile that already
130130
Turning and milling tool definitions are stored in the per-user SQLite database:
131131

132132
```text
133-
%LOCALAPPDATA%\easy-gcode-plot\tools.db
133+
%APPDATA%\easy-gcode-plot\tools.db
134134
```
135135

136136
`tools.db` is authoritative. `config.ini` stores UI, editor, plot, WCS, Stock and other application preferences; legacy `CNC/TOOLS_JSON` and `CNC/MILLING_TOOLS_JSON` values are not imported into a current database and are not used as a fallback write target.
@@ -331,11 +331,11 @@ DXF uses separate rapid and cutting layers. Turning uses plot-aligned Z/X entiti
331331
On Windows:
332332

333333
```text
334-
%LOCALAPPDATA%\easy-gcode-plot\config.ini
335-
%LOCALAPPDATA%\easy-gcode-plot\tools.db
334+
%APPDATA%\easy-gcode-plot\config.ini
335+
%APPDATA%\easy-gcode-plot\tools.db
336336
```
337337

338-
`config.ini` contains application preferences; `tools.db` contains the authoritative turning/milling tool library. A legacy `config.ini` beside the launcher may be migrated on first run.
338+
`config.ini` contains application preferences; `tools.db` contains the authoritative turning/milling tool library. Files beside the launcher are not used as configuration sources.
339339

340340
### What is available in Settings → Options?
341341

@@ -344,6 +344,7 @@ On Windows:
344344
- Application logging.
345345
- Auto Update, its sampled-segment limit and the kernel-wide Maximum generated motions limit.
346346
- G41/G42 correction, arc tolerance and milling Arc Type autodetection.
347+
- Arc-sampling presets plus maximum radius, minimum radius and minimum chord length controls for GUI trace generation.
347348
- Persistent optional-block control through `Ignore Block Skip`.
348349
- Editor font and visual settings.
349350
- Plot colors, line thickness, axes and grid.
@@ -356,7 +357,7 @@ On Windows:
356357
When logging is enabled:
357358

358359
```text
359-
%LOCALAPPDATA%\easy-gcode-plot\main.log
360+
%APPDATA%\easy-gcode-plot\main.log
360361
```
361362

362363
The application logger records startup, file operations, execution summaries, export completion and related errors.

‎README.md‎

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

2525
## Highlights
2626

27-
- FANUC turning and milling with Macro B expressions, conditions, loops and subprograms.
27+
- 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.
2929
- Milling canned cycles, helical arcs, cutter-radius compensation and G50/G51/G52/G68/G69 coordinate transforms.
3030
- G-code editor with highlighting, line numbers, search, replace and cleanup tools.
@@ -42,7 +42,7 @@ Detailed controller behavior, limitations, configuration and troubleshooting are
4242

4343
### Windows executable
4444

45-
Download the latest standalone archive from [GitHub Releases](https://github.com/MaestroFusion360/easy_gcode_plot/releases), extract it and run `easy_gcode_plot.exe`. Python and Visual Studio are not required for the packaged application.
45+
Download the latest standalone `.exe` from [GitHub Releases](https://github.com/MaestroFusion360/easy_gcode_plot/releases) and run it. Python and Visual Studio are not required for the packaged application.
4646

4747
### Run from source
4848

@@ -91,6 +91,7 @@ Unsupported or ambiguous controller behavior is reported explicitly instead of b
9191
- **Autodetect Arc Type** — selects relative or absolute-center milling IJK interpretation when only one satisfies Arc tolerance.
9292
- **Ignore Block Skip** — excludes blocks beginning with `/` without modifying the source.
9393
- **Correction (G41/G42)** and **Arc tolerance** — control compensation and arc validation.
94+
- **Arc sampling preset**, **Maximum circular radius**, **Minimum circular radius** and **Minimum chord length** — control GUI trace sampling without changing CNC execution geometry.
9495

9596
Explicit Refresh operations use a cancellable dialog covering tool discovery, parsing, execution, sampling and plot publication.
9697

‎app/gcode/export/formatting.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ def repl(match: re.Match[str]) -> str:
263263

264264

265265
def _strip_flow_event_words(line: str, step) -> str:
266+
if any(event.kind == SUBPROGRAM_START and event.code == "G65" for event in step.events):
267+
return ""
268+
266269
out = line
267270
for event in step.events:
268271
if event.kind == PROGRAM_END:

‎app/gcode/export/trace.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232

3333
def _expanded_step_control(step, options: ExportOptions) -> tuple[str, bool]:
3434
"""Return non-geometric execution controls and whether they replace step motions."""
35+
if any(event.kind == SUBPROGRAM_START and event.code == "G65" for event in step.events):
36+
return "", False
37+
3538
gcodes = {code for letter, value in step.words if letter == "G" and (code := _integer_code(value)) is not None}
3639
home_or_machine_move = bool(gcodes & {28, 30, 53})
3740
dwell = 4 in gcodes

‎app/gcode/kernel/frontend/_native_parser.pyx‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ cdef tuple _native_block(Py_ssize_t index, str raw, bytes clean):
136136
cdef object f_expr = None
137137
cdef object a_expr = None
138138
cdef object c_expr = None
139+
cdef bint g65_call = False
139140
cdef object nlabel = None
140141
cdef object olabel = None
141142
cdef object modal
@@ -198,6 +199,8 @@ cdef tuple _native_block(Py_ssize_t index, str raw, bytes clean):
198199
last_g_expr = expr
199200
if int_code is not None:
200201
g_codes.append(int_code)
202+
if int_code == 65:
203+
g65_call = True
201204
if int_code in (0, 1, 2, 3, 32, 33):
202205
motion_expr = expr
203206
motion_code = int_code
@@ -231,19 +234,24 @@ cdef tuple _native_block(Py_ssize_t index, str raw, bytes clean):
231234
elif letter == "C":
232235
c_expr = expr
233236

234-
modal = ModalSnapshot(
235-
motion_expr if motion_expr is not None else last_g_expr,
236-
x_expr, z_expr, u_expr, w_expr, f_expr,
237-
)
238-
if motion_expr is not None or x_expr is not None or z_expr is not None or u_expr is not None or w_expr is not None:
237+
if g65_call:
238+
modal = ModalSnapshot(None, None, None, None, None, None)
239+
else:
240+
modal = ModalSnapshot(
241+
motion_expr if motion_expr is not None else last_g_expr,
242+
x_expr, z_expr, u_expr, w_expr, f_expr,
243+
)
244+
if not g65_call and (
245+
motion_expr is not None or x_expr is not None or z_expr is not None or u_expr is not None or w_expr is not None
246+
):
239247
motion = MotionNode(
240248
motion_expr,
241249
x_expr, z_expr, u_expr, w_expr,
242250
i_expr, k_expr, r_expr, f_expr, a_expr, c_expr,
243251
)
244252
token_tuple = tuple(tokens)
245253
ast_tuple = tuple(ast_words)
246-
if cycle_expr is not None:
254+
if not g65_call and cycle_expr is not None:
247255
cycle = CycleNode("G" + str(cycle_code), token_tuple)
248256

249257
block = Block(index, raw, token_tuple, modal, motion, cycle, None, nlabel, olabel, optional_skip)
@@ -257,7 +265,9 @@ cdef tuple _native_block(Py_ssize_t index, str raw, bytes clean):
257265
i_expr, k_expr, r_expr, f_expr, a_expr, c_expr,
258266
)
259267
elif g_codes or m_codes:
260-
node = ControlAstNode("control", index, raw, nlabel, olabel, ast_tuple, tuple(g_codes), tuple(m_codes))
268+
node = ControlAstNode(
269+
"control", index, raw, nlabel, olabel, ast_tuple, tuple(g_codes), () if g65_call else tuple(m_codes)
270+
)
261271
elif ast_tuple:
262272
node = MetaAstNode("meta", index, raw, nlabel, olabel, ast_tuple, tuple(word.letter for word in ast_tuple))
263273
else:

‎app/gcode/kernel/frontend/ast.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def build_ast_node(block: object) -> AstNode:
174174
olabel=olabel,
175175
words=ast_words,
176176
g_codes=tuple(g_codes),
177-
m_codes=tuple(m_codes),
177+
m_codes=() if 65 in g_codes else tuple(m_codes),
178178
)
179179

180180
if ast_words:

‎app/gcode/kernel/frontend/program.py‎

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,23 @@ def _parse_blocks(lines: Iterable[str], *, start_index: int = 0):
111111
motion_g_word = next((w for w, code in reversed(g_codes) if code in motion_codes), None)
112112
cycle_g_word = next((w for w, code in reversed(g_codes) if code in cycle_codes), None)
113113
cycle_g_lit = try_literal_int(cycle_g_word.expr) if cycle_g_word is not None else None
114+
g65_call = any(code == 65 for _word, code in g_codes)
114115

115116
modal = ModalSnapshot(
116-
g_expr=(motion_g_word.expr if motion_g_word is not None else (g_words[-1].expr if g_words else None)),
117-
x_expr=word_map.get("X"),
118-
z_expr=word_map.get("Z"),
119-
u_expr=word_map.get("U"),
120-
w_expr=word_map.get("W"),
121-
f_expr=word_map.get("F"),
117+
g_expr=(
118+
None
119+
if g65_call
120+
else (motion_g_word.expr if motion_g_word is not None else (g_words[-1].expr if g_words else None))
121+
),
122+
x_expr=None if g65_call else word_map.get("X"),
123+
z_expr=None if g65_call else word_map.get("Z"),
124+
u_expr=None if g65_call else word_map.get("U"),
125+
w_expr=None if g65_call else word_map.get("W"),
126+
f_expr=None if g65_call else word_map.get("F"),
122127
)
123128

124129
motion_node: MotionNode | None = None
125-
if any(k in word_map for k in ("X", "Z", "U", "W")) or motion_g_word is not None:
130+
if not g65_call and (any(k in word_map for k in ("X", "Z", "U", "W")) or motion_g_word is not None):
126131
motion_node = MotionNode(
127132
g_expr=motion_g_word.expr if motion_g_word is not None else None,
128133
x_expr=word_map.get("X"),
@@ -138,7 +143,7 @@ def _parse_blocks(lines: Iterable[str], *, start_index: int = 0):
138143
)
139144

140145
cycle_node: CycleNode | None = None
141-
if cycle_g_lit is not None:
146+
if not g65_call and cycle_g_lit is not None:
142147
cycle_node = CycleNode(cycle=f"G{cycle_g_lit}", params=words)
143148

144149
# N/O labels are taken only from genuine address tokens. The bracket-aware

‎app/gcode/kernel/milling/diagnostics.py‎

Lines changed: 2 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,13 @@
22

33
from __future__ import annotations
44

5-
import re
6-
7-
from ..api.resources import SemanticError
85
from ..api.types import Diagnostic, ExecutionEvent
9-
from ..frontend.lang import UndefinedMacroVariableError
6+
from ..runtime.diagnostics import diagnostic_from_exception
107
from ..runtime.events import TOOL_CHANGE
118

12-
_LINE_RE = re.compile(r"\bline\s+(\d+)\b", re.IGNORECASE)
13-
14-
15-
def _exception_chain_contains(exc: Exception, exc_type: type[BaseException]) -> bool:
16-
current: BaseException | None = exc
17-
seen: set[int] = set()
18-
while current is not None and id(current) not in seen:
19-
seen.add(id(current))
20-
if isinstance(current, exc_type):
21-
return True
22-
current = current.__cause__ or current.__context__
23-
return False
24-
259

2610
def _execution_diagnostic(exc: Exception, program) -> Diagnostic:
27-
message = str(exc)
28-
code = "UNDEFINED_MACRO" if _exception_chain_contains(exc, UndefinedMacroVariableError) else "EXECUTION_ERROR"
29-
status = "malformed"
30-
current: BaseException | None = exc
31-
seen: set[int] = set()
32-
while current is not None and id(current) not in seen:
33-
seen.add(id(current))
34-
if isinstance(current, SemanticError):
35-
code = current.code
36-
status = current.status
37-
break
38-
current = current.__cause__ or current.__context__
39-
40-
lowered = message.lower()
41-
if code == "EXECUTION_ERROR":
42-
if "missing goto target" in lowered or "missing if/goto target" in lowered:
43-
code = "FLOW_TARGET_MISSING"
44-
elif "m98 targets missing" in lowered:
45-
code = "SUBPROGRAM_MISSING"
46-
elif "call depth exceeds" in lowered:
47-
code = "CALL_DEPTH_EXCEEDED"
48-
49-
line = None
50-
match = _LINE_RE.search(message)
51-
if match is not None:
52-
line = int(match.group(1))
53-
raw = None
54-
if line is not None and 1 <= line <= len(program.blocks):
55-
raw = program.blocks[line - 1].raw
56-
return Diagnostic(code=code, message=message, status=status, line=line, raw=raw)
11+
return diagnostic_from_exception(exc, program)
5712

5813

5914
def _apply_milling_tool_change(block, state, words, codes, diagnostics, occurrence_events, call_stack):

‎app/gcode/kernel/milling/executor.py‎

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@
1616
_execute_simple_blocks = None
1717

1818

19+
def _report_unknown_g_codes(diagnostics, unknown_g, position_words, block) -> None:
20+
for g in unknown_g:
21+
diagnostics.append(
22+
Diagnostic(
23+
"UNSUPPORTED_G_CODE",
24+
(
25+
f"G{g} is not modeled for fanuc_mill; execution stops before this position block"
26+
if position_words
27+
else f"G{g} is not modeled for fanuc_mill; ignored for trace execution"
28+
),
29+
"error" if position_words else "warning",
30+
"unsupported" if position_words else "unverified",
31+
block.index + 1,
32+
block.raw,
33+
)
34+
)
35+
36+
1937
def execute_milling(
2038
source: str,
2139
*,
@@ -70,6 +88,7 @@ def execute_milling(
7088
57,
7189
58,
7290
59,
91+
65,
7392
68,
7493
69,
7594
73,
@@ -144,27 +163,27 @@ def record_step(
144163
) from error
145164
codes = evaluated_block.codes
146165
gcodes = codes.all_g
166+
evaluated = evaluated_block.values
167+
168+
g65_flow = runtime.dispatch_g65(
169+
block=block,
170+
words=words,
171+
codes=codes,
172+
pc=runtime.pc,
173+
program=program,
174+
)
175+
if g65_flow.dispatch.handled:
176+
occurrence_events.extend(g65_flow.events)
177+
record_step(block, occurrence_events, words=evaluated)
178+
runtime.jump(g65_flow.dispatch.next_pc)
179+
continue
180+
147181
occurrence_signals = evaluated_block.signals
148182
signals.extend(occurrence_signals)
149-
evaluated = evaluated_block.values
150183

151184
unknown_g = tuple(g for g in gcodes if g not in recognized)
152185
position_words = any(letter in words for letter in ("X", "Y", "Z"))
153-
for g in unknown_g:
154-
diagnostics.append(
155-
Diagnostic(
156-
"UNSUPPORTED_G_CODE",
157-
(
158-
f"G{g} is not modeled for fanuc_mill; execution stops before this position block"
159-
if position_words
160-
else f"G{g} is not modeled for fanuc_mill; ignored for trace execution"
161-
),
162-
"error" if position_words else "warning",
163-
"unsupported" if position_words else "unverified",
164-
block.index + 1,
165-
block.raw,
166-
)
167-
)
186+
_report_unknown_g_codes(diagnostics, unknown_g, position_words, block)
168187
for m in codes.all_m:
169188
if 0 <= m <= 199 and m not in recognized_m:
170189
diagnostics.append(

0 commit comments

Comments
 (0)