Implemented "renamed_from" attribute of a system profile,

so that references from user profiles and .3mfs / .amfs
to system profiles are not being lost.

If a system profile has no "renamed_from" profile name assigned,
and the system profile name contains "@", then a profile name
with the "@" is implicitely assumed to be the name, from which this
profile has been renamed.
This commit is contained in:
bubnikv 2020-01-02 16:40:32 +01:00
parent bb56988916
commit 0d9022c5f6
3 changed files with 97 additions and 36 deletions

View file

@ -163,6 +163,10 @@ public:
// Alias of the preset
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.
std::vector<std::string> renamed_from;
void save();
@ -333,7 +337,8 @@ public:
// The parent preset may be a system preset or a user preset, which will be
// reflected by the UI.
const Preset* get_selected_preset_parent() const;
// get parent preset for some child preset
// Get parent preset for a child preset, based on the "inherits" field of a child,
// where the "inherits" profile name is searched for in both m_presets and m_map_system_profile_renamed.
const Preset* get_preset_parent(const Preset& child) const;
// Return the selected preset including the user modifications.
Preset& get_edited_preset() { return m_edited_preset; }
@ -465,6 +470,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_system_profile_renamed from loaded system profiles.
void update_map_system_profile_renamed();
private:
PresetCollection();
PresetCollection(const PresetCollection &other);
@ -490,6 +498,14 @@ private:
}
std::deque<Preset>::const_iterator find_preset_internal(const std::string &name) const
{ return const_cast<PresetCollection*>(this)->find_preset_internal(name); }
std::deque<Preset>::iterator find_preset_renamed(const std::string &name) {
auto it_renamed = m_map_system_profile_renamed.find(name);
auto it = (it_renamed == m_map_system_profile_renamed.end()) ? m_presets.end() : this->find_preset_internal(it_renamed->second);
assert((it_renamed == m_map_system_profile_renamed.end()) || (it != m_presets.end() && it->name == it_renamed->second));
return it;
}
std::deque<Preset>::const_iterator find_preset_renamed(const std::string &name) const
{ return const_cast<PresetCollection*>(this)->find_preset_renamed(name); }
size_t update_compatible_internal(const PresetWithVendorProfile &active_printer, const PresetWithVendorProfile *active_print, bool unselect_if_incompatible);
@ -501,6 +517,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;
// 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.
Preset m_edited_preset;
// Selected preset.