Preserve LinuxCNC comment event line numbers

This commit is contained in:
CNC Local
2026-05-22 05:11:11 +08:00
parent 14dd0facbf
commit d69b536d1d
6 changed files with 35 additions and 0 deletions

View File

@@ -414,6 +414,7 @@ void COMMENT(const char *) {
CncSimEvent event{};
event.version = 1;
event.type = CNC_SIM_EVENT_COMMENT;
event.line = event_line();
active_sink->emit_raw(event);
}
}

View File

@@ -76,6 +76,7 @@ int main() {
bool saw_spindle_cw = false;
bool saw_spindle_ccw = false;
bool saw_spindle_stop = false;
bool saw_comment_line = false;
for (const auto &event : events) {
saw_tool = saw_tool || event.type == CNC_SIM_EVENT_TOOL_CHANGE;
saw_rapid = saw_rapid || event.type == CNC_SIM_EVENT_RAPID;
@@ -154,6 +155,21 @@ int main() {
ok &= expect(saw_spindle_ccw, "expected LinuxCNC M4 counterclockwise spindle state");
ok &= expect(saw_spindle_stop, "expected LinuxCNC M5 stopped spindle state");
const char comment_program[] =
"G21 G90 G17\n"
"(operator note)\n"
"G0 X0 Y0 Z1\n"
"M30\n";
events.clear();
ok &= expect(cnc_sim_parse_program(sim, comment_program, sizeof(comment_program) - 1) == 0,
cnc_sim_last_error(sim));
for (const auto &event : events) {
saw_comment_line = saw_comment_line ||
(event.type == CNC_SIM_EVENT_COMMENT &&
event.line == 2);
}
ok &= expect(saw_comment_line, "expected LinuxCNC comment event line number");
const char probe_program[] =
"G21 G90 G17\n"
"G0 X0 Y0 Z5\n"

View File

@@ -47,6 +47,8 @@ int main() {
SET_G5X_OFFSET(1, 10.0, 20.0, 30.0, 1.0, 2.0, 3.0, 0.0, 0.0, 0.0);
SET_G92_OFFSET(1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
SET_XY_ROTATION(15.0);
cnc_sim_linuxcnc_set_current_line(20);
COMMENT("bridge comment");
PROGRAM_END();
bool ok = true;
@@ -65,6 +67,7 @@ int main() {
bool saw_g5x = false;
bool saw_g92 = false;
bool saw_rotation = false;
bool saw_comment = false;
bool saw_end = false;
for (const auto &event : events) {
saw_tool = saw_tool || (event.type == CNC_SIM_EVENT_TOOL_CHANGE && event.tool == 7);
@@ -102,6 +105,8 @@ int main() {
event.start.z == 3.0);
saw_rotation = saw_rotation || (event.type == CNC_SIM_EVENT_SET_XY_ROTATION &&
event.feed == 15.0);
saw_comment = saw_comment || (event.type == CNC_SIM_EVENT_COMMENT &&
event.line == 20);
saw_end = saw_end || event.type == CNC_SIM_EVENT_PROGRAM_END;
}
@@ -116,6 +121,7 @@ int main() {
ok &= expect(saw_g5x, "expected G5X offset event");
ok &= expect(saw_g92, "expected G92 offset event");
ok &= expect(saw_rotation, "expected XY rotation event");
ok &= expect(saw_comment, "expected comment event line");
ok &= expect(saw_end, "expected program end");
cnc_sim_linuxcnc_set_canon_sink(nullptr);