Read the positioning mode of generated G-code from the reader

emitted_xy_after_gcode() kept a G90/G91 flag of its own, which the G-code reader now tracks.
This commit is contained in:
Ian Bassi committed 2026-11-30 14:27:08 -03:00
1 parent 5f6f61c179
commit f74888580f
1 file changed
+3 -13
+3 -13
View File
@@ -167,26 +167,16 @@ namespace {
std::optional<Vec2d> emitted_xy_after_gcode(const std::string &gcode, const Vec2d &initial_xy)
{
Vec2d position = initial_xy;
bool absolute = true;
bool coordinate_frame_known = true;
GCodeReader reader;
reader.parse_buffer(gcode, [&position, &absolute, &coordinate_frame_known](GCodeReader &, const GCodeReader::GCodeLine &line) {
if (line.cmd_is("G90")) {
absolute = true;
return;
}
if (line.cmd_is("G91")) {
absolute = false;
return;
}
reader.parse_buffer(gcode, [&position, &coordinate_frame_known](GCodeReader &self, const GCodeReader::GCodeLine &line) {
const bool is_motion = line.cmd_is("G0") || line.cmd_is("G1") || line.cmd_is("G2") || line.cmd_is("G3");
if (is_motion) {
if (line.has_x())
position.x() = absolute ? line.x() : position.x() + line.x();
position.x() = self.relative_xyz() ? position.x() + line.x() : line.x();
if (line.has_y())
position.y() = absolute ? line.y() : position.y() + line.y();
position.y() = self.relative_xyz() ? position.y() + line.y() : line.y();
return;
}