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 1da855bc8..3b3c169b0 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 87a1722fb..8e5b3852d 100644 --- a/resources/profiles/BBL/machine/fdm_machine_common.json +++ b/resources/profiles/BBL/machine/fdm_machine_common.json @@ -23,6 +23,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 b1ef5abf5..434af32e8 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -3176,8 +3176,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); @@ -3690,7 +3697,7 @@ GCode::LayerResult GCode::process_layer( gcode += m_writer.set_jerk_xy(m_config.initial_layer_jerk.value); } - if (! first_layer && ! m_second_layer_things_done) { + if (!first_layer && !m_second_layer_things_done) { //BBS: open powerlost recovery { if (print.is_BBL_Printer()) { @@ -3718,7 +3725,7 @@ GCode::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 && extruder.id() != m_writer.filament()->id()) // In single extruder multi material mode, set the temperature for the current extruder only. continue; @@ -3728,7 +3735,14 @@ GCode::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 83196384d..b0dd604d8 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -966,7 +966,8 @@ static std::vector s_Preset_printer_options { "printhost_cafile","printhost_port","printhost_authorization_type", "printhost_user", "printhost_password", "printhost_ssl_ignore_revoke", "use_relative_e_distances", "extruder_type","use_firmware_retraction", - "grab_length","machine_switch_extruder_time","hotend_cooling_rate","hotend_heating_rate","enable_pre_heating", "physical_extruder_map" + "grab_length","machine_switch_extruder_time","hotend_cooling_rate","hotend_heating_rate","enable_pre_heating", "physical_extruder_map", + "bed_temperature_formula" }; static std::vector s_Preset_sla_print_options { diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 06a164c33..0575eb065 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -200,7 +200,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; @@ -1910,15 +1911,21 @@ void Print::process(std::unordered_map* slice_time, bool 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(); @@ -1951,6 +1958,12 @@ void Print::process(std::unordered_map* slice_time, bool 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(); //BBS: have no single_extruder_multi_material_priming #if 0 diff --git a/src/libslic3r/Print.hpp b/src/libslic3r/Print.hpp index 6f55cc922..14f67210f 100644 --- a/src/libslic3r/Print.hpp +++ b/src/libslic3r/Print.hpp @@ -893,6 +893,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 * @@ -1027,6 +1033,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 c6ac5d09c..c3b0d5d85 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -120,6 +120,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) }, @@ -1757,6 +1763,17 @@ void PrintConfigDef::init_fff_params() def = this->add("enable_pre_heating", coBool); def->set_default_value(new ConfigOptionBool(false)); + 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 gcode, so it's important and should be accurate"); diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 929d50a84..384f6b822 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -82,6 +82,12 @@ enum class WallInfillOrder { Count, }; +enum class BedTempFormula { + btfFirstFilament, + btfHighestTemp, + count, +}; + // BBS enum class WallSequence { InnerOuter, @@ -1037,6 +1043,7 @@ PRINT_CONFIG_CLASS_DEFINE( ((ConfigOptionFloat, machine_unload_filament_time)) ((ConfigOptionFloat, machine_switch_extruder_time)) ((ConfigOptionBool, enable_pre_heating)) + ((ConfigOptionEnum, bed_temperature_formula)) ((ConfigOptionInts, physical_extruder_map)) ((ConfigOptionFloat, hotend_cooling_rate)) ((ConfigOptionFloat, hotend_heating_rate)) diff --git a/src/libslic3r/Utils.hpp b/src/libslic3r/Utils.hpp index 4dbd43c3d..c62b23d1d 100644 --- a/src/libslic3r/Utils.hpp +++ b/src/libslic3r/Utils.hpp @@ -143,6 +143,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 6813cb296..a21bc0112 100644 --- a/src/slic3r/GUI/Preferences.cpp +++ b/src/slic3r/GUI/Preferences.cpp @@ -856,16 +856,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 71a6164ea..5c02cbfcc 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -3706,6 +3706,7 @@ void TabPrinter::build_fff() optgroup->append_single_option_line("scan_first_layer"); 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("machine_load_filament_time"); optgroup->append_single_option_line("machine_unload_filament_time");