mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2026-02-15 08:59:39 -07:00
FIX: add protection when sync presets from other printers
jira:STUDIO-12575 Signed-off-by: xun.zhang <xun.zhang@bambulab.com> Change-Id: I5a22129fe12a3600dcc4e3f387374122e349e38c (cherry picked from commit 21863f925db1eeb1db79ba5859840aa23f852180)
This commit is contained in:
parent
af0c9f7ce2
commit
e1626c26b1
3 changed files with 12 additions and 7 deletions
|
|
@ -154,7 +154,7 @@ static const std::unordered_map<std::string, std::string> pre_family_model_map {
|
|||
|
||||
|
||||
// 中间版本兼容性处理,如果是nil值,先改成default值,再进行扩展
|
||||
void extend_default_config_length(DynamicPrintConfig& config, const DynamicPrintConfig& defaults)
|
||||
void extend_default_config_length(DynamicPrintConfig& config, const bool set_nil_to_default, const DynamicPrintConfig& defaults)
|
||||
{
|
||||
constexpr int default_param_length = 1;
|
||||
int filament_variant_length = default_param_length;
|
||||
|
|
@ -171,7 +171,7 @@ void extend_default_config_length(DynamicPrintConfig& config, const DynamicPrint
|
|||
auto replace_nil_and_resize = [&](const std::string & key, int length){
|
||||
ConfigOption* raw_ptr = config.option(key);
|
||||
ConfigOptionVectorBase* opt_vec = static_cast<ConfigOptionVectorBase *>(raw_ptr);
|
||||
if(raw_ptr->is_nil() && defaults.has(key) && std::find(filament_extruder_override_keys.begin(), filament_extruder_override_keys.end(), key) == filament_extruder_override_keys.end()){
|
||||
if(set_nil_to_default && raw_ptr->is_nil() && defaults.has(key) && std::find(filament_extruder_override_keys.begin(), filament_extruder_override_keys.end(), key) == filament_extruder_override_keys.end()){
|
||||
opt_vec->clear();
|
||||
opt_vec->resize(length, defaults.option(key));
|
||||
}
|
||||
|
|
@ -1297,6 +1297,7 @@ void PresetCollection::load_presets(
|
|||
if (inherit_preset) {
|
||||
preset.config = inherit_preset->config;
|
||||
preset.filament_id = inherit_preset->filament_id;
|
||||
extend_default_config_length(config, false, {});
|
||||
preset.config.update_diff_values_to_child_config(config, extruder_id_name, extruder_variant_name, *key_set1, *key_set2);
|
||||
}
|
||||
else {
|
||||
|
|
@ -1310,7 +1311,7 @@ void PresetCollection::load_presets(
|
|||
// Find a default preset for the config. The PrintPresetCollection provides different default preset based on the "printer_technology" field.
|
||||
preset.config = default_preset.config;
|
||||
preset.config.apply(std::move(config));
|
||||
extend_default_config_length(preset.config, default_preset.config);
|
||||
extend_default_config_length(preset.config, true, default_preset.config);
|
||||
}
|
||||
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " load preset: " << name << " and filament_id: " << preset.filament_id << " and base_id: " << preset.base_id;
|
||||
|
||||
|
|
@ -1867,8 +1868,10 @@ bool PresetCollection::load_user_preset(std::string name, std::map<std::string,
|
|||
}
|
||||
// Find a default preset for the config. The PrintPresetCollection provides different default preset based on the "printer_technology" field.
|
||||
new_config = default_preset.config;
|
||||
extend_default_config_length(new_config, default_preset.config);
|
||||
}
|
||||
|
||||
extend_default_config_length(cloud_config, false, {});
|
||||
|
||||
if (inherit_preset) {
|
||||
std::string extruder_id_name, extruder_variant_name;
|
||||
std::set<std::string> *key_set1 = nullptr, *key_set2 = nullptr;
|
||||
|
|
@ -1876,8 +1879,10 @@ bool PresetCollection::load_user_preset(std::string name, std::map<std::string,
|
|||
|
||||
new_config.update_diff_values_to_child_config(cloud_config, extruder_id_name, extruder_variant_name, *key_set1, *key_set2);
|
||||
}
|
||||
else
|
||||
else{
|
||||
new_config.apply(std::move(cloud_config));
|
||||
extend_default_config_length(new_config, true, default_preset.config);
|
||||
}
|
||||
Preset::normalize(new_config);
|
||||
// Report configuration fields, which are misplaced into a wrong group.
|
||||
std::string incorrect_keys = Preset::remove_invalid_keys(new_config, default_preset.config);
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ extern int get_values_from_json(std::string file_path, std::vector<std::string>&
|
|||
|
||||
extern ConfigFileType guess_config_file_type(const boost::property_tree::ptree &tree);
|
||||
|
||||
extern void extend_default_config_length(DynamicPrintConfig& config, const DynamicPrintConfig& defaults);
|
||||
extern void extend_default_config_length(DynamicPrintConfig& config, const bool set_nil_to_default, const DynamicPrintConfig& defaults);
|
||||
|
||||
class VendorProfile
|
||||
{
|
||||
|
|
|
|||
|
|
@ -924,7 +924,7 @@ bool PresetBundle::import_json_presets(PresetsConfigSubstitutions & s
|
|||
const Preset &default_preset = collection->default_preset_for(config);
|
||||
new_config = default_preset.config;
|
||||
new_config.apply(std::move(config));
|
||||
extend_default_config_length(new_config, default_preset.config);
|
||||
extend_default_config_length(new_config, true, default_preset.config);
|
||||
}
|
||||
|
||||
Preset &preset = collection->load_preset(collection->path_from_name(name, inherit_preset == nullptr), name, std::move(new_config), false);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue