diff --git a/src/slic3r/GUI/ConfigWizard.cpp b/src/slic3r/GUI/ConfigWizard.cpp index 08a88f798..94e02d3b0 100644 --- a/src/slic3r/GUI/ConfigWizard.cpp +++ b/src/slic3r/GUI/ConfigWizard.cpp @@ -628,7 +628,23 @@ void PageMaterials::update_lists(int sel1, int sel2) const std::string &vendor = list_l2->get_data(sel2); materials->filter_presets(type, vendor, [this](const Preset *p) { - const int i = list_l3->append(p->name, p); + // #ys_FIXME_alias + // const int i = list_l3->append(p->name, p); + + int i = 0; + if (materials->technology == T_FFF) { + if (!p->alias.empty()) + return; + i = list_l3->append(p->name, &p->name); + } + else if (materials->technology == T_SLA) { + if (list_l3->find(p->alias) != wxNOT_FOUND) + return; + i = list_l3->append(p->alias, &p->alias); + } + else + return; + const bool checked = wizard_p()->appconfig_new.has(materials->appconfig_section(), p->name); list_l3->Check(i, checked); }); @@ -641,19 +657,16 @@ void PageMaterials::update_lists(int sel1, int sel2) void PageMaterials::select_material(int i) { const bool checked = list_l3->IsChecked(i); - const Preset &preset = list_l3->get_data(i); // #ys_FIXME_aliases + // const Preset &preset = list_l3->get_data(i); // if (checked) { // wizard_p()->appconfig_new.set(materials->appconfig_section(), preset.name, "1"); // } else { // wizard_p()->appconfig_new.erase(materials->appconfig_section(), preset.name); // } - if (checked) { - wizard_p()->add_presets(materials->appconfig_section(), preset.name); - } else { - wizard_p()->del_presets(materials->appconfig_section(), preset.name); - } + const std::string& alias_key = list_l3->get_data(i); + wizard_p()->update_presets_in_config(materials->appconfig_section(), alias_key, checked); } void PageMaterials::select_all(bool select) @@ -1450,7 +1463,7 @@ void ConfigWizard::priv::update_materials(Technology technology) { if (any_fff_selected && (technology & T_FFF)) { filaments.clear(); - aliases.clear(); + aliases_fff.clear(); // Iterate filaments in all bundles for (const auto &pair : bundles) { @@ -1469,7 +1482,7 @@ void ConfigWizard::priv::update_materials(Technology technology) if (filament.is_compatible_with_printer(printer)) { filaments.push(&filament); if (!filament.alias.empty()) - aliases[filament.alias].insert(filament.name); + aliases_fff[filament.alias].insert(filament.name); } } } @@ -1479,6 +1492,7 @@ void ConfigWizard::priv::update_materials(Technology technology) if (any_sla_selected && (technology & T_SLA)) { sla_materials.clear(); + aliases_sla.clear(); // Iterate SLA materials in all bundles for (const auto &pair : bundles) { @@ -1496,6 +1510,8 @@ void ConfigWizard::priv::update_materials(Technology technology) if (material.is_compatible_with_printer(printer)) { sla_materials.push(&material); + if (!material.alias.empty()) + aliases_sla[material.alias].insert(material.name); } } } @@ -1678,28 +1694,28 @@ void ConfigWizard::priv::apply_config(AppConfig *app_config, PresetBundle *prese preset_bundle->export_selections(*app_config); } -void ConfigWizard::priv::add_presets(const std::string& section, const std::string& alias_key) +void ConfigWizard::priv::update_presets_in_config(const std::string& section, const std::string& alias_key, bool add) { - // add preset to config - appconfig_new.set(section, alias_key, "1"); + const PresetAliases& aliases = section == AppConfig::SECTION_FILAMENTS ? aliases_fff : aliases_sla; - // add presets had a same alias + auto update = [this, add](const std::string& s, const std::string& key) { + if (add) + appconfig_new.set(s, key, "1"); + else + appconfig_new.erase(s, key); + }; + + // Not all of the filament preset have aliases. + // Thus, we should to delete preset with a same as an alias_key name + // add or delete preset from config + if (section == AppConfig::SECTION_FILAMENTS) + update(section, alias_key); + + // add or delete presets had a same alias auto it = aliases.find(alias_key); if (it != aliases.end()) for (const std::string& name : it->second) - appconfig_new.set(section, name, "1"); -} - -void ConfigWizard::priv::del_presets(const std::string& section, const std::string& alias_key) -{ - // delete preset from config - appconfig_new.erase(section, alias_key); - - // delete presets had a same alias - auto it = aliases.find(alias_key); - if (it != aliases.end()) - for (const std::string& name : it->second) - appconfig_new.erase(section, name); + update(section, name); } @@ -1758,6 +1774,9 @@ ConfigWizard::ConfigWizard(wxWindow *parent) p->page_msla = new PagePrinters(this, _(L("Prusa MSLA Technology Printers")), "Prusa MSLA", *vendor_prusa, 0, T_SLA); p->add_page(p->page_msla); + p->any_sla_selected = p->page_msla->any_selected(); + p->any_fff_selected = p->page_fff->any_selected(); + p->add_page(p->page_filaments = new PageMaterials(this, &p->filaments, _(L("Filament Profiles Selection")), _(L("Filaments")), _(L("Type:")) )); p->add_page(p->page_sla_materials = new PageMaterials(this, &p->sla_materials, @@ -1775,9 +1794,6 @@ ConfigWizard::ConfigWizard(wxWindow *parent) p->create_3rdparty_pages(); // Needs to ne done _before_ creating PageVendors p->add_page(p->page_vendors = new PageVendors(this)); - p->any_sla_selected = p->page_msla->any_selected(); - p->any_fff_selected = p->page_fff->any_selected(); - p->load_pages(); p->index->go_to(size_t{0}); diff --git a/src/slic3r/GUI/ConfigWizard_private.hpp b/src/slic3r/GUI/ConfigWizard_private.hpp index 500488bc9..3a936fa42 100644 --- a/src/slic3r/GUI/ConfigWizard_private.hpp +++ b/src/slic3r/GUI/ConfigWizard_private.hpp @@ -75,8 +75,7 @@ struct Materials template void filter_presets(const std::string &type, const std::string &vendor, F cb) { for (const Preset *preset : presets) { - if ((type.empty() || get_type(preset) == type) && (vendor.empty() || get_vendor(preset) == vendor)//) { - && preset->alias.empty()) { + if ((type.empty() || get_type(preset) == type) && (vendor.empty() || get_vendor(preset) == vendor)) { cb(preset); } } @@ -244,7 +243,9 @@ template struct DataList : public T }; typedef DataList StringList; -typedef DataList PresetList; +// #ys_FIXME_alias +//typedef DataList PresetList; +typedef DataList PresetList; struct PageMaterials: ConfigWizardPage { @@ -418,7 +419,8 @@ struct ConfigWizard::priv // PrinterPickers state. Materials filaments; // Holds available filament presets and their types & vendors Materials sla_materials; // Ditto for SLA materials - PresetAliases aliases; // Map of aliase to preset names + PresetAliases aliases_fff; // Map of aliase to preset names + PresetAliases aliases_sla; // Map of aliase to preset names std::unique_ptr custom_config; // Backing for custom printer definition bool any_fff_selected; // Used to decide whether to display Filaments page bool any_sla_selected; // Used to decide whether to display SLA Materials page @@ -458,7 +460,6 @@ struct ConfigWizard::priv : q(q) , filaments(T_FFF) , sla_materials(T_SLA) - , any_sla_selected(false) {} void load_pages(); @@ -478,14 +479,11 @@ struct ConfigWizard::priv void apply_config(AppConfig *app_config, PresetBundle *preset_bundle, const PresetUpdater *updater); // #ys_FIXME_alise - void add_presets(const std::string& section, const std::string& alias_key); - void del_presets(const std::string& section, const std::string& alias_key); + void update_presets_in_config(const std::string& section, const std::string& alias_key, bool add); int em() const { return index->em(); } }; - - } } diff --git a/src/slic3r/GUI/Preset.cpp b/src/slic3r/GUI/Preset.cpp index 32a03b6b2..bb8a534e7 100644 --- a/src/slic3r/GUI/Preset.cpp +++ b/src/slic3r/GUI/Preset.cpp @@ -978,7 +978,7 @@ void PresetCollection::update_platter_ui(GUI::PresetComboBox *ui) // Otherwise fill in the list from scratch. ui->Freeze(); ui->Clear(); - size_t selected_preset_item = 0; + size_t selected_preset_item = INT_MAX; // some value meaning that no one item is selected const Preset &selected_preset = this->get_selected_preset(); // Show wide icons if the currently selected preset is not compatible with the current printer, @@ -1028,7 +1028,9 @@ void PresetCollection::update_platter_ui(GUI::PresetComboBox *ui) if (preset.is_default || preset.is_system) { ui->Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()), (bmp == 0) ? (m_bitmap_main_frame ? *m_bitmap_main_frame : wxNullBitmap) : *bmp); - if (i == m_idx_selected) + if (i == m_idx_selected || + // just in case: mark selected_preset_item as a first added element + selected_preset_item == INT_MAX) selected_preset_item = ui->GetCount() - 1; } else @@ -1045,7 +1047,9 @@ void PresetCollection::update_platter_ui(GUI::PresetComboBox *ui) ui->set_label_marker(ui->Append(PresetCollection::separator(L("User presets")), wxNullBitmap)); for (std::map::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) { ui->Append(it->first, *it->second); - if (it->first == selected) + if (it->first == selected || + // just in case: mark selected_preset_item as a first added element + selected_preset_item == INT_MAX) selected_preset_item = ui->GetCount() - 1; } } @@ -1076,6 +1080,13 @@ void PresetCollection::update_platter_ui(GUI::PresetComboBox *ui) ui->set_label_marker(ui->Append(PresetCollection::separator(L("Add/Remove materials")), wxNullBitmap), GUI::PresetComboBox::LABEL_ITEM_WIZARD_MATERIALS); } + /* But, if selected_preset_item is still equal to INT_MAX, it means that + * there is no presets added to the list. + * So, select last combobox item ("Add/Remove preset") + */ + if (selected_preset_item == INT_MAX) + selected_preset_item = ui->GetCount() - 1; + ui->SetSelection(selected_preset_item); ui->SetToolTip(ui->GetString(selected_preset_item)); ui->check_selection(); @@ -1092,7 +1103,7 @@ size_t PresetCollection::update_tab_ui(wxBitmapComboBox *ui, bool show_incompati return 0; ui->Freeze(); ui->Clear(); - size_t selected_preset_item = 0; + size_t selected_preset_item = INT_MAX; // some value meaning that no one item is selected /* It's supposed that standard size of an icon is 16px*16px for 100% scaled display. * So set sizes for solid_colored(empty) icons used for preset @@ -1127,7 +1138,9 @@ size_t PresetCollection::update_tab_ui(wxBitmapComboBox *ui, bool show_incompati if (preset.is_default || preset.is_system) { ui->Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? g_suffix_modified : "")).c_str()), (bmp == 0) ? (m_bitmap_main_frame ? *m_bitmap_main_frame : wxNullBitmap) : *bmp); - if (i == m_idx_selected) + if (i == m_idx_selected || + // just in case: mark selected_preset_item as a first added element + selected_preset_item == INT_MAX) selected_preset_item = ui->GetCount() - 1; } else @@ -1144,7 +1157,9 @@ size_t PresetCollection::update_tab_ui(wxBitmapComboBox *ui, bool show_incompati ui->Append(PresetCollection::separator(L("User presets")), wxNullBitmap); for (std::map::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) { ui->Append(it->first, *it->second); - if (it->first == selected) + if (it->first == selected || + // just in case: mark selected_preset_item as a first added element + selected_preset_item == INT_MAX) selected_preset_item = ui->GetCount() - 1; } } @@ -1159,6 +1174,14 @@ size_t PresetCollection::update_tab_ui(wxBitmapComboBox *ui, bool show_incompati } ui->Append(PresetCollection::separator("Add a new printer"), *bmp); } + + /* But, if selected_preset_item is still equal to INT_MAX, it means that + * there is no presets added to the list. + * So, select last combobox item ("Add/Remove preset") + */ + if (selected_preset_item == INT_MAX) + selected_preset_item = ui->GetCount() - 1; + ui->SetSelection(selected_preset_item); ui->SetToolTip(ui->GetString(selected_preset_item)); ui->Thaw(); diff --git a/src/slic3r/GUI/PresetBundle.cpp b/src/slic3r/GUI/PresetBundle.cpp index 9604b931b..af7c2a0e7 100644 --- a/src/slic3r/GUI/PresetBundle.cpp +++ b/src/slic3r/GUI/PresetBundle.cpp @@ -1148,13 +1148,8 @@ size_t PresetBundle::load_configbundle(const std::string &path, unsigned int fla loaded = &loaded_sla_materials; preset_name = section.first.substr(13); - for (const auto& item : section.second) - { - if (boost::starts_with(item.first, "alias")) { - alias_name = item.second.data(); - break; - } - } + int end_pos = preset_name.find_first_of("0."); + alias_name = preset_name.substr(0, end_pos-1); } else if (boost::starts_with(section.first, "printer:")) { presets = &this->printers; loaded = &loaded_printers; @@ -1664,7 +1659,8 @@ void PresetBundle::update_platter_filament_ui(unsigned int idx_extruder, GUI::Pr /* But, if selected_preset_item is still equal to INT_MAX, it means that * there is no presets added to the list. - * */ So, select last combobox item ("Add/Remove filaments") + * So, select last combobox item ("Add/Remove filaments") + */ if (selected_preset_item == INT_MAX) selected_preset_item = ui->GetCount() - 1;