From 6f5ea725dc7dae6d9c1a15af4cc4a4cb5574530d Mon Sep 17 00:00:00 2001 From: "xun.zhang" Date: Thu, 20 Feb 2025 21:12:00 +0800 Subject: [PATCH] ENH: add new way to set bed temperature jira:NONE Signed-off-by: xun.zhang Change-Id: I99a9f67e9b13b2137ad371b22cf0999ccf9c096d (cherry picked from commit 69c2947daf66eb0a6732b1b980c9b87f597c8da7) --- .../BBL/machine/fdm_bbl_3dp_002_common.json | 1 + .../BBL/machine/fdm_machine_common.json | 1 + src/libslic3r/GCode.cpp | 24 +++++++++--- src/libslic3r/Preset.cpp | 3 +- src/libslic3r/Print.cpp | 21 ++++++++-- src/libslic3r/Print.hpp | 9 +++++ src/libslic3r/PrintConfig.cpp | 17 +++++++++ src/libslic3r/PrintConfig.hpp | 7 ++++ src/libslic3r/Utils.hpp | 23 +++++++++++ src/slic3r/GUI/Preferences.cpp | 38 ++++++++++++++----- src/slic3r/GUI/Tab.cpp | 1 + 11 files changed, 125 insertions(+), 20 deletions(-) diff --git a/resources/profiles/BBL/machine/fdm_bbl_3dp_002_common.json b/resources/profiles/BBL/machine/fdm_bbl_3dp_002_common.json index c33d297dc1..b207312d7b 100644 --- a/resources/profiles/BBL/machine/fdm_bbl_3dp_002_common.json +++ b/resources/profiles/BBL/machine/fdm_bbl_3dp_002_common.json @@ -11,6 +11,7 @@ "printer_variant": "0.4", "best_object_pos": "0.3x0.5", "bed_exclude_area": [], + "bed_temperature_formula": "by_highest_temp", "default_filament_profile": [ "Bambu PLA Basic @BBL H2D" ], diff --git a/resources/profiles/BBL/machine/fdm_machine_common.json b/resources/profiles/BBL/machine/fdm_machine_common.json index 25444fb4b6..a5e3953910 100644 --- a/resources/profiles/BBL/machine/fdm_machine_common.json +++ b/resources/profiles/BBL/machine/fdm_machine_common.json @@ -22,6 +22,7 @@ ], "enable_long_retraction_when_cut" : "0", "enable_pre_heating": "0", + "bed_temperature_formula" : "by_first_filament", "hotend_cooling_rate": "2", "hotend_heating_rate": "2", "extruder_offset": [ diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 904ce56031..d8afd8bf18 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -3507,8 +3507,15 @@ void GCode::_print_first_layer_bed_temperature(GCodeOutputStream &file, Print &p // Initial bed temperature based on the first extruder. // BBS std::vector temps_per_bed; - int bed_temp = get_bed_temperature(first_printing_extruder_id, true, print.config().curr_bed_type); - + int bed_temp = 0; + if (m_config.bed_temperature_formula.value == BedTempFormula::btfHighestTemp) { + for (auto fidx : print.get_slice_used_filaments(true)) { + bed_temp = std::max(bed_temp, get_bed_temperature(fidx, true, print.config().curr_bed_type)); + } + } + else { + bed_temp = get_bed_temperature(first_printing_extruder_id, true, print.config().curr_bed_type); + } // Is the bed temperature set by the provided custom G-code? int temp_by_gcode = -1; bool temp_set_by_gcode = custom_gcode_sets_temperature(gcode, 140, 190, false, temp_by_gcode); @@ -4186,7 +4193,7 @@ LayerResult GCode::process_layer( } } - if (! first_layer && ! m_second_layer_things_done) { + if (!first_layer && !m_second_layer_things_done) { if (print.is_BBL_printer()) { // BBS: open powerlost recovery { @@ -4214,7 +4221,7 @@ LayerResult GCode::process_layer( // Transition from 1st to 2nd layer. Adjust nozzle temperatures as prescribed by the nozzle dependent // nozzle_temperature_initial_layer vs. temperature settings. - for (const Extruder &extruder : m_writer.extruders()) { + for (const Extruder& extruder : m_writer.extruders()) { if ((print.config().single_extruder_multi_material.value || m_ooze_prevention.enable) && extruder.id() != m_writer.filament()->id()) // In single extruder multi material mode, set the temperature for the current extruder only. @@ -4225,7 +4232,14 @@ LayerResult GCode::process_layer( } // BBS - int bed_temp = get_bed_temperature(first_extruder_id, false, print.config().curr_bed_type); + int bed_temp = 0; + if (m_config.bed_temperature_formula == BedTempFormula::btfHighestTemp) { + for (auto fidx : print.get_slice_used_filaments(false)) { + bed_temp = std::max(bed_temp, get_bed_temperature(fidx, false, m_config.curr_bed_type)); + } + } + else + bed_temp = get_bed_temperature(first_extruder_id, false, m_config.curr_bed_type); gcode += m_writer.set_bed_temperature(bed_temp); // Mark the temperature transition from 1st to 2nd layer to be finished. m_second_layer_things_done = true; diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index fb1b9d0d2c..79ab7f6b8a 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -915,7 +915,8 @@ static std::vector s_Preset_printer_options { "cooling_tube_retraction", "cooling_tube_length", "high_current_on_filament_swap", "parking_pos_retraction", "extra_loading_move", "purge_in_prime_tower", "enable_filament_ramming", "z_offset", - "disable_m73", "preferred_orientation", "emit_machine_limits_to_gcode", "pellet_modded_printer", "support_multi_bed_types", "default_bed_type", "bed_mesh_min","bed_mesh_max","bed_mesh_probe_distance", "adaptive_bed_mesh_margin", "enable_long_retraction_when_cut","long_retractions_when_cut","retraction_distances_when_cut" + "disable_m73", "preferred_orientation", "emit_machine_limits_to_gcode", "pellet_modded_printer", "support_multi_bed_types", "default_bed_type", "bed_mesh_min","bed_mesh_max","bed_mesh_probe_distance", "adaptive_bed_mesh_margin", "enable_long_retraction_when_cut","long_retractions_when_cut","retraction_distances_when_cut", + "bed_temperature_formula" }; static std::vector s_Preset_sla_print_options { diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 44598a0a7c..da77a42765 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -219,7 +219,8 @@ bool Print::invalidate_state_by_config_options(const ConfigOptionResolver & /* n "retraction_distances_when_cut", "filament_long_retractions_when_cut", "filament_retraction_distances_when_cut", - "grab_length" + "grab_length", + "bed_temperature_formula" }; static std::unordered_set steps_ignore; @@ -2156,15 +2157,21 @@ void Print::process(long long *time_cost_with_cache, bool use_cache) if (this->config().print_sequence == PrintSequence::ByObject) { // Order object instances for sequential print. print_object_instances_ordering = sort_object_instances_by_model_order(*this); + std::vector first_layer_used_filaments; std::vector> all_filaments; for (print_object_instance_sequential_active = print_object_instances_ordering.begin(); print_object_instance_sequential_active != print_object_instances_ordering.end(); ++print_object_instance_sequential_active) { tool_ordering = ToolOrdering(*(*print_object_instance_sequential_active)->print_object, initial_extruder_id); - for (const auto& layer_tool : tool_ordering.layer_tools()) { - all_filaments.emplace_back(layer_tool.extruders); + for (size_t idx = 0; idx < tool_ordering.layer_tools().size(); ++idx) { + auto& layer_filament = tool_ordering.layer_tools()[idx].extruders; + all_filaments.emplace_back(layer_filament); + if (idx == 0) + first_layer_used_filaments.insert(first_layer_used_filaments.end(), layer_filament.begin(), layer_filament.end()); } } - + sort_remove_duplicates(first_layer_used_filaments); auto used_filaments = collect_sorted_used_filaments(all_filaments); + this->set_slice_used_filaments(first_layer_used_filaments,used_filaments); + auto physical_unprintables = this->get_physical_unprintable_filaments(used_filaments); auto geometric_unprintables = this->get_geometric_unprintable_filaments(); std::vectorfilament_maps = this->get_filament_maps(); @@ -2197,6 +2204,12 @@ void Print::process(long long *time_cost_with_cache, bool use_cache) else { tool_ordering = this->tool_ordering(); tool_ordering.assign_custom_gcodes(*this); + + std::vector first_layer_used_filaments; + if (!tool_ordering.layer_tools().empty()) + first_layer_used_filaments = tool_ordering.layer_tools().front().extruders; + + this->set_slice_used_filaments(first_layer_used_filaments, tool_ordering.all_extruders()); has_wipe_tower = this->has_wipe_tower() && tool_ordering.has_wipe_tower(); initial_extruder_id = tool_ordering.first_extruder(); print_object_instances_ordering = chain_print_object_instances(*this); diff --git a/src/libslic3r/Print.hpp b/src/libslic3r/Print.hpp index 58fc84eccb..0cada6abe7 100644 --- a/src/libslic3r/Print.hpp +++ b/src/libslic3r/Print.hpp @@ -981,6 +981,12 @@ public: void set_geometric_unprintable_filaments(const std::vector> &unprintables_filament_ids) { m_geometric_unprintable_filaments = unprintables_filament_ids; } std::vector> get_geometric_unprintable_filaments() const { return m_geometric_unprintable_filaments;} + void set_slice_used_filaments(const std::vector &first_layer_used_filaments, const std::vector &used_filaments){ + m_slice_used_filaments_first_layer = first_layer_used_filaments; + m_slice_used_filaments = used_filaments; + } + std::vector get_slice_used_filaments(bool first_layer) const { return first_layer ? m_slice_used_filaments_first_layer : m_slice_used_filaments;} + /** * @brief Determines the unprintable filaments for each extruder based on its physical attributes * @@ -1131,6 +1137,9 @@ private: bool m_support_used {false}; StatisticsByExtruderCount m_statistics_by_extruder_count; + std::vector m_slice_used_filaments; + std::vector m_slice_used_filaments_first_layer; + //BBS: plate's origin Vec3d m_origin; //BBS: modified_count diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index d36dfa3921..cf368d7c2f 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -126,6 +126,12 @@ static t_config_enum_values s_keys_map_GCodeFlavor { }; CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(GCodeFlavor) +static t_config_enum_values s_keys_map_BedTempFormula { + { "by_first_filament",int(BedTempFormula::btfFirstFilament) }, + { "by_highest_temp", int(BedTempFormula::btfHighestTemp)} +}; +CONFIG_OPTION_ENUM_DEFINE_STATIC_MAPS(BedTempFormula) + static t_config_enum_values s_keys_map_FuzzySkinType { { "none", int(FuzzySkinType::None) }, { "external", int(FuzzySkinType::External) }, @@ -2218,6 +2224,17 @@ void PrintConfigDef::init_fff_params() def->set_default_value(new ConfigOptionFloat { 0. }); + def = this->add("bed_temperature_formula", coEnum); + def->label = L("Bed temperature type"); + def->tooltip = L("With this option enabled, you can print filaments with significant bed temperature differentials."); + def->mode = comDevelop; + def->enum_keys_map = &ConfigOptionEnum::get_enum_values(); + def->enum_values.push_back("first_filament"); + def->enum_values.push_back("highest_filament"); + def->enum_labels.push_back("First filament"); + def->enum_labels.push_back("Highest temp filament"); + def->set_default_value(new ConfigOptionEnum(BedTempFormula::btfFirstFilament)); + def = this->add("filament_diameter", coFloats); def->label = L("Diameter"); def->tooltip = L("Filament diameter is used to calculate extrusion in G-code, so it is important and should be accurate."); diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index cf139c32f5..477a02cf90 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -95,6 +95,12 @@ enum class WallInfillOrder { Count, }; +enum class BedTempFormula { + btfFirstFilament, + btfHighestTemp, + count, +}; + // BBS enum class WallSequence { InnerOuter, @@ -1235,6 +1241,7 @@ PRINT_CONFIG_CLASS_DEFINE( ((ConfigOptionIntsGroups, unprintable_filament_map)) //((ConfigOptionInts, filament_extruder_id)) ((ConfigOptionStrings, filament_extruder_variant)) + ((ConfigOptionEnum, bed_temperature_formula)) ((ConfigOptionInts, physical_extruder_map)) // BBS ((ConfigOptionBool, scan_first_layer)) diff --git a/src/libslic3r/Utils.hpp b/src/libslic3r/Utils.hpp index 1b5436b561..2b328e0044 100644 --- a/src/libslic3r/Utils.hpp +++ b/src/libslic3r/Utils.hpp @@ -142,6 +142,29 @@ T get_max_element(const std::vector &vec) } +template +std::vector convert_vector(const std::vector& src) { + std::vector dst; + dst.reserve(src.size()); + for (const auto& elem : src) { + if constexpr (std::is_signed_v) { + if (elem > static_cast(std::numeric_limits::max())) { + throw std::overflow_error("Source value exceeds destination maximum"); + } + if (elem < static_cast(std::numeric_limits::min())) { + throw std::underflow_error("Source value below destination minimum"); + } + } + else { + if (elem < 0) { + throw std::invalid_argument("Negative value in source for unsigned destination"); + } + } + dst.push_back(static_cast(elem)); + } + return dst; +} + // Set a path with GUI localization files. void set_local_dir(const std::string &path); // Return a full path to the localization directory. diff --git a/src/slic3r/GUI/Preferences.cpp b/src/slic3r/GUI/Preferences.cpp index 18e3861928..bd983409d4 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -831,16 +831,34 @@ wxBoxSizer *PreferencesDialog::create_item_checkbox(wxString title, wxWindow *pa if (param == "enable_high_low_temp_mixed_printing") { if (checkbox->GetValue()) { - MessageDialog msg_wingow(nullptr, _L("Printing with multiple filaments that have a large temperature difference can cause the extruder and nozzle to be blocked or dameged during printing.\nPlease enable with caution."), - _L("Warning"), wxICON_WARNING | wxYES | wxYES_DEFAULT | wxCANCEL | wxCENTRE, wxEmptyString, - _L("Click Wiki for help."), [](const wxString){ - std::string language = wxGetApp().app_config->get("language"); - wxString region = L"en"; - if (language.find("zh") == 0) region = L"zh"; - const wxString wiki_link = wxString::Format(L"https://wiki.bambulab.com/%s/filament-acc/filament/h2d-filament-config-limit", region); - wxGetApp().open_browser_with_warning_dialog(wiki_link); - }); - if (msg_wingow.ShowModal() != wxID_YES) { + const wxString warning_title = _L("Bed Temperature Difference Warning"); + const wxString warning_message = + _L("Using filaments with significantly different temperatures may cause:\n" + "• Extruder clogging\n" + "• Nozzle damage\n" + "• Layer adhesion issues\n\n" + "Continue with enabling this feature?"); + std::function link_callback = [](const wxString&) { + const std::string lang_code = wxGetApp().app_config->get("language"); + const wxString region = (lang_code.find("zh") != std::string::npos) ? L"zh" : L"en"; + const wxString wiki_url = wxString::Format( + L"https://wiki.bambulab.com/%s/filament-acc/filament/h2d-filament-config-limit", + region + ); + wxGetApp().open_browser_with_warning_dialog(wiki_url); + }; + + MessageDialog msg_dialog( + nullptr, + warning_message, + warning_title, + wxICON_WARNING | wxYES_NO | wxCANCEL | wxYES_DEFAULT | wxCENTRE, + wxEmptyString, + _L("Click Wiki for help."), + link_callback + ); + + if (msg_dialog.ShowModal() != wxID_YES) { checkbox->SetValue(false); app_config->set_bool(param, false); app_config->save(); diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 9bd2f1aa1a..f4779b4cf1 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -4117,6 +4117,7 @@ void TabPrinter::build_fff() optgroup->append_single_option_line("use_relative_e_distances"); optgroup->append_single_option_line("use_firmware_retraction"); + optgroup->append_single_option_line("bed_temperature_formula"); // optgroup->append_single_option_line("spaghetti_detector"); optgroup->append_single_option_line("time_cost");