diff --git a/src/libslic3r/GCode/Analyzer.cpp b/src/libslic3r/GCode/Analyzer.cpp index 3805b33f0..8a18cc8f2 100644 --- a/src/libslic3r/GCode/Analyzer.cpp +++ b/src/libslic3r/GCode/Analyzer.cpp @@ -444,8 +444,10 @@ void GCodeAnalyzer::_processG92(const GCodeReader::GCodeLine& line) anyFound = true; } - if (!anyFound) + if (!anyFound && ! line.has_unknown_axis()) { + // The G92 may be called for axes that PrusaSlicer does not recognize, for example see GH issue #3510, + // where G92 A0 B0 is called although the extruder axis is till E. for (unsigned char a = X; a < Num_Axis; ++a) { _set_axis_origin((EAxis)a, _get_axis_position((EAxis)a)); diff --git a/src/libslic3r/GCodeReader.cpp b/src/libslic3r/GCodeReader.cpp index cd1ff867b..e68bc5ad2 100644 --- a/src/libslic3r/GCodeReader.cpp +++ b/src/libslic3r/GCodeReader.cpp @@ -40,7 +40,7 @@ const char* GCodeReader::parse_line_internal(const char *ptr, GCodeLine &gline, if (is_end_of_gcode_line(*c)) break; // Check the name of the axis. - Axis axis = NUM_AXES; + Axis axis = NUM_AXES_WITH_UNKNOWN; switch (*c) { case 'X': axis = X; break; case 'Y': axis = Y; break; @@ -49,15 +49,19 @@ const char* GCodeReader::parse_line_internal(const char *ptr, GCodeLine &gline, default: if (*c == m_extrusion_axis) axis = E; + else if (*c >= 'A' && *c <= 'Z') + // Unknown axis, but we still want to remember that such a axis was seen. + axis = UNKNOWN_AXIS; break; } - if (axis != NUM_AXES) { + if (axis != NUM_AXES_WITH_UNKNOWN) { // Try to parse the numeric value. char *pend = nullptr; double v = strtod(++ c, &pend); if (pend != nullptr && is_end_of_word(*pend)) { // The axis value has been parsed correctly. - gline.m_axis[int(axis)] = float(v); + if (axis != UNKNOWN_AXIS) + gline.m_axis[int(axis)] = float(v); gline.m_mask |= 1 << int(axis); c = pend; } else diff --git a/src/libslic3r/GCodeReader.hpp b/src/libslic3r/GCodeReader.hpp index fea581e20..9503ddcc1 100644 --- a/src/libslic3r/GCodeReader.hpp +++ b/src/libslic3r/GCodeReader.hpp @@ -58,6 +58,7 @@ public: bool has_z() const { return this->has(Z); } bool has_e() const { return this->has(E); } bool has_f() const { return this->has(F); } + bool has_unknown_axis() const { return this->has(UNKNOWN_AXIS); } float x() const { return m_axis[X]; } float y() const { return m_axis[Y]; } float z() const { return m_axis[Z]; } diff --git a/src/libslic3r/libslic3r.h b/src/libslic3r/libslic3r.h index d3e4992ce..41d9ac1ff 100644 --- a/src/libslic3r/libslic3r.h +++ b/src/libslic3r/libslic3r.h @@ -98,7 +98,17 @@ extern Semver SEMVER; template inline T unscale(Q v) { return T(v) * T(SCALING_FACTOR); } -enum Axis { X=0, Y, Z, E, F, NUM_AXES }; +enum Axis { + X=0, + Y, + Z, + E, + F, + NUM_AXES, + // For the GCodeReader to mark a parsed axis, which is not in "XYZEF", it was parsed correctly. + UNKNOWN_AXIS = NUM_AXES, + NUM_AXES_WITH_UNKNOWN, +}; template inline void append_to(std::vector &dst, const std::vector &src)