From 58d64bae7762e225a9755a79c80068f56a81b5f5 Mon Sep 17 00:00:00 2001 From: Vojtech Bubnik Date: Mon, 31 Jan 2022 10:18:34 +0100 Subject: [PATCH] Fix of #6336 #5073: Throw an error if G92 E0 is missing in layer change G-code with relative extruder addressing. Also thrown an error, if G92 E0 is used with absolute extruder addressing. --- src/libslic3r/Print.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index e8078931b..ebd2e8f66 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -22,6 +22,7 @@ #include #include #include +#include // Mark string for localization and translate. #define L(s) Slic3r::I18N::translate(s) @@ -438,7 +439,8 @@ static inline bool sequential_print_vertical_clearance_valid(const Print &print) return it == print_instances_ordered.end() || (*it)->print_object->height() <= scale_(print.config().extruder_clearance_height.value); } - +// Matches "G92 E0" with various forms of writing the zero and with an optional comment. +boost::regex regex_g92e0 { "^[ \\t]*[gG]92[ \\t]*[eE](0(\\.0*)?|\\.0+)[ \\t]*(;.*)?$" }; // Precondition: Print::validate() requires the Print::apply() to be called its invocation. std::string Print::validate(std::string* warning) const @@ -652,6 +654,18 @@ std::string Print::validate(std::string* warning) const return err_msg; } } + { + bool before_layer_gcode_resets_extruder = boost::regex_search(m_config.before_layer_gcode.value, regex_g92e0); + bool layer_gcode_resets_extruder = boost::regex_search(m_config.layer_gcode.value, regex_g92e0); + if (m_config.use_relative_e_distances) { + // See GH issues #6336 #5073 + if (! before_layer_gcode_resets_extruder && ! layer_gcode_resets_extruder) + return "Relative extruder addressing requires resetting the extruder position at each layer to prevent loss of floating point accuracy. Add \"G92 E0\" to layer_gcode."; + } else if (before_layer_gcode_resets_extruder) + return "\"G92 E0\" was found in before_layer_gcode, which is incompatible with absolute extruder addressing."; + else if (layer_gcode_resets_extruder) + return "\"G92 E0\" was found in layer_gcode, which is incompatible with absolute extruder addressing."; + } return std::string(); }