Fixed function to get a profile name by alias for all preset collections

This commit is contained in:
YuSanka 2019-11-29 11:02:30 +01:00
parent 71f5ed5b9e
commit 22aa17128a
6 changed files with 24 additions and 6 deletions

View file

@ -3372,10 +3372,10 @@ void Plater::priv::on_select_preset(wxCommandEvent &evt)
//! combo->GetStringSelection().ToUTF8().data());
const std::string& selected_string = combo->GetString(combo->GetSelection()).ToUTF8().data();
const std::string preset_name = wxGetApp().preset_bundle->filaments.get_preset_name_by_alias(selected_string);
const std::string preset_name = wxGetApp().preset_bundle->get_preset_name_by_alias(preset_type, selected_string);
if (preset_type == Preset::TYPE_FILAMENT) {
wxGetApp().preset_bundle->set_filament_preset(idx, /*selected_string*/preset_name);
wxGetApp().preset_bundle->set_filament_preset(idx, preset_name);
}
// TODO: ?
@ -3385,7 +3385,7 @@ void Plater::priv::on_select_preset(wxCommandEvent &evt)
}
else {
wxWindowUpdateLocker noUpdates(sidebar->presets_panel());
wxGetApp().get_tab(preset_type)->select_preset(/*selected_string*/preset_name);
wxGetApp().get_tab(preset_type)->select_preset(preset_name);
}
// update plater with new config

View file

@ -810,6 +810,8 @@ void PresetCollection::save_current_preset(const std::string &new_name)
preset.is_external = false;
// The newly saved preset will be activated -> make it visible.
preset.is_visible = true;
// Just system presets have aliases
preset.alias.clear();
}
// 2) Activate the saved preset.
this->select_preset_by_name(new_name, true);
@ -903,7 +905,7 @@ const Preset* PresetCollection::get_preset_parent(const Preset& child) const
return (preset == nullptr/* || preset->is_default */|| preset->is_external) ? nullptr : preset;
}
const std::string& PresetCollection::get_preset_name_by_alias(const std::string& alias)
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];

View file

@ -329,7 +329,7 @@ public:
Preset& get_edited_preset() { return m_edited_preset; }
const Preset& get_edited_preset() const { return m_edited_preset; }
const std::string& get_preset_name_by_alias(const std::string& alias);
const std::string& get_preset_name_by_alias(const std::string& alias) const;
// used to update preset_choice from Tab
const std::deque<Preset>& get_presets() const { return m_presets; }

View file

@ -329,6 +329,20 @@ void PresetBundle::load_installed_printers(const AppConfig &config)
}
}
const std::string& PresetBundle::get_preset_name_by_alias( const Preset::Type& preset_type, const std::string& alias) const
{
// there are not aliases for Printers profiles
if (preset_type == Preset::TYPE_PRINTER || preset_type == Preset::TYPE_INVALID)
return alias;
const PresetCollection& presets = preset_type == Preset::TYPE_PRINT ? prints :
preset_type == Preset::TYPE_SLA_PRINT ? sla_prints :
preset_type == Preset::TYPE_FILAMENT ? filaments :
sla_materials;
return presets.get_preset_name_by_alias(alias);
}
void PresetBundle::load_installed_filaments(AppConfig &config)
{
if (! config.has_section(AppConfig::SECTION_FILAMENTS)) {

View file

@ -139,6 +139,8 @@ public:
// If the "vendor" section is missing, enable all models and variants of the particular vendor.
void load_installed_printers(const AppConfig &config);
const std::string& get_preset_name_by_alias(const Preset::Type& preset_type, const std::string& alias) const;
static const char *PRUSA_BUNDLE;
private:
std::string load_system_presets();

View file

@ -3025,7 +3025,7 @@ void Tab::save_preset(std::string name /*= ""*/)
show_error(this, _(L("Cannot overwrite an external profile.")));
return;
}
if (existing && name != preset.name)
if (existing/* && name != preset.name*/)
{
wxString msg_text = GUI::from_u8((boost::format(_utf8(L("Preset with name \"%1%\" already exist."))) % name).str());
msg_text += "\n" + _(L("Replace?"));