suport renamed_from

This commit is contained in:
SoftFever 2025-01-19 00:39:45 +08:00
parent 26a55a1267
commit 7179797d55
4 changed files with 19 additions and 7 deletions

View file

@ -839,8 +839,9 @@ int ConfigBase::load_from_json(const std::string &file, ConfigSubstitutionContex
} }
else if (!load_inherits_to_config && boost::iequals(it.key(), BBL_JSON_KEY_INHERITS)) { else if (!load_inherits_to_config && boost::iequals(it.key(), BBL_JSON_KEY_INHERITS)) {
key_values.emplace(BBL_JSON_KEY_INHERITS, it.value()); key_values.emplace(BBL_JSON_KEY_INHERITS, it.value());
} } else if (boost::iequals(it.key(), ORCA_JSON_KEY_RENAMED_FROM)) {
else { key_values.emplace(ORCA_JSON_KEY_RENAMED_FROM, it.value());
} else {
t_config_option_key opt_key = it.key(); t_config_option_key opt_key = it.key();
std::string value_str; std::string value_str;

View file

@ -1137,7 +1137,7 @@ void PresetCollection::load_presets(
if (key_values.find("instantiation") != key_values.end()) if (key_values.find("instantiation") != key_values.end())
preset.is_visible = key_values["instantiation"] != "false"; preset.is_visible = key_values["instantiation"] != "false";
//BBS: use inherit config as the base //Orca: find and use the inherit config as the base
Preset* inherit_preset = nullptr; Preset* inherit_preset = nullptr;
ConfigOption* inherits_config = config.option(BBL_JSON_KEY_INHERITS); ConfigOption* inherits_config = config.option(BBL_JSON_KEY_INHERITS);
@ -1146,6 +1146,12 @@ void PresetCollection::load_presets(
ConfigOptionString * option_str = dynamic_cast<ConfigOptionString *> (inherits_config); ConfigOptionString * option_str = dynamic_cast<ConfigOptionString *> (inherits_config);
std::string inherits_value = option_str->value; std::string inherits_value = option_str->value;
inherit_preset = this->find_preset(inherits_value, false, true); inherit_preset = this->find_preset(inherits_value, false, true);
// Orca: try to find if the parent preset has been renamed
if (inherit_preset == nullptr) {
auto it = this->find_preset_renamed(inherits_value);
if (it != m_presets.end())
inherit_preset = &(*it);
}
} else { } else {
; ;
} }

View file

@ -63,7 +63,8 @@
#define BBL_JSON_KEY_DEFAULT_MATERIALS "default_materials" #define BBL_JSON_KEY_DEFAULT_MATERIALS "default_materials"
#define BBL_JSON_KEY_MODEL_ID "model_id" #define BBL_JSON_KEY_MODEL_ID "model_id"
//BBL: json path // Orca extension
#define ORCA_JSON_KEY_RENAMED_FROM "renamed_from"
namespace Slic3r { namespace Slic3r {

View file

@ -3533,6 +3533,7 @@ std::pair<PresetsConfigSubstitutions, size_t> PresetBundle::load_vendor_configs_
//parse the json elements //parse the json elements
DynamicPrintConfig config_src; DynamicPrintConfig config_src;
std::string _renamed_from_str;
config_src.load_from_json(subfile, substitution_context, false, key_values, reason); config_src.load_from_json(subfile, substitution_context, false, key_values, reason);
if (!reason.empty()) { if (!reason.empty()) {
++m_errors; ++m_errors;
@ -3586,9 +3587,12 @@ std::pair<PresetsConfigSubstitutions, size_t> PresetBundle::load_vendor_configs_
} }
if (config.has("alias")) if (config.has("alias"))
alias_name = (dynamic_cast<const ConfigOptionString *>(config.option("alias")))->value; alias_name = (dynamic_cast<const ConfigOptionString *>(config.option("alias")))->value;
if (config.has("renamed_from")) {
const ConfigOptionVectorBase *vec = static_cast<const ConfigOptionVectorBase*>(config.option("renamed_from")); if (key_values.find(ORCA_JSON_KEY_RENAMED_FROM) != key_values.end()) {
renamed_from = vec->vserialize(); if (!unescape_strings_cstyle(key_values[ORCA_JSON_KEY_RENAMED_FROM], renamed_from)) {
BOOST_LOG_TRIVIAL(error) << "Error in a Config \"" << path << "\": The preset \"" << preset_name
<< "\" contains invalid \"renamed_from\" key, which is being ignored.";
}
} }
Preset::normalize(config); Preset::normalize(config);
} }