diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index bad97a8934..caab3a4ffd 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -4159,23 +4159,25 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description, // perimeter int overhang_threshold = overhang_fan_threshold == Overhang_threshold_none ? Overhang_threshold_none : overhang_fan_threshold - 1; - if ((overhang_fan_threshold == Overhang_threshold_none && is_perimeter(path.role()) && !m_is_overhang_fan_on) || + if ((overhang_fan_threshold == Overhang_threshold_none && is_perimeter(path.role())) || (path.get_overhang_degree() > overhang_threshold || is_bridge(path.role()))) { - gcode += ";_OVERHANG_FAN_START\n"; - m_is_overhang_fan_on = true; - } - else { + if (!m_is_overhang_fan_on) { + gcode += ";_OVERHANG_FAN_START\n"; + m_is_overhang_fan_on = true; + } + } else { if (m_is_overhang_fan_on) { m_is_overhang_fan_on = false; gcode += ";_OVERHANG_FAN_END\n"; } } } - if(supp_interface_fan_speed >= 0 && path.role() == erSupportMaterialInterface && !m_is_supp_interface_fan_on) { - gcode += ";_SUPP_INTERFACE_FAN_START\n"; - m_is_supp_interface_fan_on = true; - } - else { + if (supp_interface_fan_speed >= 0 && path.role() == erSupportMaterialInterface) { + if (!m_is_supp_interface_fan_on) { + gcode += ";_SUPP_INTERFACE_FAN_START\n"; + m_is_supp_interface_fan_on = true; + } + } else { if (m_is_supp_interface_fan_on) { gcode += ";_SUPP_INTERFACE_FAN_END\n"; m_is_supp_interface_fan_on = false; diff --git a/src/libslic3r/GCode/CoolingBuffer.cpp b/src/libslic3r/GCode/CoolingBuffer.cpp index e3fc92ff58..44fc25bf4e 100644 --- a/src/libslic3r/GCode/CoolingBuffer.cpp +++ b/src/libslic3r/GCode/CoolingBuffer.cpp @@ -785,6 +785,7 @@ std::string CoolingBuffer::apply_layer_cooldown( } if (fan_speed_new != m_fan_speed) { m_fan_speed = fan_speed_new; + m_current_fan_speed = fan_speed_new; if (immediately_apply) new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, m_fan_speed); } @@ -803,7 +804,8 @@ std::string CoolingBuffer::apply_layer_cooldown( // Reduce set fan commands by deferring the GCodeWriter::set_fan calls. Inspired by SuperSlicer // define fan_speed_change_requests and initialize it with all possible types fan speed change requests std::unordered_map fan_speed_change_requests = {{CoolingLine::TYPE_OVERHANG_FAN_START, false}, - {CoolingLine::TYPE_SUPPORT_INTERFACE_FAN_START, false}}; + {CoolingLine::TYPE_SUPPORT_INTERFACE_FAN_START, false}, + {CoolingLine::TYPE_FORCE_RESUME_FAN, false}}; bool need_set_fan = false; for (const CoolingLine *line : lines) { @@ -826,8 +828,8 @@ std::string CoolingBuffer::apply_layer_cooldown( } else if (line->type & CoolingLine::TYPE_OVERHANG_FAN_END) { if (overhang_fan_control && fan_speed_change_requests[CoolingLine::TYPE_OVERHANG_FAN_START]) { fan_speed_change_requests[CoolingLine::TYPE_OVERHANG_FAN_START] = false; - need_set_fan = true; } + need_set_fan = true; } else if (line->type & CoolingLine::TYPE_SUPPORT_INTERFACE_FAN_START) { if (supp_interface_fan_control && !fan_speed_change_requests[CoolingLine::TYPE_SUPPORT_INTERFACE_FAN_START]) { fan_speed_change_requests[CoolingLine::TYPE_SUPPORT_INTERFACE_FAN_START] = true; @@ -836,11 +838,12 @@ std::string CoolingBuffer::apply_layer_cooldown( } else if (line->type & CoolingLine::TYPE_SUPPORT_INTERFACE_FAN_END && fan_speed_change_requests[CoolingLine::TYPE_SUPPORT_INTERFACE_FAN_START]) { if (supp_interface_fan_control) { fan_speed_change_requests[CoolingLine::TYPE_SUPPORT_INTERFACE_FAN_START] = false; - need_set_fan = true; } + need_set_fan = true; } else if (line->type & CoolingLine::TYPE_FORCE_RESUME_FAN) { // check if any fan speed change request is active if (m_fan_speed != -1 && !std::any_of(fan_speed_change_requests.begin(), fan_speed_change_requests.end(), [](const std::pair& p) { return p.second; })){ + fan_speed_change_requests[CoolingLine::TYPE_FORCE_RESUME_FAN] = true; need_set_fan = true; } if (m_additional_fan_speed != -1 && m_config.auxiliary_fan.value) @@ -932,10 +935,18 @@ std::string CoolingBuffer::apply_layer_cooldown( } if (need_set_fan) { - if (fan_speed_change_requests[CoolingLine::TYPE_OVERHANG_FAN_START]) + if (fan_speed_change_requests[CoolingLine::TYPE_OVERHANG_FAN_START]){ new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, overhang_fan_speed); - else if (fan_speed_change_requests[CoolingLine::TYPE_SUPPORT_INTERFACE_FAN_START]) + m_current_fan_speed = overhang_fan_speed; + } + else if (fan_speed_change_requests[CoolingLine::TYPE_SUPPORT_INTERFACE_FAN_START]){ new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, supp_interface_fan_speed); + m_current_fan_speed = supp_interface_fan_speed; + } + else if(fan_speed_change_requests[CoolingLine::TYPE_FORCE_RESUME_FAN] && m_current_fan_speed != -1){ + new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, m_current_fan_speed); + fan_speed_change_requests[CoolingLine::TYPE_FORCE_RESUME_FAN] = false; + } else new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, m_fan_speed); need_set_fan = false;