diff --git a/src/libslic3r/Config.cpp b/src/libslic3r/Config.cpp index 382cfcc86..1753318f2 100644 --- a/src/libslic3r/Config.cpp +++ b/src/libslic3r/Config.cpp @@ -750,6 +750,9 @@ ConfigSubstitutions ConfigBase::load_from_json(const std::string &file, ForwardC int ConfigBase::load_from_json(const std::string &file, ConfigSubstitutionContext& substitution_context, bool load_inherits_to_config, std::map& key_values, std::string& reason) { json j; + std::list different_settings_append; + std::string new_support_style; + bool is_project_settings = false; try { boost::nowide::ifstream ifs(file); ifs >> j; @@ -769,6 +772,8 @@ int ConfigBase::load_from_json(const std::string &file, ConfigSubstitutionContex } else if (boost::iequals(it.key(), BBL_JSON_KEY_NAME)) { key_values.emplace(BBL_JSON_KEY_NAME, it.value()); + if (it.value() == "project_settings") + is_project_settings = true; } else if (boost::iequals(it.key(), BBL_JSON_KEY_URL)) { key_values.emplace(BBL_JSON_KEY_URL, it.value()); @@ -798,6 +803,15 @@ int ConfigBase::load_from_json(const std::string &file, ConfigSubstitutionContex if (it.value().is_string()) { //bool test1 = (it.key() == std::string("end_gcode")); this->set_deserialize(opt_key, it.value(), substitution_context); + //some logic for special values + if (opt_key == "support_type") { + //std::string new_value = dynamic_cast(this->option(opt_key))->value; + if (it.value() == "hybrid(auto)") { + different_settings_append.push_back(opt_key); + different_settings_append.push_back("support_style"); + new_support_style = "tree_hybrid"; + } + } } else if (it.value().is_array()) { t_config_option_key opt_key_src = opt_key; @@ -863,6 +877,62 @@ int ConfigBase::load_from_json(const std::string &file, ConfigSubstitutionContex } } } + if (!different_settings_append.empty()) { + if (!new_support_style.empty()) { + ConfigOptionEnum* opt = this->option>("support_style", true); + opt->value = smsTreeHybrid; + } + if (is_project_settings) { + std::vector& different_settings = this->option("different_settings_to_system", true)->values; + size_t size = different_settings.size(); + if (size == 0) { + size = this->option("filament_settings_id")->values.size() + 2; + different_settings.resize(size); + } + + std::vector is_first(size, false); + std::vector> original_diffs(size); + for (int index = 0; index < size; index++) + { + if (different_settings[index].empty()) { + is_first[index] = true; + } + else { + Slic3r::unescape_strings_cstyle(different_settings[index], original_diffs[index]); + } + } + + for (auto diff_key : different_settings_append) + { + //get the index in the group + int index = 0; + bool need_insert = true; + if (diff_key == "support_type") + index = 0; + else if (diff_key == "support_style") + index = 0; + + //check whether exist firstly + if (!original_diffs[index].empty()) { + for (int j = 0; j < original_diffs[index].size(); j++) { + if (original_diffs[index][j] == diff_key) { + need_insert = false; + break; + } + } + } + if (!need_insert) + continue; + + //insert this key + if (!is_first[index]) + different_settings[index] += ";"; + else + is_first[index] = false; + different_settings[index] += diff_key; + } + } + } return 0; } catch (const std::ifstream::failure &err) {