mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-16 18:12:10 +00:00
ENH: config: add nill load/save logic for user config
Change-Id: I8da6c5b345cc088862f2c720aeb742b9617ff3e7 (cherry picked from commit 603f93d97f0ad70e01e120854887142ab05ee089)
This commit is contained in:
@@ -7534,6 +7534,8 @@ std::set<std::string> printer_options_with_variant_2 = {
|
||||
"machine_max_jerk_e"
|
||||
};
|
||||
|
||||
std::set<std::string> empty_options;
|
||||
|
||||
DynamicPrintConfig DynamicPrintConfig::full_print_config()
|
||||
{
|
||||
return DynamicPrintConfig((const PrintRegionConfig&)FullPrintConfig::defaults());
|
||||
@@ -8790,7 +8792,7 @@ void DynamicPrintConfig::update_non_diff_values_to_base_config(DynamicPrintConfi
|
||||
int stride = 1;
|
||||
if (key_set2.find(opt) != key_set2.end())
|
||||
stride = 2;
|
||||
opt_vec_src->set_with_keep(opt_vec_dest, variant_index, stride);
|
||||
opt_vec_src->set_with_restore(opt_vec_dest, variant_index, stride);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8798,6 +8800,81 @@ void DynamicPrintConfig::update_non_diff_values_to_base_config(DynamicPrintConfi
|
||||
return;
|
||||
}
|
||||
|
||||
void DynamicPrintConfig::update_diff_values_to_child_config(DynamicPrintConfig& new_config, std::string extruder_id_name, std::string extruder_variant_name, std::set<std::string>& key_set1, std::set<std::string>& key_set2)
|
||||
{
|
||||
std::vector<int> cur_extruder_ids, target_extruder_ids, variant_index;
|
||||
std::vector<std::string> cur_extruder_variants, target_extruder_variants;
|
||||
|
||||
if (!extruder_id_name.empty()) {
|
||||
if (this->option(extruder_id_name))
|
||||
cur_extruder_ids = this->option<ConfigOptionInts>(extruder_id_name)->values;
|
||||
if (new_config.option(extruder_id_name))
|
||||
target_extruder_ids = new_config.option<ConfigOptionInts>(extruder_id_name)->values;
|
||||
}
|
||||
if (this->option(extruder_variant_name))
|
||||
cur_extruder_variants = this->option<ConfigOptionStrings>(extruder_variant_name, true)->values;
|
||||
if (new_config.option(extruder_variant_name))
|
||||
target_extruder_variants = new_config.option<ConfigOptionStrings>(extruder_variant_name, true)->values;
|
||||
|
||||
int cur_variant_count = cur_extruder_variants.size();
|
||||
int target_variant_count = target_extruder_variants.size();
|
||||
|
||||
variant_index.resize(cur_variant_count, -1);
|
||||
if (target_variant_count == 0) {
|
||||
variant_index[0] = 0;
|
||||
}
|
||||
else if ((cur_extruder_ids.size() > 0) && cur_variant_count != cur_extruder_ids.size()){
|
||||
//should not happen
|
||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(" size of %1% = %2%, not equal to size of %3% = %4%")
|
||||
%extruder_variant_name %cur_variant_count %extruder_id_name %cur_extruder_ids.size();
|
||||
}
|
||||
else if ((target_extruder_ids.size() > 0) && target_variant_count != target_extruder_ids.size()){
|
||||
//should not happen
|
||||
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(" size of %1% = %2%, not equal to size of %3% = %4%")
|
||||
%extruder_variant_name %target_variant_count %extruder_id_name %target_extruder_ids.size();
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < cur_variant_count; i++)
|
||||
{
|
||||
for (int j = 0; j < target_variant_count; j++)
|
||||
{
|
||||
if ((cur_extruder_variants[i] == target_extruder_variants[j])
|
||||
&&(cur_extruder_ids.empty() || (cur_extruder_ids[i] == target_extruder_ids[j])))
|
||||
{
|
||||
variant_index[i] = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const t_config_option_keys &keys = new_config.keys();
|
||||
for (auto& opt : keys) {
|
||||
if ((opt == extruder_id_name) || (opt == extruder_variant_name))
|
||||
continue;
|
||||
ConfigOption *opt_src = this->option(opt);
|
||||
const ConfigOption *opt_target = new_config.option(opt);
|
||||
if (opt_src && opt_target && (*opt_src != *opt_target)) {
|
||||
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(" change key %1% from base_value %2% to child's value %3%")
|
||||
%opt %(opt_src->serialize()) %(opt_target->serialize());
|
||||
if (opt_target->is_scalar()
|
||||
|| ((key_set1.find(opt) == key_set1.end()) && (key_set2.empty() || (key_set2.find(opt) == key_set2.end())))) {
|
||||
//nothing to do, keep the original one
|
||||
opt_src->set(opt_target);
|
||||
}
|
||||
else {
|
||||
ConfigOptionVectorBase* opt_vec_src = static_cast<ConfigOptionVectorBase*>(opt_src);
|
||||
const ConfigOptionVectorBase* opt_vec_dest = static_cast<const ConfigOptionVectorBase*>(opt_target);
|
||||
int stride = 1;
|
||||
if (key_set2.find(opt) != key_set2.end())
|
||||
stride = 2;
|
||||
opt_vec_src->set_only_diff(opt_vec_dest, variant_index, stride);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
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<int>& f_maps)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user