ENH: add logic to convert hybrid(auto) to tree(auto) for old 3mf

Change-Id: Id35e28b295be0a4b4398b438d5e6237e05f387e5
This commit is contained in:
lane.wei 2023-02-14 15:09:20 +08:00 committed by Lane.Wei
parent 9dceb42ba3
commit a2431d7965
1 changed files with 70 additions and 0 deletions

View File

@ -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<std::string, std::string>& key_values, std::string& reason)
{
json j;
std::list<std::string> 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<ConfigOptionString*>(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<SupportMaterialStyle>* opt = this->option<ConfigOptionEnum<SupportMaterialStyle>>("support_style", true);
opt->value = smsTreeHybrid;
}
if (is_project_settings) {
std::vector<std::string>& different_settings = this->option<ConfigOptionStrings>("different_settings_to_system", true)->values;
size_t size = different_settings.size();
if (size == 0) {
size = this->option<ConfigOptionStrings>("filament_settings_id")->values.size() + 2;
different_settings.resize(size);
}
std::vector<bool> is_first(size, false);
std::vector<std::vector<std::string>> 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) {