diff --git a/src/libslic3r/Config.hpp b/src/libslic3r/Config.hpp index f3c09033c..14293a84e 100644 --- a/src/libslic3r/Config.hpp +++ b/src/libslic3r/Config.hpp @@ -292,7 +292,7 @@ public: return *this != *rhs; } // Apply an override option, possibly a nullable one. - virtual bool apply_override(const ConfigOption *rhs) { + virtual bool apply_override(const ConfigOption *rhs, std::vector& default_index) { if (*this == *rhs) return false; *this = *rhs; @@ -686,7 +686,7 @@ public: } // Apply an override option, possibly a nullable one. // assume lhs is not nullable even it is nullable - bool apply_override(const ConfigOption *rhs) override { + bool apply_override(const ConfigOption *rhs, std::vector& default_index) override { //if (this->nullable()) // throw ConfigurationError("Cannot override a nullable ConfigOption."); if (rhs->type() != this->type()) @@ -710,14 +710,16 @@ public: else this->values.resize(rhs_vec->size(), this->values.front()); - bool modified = false; - auto default_value = this->values[0]; + assert(default_index.size() == rhs_vec->size()); + + bool modified = false; + std::vector default_value = this->values; for (size_t i = 0; i < rhs_vec->size(); ++i) { if (!rhs_vec->is_nil(i)) { this->values[i] = rhs_vec->values[i]; modified = true; } else { - this->values[i] = default_value; + this->values[i] = default_value[default_index[i]-1]; } } return modified; diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 40fd16e93..239160612 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -2371,8 +2371,26 @@ void Print::update_filament_maps_to_config(std::vector f_maps) m_full_print_config = m_ori_full_print_config; m_full_print_config.update_values_to_printer_extruders_for_multiple_filaments(m_full_print_config, filament_options_with_variant, "filament_self_index", "filament_extruder_variant"); + const std::vector &extruder_retract_keys = print_config_def.extruder_retract_keys(); + const std::string filament_prefix = "filament_"; + t_config_option_keys print_diff; + DynamicPrintConfig filament_overrides; + for (auto& opt_key: extruder_retract_keys) + { + const ConfigOption *opt_new_filament = m_full_print_config.option(filament_prefix + opt_key); + const ConfigOption *opt_new_machine = m_full_print_config.option(opt_key); + const ConfigOption *opt_old_machine = m_config.option(opt_key); + + if (opt_new_filament) + compute_filament_override_value(opt_key, opt_old_machine, opt_new_machine, opt_new_filament, m_full_print_config, print_diff, filament_overrides, f_maps); + } + t_config_option_keys keys(filament_options_with_variant.begin(), filament_options_with_variant.end()); m_config.apply_only(m_full_print_config, keys, true); + if (!print_diff.empty()) { + m_placeholder_parser.apply_config(filament_overrides); + m_config.apply(filament_overrides); + } } m_has_auto_filament_map_result = true; } diff --git a/src/libslic3r/PrintApply.cpp b/src/libslic3r/PrintApply.cpp index f729273e3..1d0fec602 100644 --- a/src/libslic3r/PrintApply.cpp +++ b/src/libslic3r/PrintApply.cpp @@ -217,7 +217,8 @@ static t_config_option_keys print_config_diffs( const PrintConfig ¤t_config, const DynamicPrintConfig &new_full_config, DynamicPrintConfig &filament_overrides, - int plate_index) + int plate_index, + std::vector& filament_maps) { const std::vector &extruder_retract_keys = print_config_def.extruder_retract_keys(); const std::string filament_prefix = "filament_"; @@ -231,26 +232,9 @@ static t_config_option_keys print_config_diffs( //FIXME This may happen when executing some test cases. continue; 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. - bool overriden = opt_new->overriden_by(opt_new_filament); - if (overriden || *opt_old != *opt_new) { - auto opt_copy = opt_new->clone(); - if (!((opt_key == "long_retractions_when_cut" || opt_key == "retraction_distances_when_cut") - && new_full_config.option("enable_long_retraction_when_cut")->value != LongRectrationLevel::EnableFilament)) // ugly code, remove it later if firmware supports - opt_copy->apply_override(opt_new_filament); - bool changed = *opt_old != *opt_copy; - if (changed) - print_diff.emplace_back(opt_key); - if (changed || overriden) { - if ((opt_key == "long_retractions_when_cut" || opt_key == "retraction_distances_when_cut") - && new_full_config.option("enable_long_retraction_when_cut")->value != LongRectrationLevel::EnableFilament) - continue; - // filament_overrides will be applied to the placeholder parser, which layers these parameters over full_print_config. - filament_overrides.set_key_value(opt_key, opt_copy); - } else - delete opt_copy; - } + + if (opt_new_filament != nullptr) { + compute_filament_override_value(opt_key, opt_old, opt_new, opt_new_filament, new_full_config, print_diff, filament_overrides, filament_maps); } else if (*opt_new != *opt_old) { //BBS: add plate_index logic for wipe_tower_x/wipe_tower_y if (!opt_key.compare("wipe_tower_x") || !opt_key.compare("wipe_tower_y")) { @@ -1150,11 +1134,12 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_ print_variant_index[e_index] = e_index; } } + std::vector filament_maps = new_full_config.option("filament_map")->values; // Find modified keys of the various configs. Resolve overrides extruder retract values by filament profiles. DynamicPrintConfig filament_overrides; //BBS: add plate index - t_config_option_keys print_diff = print_config_diffs(m_config, new_full_config, filament_overrides, this->m_plate_index); + t_config_option_keys print_diff = print_config_diffs(m_config, new_full_config, filament_overrides, this->m_plate_index, filament_maps); t_config_option_keys full_config_diff = full_print_config_diffs(m_full_print_config, new_full_config, this->m_plate_index); // Collect changes to object and region configs. t_config_option_keys object_diff = m_default_object_config.diff(new_full_config); diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 7e37e4ea0..716c8b803 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -6664,6 +6664,41 @@ void update_static_print_config_from_dynamic(ConfigBase& config, const DynamicPr config.apply(dest_config, true); } +void compute_filament_override_value(const std::string& opt_key, const ConfigOption *opt_old_machine, const ConfigOption *opt_new_machine, const ConfigOption *opt_new_filament, const DynamicPrintConfig& new_full_config, + t_config_option_keys& diff_keys, DynamicPrintConfig& filament_overrides, std::vector& f_maps) +{ + bool is_nil = opt_new_filament->is_nil(); + + // ugly code, for these params, we should ignore the value in filament params + ConfigOptionBoolsNullable opt_long_retraction_default; + if (opt_key == "long_retractions_when_cut" && new_full_config.option("enable_long_retraction_when_cut")->value != LongRectrationLevel::EnableFilament) { + auto ptr = dynamic_cast(opt_new_filament); + for (size_t idx = 0; idx < ptr->values.size(); ++idx) + opt_long_retraction_default.values.push_back(ptr->nil_value()); + opt_new_filament = &opt_long_retraction_default; + } + + ConfigOptionFloatsNullable opt_retraction_distance_default; + if (opt_key == "retraction_distances_when_cut" && new_full_config.option("enable_long_retraction_when_cut")->value != LongRectrationLevel::EnableFilament) { + auto ptr = dynamic_cast(opt_new_filament); + for (size_t idx = 0; idx < ptr->values.size(); ++idx) + opt_long_retraction_default.values.push_back(ptr->nil_value()); + opt_new_filament = &opt_retraction_distance_default; + } + + auto opt_copy = opt_new_machine->clone(); + opt_copy->apply_override(opt_new_filament, f_maps); + bool changed = *opt_old_machine != *opt_copy; + + if (changed) { + diff_keys.emplace_back(opt_key); + filament_overrides.set_key_value(opt_key, opt_copy); + } + else + delete opt_copy; +} + + //BBS: pass map to recording all invalid valies //FIXME localize this function. std::map validate(const FullPrintConfig &cfg, bool under_cli) diff --git a/src/libslic3r/PrintConfig.hpp b/src/libslic3r/PrintConfig.hpp index ea43f2b9a..02cd84cc3 100644 --- a/src/libslic3r/PrintConfig.hpp +++ b/src/libslic3r/PrintConfig.hpp @@ -531,6 +531,8 @@ extern std::set printer_options_with_variant_2; extern std::set empty_options; extern void update_static_print_config_from_dynamic(ConfigBase& config, const DynamicPrintConfig& dest_config, std::vector variant_index, std::set& key_set1, int stride = 1); +extern void compute_filament_override_value(const std::string& opt_key, const ConfigOption *opt_old_machine, const ConfigOption *opt_new_machine, const ConfigOption *opt_new_filament, const DynamicPrintConfig& new_full_config, + t_config_option_keys& diff_keys, DynamicPrintConfig& filament_overrides, std::vector& f_maps); void handle_legacy_sla(DynamicPrintConfig &config);