Auto selection of presets (#6817)
PresetComboBoxes: Auto selection of printer/material preset from the new added presets in ConfigWizard + Check unsaved changes if ConfigWizard is running from the PesetComboBoxes
This commit is contained in:
parent
5be61fb31c
commit
caf8ef4aab
6 changed files with 127 additions and 58 deletions
src/slic3r/GUI
|
@ -2453,6 +2453,34 @@ bool ConfigWizard::priv::check_and_install_missing_materials(Technology technolo
|
|||
return true;
|
||||
}
|
||||
|
||||
static std::set<std::string> get_new_added_presets(const std::map<std::string, std::string>& old_data, const std::map<std::string, std::string>& new_data)
|
||||
{
|
||||
auto get_aliases = [](const std::map<std::string, std::string>& data) {
|
||||
std::set<std::string> old_aliases;
|
||||
for (auto item : data) {
|
||||
const std::string& name = item.first;
|
||||
size_t pos = name.find("@");
|
||||
old_aliases.emplace(pos == std::string::npos ? name : name.substr(0, pos-1));
|
||||
}
|
||||
return old_aliases;
|
||||
};
|
||||
|
||||
std::set<std::string> old_aliases = get_aliases(old_data);
|
||||
std::set<std::string> new_aliases = get_aliases(new_data);
|
||||
std::set<std::string> diff;
|
||||
std::set_difference(new_aliases.begin(), new_aliases.end(), old_aliases.begin(), old_aliases.end(), std::inserter(diff, diff.begin()));
|
||||
|
||||
return diff;
|
||||
}
|
||||
|
||||
static std::string get_first_added_preset(const std::map<std::string, std::string>& old_data, const std::map<std::string, std::string>& new_data)
|
||||
{
|
||||
std::set<std::string> diff = get_new_added_presets(old_data, new_data);
|
||||
if (diff.empty())
|
||||
return std::string();
|
||||
return *diff.begin();
|
||||
}
|
||||
|
||||
bool ConfigWizard::priv::apply_config(AppConfig *app_config, PresetBundle *preset_bundle, const PresetUpdater *updater)
|
||||
{
|
||||
const auto enabled_vendors = appconfig_new.vendors();
|
||||
|
@ -2525,13 +2553,61 @@ bool ConfigWizard::priv::apply_config(AppConfig *app_config, PresetBundle *prese
|
|||
preset_bundle->reset(true);
|
||||
}
|
||||
|
||||
std::string preferred_model;
|
||||
std::string preferred_variant;
|
||||
const auto enabled_vendors_old = app_config->vendors();
|
||||
auto get_preferred_printer_model = [enabled_vendors, enabled_vendors_old](const std::string& bundle_name, const Bundle& bundle, std::string& variant) {
|
||||
const auto config = enabled_vendors.find(bundle_name);
|
||||
if (config == enabled_vendors.end())
|
||||
return std::string();
|
||||
for (const auto& model : bundle.vendor_profile->models) {
|
||||
if (const auto model_it = config->second.find(model.id);
|
||||
model_it != config->second.end() && model_it->second.size() > 0) {
|
||||
variant = *model_it->second.begin();
|
||||
const auto config_old = enabled_vendors_old.find(bundle_name);
|
||||
if (config_old == enabled_vendors_old.end())
|
||||
return model.id;
|
||||
const auto model_it_old = config_old->second.find(model.id);
|
||||
if (model_it_old == config_old->second.end())
|
||||
return model.id;
|
||||
else if (model_it_old->second != model_it->second) {
|
||||
for (const auto& var : model_it->second)
|
||||
if (model_it_old->second.find(var) == model_it_old->second.end()) {
|
||||
variant = var;
|
||||
return model.id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!variant.empty())
|
||||
variant.clear();
|
||||
return std::string();
|
||||
};
|
||||
// Prusa printers are considered first, then 3rd party.
|
||||
if (preferred_model = get_preferred_printer_model("PrusaResearch", bundles.prusa_bundle(), preferred_variant);
|
||||
preferred_model.empty()) {
|
||||
for (const auto& bundle : bundles) {
|
||||
if (bundle.second.is_prusa_bundle) { continue; }
|
||||
if (preferred_model = get_preferred_printer_model(bundle.first, bundle.second, preferred_variant);
|
||||
!preferred_model.empty())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
std::string first_added_filament, first_added_sla_material;
|
||||
auto apply_section = [this, app_config](const std::string& section_name, std::string& first_added_preset) {
|
||||
if (appconfig_new.has_section(section_name)) {
|
||||
// get first of new added preset names
|
||||
const std::map<std::string, std::string>& old_presets = app_config->has_section(section_name) ? app_config->get_section(section_name) : std::map<std::string, std::string>();
|
||||
first_added_preset = get_first_added_preset(old_presets, appconfig_new.get_section(section_name));
|
||||
app_config->set_section(section_name, appconfig_new.get_section(section_name));
|
||||
}
|
||||
};
|
||||
apply_section(AppConfig::SECTION_FILAMENTS, first_added_filament);
|
||||
apply_section(AppConfig::SECTION_MATERIALS, first_added_sla_material);
|
||||
|
||||
app_config->set_vendors(appconfig_new);
|
||||
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(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");
|
||||
app_config->set("export_sources_full_pathnames", page_reload_from_disk->full_pathnames ? "1" : "0");
|
||||
|
@ -2556,44 +2632,8 @@ bool ConfigWizard::priv::apply_config(AppConfig *app_config, PresetBundle *prese
|
|||
|
||||
page_mode->serialize_mode(app_config);
|
||||
|
||||
std::string preferred_model;
|
||||
|
||||
// Figure out the default pre-selected printer based on the selections in the pickers.
|
||||
// The default is the first selected printer model (one with at least 1 variant selected).
|
||||
// The default is only applied by load_presets() if the user doesn't have a (visible) printer
|
||||
// selected already.
|
||||
// Prusa printers are considered first, then 3rd party.
|
||||
const auto config_prusa = enabled_vendors.find("PrusaResearch");
|
||||
if (config_prusa != enabled_vendors.end()) {
|
||||
for (const auto &model : bundles.prusa_bundle().vendor_profile->models) {
|
||||
const auto model_it = config_prusa->second.find(model.id);
|
||||
if (model_it != config_prusa->second.end() && model_it->second.size() > 0) {
|
||||
preferred_model = model.id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (preferred_model.empty()) {
|
||||
for (const auto &bundle : bundles) {
|
||||
if (bundle.second.is_prusa_bundle) { continue; }
|
||||
|
||||
const auto config = enabled_vendors.find(bundle.first);
|
||||
if (config == enabled_vendors.end()) { continue; }
|
||||
for (const auto &model : bundle.second.vendor_profile->models) {
|
||||
const auto model_it = config->second.find(model.id);
|
||||
if (model_it != config->second.end() && model_it->second.size() > 0) {
|
||||
preferred_model = model.id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Reloading the configs after some modifications were done to PrusaSlicer.ini.
|
||||
// Just perform the substitutions silently, as the substitutions were already presented to the user on application start-up
|
||||
// and the Wizard shall not create any new values that would require substitution.
|
||||
// Throw on substitutions in system profiles, as the system profiles provided over the air should be compatible with this PrusaSlicer version.
|
||||
preset_bundle->load_presets(*app_config, ForwardCompatibilitySubstitutionRule::EnableSilentDisableSystem, preferred_model);
|
||||
preset_bundle->load_presets(*app_config, ForwardCompatibilitySubstitutionRule::EnableSilentDisableSystem,
|
||||
{preferred_model, preferred_variant, first_added_filament, first_added_sla_material});
|
||||
|
||||
if (page_custom->custom_wanted()) {
|
||||
page_firmware->apply_custom_config(*custom_config);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue