From fab6b21e4d39a940cdb497971b68c6439076e0ca Mon Sep 17 00:00:00 2001 From: "zhimin.zeng" Date: Fri, 28 Jun 2024 09:35:56 +0800 Subject: [PATCH] FIX: parameters modify of printer preset Ensure correct behavior when modifying parameters of printer preset Change-Id: Ic627a8e202bf4224b742336cc43ac611ddc5c997 (cherry picked from commit 366a14d8f715cbeca3d0f70a4727d91b6f0ca82e) --- src/libslic3r/GCode/ToolOrdering.hpp | 2 +- src/libslic3r/PrintConfig.cpp | 44 ++++++++++++++++++++++++---- src/libslic3r/PrintConfig.hpp | 2 ++ src/slic3r/GUI/OptionsGroup.cpp | 30 ++++++++++--------- src/slic3r/GUI/Tab.cpp | 32 +++++++++++++++----- src/slic3r/GUI/Tab.hpp | 1 - src/slic3r/GUI/Widgets/ComboBox.cpp | 1 + 7 files changed, 82 insertions(+), 30 deletions(-) diff --git a/src/libslic3r/GCode/ToolOrdering.hpp b/src/libslic3r/GCode/ToolOrdering.hpp index 1cd7f1c73e..0d10100c22 100644 --- a/src/libslic3r/GCode/ToolOrdering.hpp +++ b/src/libslic3r/GCode/ToolOrdering.hpp @@ -157,7 +157,7 @@ public: ToolOrdering(const Print& print, unsigned int first_extruder, bool prime_multi_material = false); void clear() { - m_layer_tools.clear(); m_tool_order_cache.clear(); + m_layer_tools.clear(); m_tool_order_cache.clear(); } // Only valid for non-sequential print: diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 89024764f6..2819c4ad57 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -7160,11 +7160,15 @@ std::set filament_options_with_variant = { "filament_extruder_variant" }; -std::set printer_options_with_variant_1 = { - /*"extruder_type", +// Parameters that are the same as the number of extruders +std::set printer_extruder_options = { + "extruder_type", "nozzle_diameter", - "nozzle_volume_type". - "min_layer_height", + "nozzle_volume_type" +}; + +std::set printer_options_with_variant_1 = { + /*"min_layer_height", "max_layer_height",*/ //"retraction_length", "z_hop", @@ -7439,6 +7443,33 @@ void handle_legacy_sla(DynamicPrintConfig &config) } } +size_t DynamicPrintConfig::get_parameter_size(const std::string& param_name, size_t extruder_nums) +{ + if (extruder_nums > 1) { + size_t volume_type_size = 2; + auto nozzle_volume_type_opt = dynamic_cast(this->option("nozzle_volume_type")); + if (nozzle_volume_type_opt) { + volume_type_size = nozzle_volume_type_opt->values.size(); + } + if (printer_options_with_variant_1.count(param_name) > 0) { + return extruder_nums * volume_type_size; + } + else if (printer_options_with_variant_2.count(param_name) > 0) { + return extruder_nums * volume_type_size * 2; + } + else if (filament_options_with_variant.count(param_name) > 0) { + return extruder_nums * volume_type_size; + } + else if (print_options_with_variant.count(param_name) > 0) { + return extruder_nums * volume_type_size; + } + else { + return extruder_nums; + } + } + return extruder_nums; +} + void DynamicPrintConfig::set_num_extruders(unsigned int num_extruders) { const auto &defaults = FullPrintConfig::defaults(); @@ -7450,8 +7481,9 @@ void DynamicPrintConfig::set_num_extruders(unsigned int num_extruders) auto *opt = this->option(key, false); assert(opt != nullptr); assert(opt->is_vector()); - if (opt != nullptr && opt->is_vector()) - static_cast(opt)->resize(num_extruders, defaults.option(key)); + if (opt != nullptr && opt->is_vector()) { + static_cast(opt)->resize(get_parameter_size(key, num_extruders), defaults.option(key)); + } } } diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index 14734150e1..31a411ef1d 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -576,6 +576,7 @@ public: //return the changed param set t_config_option_keys normalize_fdm_2(int num_objects, int used_filaments = 0); + size_t get_parameter_size(const std::string& param_name, size_t extruder_nums); void set_num_extruders(unsigned int num_extruders); // BBS @@ -609,6 +610,7 @@ public: bool is_custom_defined(); }; +extern std::set printer_extruder_options; extern std::set print_options_with_variant; extern std::set filament_options_with_variant; extern std::set printer_options_with_variant_1; diff --git a/src/slic3r/GUI/OptionsGroup.cpp b/src/slic3r/GUI/OptionsGroup.cpp index dbc80015f2..0ea22c37c3 100644 --- a/src/slic3r/GUI/OptionsGroup.cpp +++ b/src/slic3r/GUI/OptionsGroup.cpp @@ -22,17 +22,24 @@ namespace Slic3r { namespace GUI { - // BBS: new layout - constexpr int titleWidth = 20; +// BBS: new layout +constexpr int titleWidth = 20; + +// get the param index of cur_exturder int get_extruder_idx(const DynamicPrintConfig& config, const std::string &opt_key, int cur_extruder_id) { + if (printer_extruder_options.find(opt_key) != printer_extruder_options.end()) { + return 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")); + const DynamicPrintConfig& cur_printer_config = wxGetApp().preset_bundle->printers.get_selected_preset().config; + auto opt_extruder_type = dynamic_cast(cur_printer_config.option("extruder_type")); + auto opt_nozzle_volume_type = dynamic_cast(cur_printer_config.option("nozzle_volume_type")); if (!opt_extruder_type || !opt_nozzle_volume_type) return 0; @@ -745,6 +752,7 @@ void ConfigOptionsGroup::back_to_config_value(const DynamicPrintConfig& config, auto opt_id = m_opt_map.find(opt_key)->first; std::string opt_short_key = m_opt_map.at(opt_id).first; int opt_index = m_opt_map.at(opt_id).second; + opt_index = get_extruder_idx(*m_config, opt_short_key, opt_index); value = get_config_value(config, opt_short_key, opt_index); } @@ -1270,17 +1278,11 @@ void ExtruderOptionsGroup::on_change_OG(const t_config_option_key& opt_id, const auto itOption = it->second; const std::string& opt_key = itOption.first; - auto opt = m_config->option(opt_key); - const ConfigOptionVectorBase* opt_vec = dynamic_cast(opt); - if (opt_vec != nullptr) { - for (int opt_index = 0; opt_index < opt_vec->size(); opt_index++) { - this->change_opt_value(opt_key, value, opt_index); - } - } - else { - int opt_index = itOption.second; - this->change_opt_value(opt_key, value, opt_index == -1 ? 0 : opt_index); + int opt_index = itOption.second; + if (printer_extruder_options.find(opt_key) == printer_extruder_options.end()) { + opt_index = get_extruder_idx(*m_config, itOption.first, itOption.second); } + this->change_opt_value(opt_key, value, opt_index == -1 ? 0 : opt_index); } OptionsGroup::on_change_OG(opt_id, value); diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index f661545c16..0cc3d06dd1 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -872,17 +872,28 @@ std::vector Tab::filter_diff_option(const std::vector } return std::make_pair(param_name, index); } - return std::make_pair(value, 0); + return std::make_pair(value, -1); }; 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); + if (name_to_index.second == -1) { + diff_options.emplace_back(option); + continue; + } + + size_t nozzle_nums = wxGetApp().preset_bundle->get_printer_extruder_count(); + std::vector support_indexes; + for (size_t i = 0; i < nozzle_nums; ++i) { + support_indexes.push_back(get_extruder_idx(*m_config, name_to_index.first, i)); + } + auto iter = std::find(support_indexes.begin(), support_indexes.end(), name_to_index.second); + if (iter != support_indexes.end()) { + int extruder_id = std::distance(support_indexes.begin(), iter); + std::string name_to_extruder_id = name_to_index.first + "#" + std::to_string(extruder_id); diff_options.emplace_back(name_to_extruder_id); - } + } } return diff_options; @@ -909,6 +920,7 @@ void Tab::update_changed_ui() it.second = m_opt_status_value; dirty_options = filter_diff_option(dirty_options); + nonsys_options = filter_diff_option(nonsys_options); for (auto opt_key : dirty_options) { m_options_list[opt_key] &= ~osInitValue; @@ -4464,11 +4476,11 @@ 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"); optgroup->append_single_option_line("nozzle_diameter", "", extruder_idx); + optgroup->append_single_option_line("nozzle_volume_type", "", extruder_idx); optgroup->m_on_change = [this, extruder_idx](const t_config_option_key& opt_key, boost::any value) { @@ -4502,7 +4514,6 @@ if (is_marlin_flavor) load_config(new_conf); } } - update_dirty(); on_value_change(opt_key, value); update(); @@ -6148,7 +6159,12 @@ wxSizer* Tab::compatible_widget_create(wxWindow* parent, PresetDependencies &dep return sizer; } -void TabPrinter::set_extruder_volume_type(int extruder_id, NozzleVolumeType type) {} +void TabPrinter::set_extruder_volume_type(int extruder_id, NozzleVolumeType type) +{ + auto nozzle_volumes = m_config->option("nozzle_volume_type"); + assert(nozzle_volumes->values.size() > (size_t)extruder_id); + nozzle_volumes->values[extruder_id] = type; +} // Return a callback to create a TabPrinter widget to edit bed shape wxSizer* TabPrinter::create_bed_shape_widget(wxWindow* parent) diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index c406a4b0e0..7aea5b120e 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -78,7 +78,6 @@ 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; diff --git a/src/slic3r/GUI/Widgets/ComboBox.cpp b/src/slic3r/GUI/Widgets/ComboBox.cpp index 55b8e12bcb..51f97a293a 100644 --- a/src/slic3r/GUI/Widgets/ComboBox.cpp +++ b/src/slic3r/GUI/Widgets/ComboBox.cpp @@ -160,6 +160,7 @@ int ComboBox::Append(const wxString &item, icons.push_back(bitmap); datas.push_back(clientData); types.push_back(wxClientData_None); + SetClientDataType(wxClientData_Void); drop.Invalidate(); return texts.size() - 1; }