From 6a26284ba6508774a173dfdb1f8b305017a34fa0 Mon Sep 17 00:00:00 2001 From: Kiss Lorand <50251547+kisslorand@users.noreply.github.com> Date: Sun, 31 May 2026 07:11:40 +0300 Subject: [PATCH] Fix air filtration gcode emitted even if not not supported by the printer (#13868) * Fix air filtration gcode emitted even if not not supported - do not emit air filtration gcode if not supported by the printer - removed redundant "add_eol" parameter from "set_exhaust_fan()" function --- src/libslic3r/GCode.cpp | 49 ++++++++++++++++++++++------------- src/libslic3r/GCodeWriter.cpp | 12 ++++++--- src/libslic3r/GCodeWriter.hpp | 2 +- 3 files changed, 41 insertions(+), 22 deletions(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 867f324301..179bd564c1 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -3172,18 +3172,24 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato if (is_bbl_printers) { this->_print_first_layer_extruder_temperatures(file, print, machine_start_gcode, initial_extruder_id, true); } - // Orca: when activate_air_filtration is set on any extruder, find and set the highest during_print_exhaust_fan_speed - bool activate_air_filtration_during_print = false; - int during_print_exhaust_fan_speed = 0; - for (const auto &extruder : m_writer.extruders()) { - if (m_config.activate_air_filtration.get_at(extruder.id()) && m_config.activate_air_filtration_during_print.get_at(extruder.id())) { - activate_air_filtration_during_print = true; - during_print_exhaust_fan_speed = std::max(during_print_exhaust_fan_speed, - m_config.during_print_exhaust_fan_speed.get_at(extruder.id())); + + // Orca: when air filtration is supported, check if it needs to be activated during printing and set the exhaust fan speed accordingly + if (m_config.support_air_filtration.value) { + bool activate_air_filtration_during_print = false; + int during_print_exhaust_fan_speed = 0; + + // Orca: when activate_air_filtration is set on any extruder, find and set the highest during_print_exhaust_fan_speed + for (const auto &extruder : m_writer.extruders()) { + if (m_config.activate_air_filtration.get_at(extruder.id()) && m_config.activate_air_filtration_during_print.get_at(extruder.id())) { + activate_air_filtration_during_print = true; + during_print_exhaust_fan_speed = std::max(during_print_exhaust_fan_speed, + m_config.during_print_exhaust_fan_speed.get_at(extruder.id())); + } } + + if (activate_air_filtration_during_print) + file.write(m_writer.set_exhaust_fan(during_print_exhaust_fan_speed)); } - if (activate_air_filtration_during_print) - file.write(m_writer.set_exhaust_fan(during_print_exhaust_fan_speed, true)); print.throw_if_canceled(); @@ -3482,16 +3488,23 @@ void GCode::_do_export(Print& print, GCodeOutputStream &file, ThumbnailsGenerato if (activate_chamber_temp_control && max_chamber_temp > 0) file.write(m_writer.set_chamber_temperature(0, false)); //close chamber_temperature - bool activate_air_filtration_on_completion = false; - int complete_print_exhaust_fan_speed = 0; - for (const auto& extruder : m_writer.extruders()) { - if (m_config.activate_air_filtration.get_at(extruder.id()) && m_config.activate_air_filtration_on_completion.get_at(extruder.id())) { - activate_air_filtration_on_completion = true; - complete_print_exhaust_fan_speed = std::max(complete_print_exhaust_fan_speed, m_config.complete_print_exhaust_fan_speed.get_at(extruder.id())); + // Orca: when air filtration is supported, check if it needs to be activated after print completion and set the exhaust fan speed accordingly + if (m_config.support_air_filtration.value) { + bool activate_air_filtration_on_completion = false; + int complete_print_exhaust_fan_speed = 0; + + // Orca: when activate_air_filtration is set on any extruder, find and set the highest complete_print_exhaust_fan_speed + for (const auto& extruder : m_writer.extruders()) { + if (m_config.activate_air_filtration.get_at(extruder.id()) && m_config.activate_air_filtration_on_completion.get_at(extruder.id())) { + activate_air_filtration_on_completion = true; + complete_print_exhaust_fan_speed = std::max(complete_print_exhaust_fan_speed, m_config.complete_print_exhaust_fan_speed.get_at(extruder.id())); + } } + + if (activate_air_filtration_on_completion) + file.write(m_writer.set_exhaust_fan(complete_print_exhaust_fan_speed)); } - if (activate_air_filtration_on_completion) - file.write(m_writer.set_exhaust_fan(complete_print_exhaust_fan_speed, true)); + // adds tags for time estimators file.write_format(";%s\n", GCodeProcessor::reserved_tag(GCodeProcessor::ETags::Last_Line_M73_Placeholder).c_str()); file.write_format("; EXECUTABLE_BLOCK_END\n\n"); diff --git a/src/libslic3r/GCodeWriter.cpp b/src/libslic3r/GCodeWriter.cpp index 417a35b2ee..0e5a110c44 100644 --- a/src/libslic3r/GCodeWriter.cpp +++ b/src/libslic3r/GCodeWriter.cpp @@ -1154,13 +1154,19 @@ std::string GCodeWriter::set_additional_fan(unsigned int speed) return gcode.str(); } -std::string GCodeWriter::set_exhaust_fan( int speed,bool add_eol) +std::string GCodeWriter::set_exhaust_fan(int speed) { std::ostringstream gcode; gcode << "M106" << " P3" << " S" << (int)(speed / 100.0 * 255); - if(add_eol) - gcode << "\n"; + if (GCodeWriter::full_gcode_comment) { + if (speed == 0) + gcode << " ; disable exhaust fan "; + else + gcode << " ; enable exhaust fan "; + } + + gcode << "\n"; return gcode.str(); } diff --git a/src/libslic3r/GCodeWriter.hpp b/src/libslic3r/GCodeWriter.hpp index 3fd7a7668b..10e52a1c8e 100644 --- a/src/libslic3r/GCodeWriter.hpp +++ b/src/libslic3r/GCodeWriter.hpp @@ -106,7 +106,7 @@ public: std::string set_fan(unsigned int speed) const; //BBS: set additional fan speed for BBS machine only static std::string set_additional_fan(unsigned int speed); - static std::string set_exhaust_fan(int speed,bool add_eol); + static std::string set_exhaust_fan(int speed); //BBS void set_object_start_str(std::string start_string) { m_gcode_label_objects_start = start_string; } bool is_object_start_str_empty() { return m_gcode_label_objects_start.empty(); }