Little optimization of the profile aliases.
This commit is contained in:
parent
4f8f619686
commit
3d9ac0ada1
@ -600,6 +600,7 @@ void PresetCollection::reset(bool delete_files)
|
||||
m_presets.erase(m_presets.begin() + m_num_default_presets, m_presets.end());
|
||||
this->select_preset(0);
|
||||
}
|
||||
m_map_alias_to_profile_name.clear();
|
||||
m_map_system_profile_renamed.clear();
|
||||
}
|
||||
|
||||
@ -944,15 +945,15 @@ PresetWithVendorProfile PresetCollection::get_preset_with_vendor_profile(const P
|
||||
|
||||
const std::string& PresetCollection::get_preset_name_by_alias(const std::string& alias) const
|
||||
{
|
||||
for (size_t i = this->m_presets.front().is_visible ? 0 : m_num_default_presets; i < this->m_presets.size(); ++i) {
|
||||
const Preset& preset = this->m_presets[i];
|
||||
if (!preset.is_visible || (!preset.is_compatible && i != m_idx_selected))
|
||||
continue;
|
||||
|
||||
if (preset.alias == alias)
|
||||
return preset.name;
|
||||
}
|
||||
|
||||
for (
|
||||
// Find the 1st profile name with the alias.
|
||||
auto it = Slic3r::lower_bound_by_predicate(m_map_alias_to_profile_name.begin(), m_map_alias_to_profile_name.end(), [&alias](auto &l){ return l.first < alias; });
|
||||
// Continue over all profile names with the same alias.
|
||||
it != m_map_alias_to_profile_name.end() && it->first == alias; ++ it)
|
||||
if (auto it_preset = this->find_preset_internal(it->second);
|
||||
it_preset != m_presets.end() && it_preset->name == it->second &&
|
||||
it_preset->is_visible && (it_preset->is_compatible || (it_preset - m_presets.begin()) == m_idx_selected))
|
||||
return it_preset->name;
|
||||
return alias;
|
||||
}
|
||||
|
||||
@ -1426,6 +1427,14 @@ std::vector<std::string> PresetCollection::merge_presets(PresetCollection &&othe
|
||||
return duplicates;
|
||||
}
|
||||
|
||||
void PresetCollection::update_map_alias_to_profile_name()
|
||||
{
|
||||
m_map_alias_to_profile_name.clear();
|
||||
for (const Preset &preset : m_presets)
|
||||
m_map_alias_to_profile_name.emplace_back(preset.alias, preset.name);
|
||||
std::sort(m_map_alias_to_profile_name.begin(), m_map_alias_to_profile_name.end(), [](auto &l, auto &r) { return l.first < r.first; });
|
||||
}
|
||||
|
||||
void PresetCollection::update_map_system_profile_renamed()
|
||||
{
|
||||
m_map_system_profile_renamed.clear();
|
||||
|
@ -166,7 +166,7 @@ public:
|
||||
DynamicPrintConfig config;
|
||||
|
||||
// Alias of the preset
|
||||
std::string alias = "";
|
||||
std::string alias;
|
||||
// List of profile names, from which this profile was renamed at some point of time.
|
||||
// This list is then used to match profiles by their names when loaded from .gcode, .3mf, .amf,
|
||||
// and to match the "inherits" field of user profiles with updated system profiles.
|
||||
@ -356,7 +356,7 @@ public:
|
||||
|
||||
// used to update preset_choice from Tab
|
||||
const std::deque<Preset>& get_presets() const { return m_presets; }
|
||||
int get_idx_selected() { return m_idx_selected; }
|
||||
int get_idx_selected() { return m_idx_selected; }
|
||||
static const std::string& get_suffix_modified();
|
||||
|
||||
// Return a preset possibly with modifications.
|
||||
@ -475,6 +475,9 @@ protected:
|
||||
// Merge one vendor's presets with the other vendor's presets, report duplicates.
|
||||
std::vector<std::string> merge_presets(PresetCollection &&other, const VendorMap &new_vendors);
|
||||
|
||||
// Update m_map_alias_to_profile_name from loaded system profiles.
|
||||
void update_map_alias_to_profile_name();
|
||||
|
||||
// Update m_map_system_profile_renamed from loaded system profiles.
|
||||
void update_map_system_profile_renamed();
|
||||
|
||||
@ -522,6 +525,8 @@ private:
|
||||
// Use deque to force the container to allocate an object per each entry,
|
||||
// so that the addresses of the presets don't change during resizing of the container.
|
||||
std::deque<Preset> m_presets;
|
||||
// System profiles may have aliases. Map to the full profile name.
|
||||
std::vector<std::pair<std::string, std::string>> m_map_alias_to_profile_name;
|
||||
// Map from old system profile name to a current system profile name.
|
||||
std::map<std::string, std::string> m_map_system_profile_renamed;
|
||||
// Initially this preset contains a copy of the selected preset. Later on, this copy may be modified by the user.
|
||||
|
@ -288,11 +288,18 @@ std::string PresetBundle::load_system_presets()
|
||||
// No config bundle loaded, reset.
|
||||
this->reset(false);
|
||||
}
|
||||
|
||||
this->prints .update_map_system_profile_renamed();
|
||||
this->sla_prints .update_map_system_profile_renamed();
|
||||
this->filaments .update_map_system_profile_renamed();
|
||||
this->sla_materials.update_map_system_profile_renamed();
|
||||
this->printers .update_map_system_profile_renamed();
|
||||
|
||||
this->prints .update_map_alias_to_profile_name();
|
||||
this->sla_prints .update_map_alias_to_profile_name();
|
||||
this->filaments .update_map_alias_to_profile_name();
|
||||
this->sla_materials.update_map_alias_to_profile_name();
|
||||
|
||||
return errors_cummulative;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user