When loading an archive (AMF/3MF/Config), the original name
of the profile is show in braces next to the file name.
This commit is contained in:
parent
1175dc95f6
commit
59510c42d1
2 changed files with 57 additions and 23 deletions
|
@ -427,6 +427,19 @@ Preset& PresetCollection::load_preset(const std::string &path, const std::string
|
||||||
return this->load_preset(path, name, std::move(cfg), select);
|
return this->load_preset(path, name, std::move(cfg), select);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool profile_print_params_same(const DynamicPrintConfig &cfg1, const DynamicPrintConfig &cfg2)
|
||||||
|
{
|
||||||
|
t_config_option_keys diff = cfg1.diff(cfg2);
|
||||||
|
// Following keys are used by the UI, not by the slicing core, therefore they are not important
|
||||||
|
// when comparing profiles for equality. Ignore them.
|
||||||
|
for (const char *key : { "compatible_printers", "compatible_printers_condition", "inherits",
|
||||||
|
"print_settings_id", "filament_settings_id", "printer_settings_id",
|
||||||
|
"printer_model", "printer_variant", "default_print_profile", "default_filament_profile" })
|
||||||
|
diff.erase(std::remove(diff.begin(), diff.end(), key), diff.end());
|
||||||
|
// Preset with the same name as stored inside the config exists.
|
||||||
|
return diff.empty();
|
||||||
|
}
|
||||||
|
|
||||||
// Load a preset from an already parsed config file, insert it into the sorted sequence of presets
|
// Load a preset from an already parsed config file, insert it into the sorted sequence of presets
|
||||||
// and select it, losing previous modifications.
|
// and select it, losing previous modifications.
|
||||||
// In case
|
// In case
|
||||||
|
@ -447,24 +460,40 @@ Preset& PresetCollection::load_external_preset(
|
||||||
cfg.apply_only(config, cfg.keys(), true);
|
cfg.apply_only(config, cfg.keys(), true);
|
||||||
// Is there a preset already loaded with the name stored inside the config?
|
// Is there a preset already loaded with the name stored inside the config?
|
||||||
std::deque<Preset>::iterator it = original_name.empty() ? m_presets.end() : this->find_preset_internal(original_name);
|
std::deque<Preset>::iterator it = original_name.empty() ? m_presets.end() : this->find_preset_internal(original_name);
|
||||||
if (it != m_presets.end()) {
|
if (it != m_presets.end() && profile_print_params_same(it->config, cfg)) {
|
||||||
t_config_option_keys diff = it->config.diff(cfg);
|
// The preset exists and it matches the values stored inside config.
|
||||||
// Following keys are used by the UI, not by the slicing core, therefore they are not important
|
if (select)
|
||||||
// when comparing profiles for equality. Ignore them.
|
this->select_preset(it - m_presets.begin());
|
||||||
for (const char *key : { "compatible_printers", "compatible_printers_condition", "inherits",
|
return *it;
|
||||||
"print_settings_id", "filament_settings_id", "printer_settings_id",
|
}
|
||||||
"printer_model", "printer_variant", "default_print_profile", "default_filament_profile" })
|
// The external preset does not match an internal preset, load the external preset.
|
||||||
diff.erase(std::remove(diff.begin(), diff.end(), key), diff.end());
|
std::string new_name;
|
||||||
// Preset with the same name as stored inside the config exists.
|
for (size_t idx = 0;; ++ idx) {
|
||||||
if (diff.empty()) {
|
std::string suffix;
|
||||||
|
if (original_name.empty()) {
|
||||||
|
if (idx > 0)
|
||||||
|
suffix = " (" + std::to_string(idx) + ")";
|
||||||
|
} else {
|
||||||
|
if (idx == 0)
|
||||||
|
suffix = " (" + original_name + ")";
|
||||||
|
else
|
||||||
|
suffix = " (" + original_name + "-" + std::to_string(idx) + ")";
|
||||||
|
}
|
||||||
|
new_name = name + suffix;
|
||||||
|
it = this->find_preset_internal(new_name);
|
||||||
|
if (it == m_presets.end())
|
||||||
|
// Unique profile name. Insert a new profile.
|
||||||
|
break;
|
||||||
|
if (profile_print_params_same(it->config, cfg)) {
|
||||||
// The preset exists and it matches the values stored inside config.
|
// The preset exists and it matches the values stored inside config.
|
||||||
if (select)
|
if (select)
|
||||||
this->select_preset(it - m_presets.begin());
|
this->select_preset(it - m_presets.begin());
|
||||||
return *it;
|
return *it;
|
||||||
}
|
}
|
||||||
|
// Form another profile name.
|
||||||
}
|
}
|
||||||
// The external preset does not match an internal preset, load the external preset.
|
// Insert a new profile.
|
||||||
Preset &preset = this->load_preset(path, name, std::move(cfg), select);
|
Preset &preset = this->load_preset(path, new_name, std::move(cfg), select);
|
||||||
preset.is_external = true;
|
preset.is_external = true;
|
||||||
return preset;
|
return preset;
|
||||||
}
|
}
|
||||||
|
|
|
@ -618,21 +618,26 @@ void PresetBundle::load_config_file_config(const std::string &name_or_path, bool
|
||||||
// Load the configs into this->filaments and make them active.
|
// Load the configs into this->filaments and make them active.
|
||||||
this->filament_presets.clear();
|
this->filament_presets.clear();
|
||||||
for (size_t i = 0; i < configs.size(); ++ i) {
|
for (size_t i = 0; i < configs.size(); ++ i) {
|
||||||
char suffix[64];
|
|
||||||
if (i == 0)
|
|
||||||
suffix[0] = 0;
|
|
||||||
else
|
|
||||||
sprintf(suffix, " (%d)", i);
|
|
||||||
std::string new_name = name + suffix;
|
|
||||||
// Load all filament presets, but only select the first one in the preset dialog.
|
// Load all filament presets, but only select the first one in the preset dialog.
|
||||||
|
Preset *loaded = nullptr;
|
||||||
if (is_external)
|
if (is_external)
|
||||||
this->filaments.load_external_preset(name_or_path, new_name,
|
loaded = &this->filaments.load_external_preset(name_or_path, name,
|
||||||
(i < old_filament_profile_names->values.size()) ? old_filament_profile_names->values[i] : "",
|
(i < old_filament_profile_names->values.size()) ? old_filament_profile_names->values[i] : "",
|
||||||
std::move(configs[i]), i == 0);
|
std::move(configs[i]), i == 0);
|
||||||
else
|
else {
|
||||||
this->filaments.load_preset(this->filaments.path_from_name(new_name),
|
// Used by the config wizard when creating a custom setup.
|
||||||
new_name, std::move(configs[i]), i == 0).save();
|
// Therefore this block should only be called for a single extruder.
|
||||||
this->filament_presets.emplace_back(new_name);
|
char suffix[64];
|
||||||
|
if (i == 0)
|
||||||
|
suffix[0] = 0;
|
||||||
|
else
|
||||||
|
sprintf(suffix, "%d", i);
|
||||||
|
std::string new_name = name + suffix;
|
||||||
|
loaded = &this->filaments.load_preset(this->filaments.path_from_name(new_name),
|
||||||
|
new_name, std::move(configs[i]), i == 0);
|
||||||
|
loaded->save();
|
||||||
|
}
|
||||||
|
this->filament_presets.emplace_back(loaded->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue