Filament and material default installation based on enabled printers

This commit is contained in:
Vojtech Kral 2019-08-27 16:59:07 +02:00
parent 270008a3fd
commit 9a465514ff
2 changed files with 58 additions and 27 deletions

View file

@ -8,6 +8,7 @@
#include <algorithm> #include <algorithm>
#include <fstream> #include <fstream>
#include <unordered_set>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/algorithm/clamp.hpp> #include <boost/algorithm/clamp.hpp>
#include <boost/algorithm/string/predicate.hpp> #include <boost/algorithm/string/predicate.hpp>
@ -239,10 +240,6 @@ void PresetBundle::load_presets(AppConfig &config, const std::string &preferred_
if (! errors_cummulative.empty()) if (! errors_cummulative.empty())
throw std::runtime_error(errors_cummulative); 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); this->load_selections(config, preferred_model_id);
} }
@ -371,10 +368,56 @@ void PresetBundle::load_installed_printers(const AppConfig &config)
for (auto &preset : printers) { for (auto &preset : printers) {
preset.set_visible_from_appconfig(config); preset.set_visible_from_appconfig(config);
} }
}
void PresetBundle::load_installed_filaments(AppConfig &config)
{
if (! config.has_section(AppConfig::SECTION_FILAMENTS)) {
std::unordered_set<const Preset*> 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) { for (auto &preset : filaments) {
preset.set_visible_from_appconfig(config); preset.set_visible_from_appconfig(config);
} }
}
void PresetBundle::load_installed_sla_materials(AppConfig &config)
{
if (! config.has_section(AppConfig::SECTION_MATERIALS)) {
std::unordered_set<const Preset*> 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) { for (auto &preset : sla_materials) {
preset.set_visible_from_appconfig(config); 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 // Load selections (current print, current filaments, current printer) from config.ini
// This is done on application start up or after updates are applied. // 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. // Update visibility of presets based on application vendor / model / variant configuration.
this->load_installed_printers(config); 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. // Parse the initial print / filament / printer profile names.
std::string initial_print_profile_name = remove_ini_suffix(config.get("presets", "print")); 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")); 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()); 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) void PresetBundle::load_compatible_bitmaps(wxWindow *window)
{ {
// We don't actually pass the window pointer here and instead generate // We don't actually pass the window pointer here and instead generate

View file

@ -38,10 +38,6 @@ public:
// Export selections (current print, current filaments, current printer) into config.ini // Export selections (current print, current filaments, current printer) into config.ini
void export_selections(AppConfig &config); 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 prints;
PresetCollection sla_prints; PresetCollection sla_prints;
PresetCollection filaments; PresetCollection filaments;
@ -151,9 +147,14 @@ private:
// If the "vendor" section is missing, enable all models and variants of the particular vendor. // If the "vendor" section is missing, enable all models and variants of the particular vendor.
void load_installed_printers(const AppConfig &config); 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 // Load selections (current print, current filaments, current printer) from config.ini
// This is done just once on application start up. // 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. // 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. // and the external config is just referenced, not stored into user profile directory.