mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-06-17 09:23:05 +00:00
Enhance G92 E0 case sensitivity check (#13933)
This commit is contained in:
@@ -1254,10 +1254,6 @@ StringObjectException Print::check_multi_filament_valid(const Print& print)
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Orca: this g92e0 regex is used copied from PrusaSlicer
|
||||
// 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.
|
||||
//BBS: refine seq-print validation logic.....FIXME:StringObjectException *warning can only contain one warning, but there might be many warnings, need a vector<StringObjectException>
|
||||
StringObjectException Print::validate(StringObjectException *warning, Polygons* collison_polygons, std::vector<std::pair<Polygon, float>>* height_polygons) const
|
||||
@@ -1675,26 +1671,60 @@ StringObjectException Print::validate(StringObjectException *warning, Polygons*
|
||||
}
|
||||
|
||||
// Orca: G92 E0 is not supported when using absolute extruder addressing
|
||||
// This check is copied from PrusaSlicer, the original author is Vojtech Bubnik
|
||||
if(!is_BBL_printer()) {
|
||||
bool before_layer_gcode_resets_extruder =
|
||||
boost::regex_search(m_config.before_layer_change_gcode.value, regex_g92e0);
|
||||
bool layer_gcode_resets_extruder = boost::regex_search(m_config.layer_change_gcode.value, regex_g92e0);
|
||||
if (m_config.use_relative_e_distances) {
|
||||
// See GH issues #6336 #5073
|
||||
if ((m_config.gcode_flavor == gcfMarlinLegacy || m_config.gcode_flavor == gcfMarlinFirmware) &&
|
||||
!before_layer_gcode_resets_extruder && !layer_gcode_resets_extruder)
|
||||
return {L("Relative extruder addressing requires resetting the extruder position at each layer to "
|
||||
"prevent loss of floating point accuracy. Add \"G92 E0\" to layer_gcode."),
|
||||
nullptr, "before_layer_change_gcode"};
|
||||
} else if (before_layer_gcode_resets_extruder)
|
||||
return {L("\"G92 E0\" was found in before_layer_gcode, which is incompatible with absolute extruder "
|
||||
// This check is modified from PrusaSlicer, the original author is Vojtech Bubnik
|
||||
// Orca: case‑sensitive match for exactly "G92 E0" (uppercase G and E only)
|
||||
// because gcode is case sensitive and G92 e0 satisfies the regex but causes a slicing error
|
||||
// https://github.com/OrcaSlicer/OrcaSlicer/issues/13927
|
||||
|
||||
// Matches any case of "G92 E0" (original pattern)
|
||||
static const boost::regex regex_g92e0 {
|
||||
"^[ \\t]*[gG]92[ \\t]*[eE](0(\\.0*)?|\\.0+)[ \\t]*(;.*)?$"
|
||||
};
|
||||
// Matches only the exact uppercase "G92 E0"
|
||||
static const boost::regex regex_g92e0_correct {
|
||||
"^[ \\t]*G92[ \\t]*E(0(\\.0*)?|\\.0+)[ \\t]*(;.*)?$"
|
||||
};
|
||||
|
||||
const bool before_has_g92_any = boost::regex_search(
|
||||
m_config.before_layer_change_gcode.value, regex_g92e0);
|
||||
const bool layer_has_g92_any = boost::regex_search(
|
||||
m_config.layer_change_gcode.value, regex_g92e0);
|
||||
|
||||
if (m_config.use_relative_e_distances) {
|
||||
// Relative mode: "G92 E0" is required to reset extruder position.
|
||||
const bool before_has_g92_exact = boost::regex_search(
|
||||
m_config.before_layer_change_gcode.value, regex_g92e0_correct);
|
||||
const bool layer_has_g92_exact = boost::regex_search(
|
||||
m_config.layer_change_gcode.value, regex_g92e0_correct);
|
||||
|
||||
// Wrong case found?
|
||||
if (before_has_g92_any && !before_has_g92_exact)
|
||||
return {L("\"G92 E0\" was found in before_layer_change_gcode, but the G or E are not uppercase. "
|
||||
"Please change them to the exact uppercase \"G92 E0\"."),
|
||||
nullptr, "before_layer_change_gcode"};
|
||||
if (layer_has_g92_any && !layer_has_g92_exact)
|
||||
return {L("\"G92 E0\" was found in layer_change_gcode, but the G or E are not uppercase. "
|
||||
"Please change them to the exact uppercase \"G92 E0\"."),
|
||||
nullptr, "layer_change_gcode"};
|
||||
|
||||
// Only Marlin flavours need the reset; BBL printers do not.
|
||||
if ((m_config.gcode_flavor == gcfMarlinLegacy || m_config.gcode_flavor == gcfMarlinFirmware) &&
|
||||
!is_BBL_printer() &&
|
||||
!before_has_g92_exact && !layer_has_g92_exact)
|
||||
return {L("Relative extruder addressing requires resetting the extruder position at each layer to "
|
||||
"prevent loss of floating point accuracy. Add \"G92 E0\" to layer_gcode."),
|
||||
nullptr, "before_layer_change_gcode"};
|
||||
} else {
|
||||
// Absolute mode: any occurrence of "G92 E0" is incompatible.
|
||||
if (before_has_g92_any)
|
||||
return {L("\"G92 E0\" was found in before_layer_change_gcode, which is incompatible with absolute extruder "
|
||||
"addressing."),
|
||||
nullptr, "before_layer_change_gcode"};
|
||||
else if (layer_gcode_resets_extruder)
|
||||
return {L("\"G92 E0\" was found in layer_gcode, which is incompatible with absolute extruder addressing."),
|
||||
if (layer_has_g92_any)
|
||||
return {L("\"G92 E0\" was found in layer_change_gcode, which is incompatible with absolute extruder "
|
||||
"addressing."),
|
||||
nullptr, "layer_change_gcode"};
|
||||
}
|
||||
}
|
||||
|
||||
const ConfigOptionDef* bed_type_def = print_config_def.get("curr_bed_type");
|
||||
assert(bed_type_def != nullptr);
|
||||
|
||||
Reference in New Issue
Block a user