diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index ce809ac03b..701b9afaf5 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -7605,7 +7605,7 @@ bool DynamicPrintConfig::support_different_extruders(int& extruder_count) return (variant_set.size() > 1); } -int DynamicPrintConfig::get_index_for_extruder(int extruder_id, std::string id_name, ExtruderType extruder_type, NozzleVolumeType nozzle_volume_type, std::string variant_name) +int DynamicPrintConfig::get_index_for_extruder(int extruder_id, std::string id_name, ExtruderType extruder_type, NozzleVolumeType nozzle_volume_type, std::string variant_name) const { int ret = -1; diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 9e8b891134..94b9f0ebbe 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -604,7 +604,7 @@ public: //BBS bool is_using_different_extruders(); bool support_different_extruders(int& extruder_count); - int get_index_for_extruder(int extruder_id, std::string id_name, ExtruderType extruder_type, NozzleVolumeType nozzle_volume_type, std::string variant_name); + int get_index_for_extruder(int extruder_id, std::string id_name, ExtruderType extruder_type, NozzleVolumeType nozzle_volume_type, std::string variant_name) const; void update_values_to_printer_extruders(DynamicPrintConfig& printer_config, std::set& key_set, std::string id_name, std::string variant_name, unsigned int stride = 1, unsigned int extruder_id = 0); bool is_custom_defined(); diff --git a/src/slic3r/GUI/OptionsGroup.cpp b/src/slic3r/GUI/OptionsGroup.cpp index ba6ff14f37..7674d085d3 100644 --- a/src/slic3r/GUI/OptionsGroup.cpp +++ b/src/slic3r/GUI/OptionsGroup.cpp @@ -24,6 +24,48 @@ namespace Slic3r { namespace GUI { // BBS: new layout constexpr int titleWidth = 20; +int get_extruder_idx(const DynamicPrintConfig& config, const std::string &opt_key, int cur_extruder_id) +{ + int extruder_count = wxGetApp().preset_bundle->get_printer_extruder_count(); + if (extruder_count == 1 || cur_extruder_id == -1) + return 0; + + assert(cur_extruder_id < extruder_count); + auto opt_extruder_type = dynamic_cast(config.option("extruder_type")); + auto opt_nozzle_volume_type = dynamic_cast(config.option("nozzle_volume_type")); + + if (!opt_extruder_type || !opt_nozzle_volume_type) + return 0; + + ExtruderType extruder_type = (ExtruderType) (opt_extruder_type->get_at(cur_extruder_id)); + NozzleVolumeType nozzle_volume_type = (NozzleVolumeType) (opt_nozzle_volume_type->get_at(cur_extruder_id)); + + std::string id_name, variant_name; + if (printer_options_with_variant_1.count(opt_key) > 0) { // printer parameter + id_name = "printer_extruder_id"; + variant_name = "printer_extruder_variant"; + } else if (printer_options_with_variant_2.count(opt_key) > 0) { + id_name = "printer_extruder_id"; + variant_name = "printer_extruder_variant"; + } else if (filament_options_with_variant.count(opt_key) > 0) { + id_name = "filament_extruder_id"; + variant_name = "filament_extruder_variant"; + } else if (print_options_with_variant.count(opt_key) > 0) { + id_name = "print_extruder_id"; + variant_name = "print_extruder_variant"; + } else { + return 0; + } + + // variant index + int variant_index = config.get_index_for_extruder(cur_extruder_id + 1, id_name, extruder_type, nozzle_volume_type, variant_name); + if (variant_index < 0) { + assert(false); + return 0; + } + + return variant_index; +} const t_field& OptionsGroup::build_field(const Option& opt) { return build_field(opt.opt_id, opt.opt); @@ -643,8 +685,7 @@ void ConfigOptionsGroup::on_change_OG(const t_config_option_key& opt_id, const b auto itOption = it->second; const std::string &opt_key = itOption.first; - int opt_index = itOption.second; - + int opt_index = get_extruder_idx(*m_config, itOption.first, itOption.second); this->change_opt_value(opt_key, value, opt_index == -1 ? 0 : opt_index); } @@ -733,7 +774,7 @@ void ConfigOptionsGroup::reload_config() // option key (may be scalar or vector) const std::string &opt_key = kvp.second.first; // index in the vector option, zero for scalars - int opt_index = kvp.second.second; + int opt_index = get_extruder_idx(*m_config, kvp.second.first, kvp.second.second); const ConfigOptionDef &option = m_options.at(opt_id).opt; this->set_value(opt_id, config_value(opt_key, opt_index, option.gui_flags == "serialized")); } diff --git a/src/slic3r/GUI/OptionsGroup.hpp b/src/slic3r/GUI/OptionsGroup.hpp index a3809a0cb7..eb984b1646 100644 --- a/src/slic3r/GUI/OptionsGroup.hpp +++ b/src/slic3r/GUI/OptionsGroup.hpp @@ -24,6 +24,8 @@ namespace Slic3r { namespace GUI { +extern int get_extruder_idx(const DynamicPrintConfig& config, const std::string &opt_key, int cur_extruder_id); + // Thrown if the building of a parameter page is canceled. class UIBuildCanceled : public std::exception {}; class OG_CustomCtrl; diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 998f4245bd..f661545c16 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -859,6 +859,35 @@ void Tab::decorate() m_active_page->refresh(); } +std::vector Tab::filter_diff_option(const std::vector &options) +{ + auto get_name_and_index = [](const std::string& value) -> std::pair{ + size_t pos = value.find("#"); + if (pos != std::string::npos) { + std::string param_name = value.substr(0, pos); + std::string number_str = value.substr(pos + 1); + int index = 0; + if (!number_str.empty()) { + index = std::stoi(number_str); + } + return std::make_pair(param_name, index); + } + return std::make_pair(value, 0); + }; + + std::vector diff_options; + for (std::string option : options) { + auto name_to_index = get_name_and_index(option); + int active_index = get_extruder_idx(*m_config, name_to_index.first, m_active_page->m_extruder_idx); + if (active_index == name_to_index.second) { + std::string name_to_extruder_id = name_to_index.first + "#" + std::to_string(m_active_page->m_extruder_idx); + diff_options.emplace_back(name_to_extruder_id); + } + } + + return diff_options; +} + // Update UI according to changes void Tab::update_changed_ui() { @@ -879,8 +908,14 @@ void Tab::update_changed_ui() for (auto& it : m_options_list) it.second = m_opt_status_value; - for (auto opt_key : dirty_options) m_options_list[opt_key] &= ~osInitValue; - for (auto opt_key : nonsys_options) m_options_list[opt_key] &= ~osSystemValue; + dirty_options = filter_diff_option(dirty_options); + + for (auto opt_key : dirty_options) { + m_options_list[opt_key] &= ~osInitValue; + } + for (auto opt_key : nonsys_options) { + m_options_list[opt_key] &= ~osSystemValue; + } update_custom_dirty(); @@ -4429,6 +4464,7 @@ if (is_marlin_flavor) //# build page //const wxString& page_name = wxString::Format(_L("Extruder %d"), int(extruder_idx + 1)); auto page = add_options_page(page_name, "custom-gcode_extruder", true); // ORCA: icon only visible on placeholders + page->m_extruder_idx = extruder_idx; m_pages.insert(m_pages.begin() + n_before_extruders + extruder_idx, page); auto optgroup = page->new_optgroup(L("Size"), L"param_extruder_size"); diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index b3831b41f1..c406a4b0e0 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -78,6 +78,7 @@ public: // BBS bool m_split_multi_line = false; bool m_option_label_at_right = false; + int m_extruder_idx = 0; // if is multi extruder, recorde the page is belong to which extruder public: std::vector m_optgroups; @@ -434,6 +435,7 @@ protected: void update_preset_description_line(); void update_frequently_changed_parameters(); void set_tooltips_text(); + std::vector filter_diff_option(const std::vector &options); ConfigManipulation m_config_manipulation; ConfigManipulation get_config_manipulation();