diff --git a/src/libslic3r/GCode/GCodeEditor.cpp b/src/libslic3r/GCode/GCodeEditor.cpp index ef86504a5..41396da5a 100644 --- a/src/libslic3r/GCode/GCodeEditor.cpp +++ b/src/libslic3r/GCode/GCodeEditor.cpp @@ -321,6 +321,10 @@ std::vector GCodeEditor::parse_layer_gcode( line.type = CoolingLine::TYPE_FORCE_RESUME_FAN; } else if (boost::starts_with(sline, ";_SET_FAN_SPEED_CHANGING_LAYER")) { line.type = CoolingLine::TYPE_SET_FAN_CHANGING_LAYER; + } else if (boost::starts_with(sline, "M624")) { + line.type = CoolingLine::TYPE_OBJECT_START; + } else if (boost::starts_with(sline, "M625")) { + line.type = CoolingLine::TYPE_OBJECT_END; } if (line.type != 0) adjustment->lines.emplace_back(std::move(line)); @@ -440,7 +444,34 @@ std::string GCodeEditor::write_layer_gcode( m_set_fan_changing_layer = false; m_set_addition_fan_changing_layer = false; change_extruder_set_fan(SetFanType::sfChangingLayer); - for (const CoolingLine *line : lines) { + + //BBS: start the fan earlier for overhangs + const float pre_start_overhang_fan_time = overhang_fan_control? m_config.pre_start_fan_time.get_at(m_current_extruder):0.f; + float cumulative_time = 0.f; + float search_time = 0.f; + + for (int i = 0,j = 0; i < lines.size(); i++) { + const CoolingLine *line = lines[i]; + if (pre_start_overhang_fan_time > 0.f && overhang_fan_speed > m_fan_speed) { + cumulative_time += line->time; + j = jtype & CoolingLine::TYPE_FORCE_RESUME_FAN) { + //stop search when find a force resume fan command + break; + } + search_time += line_iter->time; + if (line_iter->type & CoolingLine::TYPE_OVERHANG_FAN_START) { + m_current_fan_speed = overhang_fan_speed; + new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, overhang_fan_speed); + break; + } + } + } const char *line_start = gcode.c_str() + line->line_start; const char *line_end = gcode.c_str() + line->line_end; if (line_start > pos) @@ -453,7 +484,7 @@ std::string GCodeEditor::write_layer_gcode( } new_gcode.append(line_start, line_end - line_start); } else if (line->type & CoolingLine::TYPE_OVERHANG_FAN_START) { - if (overhang_fan_control) { + if (overhang_fan_control && m_current_fan_speed < overhang_fan_speed) { //BBS m_current_fan_speed = overhang_fan_speed; new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, overhang_fan_speed); @@ -562,7 +593,15 @@ std::string GCodeEditor::write_layer_gcode( new_gcode.append(end, line_end - end); } } - } else { + } else if (line->type & CoolingLine::TYPE_OBJECT_START) { + new_gcode.append(line_start, line_end - line_start); + if (pre_start_overhang_fan_time > 0.f && m_current_fan_speed > m_fan_speed) + new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, m_current_fan_speed); + } else if (line->type & CoolingLine::TYPE_OBJECT_END) { + if (pre_start_overhang_fan_time > 0.f && m_current_fan_speed > m_fan_speed) + new_gcode += GCodeWriter::set_fan(m_config.gcode_flavor, m_fan_speed); + new_gcode.append(line_start, line_end - line_start); + }else { new_gcode.append(line_start, line_end - line_start); } pos = line_end; diff --git a/src/libslic3r/GCode/GCodeEditor.hpp b/src/libslic3r/GCode/GCodeEditor.hpp index 2c241af7c..f20e59db6 100644 --- a/src/libslic3r/GCode/GCodeEditor.hpp +++ b/src/libslic3r/GCode/GCodeEditor.hpp @@ -34,6 +34,8 @@ struct CoolingLine TYPE_G3 = 1 << 13, TYPE_FORCE_RESUME_FAN = 1 << 14, TYPE_SET_FAN_CHANGING_LAYER = 1 << 15, + TYPE_OBJECT_START = 1 << 16, + TYPE_OBJECT_END = 1 << 17, }; CoolingLine(unsigned int type, size_t line_start, size_t line_end) diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 78f27816b..83196384d 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -918,7 +918,7 @@ static std::vector s_Preset_filament_options { // "bed_type", //BBS:temperature_vitrification "temperature_vitrification", "reduce_fan_stop_start_freq", "slow_down_for_layer_cooling", "fan_min_speed", - "fan_max_speed", "enable_overhang_bridge_fan", "overhang_fan_speed", "overhang_fan_threshold", "overhang_threshold_participating_cooling","close_fan_the_first_x_layers", "full_fan_speed_layer", "fan_cooling_layer_time", "slow_down_layer_time", "slow_down_min_speed", + "fan_max_speed", "enable_overhang_bridge_fan", "overhang_fan_speed", "pre_start_fan_time", "overhang_fan_threshold", "overhang_threshold_participating_cooling","close_fan_the_first_x_layers", "full_fan_speed_layer", "fan_cooling_layer_time", "slow_down_layer_time", "slow_down_min_speed", "filament_start_gcode", "filament_end_gcode", //exhaust fan control "activate_air_filtration","during_print_exhaust_fan_speed","complete_print_exhaust_fan_speed", diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 865cc7097..06a164c33 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -101,6 +101,7 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n "pressure_advance", "enable_overhang_bridge_fan" "overhang_fan_speed", + "pre_start_fan_time", "overhang_fan_threshold", "overhang_threshold_participating_cooling", "slow_down_for_layer_cooling", diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 74b246913..f892d5cfb 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -916,6 +916,16 @@ void PrintConfigDef::init_fff_params() def->mode = comAdvanced; def->set_default_value(new ConfigOptionInts { 100 }); + def = this->add("pre_start_fan_time", coFloats); + def->label = L("Pre start fan time"); + def->tooltip = L("Force fan start early(0-5 second) when encountering overhangs. " + "This is because the fan needs time to physically increase its speed."); + def->sidetext = L("s"); + def->min = 0.; + def->max = 5.; + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionFloats{2.0}); + def = this->add("overhang_fan_threshold", coEnums); def->label = L("Cooling overhang threshold"); def->tooltip = L("Force cooling fan to be specific speed when overhang degree of printed part exceeds this value. " diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 6f03ad3c7..929d50a84 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -1130,6 +1130,7 @@ PRINT_CONFIG_CLASS_DERIVED_DEFINE( ((ConfigOptionInts, textured_plate_temp_initial_layer)) ((ConfigOptionBools, enable_overhang_bridge_fan)) ((ConfigOptionInts, overhang_fan_speed)) + ((ConfigOptionFloats, pre_start_fan_time)) ((ConfigOptionEnumsGeneric, overhang_fan_threshold)) ((ConfigOptionEnumsGeneric, overhang_threshold_participating_cooling)) ((ConfigOptionEnum,print_sequence)) diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 8eb0aae2f..71a6164ea 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -3332,6 +3332,7 @@ void TabFilament::build() optgroup->append_single_option_line("overhang_fan_threshold", "auto-cooling"); optgroup->append_single_option_line("overhang_threshold_participating_cooling", "auto-cooling"); optgroup->append_single_option_line("overhang_fan_speed", "auto-cooling"); + optgroup->append_single_option_line("pre_start_fan_time", "auto-cooling"); optgroup = page->new_optgroup(L("Auxiliary part cooling fan"), L"param_cooling_fan"); optgroup->append_single_option_line("additional_cooling_fan_speed"); @@ -3464,7 +3465,7 @@ void TabFilament::toggle_options() toggle_option("slow_down_min_speed", cooling); bool has_enable_overhang_bridge_fan = m_config->opt_bool("enable_overhang_bridge_fan", 0); - for (auto el : { "overhang_fan_speed", "overhang_fan_threshold" }) + for (auto el : {"overhang_fan_speed", "pre_start_fan_time", "overhang_fan_threshold"}) toggle_option(el, has_enable_overhang_bridge_fan); bool support_air_filtration = m_preset_bundle->printers.get_edited_preset().config.opt_bool("support_air_filtration");