Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbubnikv <bubnikv@gmail.com>2018-06-26 12:31:01 +0300
committerbubnikv <bubnikv@gmail.com>2018-06-26 12:31:01 +0300
commit59510c42d1b2e03a9d08dedc5d330801f12e269a (patch)
tree2e1537a775b3ca3f65f2861f57094c58b71f645e
parent1175dc95f688a8b17e75a7cdf5ef1b472905bede (diff)
When loading an archive (AMF/3MF/Config), the original name
of the profile is show in braces next to the file name.
-rw-r--r--xs/src/slic3r/GUI/Preset.cpp53
-rw-r--r--xs/src/slic3r/GUI/PresetBundle.cpp27
2 files changed, 57 insertions, 23 deletions
diff --git a/xs/src/slic3r/GUI/Preset.cpp b/xs/src/slic3r/GUI/Preset.cpp
index 120e1c9a7..d52ea6215 100644
--- a/xs/src/slic3r/GUI/Preset.cpp
+++ b/xs/src/slic3r/GUI/Preset.cpp
@@ -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);
}
+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
// and select it, losing previous modifications.
// In case
@@ -447,24 +460,40 @@ Preset& PresetCollection::load_external_preset(
cfg.apply_only(config, cfg.keys(), true);
// 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);
- if (it != m_presets.end()) {
- t_config_option_keys diff = it->config.diff(cfg);
- // 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.
- if (diff.empty()) {
+ if (it != m_presets.end() && profile_print_params_same(it->config, cfg)) {
+ // The preset exists and it matches the values stored inside config.
+ if (select)
+ this->select_preset(it - m_presets.begin());
+ return *it;
+ }
+ // The external preset does not match an internal preset, load the external preset.
+ std::string new_name;
+ for (size_t idx = 0;; ++ idx) {
+ 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.
if (select)
this->select_preset(it - m_presets.begin());
return *it;
}
+ // Form another profile name.
}
- // The external preset does not match an internal preset, load the external preset.
- Preset &preset = this->load_preset(path, name, std::move(cfg), select);
+ // Insert a new profile.
+ Preset &preset = this->load_preset(path, new_name, std::move(cfg), select);
preset.is_external = true;
return preset;
}
diff --git a/xs/src/slic3r/GUI/PresetBundle.cpp b/xs/src/slic3r/GUI/PresetBundle.cpp
index 147975f16..fcf8ce859 100644
--- a/xs/src/slic3r/GUI/PresetBundle.cpp
+++ b/xs/src/slic3r/GUI/PresetBundle.cpp
@@ -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.
this->filament_presets.clear();
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.
+ Preset *loaded = nullptr;
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] : "",
std::move(configs[i]), i == 0);
- else
- this->filaments.load_preset(this->filaments.path_from_name(new_name),
- new_name, std::move(configs[i]), i == 0).save();
- this->filament_presets.emplace_back(new_name);
+ else {
+ // Used by the config wizard when creating a custom setup.
+ // Therefore this block should only be called for a single extruder.
+ 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);
}
}