Fix for SPE-2039 : Wrong preset selection, when loading configuration from 3mf.

Bug description: If all new presets are actualized from current update
but some of them isn't installed (doesn't selected in ConfigWizard),
and user try to load 3mf with those non-installed presets, than first visible preset is selected
instead of temporary installed preset.

+ Update dirty state for edited preset only it's needed.
This commit is contained in:
YuSanka 2023-11-14 14:58:19 +01:00
parent ff8a351a1b
commit f69b1a2247

View File

@ -814,8 +814,8 @@ std::pair<Preset*, bool> PresetCollection::load_external_preset(
it = this->find_preset_renamed(original_name); it = this->find_preset_renamed(original_name);
found = it != m_presets.end(); found = it != m_presets.end();
} }
if (found && profile_print_params_same(it->config, cfg)) { if (found && profile_print_params_same(it->config, cfg) && it->is_visible) {
// The preset exists and it matches the values stored inside config. // The preset exists and is visible and it matches the values stored inside config.
if (select == LoadAndSelect::Always) if (select == LoadAndSelect::Always)
this->select_preset(it - m_presets.begin()); this->select_preset(it - m_presets.begin());
return std::make_pair(&(*it), false); return std::make_pair(&(*it), false);
@ -838,19 +838,23 @@ std::pair<Preset*, bool> PresetCollection::load_external_preset(
// Select the existing preset and override it with new values, so that // Select the existing preset and override it with new values, so that
// the differences will be shown in the preset editor against the referenced profile. // the differences will be shown in the preset editor against the referenced profile.
this->select_preset(it - m_presets.begin()); this->select_preset(it - m_presets.begin());
// The source config may contain keys from many possible preset types. Just copy those that relate to this preset.
// Following keys are not used neither by the UI nor by the slicing core, therefore they are not important // update dirty state only if it's needed
// Erase them from config appl to avoid redundant "dirty" parameter in loaded preset. if (!profile_print_params_same(it->config, cfg)) {
for (const char* key : { "print_settings_id", "filament_settings_id", "sla_print_settings_id", "sla_material_settings_id", "printer_settings_id", // The source config may contain keys from many possible preset types. Just copy those that relate to this preset.
"printer_model", "printer_variant", "default_print_profile", "default_filament_profile", "default_sla_print_profile", "default_sla_material_profile" })
keys.erase(std::remove(keys.begin(), keys.end(), key), keys.end());
this->get_edited_preset().config.apply_only(combined_config, keys, true); // Following keys are not used neither by the UI nor by the slicing core, therefore they are not important
this->update_dirty(); // Erase them from config apply to avoid redundant "dirty" parameter in loaded preset.
// Don't save the newly loaded project as a "saved into project" state. for (const char* key : { "print_settings_id", "filament_settings_id", "sla_print_settings_id", "sla_material_settings_id", "printer_settings_id",
//update_saved_preset_from_current_preset(); "printer_model", "printer_variant", "default_print_profile", "default_filament_profile", "default_sla_print_profile", "default_sla_material_profile" })
assert(this->get_edited_preset().is_dirty); keys.erase(std::remove(keys.begin(), keys.end(), key), keys.end());
this->get_edited_preset().config.apply_only(combined_config, keys, true);
this->update_dirty();
// Don't save the newly loaded project as a "saved into project" state.
//update_saved_preset_from_current_preset();
assert(this->get_edited_preset().is_dirty);
}
return std::make_pair(&(*it), this->get_edited_preset().is_dirty); return std::make_pair(&(*it), this->get_edited_preset().is_dirty);
} }
if (inherits.empty()) { if (inherits.empty()) {