2376{
2377 wxString header, caption =
_L(
"Configuration is edited in ConfigWizard");
2379
2382 auto get_preferred_printer_technology = [enabled_vendors, suppress_sla_printer](const std::string& bundle_name, const Bundle& bundle) {
2383 const auto config = enabled_vendors.find(bundle_name);
2385 if (config != enabled_vendors.end()) {
2386 for (const auto& model : bundle.vendor_profile->models) {
2387 if (const auto model_it = config->second.find(model.id);
2388 model_it != config->second.end() && model_it->second.size() > 0) {
2390 pt = model.technology;
2391
2392 if (pt ==
ptSLA && suppress_sla_printer)
2393 continue;
2394 else
2395 return pt;
2396 }
2397 }
2398 }
2399 return pt;
2400 };
2401
2402 if (preferred_pt = get_preferred_printer_technology(
"BBL",
bundles.bbl_bundle());
2403 preferred_pt ==
ptAny || (preferred_pt ==
ptSLA && suppress_sla_printer)) {
2404 for (
const auto& bundle :
bundles) {
2405
2406 if (bundle.second.is_bbl_bundle) { continue; }
2408 continue;
2409 else if (preferred_pt ==
ptAny)
2410 preferred_pt = pt;
2411 if(!(preferred_pt ==
ptAny || (preferred_pt ==
ptSLA && suppress_sla_printer)))
2412 break;
2413 }
2414 }
2415
2416 if (preferred_pt ==
ptSLA && !wxGetApp().may_switch_to_SLA_preset(caption))
2417 return false;
2418
2419 bool check_unsaved_preset_changes = false;
2420 if (check_unsaved_preset_changes)
2421 header =
_L(
"All user presets will be deleted.");
2423 if (!check_unsaved_preset_changes)
2425
2426
2427 std::vector<std::string> install_bundles;
2428 for (
const auto &pair :
bundles) {
2429 if (! pair.second.is_in_resources) { continue; }
2430
2431
2432 if (pair.second.is_bbl_bundle) {
2433
2434
2435 install_bundles.emplace_back(pair.first);
2436 continue;
2437 }
2438
2439 const auto vendor = enabled_vendors.find(pair.first);
2440 if (vendor == enabled_vendors.end()) { continue; }
2441
2442 size_t size_sum = 0;
2443 for (const auto &model : vendor->second) { size_sum += model.second.size(); }
2444
2445 if (size_sum > 0) {
2446
2447 install_bundles.emplace_back(pair.first);
2448 }
2449 }
2450 if (!check_unsaved_preset_changes)
2451 if ((check_unsaved_preset_changes = install_bundles.size() > 0))
2452 header =
_L_PLURAL(
"A new vendor was installed and one of its printers will be activated",
"New vendors were installed and one of their printers will be activated", install_bundles.size());
2453
2454
2455 bool snapshot = true;
2459 snapshot = false;
2460 break;
2462 snapshot = true;
2463 break;
2465
2466
2467 snapshot = false;
2468 break;
2470 snapshot = false;
2472 break;
2473 }
2474
2475
2476
2477
2478
2479 if (check_unsaved_preset_changes &&
2480 !wxGetApp().check_and_keep_current_preset_changes(caption, header, act_btns, &apply_keeped_changes))
2481 return false;
2482
2483 if (install_bundles.size() > 0) {
2484
2485
2486 if (! updater->install_bundles_rsrc(std::move(install_bundles), false))
2487 return false;
2488 } else {
2489 BOOST_LOG_TRIVIAL(info) << "No bundles need to be installed from resources";
2490 }
2491
2492 std::string preferred_model;
2493 std::string preferred_variant;
2494 const auto enabled_vendors_old = app_config->vendors();
2495 auto get_preferred_printer_model = [enabled_vendors, enabled_vendors_old, preferred_pt](const std::string& bundle_name, const Bundle& bundle, std::string& variant) {
2496 const auto config = enabled_vendors.find(bundle_name);
2497 if (config == enabled_vendors.end())
2498 return std::string();
2499 for (const auto& model : bundle.vendor_profile->models) {
2500 if (const auto model_it = config->second.find(model.id);
2501 model_it != config->second.end() && model_it->second.size() > 0 &&
2502 preferred_pt == model.technology) {
2503 variant = *model_it->second.begin();
2504 const auto config_old = enabled_vendors_old.find(bundle_name);
2505 if (config_old == enabled_vendors_old.end())
2506 return model.id;
2507 const auto model_it_old = config_old->second.find(model.id);
2508 if (model_it_old == config_old->second.end())
2509 return model.id;
2510 else if (model_it_old->second != model_it->second) {
2511 for (
const auto&
var : model_it->second)
2512 if (model_it_old->second.find(
var) == model_it_old->second.end()) {
2514 return model.id;
2515 }
2516 }
2517 }
2518 }
2519 if (!variant.empty())
2520 variant.clear();
2521 return std::string();
2522 };
2523
2524 if (preferred_model = get_preferred_printer_model(
"BBL",
bundles.bbl_bundle(), preferred_variant);
2525 preferred_model.empty()) {
2526 for (
const auto& bundle :
bundles) {
2527 if (bundle.second.is_bbl_bundle) { continue; }
2528 if (preferred_model = get_preferred_printer_model(bundle.first, bundle.second, preferred_variant);
2529 !preferred_model.empty())
2530 break;
2531 }
2532 }
2533
2534
2535 if (!check_unsaved_preset_changes) {
2536 if ((check_unsaved_preset_changes = !preferred_model.empty())) {
2537 header =
_L(
"A new Printer was installed and it will be activated.");
2538 if (!wxGetApp().check_and_keep_current_preset_changes(caption, header, act_btns, &apply_keeped_changes))
2539 return false;
2540 }
2541 else if ((check_unsaved_preset_changes = enabled_vendors_old != enabled_vendors)) {
2542 header =
_L(
"Some Printers were uninstalled.");
2543 if (!wxGetApp().check_and_keep_current_preset_changes(caption, header, act_btns, &apply_keeped_changes))
2544 return false;
2545 }
2546 }
2547
2548 std::string first_added_filament, first_added_sla_material;
2549 auto get_first_added_material_preset = [
this, app_config](
const std::string&
section_name, std::string& first_added_preset) {
2551
2552 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>();
2554 }
2555 };
2557
2558
2559
2560
2561 if (!check_unsaved_preset_changes) {
2562 if ((check_unsaved_preset_changes = !first_added_filament.empty() || !first_added_sla_material.empty())) {
2563 header = !first_added_filament.empty() ?
2564 _L(
"A new filament was installed and it will be activated.") :
2565 _L(
"A new SLA material was installed and it will be activated.");
2566 if (!wxGetApp().check_and_keep_current_preset_changes(caption, header, act_btns, &apply_keeped_changes))
2567 return false;
2568 }
2569 else {
2570
2572 if ((check_unsaved_preset_changes = is_filaments_changed)) {
2573 header =
_L(
"Some filaments were uninstalled.");
2574 if (!wxGetApp().check_and_keep_current_preset_changes(caption, header, act_btns, &apply_keeped_changes))
2575 return false;
2576 }
2577
2578
2579
2580
2581
2582
2583
2584
2585 }
2586 }
2587
2588
2589
2592
2594
2595 if (check_unsaved_preset_changes)
2597 {preferred_model, preferred_variant, first_added_filament, first_added_sla_material});
2598
2600
2601 if (!check_unsaved_preset_changes &&
2602 !wxGetApp().check_and_keep_current_preset_changes(caption,
_L(
"Custom printer was installed and it will be activated."), act_btns, &apply_keeped_changes))
2603 return false;
2604
2608
2609
2610#if ENABLE_COPY_CUSTOM_BED_MODEL_AND_TEXTURE
2612#endif
2613
2614 custom_config->set_key_value(
"filament_colour", wxGetApp().preset_bundle->project_config.option(
"filament_colour"));
2615 const std::string profile_name =
page_custom->profile_name();
2616 Semver semver(SLIC3R_VERSION);
2617 preset_bundle->load_config_from_wizard(profile_name, *
custom_config, semver);
2618
2622 }
2623
2624
2625 preset_bundle->export_selections(*app_config);
2626
2627
2628
2629
2630
2631 return true;
2632}
static const std::string SECTION_FILAMENTS
Definition AppConfig.hpp:408
@ RR_DATA_EMPTY
Definition ConfigWizard.hpp:24
@ RR_DATA_LEGACY
Definition ConfigWizard.hpp:25
@ RR_USER
Definition ConfigWizard.hpp:27
@ RR_DATA_INCOMPAT
Definition ConfigWizard.hpp:26
Reason
Definition Snapshot.hpp:36
@ SNAPSHOT_UPGRADE
Definition Snapshot.hpp:38
@ SNAPSHOT_USER
Definition Snapshot.hpp:41
@ TYPE_PRINTER
Definition Preset.hpp:250
@ TYPE_PRINT
Definition Preset.hpp:246
@ TYPE_FILAMENT
Definition Preset.hpp:248
const char * section_name(ShortcutSection section)
Definition Shortcuts.cpp:248
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)
Definition ConfigWizard.cpp:2367
@ KEEP
Definition UnsavedChangesDialog.hpp:252
@ SAVE
Definition UnsavedChangesDialog.hpp:253
std::string var(const std::string &file_name)
Definition utils.cpp:278
@ EnableSilentDisableSystem
Definition Config.hpp:251
PrinterTechnology
Definition Config.hpp:229
@ ptSLA
Definition Config.hpp:233
@ ptAny
Definition Config.hpp:237
bool model_has_multi_part_objects(const Model &model)
Definition Model.cpp:4311
#define _L_PLURAL(s, plural, n)
Definition I18N.hpp:96
PageFirmware * page_firmware
Definition ConfigWizard_private.hpp:584
bool only_sla_mode
Definition ConfigWizard_private.hpp:558
std::unique_ptr< DynamicPrintConfig > custom_config
Definition ConfigWizard_private.hpp:553
BundleMap bundles
Definition ConfigWizard_private.hpp:545
PageBedShape * page_bed
Definition ConfigWizard_private.hpp:585
PageDiameters * page_diams
Definition ConfigWizard_private.hpp:586
PageCustom * page_custom
Definition ConfigWizard_private.hpp:575
ConfigWizard::RunReason run_reason
Definition ConfigWizard_private.hpp:543