diff --git a/src/slic3r/GUI/PresetBundle.cpp b/src/slic3r/GUI/PresetBundle.cpp index 579c74dca..e3ee84e87 100644 --- a/src/slic3r/GUI/PresetBundle.cpp +++ b/src/slic3r/GUI/PresetBundle.cpp @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -239,10 +240,6 @@ void PresetBundle::load_presets(AppConfig &config, const std::string &preferred_ if (! errors_cummulative.empty()) throw std::runtime_error(errors_cummulative); - // Make sure there are filament / material selections in the AppConfig, - // if there are none, load up defaults from vendor profiles. - this->init_materials_selection(config); - this->load_selections(config, preferred_model_id); } @@ -371,10 +368,56 @@ void PresetBundle::load_installed_printers(const AppConfig &config) for (auto &preset : printers) { preset.set_visible_from_appconfig(config); } +} + +void PresetBundle::load_installed_filaments(AppConfig &config) +{ + if (! config.has_section(AppConfig::SECTION_FILAMENTS)) { + std::unordered_set comp_filaments; + + for (const Preset &printer : printers) { + if (! printer.is_visible || printer.printer_technology() != ptFFF) { + continue; + } + + for (const Preset &filament : filaments) { + if (filament.is_compatible_with_printer(printer)) { + comp_filaments.insert(&filament); + } + } + } + + for (const auto &filament: comp_filaments) { + config.set(AppConfig::SECTION_FILAMENTS, filament->name, "1"); + } + } for (auto &preset : filaments) { preset.set_visible_from_appconfig(config); } +} + +void PresetBundle::load_installed_sla_materials(AppConfig &config) +{ + if (! config.has_section(AppConfig::SECTION_MATERIALS)) { + std::unordered_set comp_sla_materials; + + for (const Preset &printer : printers) { + if (! printer.is_visible || printer.printer_technology() != ptSLA) { + continue; + } + + for (const Preset &material : sla_materials) { + if (material.is_compatible_with_printer(printer)) { + comp_sla_materials.insert(&material); + } + } + } + + for (const auto &material: comp_sla_materials) { + config.set(AppConfig::SECTION_MATERIALS, material->name, "1"); + } + } for (auto &preset : sla_materials) { preset.set_visible_from_appconfig(config); @@ -383,11 +426,15 @@ void PresetBundle::load_installed_printers(const AppConfig &config) // Load selections (current print, current filaments, current printer) from config.ini // This is done on application start up or after updates are applied. -void PresetBundle::load_selections(const AppConfig &config, const std::string &preferred_model_id) +void PresetBundle::load_selections(AppConfig &config, const std::string &preferred_model_id) { // Update visibility of presets based on application vendor / model / variant configuration. this->load_installed_printers(config); + // Update visibility of filament and sla material presets + this->load_installed_filaments(config); + this->load_installed_sla_materials(config); + // Parse the initial print / filament / printer profile names. std::string initial_print_profile_name = remove_ini_suffix(config.get("presets", "print")); std::string initial_sla_print_profile_name = remove_ini_suffix(config.get("presets", "sla_print")); @@ -455,23 +502,6 @@ void PresetBundle::export_selections(AppConfig &config) config.set("presets", "printer", printers.get_selected_preset_name()); } -void PresetBundle::init_materials_selection(AppConfig &config) const { - if (! config.has_section(AppConfig::SECTION_FILAMENTS)) { - for (const auto &vendor : this->vendors) { - for (const auto &profile : vendor.second.default_filaments) { - config.set(AppConfig::SECTION_FILAMENTS, profile, "1"); - } - } - } - if (! config.has_section(AppConfig::SECTION_MATERIALS)) { - for (const auto &vendor : this->vendors) { - for (const auto &profile : vendor.second.default_sla_materials) { - config.set(AppConfig::SECTION_MATERIALS, profile, "1"); - } - } - } -} - void PresetBundle::load_compatible_bitmaps(wxWindow *window) { // We don't actually pass the window pointer here and instead generate diff --git a/src/slic3r/GUI/PresetBundle.hpp b/src/slic3r/GUI/PresetBundle.hpp index d7ec5e3f0..0fea2a0f8 100644 --- a/src/slic3r/GUI/PresetBundle.hpp +++ b/src/slic3r/GUI/PresetBundle.hpp @@ -38,10 +38,6 @@ public: // Export selections (current print, current filaments, current printer) into config.ini void export_selections(AppConfig &config); - // Make sure filament and sla_materials section in AppConfig are initialized - // to defaults from vendor profiles if they don't exist already - void init_materials_selection(AppConfig &config) const; - PresetCollection prints; PresetCollection sla_prints; PresetCollection filaments; @@ -151,9 +147,14 @@ private: // If the "vendor" section is missing, enable all models and variants of the particular vendor. void load_installed_printers(const AppConfig &config); + // Set the enabled flag for filaments and sla materials, + // apply defaults based on enabled printers when no filaments/materials are installed. + void load_installed_filaments(AppConfig &config); + void load_installed_sla_materials(AppConfig &config); + // Load selections (current print, current filaments, current printer) from config.ini // This is done just once on application start up. - void load_selections(const AppConfig &config, const std::string &preferred_model_id = ""); + void load_selections(AppConfig &config, const std::string &preferred_model_id = ""); // Load print, filament & printer presets from a config. If it is an external config, then the name is extracted from the external path. // and the external config is just referenced, not stored into user profile directory.