From 87b7b1cc1dc79ea77d2100481fd0f58a85b59037 Mon Sep 17 00:00:00 2001 From: Vojtech Kral Date: Mon, 3 Jun 2019 10:15:26 +0200 Subject: [PATCH] Load default filament/material selections from vendor profiles --- src/slic3r/GUI/AppConfig.cpp | 3 ++ src/slic3r/GUI/AppConfig.hpp | 2 ++ src/slic3r/GUI/ConfigWizard.cpp | 42 ++++++++----------------- src/slic3r/GUI/ConfigWizard_private.hpp | 2 -- src/slic3r/GUI/PresetBundle.cpp | 23 +++++++++++++- src/slic3r/GUI/PresetBundle.hpp | 6 +++- 6 files changed, 45 insertions(+), 33 deletions(-) diff --git a/src/slic3r/GUI/AppConfig.cpp b/src/slic3r/GUI/AppConfig.cpp index 5a165e8ae..6b3f54f3a 100644 --- a/src/slic3r/GUI/AppConfig.cpp +++ b/src/slic3r/GUI/AppConfig.cpp @@ -28,6 +28,9 @@ static const std::string VENDOR_PREFIX = "vendor:"; static const std::string MODEL_PREFIX = "model:"; static const std::string VERSION_CHECK_URL = "https://files.prusa3d.com/wp-content/uploads/repository/PrusaSlicer-settings-master/live/PrusaSlicer.version"; +const std::string AppConfig::SECTION_FILAMENTS = "filaments"; +const std::string AppConfig::SECTION_MATERIALS = "sla_materials"; + void AppConfig::reset() { m_storage.clear(); diff --git a/src/slic3r/GUI/AppConfig.hpp b/src/slic3r/GUI/AppConfig.hpp index fe30c0af6..97c369ab6 100644 --- a/src/slic3r/GUI/AppConfig.hpp +++ b/src/slic3r/GUI/AppConfig.hpp @@ -131,6 +131,8 @@ public: std::vector get_recent_projects() const; void set_recent_projects(const std::vector& recent_projects); + static const std::string SECTION_FILAMENTS; + static const std::string SECTION_MATERIALS; private: // Map of section, name -> value std::map> m_storage; diff --git a/src/slic3r/GUI/ConfigWizard.cpp b/src/slic3r/GUI/ConfigWizard.cpp index 0d35ce1af..9dbf3d037 100644 --- a/src/slic3r/GUI/ConfigWizard.cpp +++ b/src/slic3r/GUI/ConfigWizard.cpp @@ -1049,12 +1049,10 @@ void ConfigWizardIndex::msw_rescale() // Materials const std::string Materials::UNKNOWN = "(Unknown)"; -const std::string Materials::SECTION_FILAMENTS = "filaments"; -const std::string Materials::SECTION_MATERIALS = "sla_materials"; const std::string& Materials::appconfig_section() const { - return (technology & T_FFF) ? SECTION_FILAMENTS : SECTION_MATERIALS; + return (technology & T_FFF) ? AppConfig::SECTION_FILAMENTS : AppConfig::SECTION_MATERIALS; } const std::string& Materials::get_type(Preset &preset) const @@ -1236,7 +1234,7 @@ void ConfigWizard::priv::load_vendors() } // Load up the set of vendors / models / variants the user has had enabled up till now - const AppConfig *app_config = GUI::get_app_config(); + AppConfig *app_config = GUI::get_app_config(); if (! app_config->legacy_datadir()) { appconfig_new.set_vendors(*app_config); } else { @@ -1253,27 +1251,13 @@ void ConfigWizard::priv::load_vendors() } } - // Load up the materials enabled till now - if (app_config->has_section(Materials::SECTION_FILAMENTS)) { - appconfig_new.set_section(Materials::SECTION_FILAMENTS, app_config->get_section(Materials::SECTION_FILAMENTS)); - } else { - // No AppConfig settings, load up defaults from vendor section(s) - for (const auto &vendor : bundle.vendors) { - for (const auto &profile : vendor.default_filaments) { - appconfig_new.set(Materials::SECTION_FILAMENTS, profile, "1"); - } - } - } - if (app_config->has_section(Materials::SECTION_MATERIALS)) { - appconfig_new.set_section(Materials::SECTION_MATERIALS, app_config->get_section(Materials::SECTION_MATERIALS)); - } else { - // No AppConfig settings, load up defaults from vendor section(s) - for (const auto &vendor : bundle.vendors) { - for (const auto &profile : vendor.default_sla_materials) { - appconfig_new.set(Materials::SECTION_MATERIALS, profile, "1"); - } - } - } + // Load up the materials enabled till now, + // apply defaults from vendor profiles if there are no selections yet. + bundle.init_materials_selection(*app_config); + wxCHECK_RET(app_config->has_section(AppConfig::SECTION_FILAMENTS) && app_config->has_section(AppConfig::SECTION_MATERIALS), + "Failed to initialize default material selections"); + appconfig_new.set_section(AppConfig::SECTION_FILAMENTS, app_config->get_section(AppConfig::SECTION_FILAMENTS)); + appconfig_new.set_section(AppConfig::SECTION_MATERIALS, app_config->get_section(AppConfig::SECTION_MATERIALS)); } void ConfigWizard::priv::add_page(ConfigWizardPage *page) @@ -1361,11 +1345,11 @@ void ConfigWizard::priv::apply_config(AppConfig *app_config, PresetBundle *prese } app_config->set_vendors(appconfig_new); - if (appconfig_new.has_section(Materials::SECTION_FILAMENTS)) { - app_config->set_section(Materials::SECTION_FILAMENTS, appconfig_new.get_section(Materials::SECTION_FILAMENTS)); + if (appconfig_new.has_section(AppConfig::SECTION_FILAMENTS)) { + app_config->set_section(AppConfig::SECTION_FILAMENTS, appconfig_new.get_section(AppConfig::SECTION_FILAMENTS)); } - if (appconfig_new.has_section(Materials::SECTION_MATERIALS)) { - app_config->set_section(Materials::SECTION_MATERIALS, appconfig_new.get_section(Materials::SECTION_MATERIALS)); + if (appconfig_new.has_section(AppConfig::SECTION_MATERIALS)) { + app_config->set_section(AppConfig::SECTION_MATERIALS, appconfig_new.get_section(AppConfig::SECTION_MATERIALS)); } app_config->set("version_check", page_update->version_check ? "1" : "0"); app_config->set("preset_update", page_update->preset_update ? "1" : "0"); diff --git a/src/slic3r/GUI/ConfigWizard_private.hpp b/src/slic3r/GUI/ConfigWizard_private.hpp index b57161c00..1c7cc94de 100644 --- a/src/slic3r/GUI/ConfigWizard_private.hpp +++ b/src/slic3r/GUI/ConfigWizard_private.hpp @@ -152,8 +152,6 @@ struct Materials } static const std::string UNKNOWN; - static const std::string SECTION_FILAMENTS; - static const std::string SECTION_MATERIALS; static const std::string& get_filament_type(const Preset &preset); static const std::string& get_filament_vendor(const Preset &preset); static const std::string& get_material_type(Preset &preset); diff --git a/src/slic3r/GUI/PresetBundle.cpp b/src/slic3r/GUI/PresetBundle.cpp index f254ad15c..2ea03d755 100644 --- a/src/slic3r/GUI/PresetBundle.cpp +++ b/src/slic3r/GUI/PresetBundle.cpp @@ -194,7 +194,7 @@ void PresetBundle::setup_directories() } } -void PresetBundle::load_presets(const AppConfig &config, const std::string &preferred_model_id) +void PresetBundle::load_presets(AppConfig &config, const std::string &preferred_model_id) { // First load the vendor specific system presets. std::string errors_cummulative = this->load_system_presets(); @@ -237,6 +237,10 @@ void PresetBundle::load_presets(const AppConfig &config, const std::string &pref 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); } @@ -407,6 +411,23 @@ 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.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.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 f351f66ac..847b37018 100644 --- a/src/slic3r/GUI/PresetBundle.hpp +++ b/src/slic3r/GUI/PresetBundle.hpp @@ -31,11 +31,15 @@ public: // Load ini files of all types (print, filament, printer) from Slic3r::data_dir() / presets. // Load selections (current print, current filaments, current printer) from config.ini // This is done just once on application start up. - void load_presets(const AppConfig &config, const std::string &preferred_model_id = ""); + void load_presets(AppConfig &config, const std::string &preferred_model_id = ""); // 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;