From abb2356e6e134cafbad618b7161bbe75cfc0ebfa Mon Sep 17 00:00:00 2001 From: "xun.zhang" Date: Mon, 1 Apr 2024 11:31:01 +0800 Subject: [PATCH] ENH: refine long retraction ui 1. associate button display logic 2. Add valid range tip 3. seperate the printer into three types jira:NEW Signed-off-by: xun.zhang Change-Id: Ie14c8746eb20456dacd5c129a5449c1e7c7db372 --- .../BBL/machine/Bambu Lab X1 0.4 nozzle.json | 2 +- .../Bambu Lab X1 Carbon 0.4 nozzle.json | 2 +- src/libslic3r/PrintApply.cpp | 3 +++ src/libslic3r/PrintConfig.cpp | 8 +++++--- src/libslic3r/PrintConfig.hpp | 2 +- src/slic3r/GUI/Field.cpp | 14 +++++++++++++ src/slic3r/GUI/Plater.cpp | 8 ++++---- src/slic3r/GUI/Plater.hpp | 7 +++++++ src/slic3r/GUI/Tab.cpp | 20 +++++++++++-------- 9 files changed, 48 insertions(+), 18 deletions(-) diff --git a/resources/profiles/BBL/machine/Bambu Lab X1 0.4 nozzle.json b/resources/profiles/BBL/machine/Bambu Lab X1 0.4 nozzle.json index 4843283bb..075d339ce 100644 --- a/resources/profiles/BBL/machine/Bambu Lab X1 0.4 nozzle.json +++ b/resources/profiles/BBL/machine/Bambu Lab X1 0.4 nozzle.json @@ -21,7 +21,7 @@ "Bambu PLA Basic @BBL X1" ], "default_print_profile": "0.20mm Standard @BBL X1C", - "enable_long_retraction_when_cut" : "1", + "enable_long_retraction_when_cut" : "2", "extruder_offset": [ "0x2" ], diff --git a/resources/profiles/BBL/machine/Bambu Lab X1 Carbon 0.4 nozzle.json b/resources/profiles/BBL/machine/Bambu Lab X1 Carbon 0.4 nozzle.json index 73d315fec..572dfe19a 100644 --- a/resources/profiles/BBL/machine/Bambu Lab X1 Carbon 0.4 nozzle.json +++ b/resources/profiles/BBL/machine/Bambu Lab X1 Carbon 0.4 nozzle.json @@ -23,7 +23,7 @@ "extruder_offset": [ "0x2" ], - "enable_long_retraction_when_cut" : "1", + "enable_long_retraction_when_cut" : "2", "machine_load_filament_time": "29", "machine_unload_filament_time": "28", "nozzle_height": "4.2", diff --git a/src/libslic3r/PrintApply.cpp b/src/libslic3r/PrintApply.cpp index 54aa20a00..1b20d3142 100644 --- a/src/libslic3r/PrintApply.cpp +++ b/src/libslic3r/PrintApply.cpp @@ -230,6 +230,9 @@ static t_config_option_keys print_config_diffs( if (opt_new == nullptr) //FIXME This may happen when executing some test cases. continue; + if ((opt_key == "long_retractions_when_cut" || opt_key == "retraction_distances_when_cut") + && current_config.enable_long_retraction_when_cut.getInt() != 2) + continue; //BBS: hard code here, remove it later if the machine firwmare support const ConfigOption *opt_new_filament = std::binary_search(extruder_retract_keys.begin(), extruder_retract_keys.end(), opt_key) ? new_full_config.option(filament_prefix + opt_key) : nullptr; if (opt_new_filament != nullptr && ! opt_new_filament->is_nil()) { // An extruder retract override is available at some of the filament presets. diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 8721b095a..55c172564 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -2700,9 +2700,9 @@ void PrintConfigDef::init_fff_params() def->mode = comSimple; def->set_default_value(new ConfigOptionFloats { 0.8 }); - def = this->add("enable_long_retraction_when_cut",coBool); + def = this->add("enable_long_retraction_when_cut",coInt); def->mode = comDevelop; - def->set_default_value(new ConfigOptionBool {false}); + def->set_default_value(new ConfigOptionInt {0}); def = this->add("long_retractions_when_cut", coBools); def->label = L("Long retraction when cut(experimental)"); @@ -3873,7 +3873,9 @@ void PrintConfigDef::init_fff_params() def->max = it_opt->second.max; //BBS: shown specific filament retract config because we hide the machine retract into comDevelop mode if ((strcmp(opt_key, "retraction_length") == 0) || - (strcmp(opt_key, "z_hop") == 0)) + (strcmp(opt_key, "z_hop") == 0)|| + (strcmp(opt_key, "long_retractions_when_cut") == 0)|| + (strcmp(opt_key, "retraction_distances_when_cut") == 0)) def->mode = comSimple; else def->mode = comAdvanced; diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 1379a7f30..81b656533 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -916,7 +916,7 @@ PRINT_CONFIG_CLASS_DEFINE( ((ConfigOptionPercents, retract_before_wipe)) ((ConfigOptionFloats, retraction_length)) ((ConfigOptionFloats, retract_length_toolchange)) - ((ConfigOptionBool, enable_long_retraction_when_cut)) + ((ConfigOptionInt, enable_long_retraction_when_cut)) ((ConfigOptionFloats, retraction_distances_when_cut)) ((ConfigOptionBools, long_retractions_when_cut)) ((ConfigOptionFloats, z_hop)) diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index de3c7666a..6cacf0607 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -294,6 +294,7 @@ void Field::get_value_by_opt_type(wxString& str, const bool check_value/* = true m_value.clear(); break; } + std::string opt_key_without_idx = m_opt_id.substr(0, m_opt_id.find('#')); if (m_opt_id == "filament_flow_ratio") { if (m_value.empty() || boost::any_cast(m_value) != val) { wxString msg_text = format_wxstr(_L("Value %s is out of range, continue?"), str); @@ -310,6 +311,19 @@ void Field::get_value_by_opt_type(wxString& str, const bool check_value/* = true } } } + else if(m_opt_id == "filament_retraction_distances_when_cut" || opt_key_without_idx == "retraction_distances_when_cut"){ + wxString msg_text = format_wxstr(_L("Value %s is out of range. The valid range is from %d to %d."), str, m_opt.min, m_opt.max); + WarningDialog dialog(m_parent, msg_text, _L("Parameter validation") + ": " + m_opt_id, wxYES); + if (dialog.ShowModal()) { + if (m_value.empty()) { + if (m_opt.min > val) val = m_opt.min; + if (val > m_opt.max) val = m_opt.max; + } + else + val = boost::any_cast(m_value); + set_value(double_to_string(val), true); + } + } else { show_error(m_parent, _L("Value is out of range.")); if (m_opt.min > val) val = m_opt.min; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 93114a3bb..843709cf5 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -472,7 +472,7 @@ std::vector get_min_flush_volumes() ConfigOption* nozzle_volume_opt = printer_config.option("nozzle_volume"); int nozzle_volume_val = nozzle_volume_opt ? (int)nozzle_volume_opt->getFloat() : 0; - bool machine_enabled = printer_config.option("enable_long_retraction_when_cut")->value; + int machine_enabled_level = printer_config.option("enable_long_retraction_when_cut")->value; bool machine_activated = printer_config.option("long_retractions_when_cut")->values[0] == 1; auto filament_retraction_distance_when_cut = full_config.option("filament_retraction_distances_when_cut"); @@ -482,14 +482,14 @@ std::vector get_min_flush_volumes() size_t filament_size = filament_retraction_distance_when_cut->values.size(); for (size_t idx = 0; idx < filament_size; ++idx) { int extra_flush_volume = nozzle_volume_val; - int retract_length = machine_enabled && machine_activated ? printer_retraction_distance_when_cut->values[0] : 0; + int retract_length = machine_enabled_level && machine_activated ? printer_retraction_distance_when_cut->values[0] : 0; char filament_activated = filament_long_retractions_when_cut->values[idx]; double filament_retract_length = filament_retraction_distance_when_cut->values[idx]; - if(filament_activated == 0) + if (filament_activated == 0) retract_length = 0; - else if (filament_activated == 1 && machine_enabled) { + else if (filament_activated == 1 && machine_enabled_level == LongRectrationLevel::EnableFilament) { if (!std::isnan(filament_retract_length)) retract_length = (int)filament_retraction_distance_when_cut->values[idx]; else diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index 84069d092..9d49eafa8 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -54,6 +54,13 @@ class Ams; using ModelInstancePtrs = std::vector; +enum LongRectrationLevel +{ + Disabled=0, + EnableMachine, + EnableFilament +}; + namespace UndoRedo { class Stack; enum class SnapshotType : unsigned char; diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 6845abfd5..185214e63 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -1573,7 +1573,7 @@ void Tab::on_value_change(const std::string& opt_key, const boost::any& value) if (activate == 1) { MessageDialog dialog(wxGetApp().plater(), _L("Experimental feature: Retracting and cutting off the filament at a greater distance during filament changes to minimize flush." - "Although it can notably reduce flush, it may also elevate the risk of nozzle clogs or other printing complications."), "", wxICON_WARNING | wxOK); + "Although it can notably reduce flush, it may also elevate the risk of nozzle clogs or other printing complications.Please use with the latest printer firmware."), "", wxICON_WARNING | wxOK); dialog.ShowModal(); } update_flush_volume(); @@ -2976,12 +2976,16 @@ void TabFilament::update_filament_overrides_page() Field* field = optgroup->get_fieldc(opt_key, extruder_idx); if (field != nullptr) { if (opt_key == "filament_long_retractions_when_cut") { - bool machine_enabled = wxGetApp().preset_bundle->printers.get_edited_preset().config.option("enable_long_retraction_when_cut")->value; - field->toggle(is_checked&&machine_enabled); + int machine_enabled_level = wxGetApp().preset_bundle->printers.get_edited_preset().config.option("enable_long_retraction_when_cut")->value; + bool machine_enabled = machine_enabled_level == LongRectrationLevel::EnableFilament; + toggle_line(opt_key, machine_enabled); + field->toggle(is_checked && machine_enabled); } else if (opt_key == "filament_retraction_distances_when_cut") { - bool machine_enabled = wxGetApp().preset_bundle->printers.get_edited_preset().config.option("enable_long_retraction_when_cut")->value; - bool filament_enabled = m_config->option("filament_long_retractions_when_cut")->values[extruder_idx]==1; + int machine_enabled_level = wxGetApp().preset_bundle->printers.get_edited_preset().config.option("enable_long_retraction_when_cut")->value; + bool machine_enabled = machine_enabled_level == LongRectrationLevel::EnableFilament; + bool filament_enabled = m_config->option("filament_long_retractions_when_cut")->values[extruder_idx] == 1; + toggle_line(opt_key, filament_enabled && machine_enabled); field->toggle(is_checked && filament_enabled && machine_enabled); } else @@ -4190,9 +4194,9 @@ void TabPrinter::toggle_options() bool toolchange_retraction = m_config->opt_float("retract_length_toolchange", i) > 0; toggle_option("retract_restart_extra_toolchange", have_multiple_extruders && toolchange_retraction, i); - // do not display this extruder param now - toggle_option("long_retractions_when_cut", !use_firmware_retraction && m_config->opt_bool("enable_long_retraction_when_cut"),i); - toggle_option("retraction_distances_when_cut", m_config->opt_bool("long_retractions_when_cut",i),i); + toggle_option("long_retractions_when_cut", !use_firmware_retraction && m_config->opt_int("enable_long_retraction_when_cut"),i); + toggle_line("retraction_distances_when_cut#0", m_config->opt_bool("long_retractions_when_cut", i)); + //toggle_option("retraction_distances_when_cut", m_config->opt_bool("long_retractions_when_cut",i),i); } if (m_active_page->title() == "Motion ability") {