From 631897c0a6e9a24931e482ca70000cde24972db8 Mon Sep 17 00:00:00 2001 From: "lane.wei" Date: Tue, 18 Oct 2022 16:07:50 +0800 Subject: [PATCH] ENH: add logic to load default filaments of newly added model 1. fix the prefer_model issue 2. when a printer is visible and no filament is selected, just set its default materials to visible 3. add some log for shutdown debug Change-Id: I599dbd9c8b180c944ff4086c7638267ff002f94a --- src/libslic3r/PresetBundle.cpp | 25 ++++++++++++++++++++++--- src/slic3r/GUI/GUI_App.cpp | 10 ++++++++-- src/slic3r/GUI/MainFrame.cpp | 9 ++++++--- src/slic3r/GUI/WebGuideDialog.cpp | 27 +++++++++++---------------- 4 files changed, 47 insertions(+), 24 deletions(-) diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index 6cef34a02..579bd47fb 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -1128,14 +1128,33 @@ void PresetBundle::save_changes_for_preset(const std::string& new_name, Preset:: void PresetBundle::load_installed_filaments(AppConfig &config) { - if (! config.has_section(AppConfig::SECTION_FILAMENTS) - || config.get_section(AppConfig::SECTION_FILAMENTS).empty()) { + //if (! config.has_section(AppConfig::SECTION_FILAMENTS) + // || config.get_section(AppConfig::SECTION_FILAMENTS).empty()) { // Compatibility with the PrusaSlicer 2.1.1 and older, where the filament profiles were not installable yet. // Find all filament profiles, which are compatible with installed printers, and act as if these filament profiles // were installed. std::unordered_set compatible_filaments; for (const Preset &printer : printers) if (printer.is_visible && printer.printer_technology() == ptFFF && printer.vendor && (!printer.vendor->models.empty())) { + bool add_default_materials = true; + if (config.has_section(AppConfig::SECTION_FILAMENTS)) + { + const std::map& installed_filament = config.get_section(AppConfig::SECTION_FILAMENTS); + for (auto filament_iter : installed_filament) + { + Preset* filament = filaments.find_preset(filament_iter.first, false, true); + if (filament && is_compatible_with_printer(PresetWithVendorProfile(*filament, filament->vendor), PresetWithVendorProfile(printer, printer.vendor))) + { + //already has compatible filament + add_default_materials = false; + break; + } + } + } + + if (!add_default_materials) + continue; + for (auto default_filament: printer.vendor->models[0].default_materials) { Preset* filament = filaments.find_preset(default_filament, false, true); @@ -1150,7 +1169,7 @@ void PresetBundle::load_installed_filaments(AppConfig &config) // and mark these filaments as installed, therefore this code will not be executed at the next start of the application. for (const auto &filament: compatible_filaments) config.set(AppConfig::SECTION_FILAMENTS, filament->name, "true"); - } + //} for (auto &preset : filaments) preset.set_visible_from_appconfig(config); diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 6aabbc0e9..d33ef46d1 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -1196,7 +1196,7 @@ GUI_App::GUI_App() void GUI_App::shutdown() { - BOOST_LOG_TRIVIAL(info) << "shutdown"; + BOOST_LOG_TRIVIAL(info) << "GUI_App::shutdown enter"; if (m_removable_drive_manager) { removable_drive_manager()->shutdown(); @@ -1216,6 +1216,7 @@ void GUI_App::shutdown() delete m_agent; m_agent = nullptr; } + BOOST_LOG_TRIVIAL(info) << "GUI_App::shutdown exit"; } @@ -1788,7 +1789,7 @@ static boost::optional parse_semver_from_ini(std::string path) return Semver::parse(body); } -void GUI_App::init_download_path() +void GUI_App::init_download_path() { std::string down_path = app_config->get("download_path"); @@ -1971,6 +1972,7 @@ bool GUI_App::on_init_inner() #endif wxGetApp().Bind(wxEVT_QUERY_END_SESSION, [this](auto & e) { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< "received wxEVT_QUERY_END_SESSION"; if (mainframe) { wxCloseEvent e2(wxEVT_CLOSE_WINDOW); e2.SetCanVeto(true); @@ -2762,6 +2764,7 @@ void GUI_App::check_printer_presets() void GUI_App::recreate_GUI(const wxString& msg_name) { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "recreate_GUI enter"; m_is_recreating_gui = true; mainframe->shutdown(); @@ -2809,6 +2812,8 @@ void GUI_App::recreate_GUI(const wxString& msg_name) // }); m_is_recreating_gui = false; + + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "recreate_GUI exit"; } void GUI_App::system_info() @@ -2968,6 +2973,7 @@ void GUI_App::persist_window_geometry(wxTopLevelWindow *window, bool default_max const std::string name = into_u8(window->GetName()); window->Bind(wxEVT_CLOSE_WINDOW, [=](wxCloseEvent &event) { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< ": received wxEVT_CLOSE_WINDOW, trigger save for window_mainframe"; window_pos_save(window, "mainframe"); event.Skip(); }); diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 3cc952ace..9051d113b 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -394,7 +394,7 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, BORDERLESS_FRAME_ // declare events Bind(wxEVT_CLOSE_WINDOW, [this](wxCloseEvent& event) { - BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< "received close_widow event"; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< ": mainframe received close_widow event"; if (event.CanVeto() && m_plater->get_view3D_canvas3D()->get_gizmos_manager().is_in_editing_mode(true)) { // prevents to open the save dirty project dialog event.Veto(); @@ -447,7 +447,7 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, BORDERLESS_FRAME_ this->shutdown(); // propagate event event.Skip(); - BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< "finished process close_widow event"; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< ": mainframe finished process close_widow event"; }); //FIXME it seems this method is not called on application start-up, at least not on Windows. Why? @@ -722,6 +722,7 @@ void MainFrame::update_layout() // Called when closing the application and when switching the application language. void MainFrame::shutdown() { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "MainFrame::shutdown enter"; // BBS: backup Slic3r::set_backup_callback(nullptr); #ifdef _WIN32 @@ -783,6 +784,8 @@ void MainFrame::shutdown() wxGetApp().shutdown(); // BBS: why clear ? //wxGetApp().plater_ = nullptr; + + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "MainFrame::shutdown exit"; } void MainFrame::update_title() @@ -1431,7 +1434,7 @@ wxBoxSizer* MainFrame::create_side_tools() p->append_button(send_to_printer_btn); p->append_button(export_sliced_file_btn); } - + p->Popup(m_print_btn); } ); diff --git a/src/slic3r/GUI/WebGuideDialog.cpp b/src/slic3r/GUI/WebGuideDialog.cpp index 03c6d80af..b50a9d7e7 100644 --- a/src/slic3r/GUI/WebGuideDialog.cpp +++ b/src/slic3r/GUI/WebGuideDialog.cpp @@ -749,28 +749,23 @@ bool GuideFrame::apply_config(AppConfig *app_config, PresetBundle *preset_bundle const auto config = enabled_vendors.find(bundle_name); if (config == enabled_vendors.end()) return std::string(); - auto vendor_profile = preset_bundle->vendors.find(bundle_name); - if (vendor_profile == preset_bundle->vendors.end()) { - BOOST_LOG_TRIVIAL(info) << boost::format("%1%, can not find bundle %2% in preset bundles")%__FUNCTION__ %bundle_name; - return std::string(); - } + + const std::map>& model_maps = config->second; //for (const auto& vendor_profile : preset_bundle->vendors) { - for (const auto model: vendor_profile->second.models) { - if (const auto model_it = config->second.find(model.id); - model_it != config->second.end() && model_it->second.size() > 0 && - preferred_pt == model.technology) { - variant = *model_it->second.begin(); + for (const auto model_it: model_maps) { + if (model_it.second.size() > 0) { + variant = *model_it.second.begin(); const auto config_old = old_enabled_vendors.find(bundle_name); if (config_old == old_enabled_vendors.end()) - return model.id; - const auto model_it_old = config_old->second.find(model.id); + return model_it.first; + const auto model_it_old = config_old->second.find(model_it.first); 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) + return model_it.first; + 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; + return model_it.first; } } }