diff --git a/src/libslic3r/Extruder.cpp b/src/libslic3r/Extruder.cpp index f6632c57ef..5f193c6fd3 100644 --- a/src/libslic3r/Extruder.cpp +++ b/src/libslic3r/Extruder.cpp @@ -168,7 +168,13 @@ double Extruder::filament_flow_ratio() const // Return a "retract_before_wipe" percentage as a factor clamped to <0, 1> double Extruder::retract_before_wipe() const { - return std::min(1., std::max(0., m_config->retract_before_wipe.get_at(m_id) * 0.01)); + return std::clamp(m_config->retract_before_wipe.get_at(m_id) * 0.01, 0., 1.); +} + +// Return a "retract_after_wipe" percentage as a factor clamped to <0, 1> +double Extruder::retract_after_wipe() const +{ + return std::min(std::clamp(m_config->retract_after_wipe.get_at(m_id) * 0.01, 0., 1.), 1. - retract_before_wipe()); } double Extruder::retraction_length() const diff --git a/src/libslic3r/Extruder.hpp b/src/libslic3r/Extruder.hpp index 0d76ede8c9..ac2bf665cc 100644 --- a/src/libslic3r/Extruder.hpp +++ b/src/libslic3r/Extruder.hpp @@ -63,6 +63,7 @@ public: double filament_cost() const; double filament_flow_ratio() const; double retract_before_wipe() const; + double retract_after_wipe() const; double retraction_length() const; double retract_lift() const; int retract_speed() const; diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 707dadd9f9..a76c39464c 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -306,46 +306,61 @@ static std::vector get_path_of_change_filament(const Print& print) // Declare & initialize retraction lengths double retraction_length_remaining = 0, - retractionBeforeWipe = 0, - retractionDuringWipe = 0; + retraction_length_before_wipe = 0, + retraction_length_during_wipe = 0, + retraction_length_after_wipe = 0; - // initialise the remaining retraction amount with the full retraction amount. - retraction_length_remaining = toolchange ? extruder->retract_length_toolchange() : extruder->retraction_length(); + // Initialise the remaining retraction amount with the full retraction amount. + retraction_length_remaining = toolchange ? + extruder->retract_length_toolchange() : extruder->retraction_length(); - // nothing to retract - return early - if(retraction_length_remaining <=EPSILON) return {0.f,0.f}; + // Nothing to retract - return early + if (retraction_length_remaining <= EPSILON) + return { 0.f, 0.f, 0.f }; - // calculate retraction before wipe distance from the user setting. Keep adding to this variable any excess retraction needed - // to be performed before the wipe. - retractionBeforeWipe = retraction_length_remaining * extruder->retract_before_wipe(); - retraction_length_remaining -= retractionBeforeWipe; // subtract it from the remaining retraction length - - // all of the retraction is to be done before the wipe - if(retraction_length_remaining <=EPSILON) return {retractionBeforeWipe,0.f}; + // Calculate retraction before and after wipe distances from the user setting. + // Keep adding to the for retraction before wipe variable any excess retraction + // needed to be performed before the wipe. + retraction_length_before_wipe = retraction_length_remaining * extruder->retract_before_wipe(); + retraction_length_after_wipe = retraction_length_remaining * extruder->retract_after_wipe(); + + // Subtract it from the remaining retraction length + retraction_length_remaining -= retraction_length_before_wipe + retraction_length_after_wipe; + + // All of the retraction is to be done before the wipe + if (retraction_length_remaining <= EPSILON) + return { retraction_length_before_wipe, 0., retraction_length_after_wipe }; // Calculate wipe speed - double wipe_speed = config.role_based_wipe_speed ? writer.get_current_speed() / 60.0 : config.get_abs_value("wipe_speed"); + double wipe_speed = config.role_based_wipe_speed ? + writer.get_current_speed() / 60.0 : config.get_abs_value("wipe_speed"); wipe_speed = std::max(wipe_speed, 10.0); // Process wipe path & calculate wipe path length double wipe_dist = scale_(config.wipe_distance.get_at(extruder_id)); - Polyline wipe_path = {last_pos}; + Polyline wipe_path = { last_pos }; wipe_path.append(this->path.points.begin() + 1, this->path.points.end()); double wipe_path_length = std::min(wipe_path.length(), wipe_dist); // Calculate the maximum retraction amount during wipe - retractionDuringWipe = config.retraction_speed.get_at(extruder_id) * unscale_(wipe_path_length) / wipe_speed; - // If the maximum retraction amount during wipe is too small, return 0 and retract everything prior to the wipe. - if(retractionDuringWipe <= EPSILON) return {retractionBeforeWipe,0.f}; + retraction_length_during_wipe = config.retraction_speed.get_at(extruder_id) * + unscale_(wipe_path_length) / wipe_speed; + + // If the maximum retraction amount during wipe is too small, + // return 0 and retract everything prior to the wipe. + if (retraction_length_during_wipe <= EPSILON) + return { retraction_length_before_wipe, 0., retraction_length_after_wipe }; // If the maximum retraction amount during wipe is greater than any remaining retraction length // return the remaining retraction length to be retracted during the wipe - if (retractionDuringWipe - retraction_length_remaining > EPSILON) return {retractionBeforeWipe,retraction_length_remaining}; + if (retraction_length_during_wipe - retraction_length_remaining > EPSILON) + return { retraction_length_before_wipe, retraction_length_remaining, retraction_length_after_wipe }; // We will always proceed with incrementing the retraction amount before wiping with the difference // and return the maximum allowed wipe amount to be retracted during the wipe move - retractionBeforeWipe += retraction_length_remaining - retractionDuringWipe; - return {retractionBeforeWipe, retractionDuringWipe}; + retraction_length_before_wipe += retraction_length_remaining - retraction_length_during_wipe; + + return { retraction_length_before_wipe, retraction_length_during_wipe, retraction_length_after_wipe }; } std::string transform_gcode(const std::string &gcode, Vec2f pos, const Vec2f &translation, float angle) @@ -7139,8 +7154,9 @@ std::string GCode::retract(bool toolchange, bool is_last_retraction, LiftType li // wipe (if it's enabled for this extruder and we have a stored wipe path and no-zero wipe distance) if (FILAMENT_CONFIG(wipe) && m_wipe.has_path() && scale_(FILAMENT_CONFIG(wipe_distance)) > SCALED_EPSILON) { Wipe::RetractionValues wipeRetractions = m_wipe.calculateWipeRetractionLengths(*this, toolchange); - gcode += toolchange ? m_writer.retract_for_toolchange(true,wipeRetractions.retractLengthBeforeWipe) : m_writer.retract(true, wipeRetractions.retractLengthBeforeWipe); - gcode += m_wipe.wipe(*this,wipeRetractions.retractLengthDuringWipe, toolchange, is_last_retraction); + gcode += toolchange ? m_writer.retract_for_toolchange(true, wipeRetractions.retraction_length_before_wipe) : + m_writer.retract(true, wipeRetractions.retraction_length_before_wipe); + gcode += m_wipe.wipe(*this, wipeRetractions.retraction_length_during_wipe, toolchange, is_last_retraction); } /* The parent class will decide whether we need to perform an actual retraction diff --git a/src/libslic3r/GCode.hpp b/src/libslic3r/GCode.hpp index 2bf29aa002..cfde7b5267 100644 --- a/src/libslic3r/GCode.hpp +++ b/src/libslic3r/GCode.hpp @@ -60,9 +60,11 @@ class Wipe { public: bool enable; Polyline path; + struct RetractionValues{ - double retractLengthBeforeWipe; - double retractLengthDuringWipe; + double retraction_length_before_wipe = 0.; + double retraction_length_during_wipe = 0.; + double retraction_length_after_wipe = 0.; }; Wipe() : enable(false) {} diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 3ca75d28f3..d0ea638c84 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -971,7 +971,7 @@ static std::vector s_Preset_filament_options {/*"filament_colour", "activate_air_filtration","during_print_exhaust_fan_speed","complete_print_exhaust_fan_speed", // Retract overrides "filament_retraction_length", "filament_z_hop", "filament_z_hop_types", "filament_retract_lift_above", "filament_retract_lift_below", "filament_retract_lift_enforce", "filament_retraction_speed", "filament_deretraction_speed", "filament_retract_restart_extra", "filament_retraction_minimum_travel", - "filament_retract_when_changing_layer", "filament_wipe", "filament_retract_before_wipe", + "filament_retract_when_changing_layer", "filament_wipe", "filament_retract_before_wipe", "filament_retract_after_wipe", // Profile compatibility "filament_vendor", "compatible_prints", "compatible_prints_condition", "compatible_printers", "compatible_printers_condition", "inherits", //BBS diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 330b489141..1a34b8ca6e 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -172,6 +172,7 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n "filename_format", "retraction_minimum_travel", "retract_before_wipe", + "retract_after_wipe", "retract_when_changing_layer", "retraction_length", "retract_length_toolchange", diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 2fb29fc2cd..e5a007ed7f 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -78,6 +78,9 @@ const std::vector filament_extruder_override_keys = { "filament_wipe", // percents "filament_retract_before_wipe", + // Orca + "filament_retract_after_wipe", + // BBS "filament_long_retractions_when_cut", "filament_retraction_distances_when_cut" }; @@ -4630,6 +4633,14 @@ void PrintConfigDef::init_fff_params() def->mode = comAdvanced; def->set_default_value(new ConfigOptionPercents { 100 }); + def = this->add("retract_after_wipe", coPercents); + def->label = L("Retract amount after wipe"); + def->tooltip = L("The length of fast retraction after wipe, relative to retraction length. " + "The value will be clamped by 100% minus the retract amount before the wipe value."); + def->sidetext = "%"; + def->mode = comAdvanced; + def->set_default_value(new ConfigOptionPercents { 0 }); + def = this->add("retract_when_changing_layer", coBools); def->label = L("Retract when change layer"); def->tooltip = L("Force a retraction when changes layer."); @@ -6634,7 +6645,7 @@ void PrintConfigDef::init_extruder_option_keys() m_extruder_option_keys = { "extruder_type", "nozzle_diameter", "default_nozzle_volume_type", "min_layer_height", "max_layer_height", "extruder_offset", "retraction_length", "z_hop", "z_hop_types", "travel_slope", "retract_lift_above", "retract_lift_below", "retract_lift_enforce", "retraction_speed", "deretraction_speed", - "retract_before_wipe", "retract_restart_extra", "retraction_minimum_travel", "wipe", "wipe_distance", + "retract_before_wipe", "retract_after_wipe", "retract_restart_extra", "retraction_minimum_travel", "wipe", "wipe_distance", "retract_when_changing_layer", "retract_length_toolchange", "retract_restart_extra_toolchange", "extruder_colour", "default_filament_profile","retraction_distances_when_cut","long_retractions_when_cut" }; @@ -6642,6 +6653,7 @@ void PrintConfigDef::init_extruder_option_keys() m_extruder_retract_keys = { "deretraction_speed", "long_retractions_when_cut", + "retract_after_wipe", "retract_before_wipe", "retract_lift_above", "retract_lift_below", @@ -6666,7 +6678,7 @@ void PrintConfigDef::init_filament_option_keys() m_filament_option_keys = { "filament_diameter", "min_layer_height", "max_layer_height","volumetric_speed_coefficients", "retraction_length", "z_hop", "z_hop_types", "retract_lift_above", "retract_lift_below", "retract_lift_enforce", "retraction_speed", "deretraction_speed", - "retract_before_wipe", "retract_restart_extra", "retraction_minimum_travel", "wipe", "wipe_distance", + "retract_before_wipe", "retract_after_wipe", "retract_restart_extra", "retraction_minimum_travel", "wipe", "wipe_distance", "retract_when_changing_layer", "retract_length_toolchange", "retract_restart_extra_toolchange", "filament_colour", "default_filament_profile","retraction_distances_when_cut","long_retractions_when_cut"/*,"filament_seam_gap"*/ }; @@ -6674,6 +6686,7 @@ void PrintConfigDef::init_filament_option_keys() m_filament_retract_keys = { "deretraction_speed", "long_retractions_when_cut", + "retract_after_wipe", "retract_before_wipe", "retract_lift_above", "retract_lift_below", @@ -7658,6 +7671,9 @@ std::set filament_options_with_variant = { //BBS "filament_wipe_distance", "filament_retract_before_wipe", + // Orca + "filament_retract_after_wipe", + //BBS "filament_long_retractions_when_cut", "filament_retraction_distances_when_cut", "long_retractions_when_ec", @@ -7701,6 +7717,7 @@ std::set printer_options_with_variant_1 = { "wipe", "wipe_distance", "retract_before_wipe", + "retract_after_wipe", "retract_length_toolchange", "retract_restart_extra", "retract_restart_extra_toolchange", diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 3e34a8362b..d8ce78ed8c 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -1292,6 +1292,9 @@ PRINT_CONFIG_CLASS_DEFINE( ((ConfigOptionPercents, retract_before_wipe)) + // Orca + ((ConfigOptionPercents, retract_after_wipe)) + ((ConfigOptionFloats, retraction_length)) ((ConfigOptionFloats, retract_length_toolchange)) ((ConfigOptionInt, enable_long_retraction_when_cut)) diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index ab3a43ab4e..e5343e6deb 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -1474,6 +1474,10 @@ static wxString pad_combo_value_for_config(const DynamicPrintConfig &config) void Tab::on_value_change(const std::string& opt_key, const boost::any& value) { + // Orca: + // TODO: Move filament-specific checks to TabFilament::on_value_change() + // TODO: Move printer-specific checks to TabPrinter::on_value_change() + if (wxGetApp().plater() == nullptr) { return; } @@ -3607,6 +3611,9 @@ void TabFilament::add_filament_overrides_page() //BBS "filament_wipe_distance", "filament_retract_before_wipe", + // Orca + "filament_retract_after_wipe", + // BBS "filament_long_retractions_when_cut", "filament_retraction_distances_when_cut" //SoftFever @@ -3733,6 +3740,9 @@ void TabFilament::update_filament_overrides_page(const DynamicPrintConfig* print //BBS "filament_wipe_distance", "filament_retract_before_wipe", + // Orca + "filament_retract_after_wipe", + // BBS "filament_long_retractions_when_cut", "filament_retraction_distances_when_cut" //SoftFever @@ -4296,6 +4306,68 @@ void TabFilament::clear_pages() m_overrides_options.clear(); } +void TabFilament::on_value_change(const std::string& opt_key, const boost::any& value) +{ + if (wxGetApp().plater() == nullptr || m_config_manipulation.is_applying()) + return; + + const int pos = opt_key.find("#"); + + if (pos > 0) { + std::string temp_str = opt_key; + boost::erase_head(temp_str, pos + 1); + int orig_opt_idx = static_cast(atoi(temp_str.c_str())); + int opt_idx = orig_opt_idx >= 0 ? orig_opt_idx : 0; + + std::string opt_key_pure = opt_key; + boost::erase_tail(opt_key_pure, opt_key_pure.size() - pos); + + if (opt_key_pure == "filament_retract_after_wipe" || opt_key_pure == "filament_retract_before_wipe") { + double dvalue = boost::any_cast(value); + auto percent_value_clamp = [](double percent_value) { return std::clamp(percent_value, 0., 100.); }; + auto get_value_by_opt_key = [&](const std::string& opt_key) { + if (opt_key_pure == opt_key && !std::isnan(dvalue)) { + // Return the incoming value (if it is valid) if the opt_key equals the key of the changed option. + return percent_value_clamp(dvalue); + } else if (!m_config->option(opt_key)->is_nil(opt_idx)) { + // Return the overridden value if the option value for the opt_key was overridden for the given filament. + return percent_value_clamp(m_config->option(opt_key)->get_at(opt_idx)); + } else { + // Return the value of the option value for opt_key from the printer setting if it was not overridden for the filament. + const auto& printer_config = m_preset_bundle->printers.get_edited_preset().config; + const std::string printer_opt_key = opt_key.substr(strlen("filament_")); + return percent_value_clamp(printer_config.option(printer_opt_key)->get_at(opt_idx)); + } + + return 0.; + }; + + double retract_before_wipe = get_value_by_opt_key("filament_retract_before_wipe"); + double retract_after_wipe = get_value_by_opt_key("filament_retract_after_wipe"); + + bool need_to_reload_config = false; + + if (percent_value_clamp(dvalue) != dvalue) { + change_opt_value(*m_config, opt_key_pure, percent_value_clamp(dvalue), opt_idx); + need_to_reload_config = true; + } + + if (retract_after_wipe > 100. - retract_before_wipe) { + change_opt_value(*m_config, "filament_retract_after_wipe", 100. - retract_before_wipe, opt_idx); + need_to_reload_config = true; + } + + if (need_to_reload_config && !m_postpone_update_ui) { + update_dirty(); + reload_config(); + update_tab_ui(); + } + } + } + + Tab::on_value_change(opt_key, value); +} + wxSizer* Tab::description_line_widget(wxWindow* parent, ogStaticText* *StaticText, wxString text /*= wxEmptyString*/) { *StaticText = new ogStaticText(parent, text); @@ -4990,6 +5062,8 @@ if (is_marlin_flavor) optgroup->append_single_option_line("wipe", "printer_extruder_retraction#wipe-while-retracting", extruder_idx); optgroup->append_single_option_line("wipe_distance", "printer_extruder_retraction#wipe-distance", extruder_idx); optgroup->append_single_option_line("retract_before_wipe", "printer_extruder_retraction#retract-amount-before-wipe", extruder_idx); + // Orca + optgroup->append_single_option_line("retract_after_wipe", "printer_extruder_retraction#retract-amount-after-wipe", extruder_idx); optgroup = page->new_optgroup(L("Z-Hop"), L"param_extruder_lift_enforcement"); optgroup->append_single_option_line("retract_lift_enforce", "printer_extruder_z_hop#on-surfaces", extruder_idx); @@ -5281,15 +5355,20 @@ void TabPrinter::toggle_options() // some options only apply when not using firmware retraction vec.resize(0); - vec = {"retraction_speed", "deretraction_speed", "retract_before_wipe", - "retract_length", "retract_restart_extra", "wipe", - "wipe_distance"}; + vec = {"retraction_speed", "deretraction_speed", "retract_before_wipe", "retract_after_wipe", + "retract_length", "retract_restart_extra", "wipe", "wipe_distance"}; for (auto el : vec) //BBS toggle_option(el, retraction && !use_firmware_retraction, i); bool wipe = retraction && m_config->opt_bool("wipe", variant_index); - toggle_option("retract_before_wipe", wipe, i); + + // Orca + double retract_before_wipe = m_config->option("retract_before_wipe")->get_at(i); + double retract_after_wipe = m_config->option("retract_after_wipe")->get_at(i); + + toggle_option("retract_before_wipe", wipe && !is_approx(retract_after_wipe, 100.), i); + toggle_option("retract_after_wipe", wipe && !is_approx(retract_before_wipe, 100.), i); if (use_firmware_retraction && wipe) { //wxMessageDialog dialog(parent(), @@ -5359,6 +5438,55 @@ void TabPrinter::toggle_options() } } +void TabPrinter::on_value_change(const std::string& opt_key, const boost::any& value) +{ + if (wxGetApp().plater() == nullptr || m_config_manipulation.is_applying()) + return; + + const int pos = opt_key.find("#"); + + if (pos > 0) { + std::string temp_str = opt_key; + boost::erase_head(temp_str, pos + 1); + int orig_opt_idx = static_cast(atoi(temp_str.c_str())); + int opt_idx = orig_opt_idx >= 0 ? orig_opt_idx : 0; + + std::string opt_key_pure = opt_key; + boost::erase_tail(opt_key_pure, opt_key_pure.size() - pos); + + if (opt_key_pure == "retract_after_wipe" || opt_key_pure == "retract_before_wipe") { + auto percent_value_clamp = [](double percent_value) { return std::clamp(percent_value, 0., 100.); }; + double dvalue = boost::any_cast(value); + + double retract_before_wipe = percent_value_clamp(opt_key_pure == "retract_before_wipe" + ? dvalue : m_config->option("retract_before_wipe")->get_at(opt_idx)); + + double retract_after_wipe = percent_value_clamp(opt_key_pure == "retract_after_wipe" + ? dvalue : m_config->option("retract_after_wipe")->get_at(opt_idx)); + + bool need_to_reload_config = false; + + if (percent_value_clamp(dvalue) != dvalue) { + change_opt_value(*m_config, opt_key_pure, percent_value_clamp(dvalue), opt_idx); + need_to_reload_config = true; + } + + if (retract_after_wipe > 100. - retract_before_wipe) { + change_opt_value(*m_config, "retract_after_wipe", 100. - retract_before_wipe, opt_idx); + need_to_reload_config = true; + } + + if (need_to_reload_config && !m_postpone_update_ui) { + update_dirty(); + reload_config(); + update_tab_ui(); + } + } + } + + Tab::on_value_change(opt_key, value); +} + void TabPrinter::update() { m_update_cnt++; diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index 96b35b26e1..b201be3821 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -584,6 +584,8 @@ public: void clear_pages() override; bool supports_printer_technology(const PrinterTechnology tech) const override { return tech == ptFFF; } + void on_value_change(const std::string& opt_key, const boost::any& value) override; + const std::string& get_custom_gcode(const t_config_option_key& opt_key) override; void set_custom_gcode(const t_config_option_key& opt_key, const std::string& value) override; }; @@ -640,11 +642,11 @@ public: bool supports_printer_technology(const PrinterTechnology /* tech */) const override { return true; } void set_extruder_volume_type(int extruder_id, NozzleVolumeType type); + void on_value_change(const std::string& opt_key, const boost::any& value) override; wxSizer* create_bed_shape_widget(wxWindow* parent); void cache_extruder_cnt(const DynamicPrintConfig* config = nullptr); bool apply_extruder_cnt_from_cache(); - }; class TabSLAMaterial : public Tab