From 580f157d283757889c4eba7d486bedd9a7a7eee2 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Mon, 4 Oct 2021 11:35:27 +0200 Subject: [PATCH] ConfigWizard: Suppress to select SLA printer if a multi-parts object is on a Plater --- src/slic3r/GUI/ConfigWizard.cpp | 50 +++++++++++++++++++++++++++++---- src/slic3r/GUI/GUI_App.cpp | 24 +++++++++++----- src/slic3r/GUI/GUI_App.hpp | 1 + src/slic3r/GUI/Tab.cpp | 17 +---------- src/slic3r/GUI/Tab.hpp | 1 - 5 files changed, 64 insertions(+), 29 deletions(-) diff --git a/src/slic3r/GUI/ConfigWizard.cpp b/src/slic3r/GUI/ConfigWizard.cpp index ee6e3d5ab5..4d50e14905 100644 --- a/src/slic3r/GUI/ConfigWizard.cpp +++ b/src/slic3r/GUI/ConfigWizard.cpp @@ -30,6 +30,8 @@ #include "libslic3r/Platform.hpp" #include "libslic3r/Utils.hpp" #include "libslic3r/Config.hpp" +#include "libslic3r/libslic3r.h" +#include "libslic3r/Model.hpp" #include "GUI.hpp" #include "GUI_App.hpp" #include "GUI_Utils.hpp" @@ -40,7 +42,6 @@ #include "slic3r/Utils/PresetUpdater.hpp" #include "format.hpp" #include "MsgDialog.hpp" -#include "libslic3r/libslic3r.h" #include "UnsavedChangesDialog.hpp" #if defined(__linux__) && defined(__WXGTK3__) @@ -2477,6 +2478,46 @@ static std::string get_first_added_preset(const std::mapmodels) { + if (const auto model_it = config->second.find(model.id); + model_it != config->second.end() && model_it->second.size() > 0) { + if (pt == ptAny) + pt = model.technology; + // if preferred printer model has SLA printer technology it's important to check the model for multypart state + if (pt == ptSLA && suppress_sla_printer) + continue; + else + return pt; + } + } + } + return pt; + }; + // Prusa printers are considered first, then 3rd party. + if (preferred_pt = get_preferred_printer_technology("PrusaResearch", bundles.prusa_bundle()); + preferred_pt == ptAny || (preferred_pt == ptSLA && suppress_sla_printer)) { + for (const auto& bundle : bundles) { + if (bundle.second.is_prusa_bundle) { continue; } + if (PrinterTechnology pt = get_preferred_printer_technology(bundle.first, bundle.second); pt == ptAny) + continue; + else if (preferred_pt == ptAny) + preferred_pt = pt; + if(!(preferred_pt == ptAny || (preferred_pt == ptSLA && suppress_sla_printer))) + break; + } + } + + if (preferred_pt == ptSLA && !wxGetApp().may_switch_to_SLA_preset(caption)) + return false; + bool check_unsaved_preset_changes = page_welcome->reset_user_profile(); if (check_unsaved_preset_changes) header = _L("All user presets will be deleted."); @@ -2484,8 +2525,6 @@ bool ConfigWizard::priv::apply_config(AppConfig *app_config, PresetBundle *prese if (!check_unsaved_preset_changes) act_btns |= UnsavedChangesDialog::ActionButtons::SAVE; - const auto enabled_vendors = appconfig_new.vendors(); - // Install bundles from resources if needed: std::vector install_bundles; for (const auto &pair : bundles) { @@ -2564,13 +2603,14 @@ bool ConfigWizard::priv::apply_config(AppConfig *app_config, PresetBundle *prese 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) { + auto get_preferred_printer_model = [enabled_vendors, enabled_vendors_old, preferred_pt](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) { + model_it != config->second.end() && model_it->second.size() > 0 && + preferred_pt == model.technology) { variant = *model_it->second.begin(); const auto config_old = enabled_vendors_old.find(bundle_name); if (config_old == enabled_vendors_old.end()) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 9c08159fce..41f4c4b892 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -2432,6 +2432,20 @@ void GUI_App::open_web_page_localized(const std::string &http_address) open_browser_with_warning_dialog(http_address + "&lng=" + this->current_language_code_safe()); } +// If we are switching from the FFF-preset to the SLA, we should to control the printed objects if they have a part(s). +// Because of we can't to print the multi-part objects with SLA technology. +bool GUI_App::may_switch_to_SLA_preset(const wxString& caption) +{ + if (model_has_multi_part_objects(model())) { + show_info(nullptr, + _L("It's impossible to print multi-part object(s) with SLA technology.") + "\n\n" + + _L("Please check your object list before preset changing."), + caption); + return false; + } + return true; +} + bool GUI_App::run_wizard(ConfigWizard::RunReason reason, ConfigWizard::StartPage start_page) { wxCHECK_MSG(mainframe != nullptr, false, "Internal error: Main frame not created / null"); @@ -2447,13 +2461,9 @@ bool GUI_App::run_wizard(ConfigWizard::RunReason reason, ConfigWizard::StartPage if (res) { load_current_presets(); - if (preset_bundle->printers.get_edited_preset().printer_technology() == ptSLA - && Slic3r::model_has_multi_part_objects(wxGetApp().model())) { - GUI::show_info(nullptr, - _L("It's impossible to print multi-part object(s) with SLA technology.") + "\n\n" + - _L("Please check and fix your object list."), - _L("Attention!")); - } + // #ysFIXME - delete after testing: This part of code looks redundant. All checks are inside ConfigWizard::priv::apply_config() + if (preset_bundle->printers.get_edited_preset().printer_technology() == ptSLA) + may_switch_to_SLA_preset(_L("Configuration is editing from ConfigWizard")); } return res; diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index 60a143144f..a581cf8b30 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -309,6 +309,7 @@ public: PrintHostJobQueue& printhost_job_queue() { return *m_printhost_job_queue.get(); } void open_web_page_localized(const std::string &http_address); + bool may_switch_to_SLA_preset(const wxString& caption); bool run_wizard(ConfigWizard::RunReason reason, ConfigWizard::StartPage start_page = ConfigWizard::SP_WELCOME); void show_desktop_integration_dialog(); diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index c91ac47843..8b3cd4cf89 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -3236,7 +3236,7 @@ void Tab::select_preset(std::string preset_name, bool delete_current /*=false*/, const PresetWithVendorProfile new_printer_preset_with_vendor_profile = m_presets->get_preset_with_vendor_profile(new_printer_preset); PrinterTechnology old_printer_technology = m_presets->get_edited_preset().printer_technology(); PrinterTechnology new_printer_technology = new_printer_preset.printer_technology(); - if (new_printer_technology == ptSLA && old_printer_technology == ptFFF && !may_switch_to_SLA_preset()) + if (new_printer_technology == ptSLA && old_printer_technology == ptFFF && !wxGetApp().may_switch_to_SLA_preset(_L("New printer preset is selecting"))) canceled = true; else { struct PresetUpdate { @@ -3409,21 +3409,6 @@ bool Tab::may_discard_current_dirty_preset(PresetCollection* presets /*= nullptr return true; } -// If we are switching from the FFF-preset to the SLA, we should to control the printed objects if they have a part(s). -// Because of we can't to print the multi-part objects with SLA technology. -bool Tab::may_switch_to_SLA_preset() -{ - if (model_has_multi_part_objects(wxGetApp().model())) - { - show_info( parent(), - _(L("It's impossible to print multi-part object(s) with SLA technology.")) + "\n\n" + - _(L("Please check your object list before preset changing.")), - _(L("Attention!")) ); - return false; - } - return true; -} - void Tab::clear_pages() { // invalidated highlighter, if any exists diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index 5b7983711e..6a7b56fe40 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -282,7 +282,6 @@ public: // Select a new preset, possibly delete the current one. void select_preset(std::string preset_name = "", bool delete_current = false, const std::string& last_selected_ph_printer_name = ""); bool may_discard_current_dirty_preset(PresetCollection* presets = nullptr, const std::string& new_printer_name = ""); - bool may_switch_to_SLA_preset(); virtual void clear_pages(); virtual void update_description_lines();