ConfigWizard: Select an appropriate printer based on the bundle order
This commit is contained in:
parent
c8815041e2
commit
fb0836b0b2
6 changed files with 57 additions and 21 deletions
|
@ -982,10 +982,11 @@ void ConfigWizard::priv::apply_config(AppConfig *app_config, PresetBundle *prese
|
|||
|
||||
size_t size_sum = 0;
|
||||
for (const auto &model : vendor->second) { size_sum += model.second.size(); }
|
||||
if (size_sum == 0) { continue; }
|
||||
|
||||
// This vendor needs to be installed
|
||||
install_bundles.emplace_back(vendor_rsrc.second);
|
||||
if (size_sum > 0) {
|
||||
// This vendor needs to be installed
|
||||
install_bundles.emplace_back(vendor_rsrc.second);
|
||||
}
|
||||
}
|
||||
|
||||
// Decide whether to create snapshot based on run_reason and the reset profile checkbox
|
||||
|
@ -1011,9 +1012,26 @@ void ConfigWizard::priv::apply_config(AppConfig *app_config, PresetBundle *prese
|
|||
app_config->set_vendors(appconfig_vendors);
|
||||
app_config->set("version_check", page_update->version_check ? "1" : "0");
|
||||
app_config->set("preset_update", page_update->preset_update ? "1" : "0");
|
||||
app_config->reset_selections();
|
||||
preset_bundle->load_presets(*app_config);
|
||||
|
||||
std::string preferred_model;
|
||||
|
||||
// Figure out the default pre-selected printer based on the seletions in the picker.
|
||||
// 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.
|
||||
const auto vendor_prusa = vendors.find("PrusaResearch");
|
||||
const auto config_prusa = enabled_vendors.find("PrusaResearch");
|
||||
if (vendor_prusa != vendors.end() && config_prusa != enabled_vendors.end()) {
|
||||
for (const auto &model : vendor_prusa->second.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
preset_bundle->load_presets(*app_config, preferred_model);
|
||||
|
||||
if (page_custom->custom_wanted()) {
|
||||
page_firmware->apply_custom_config(*custom_config);
|
||||
|
|
|
@ -125,9 +125,6 @@ void config_wizard(int reason)
|
|||
if (! wxGetApp().check_unsaved_changes())
|
||||
return;
|
||||
|
||||
// save selected preset before config wizard running
|
||||
const auto printer_preset_name = wxGetApp().preset_bundle->printers.get_edited_preset().name;
|
||||
|
||||
try {
|
||||
ConfigWizard wizard(nullptr, static_cast<ConfigWizard::RunReason>(reason));
|
||||
wizard.run(wxGetApp().preset_bundle, wxGetApp().preset_updater);
|
||||
|
@ -136,10 +133,8 @@ void config_wizard(int reason)
|
|||
show_error(nullptr, e.what());
|
||||
}
|
||||
|
||||
// select old(before config wizard running) preset
|
||||
wxGetApp().get_tab(Preset::TYPE_PRINTER)->select_preset(printer_preset_name);
|
||||
// If old preset if invisible now, then first visible preset will be selected
|
||||
// So, let control the case if multi-part object is on the scene and first visible preset is SLA
|
||||
wxGetApp().load_current_presets();
|
||||
|
||||
if (wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology() == ptSLA &&
|
||||
wxGetApp().obj_list()->has_multi_part_objects())
|
||||
{
|
||||
|
|
|
@ -1330,4 +1330,15 @@ const Preset& PrinterPresetCollection::default_preset_for(const DynamicPrintConf
|
|||
return this->default_preset((opt_printer_technology == nullptr || opt_printer_technology->value == ptFFF) ? 0 : 1);
|
||||
}
|
||||
|
||||
const Preset* PrinterPresetCollection::find_by_model_id(const std::string &model_id) const
|
||||
{
|
||||
if (model_id.empty()) { return nullptr; }
|
||||
|
||||
const auto it = std::find_if(cbegin(), cend(), [&](const Preset &preset) {
|
||||
return preset.config.opt_string("printer_model") == model_id;
|
||||
});
|
||||
|
||||
return it != cend() ? &*it : nullptr;
|
||||
}
|
||||
|
||||
} // namespace Slic3r
|
||||
|
|
|
@ -312,7 +312,7 @@ public:
|
|||
const Preset& get_edited_preset() const { return m_edited_preset; }
|
||||
|
||||
// used to update preset_choice from Tab
|
||||
const std::deque<Preset>& get_presets() { return m_presets; }
|
||||
const std::deque<Preset>& get_presets() const { return m_presets; }
|
||||
int get_idx_selected() { return m_idx_selected; }
|
||||
static const std::string& get_suffix_modified();
|
||||
|
||||
|
@ -503,6 +503,8 @@ public:
|
|||
PrinterPresetCollection(Preset::Type type, const std::vector<std::string> &keys, const Slic3r::StaticPrintConfig &defaults, const std::string &default_name = "- default -") :
|
||||
PresetCollection(type, keys, defaults, default_name) {}
|
||||
const Preset& default_preset_for(const DynamicPrintConfig &config) const override;
|
||||
|
||||
const Preset* find_by_model_id(const std::string &model_id) const;
|
||||
};
|
||||
|
||||
} // namespace Slic3r
|
||||
|
|
|
@ -191,7 +191,7 @@ void PresetBundle::setup_directories()
|
|||
}
|
||||
}
|
||||
|
||||
void PresetBundle::load_presets(const AppConfig &config)
|
||||
void PresetBundle::load_presets(const AppConfig &config, const std::string &preferred_model_id)
|
||||
{
|
||||
// First load the vendor specific system presets.
|
||||
std::string errors_cummulative = this->load_system_presets();
|
||||
|
@ -234,7 +234,7 @@ void PresetBundle::load_presets(const AppConfig &config)
|
|||
if (! errors_cummulative.empty())
|
||||
throw std::runtime_error(errors_cummulative);
|
||||
|
||||
this->load_selections(config);
|
||||
this->load_selections(config, preferred_model_id);
|
||||
}
|
||||
|
||||
// Load system presets into this PresetBundle.
|
||||
|
@ -324,7 +324,7 @@ 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)
|
||||
void PresetBundle::load_selections(const AppConfig &config, const std::string &preferred_model_id)
|
||||
{
|
||||
// Update visibility of presets based on application vendor / model / variant configuration.
|
||||
this->load_installed_printers(config);
|
||||
|
@ -336,11 +336,21 @@ void PresetBundle::load_selections(const AppConfig &config)
|
|||
std::string initial_sla_material_profile_name = remove_ini_suffix(config.get("presets", "sla_material"));
|
||||
std::string initial_printer_profile_name = remove_ini_suffix(config.get("presets", "printer"));
|
||||
|
||||
// Activate print / filament / printer profiles from the config.
|
||||
// If the printer profile enumerated by the config are not visible, select an alternate preset.
|
||||
// Activate print / filament / printer profiles from either the config,
|
||||
// or from the preferred_model_id suggestion passed in by ConfigWizard.
|
||||
// If the printer profile enumerated by the config are not visible, select an alternate preset.
|
||||
// Do not select alternate profiles for the print / filament profiles as those presets
|
||||
// will be selected by the following call of this->update_compatible(true).
|
||||
printers.select_preset_by_name(initial_printer_profile_name, true);
|
||||
|
||||
const Preset *initial_printer = printers.find_preset(initial_printer_profile_name);
|
||||
const Preset *preferred_printer = printers.find_by_model_id(preferred_model_id);
|
||||
|
||||
if (preferred_printer != nullptr && (initial_printer == nullptr || !initial_printer->is_visible)) {
|
||||
printers.select_preset_by_name(preferred_printer->name, true);
|
||||
} else {
|
||||
printers.select_preset_by_name(initial_printer_profile_name, true);
|
||||
}
|
||||
|
||||
PrinterTechnology printer_technology = printers.get_selected_preset().printer_technology();
|
||||
if (printer_technology == ptFFF) {
|
||||
prints.select_preset_by_name_strict(initial_print_profile_name);
|
||||
|
|
|
@ -31,7 +31,7 @@ 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);
|
||||
void load_presets(const AppConfig &config, const std::string &preferred_model_id = "");
|
||||
|
||||
// Export selections (current print, current filaments, current printer) into config.ini
|
||||
void export_selections(AppConfig &config);
|
||||
|
@ -143,7 +143,7 @@ private:
|
|||
|
||||
// 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);
|
||||
void load_selections(const 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.
|
||||
|
|
Loading…
Reference in a new issue