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
This commit is contained in:
parent
16e7993a65
commit
631897c0a6
|
@ -1128,14 +1128,33 @@ void PresetBundle::save_changes_for_preset(const std::string& new_name, Preset::
|
||||||
|
|
||||||
void PresetBundle::load_installed_filaments(AppConfig &config)
|
void PresetBundle::load_installed_filaments(AppConfig &config)
|
||||||
{
|
{
|
||||||
if (! config.has_section(AppConfig::SECTION_FILAMENTS)
|
//if (! config.has_section(AppConfig::SECTION_FILAMENTS)
|
||||||
|| config.get_section(AppConfig::SECTION_FILAMENTS).empty()) {
|
// || config.get_section(AppConfig::SECTION_FILAMENTS).empty()) {
|
||||||
// Compatibility with the PrusaSlicer 2.1.1 and older, where the filament profiles were not installable yet.
|
// 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
|
// Find all filament profiles, which are compatible with installed printers, and act as if these filament profiles
|
||||||
// were installed.
|
// were installed.
|
||||||
std::unordered_set<const Preset*> compatible_filaments;
|
std::unordered_set<const Preset*> compatible_filaments;
|
||||||
for (const Preset &printer : printers)
|
for (const Preset &printer : printers)
|
||||||
if (printer.is_visible && printer.printer_technology() == ptFFF && printer.vendor && (!printer.vendor->models.empty())) {
|
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<std::string, std::string>& 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)
|
for (auto default_filament: printer.vendor->models[0].default_materials)
|
||||||
{
|
{
|
||||||
Preset* filament = filaments.find_preset(default_filament, false, true);
|
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.
|
// 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)
|
for (const auto &filament: compatible_filaments)
|
||||||
config.set(AppConfig::SECTION_FILAMENTS, filament->name, "true");
|
config.set(AppConfig::SECTION_FILAMENTS, filament->name, "true");
|
||||||
}
|
//}
|
||||||
|
|
||||||
for (auto &preset : filaments)
|
for (auto &preset : filaments)
|
||||||
preset.set_visible_from_appconfig(config);
|
preset.set_visible_from_appconfig(config);
|
||||||
|
|
|
@ -1196,7 +1196,7 @@ GUI_App::GUI_App()
|
||||||
|
|
||||||
void GUI_App::shutdown()
|
void GUI_App::shutdown()
|
||||||
{
|
{
|
||||||
BOOST_LOG_TRIVIAL(info) << "shutdown";
|
BOOST_LOG_TRIVIAL(info) << "GUI_App::shutdown enter";
|
||||||
|
|
||||||
if (m_removable_drive_manager) {
|
if (m_removable_drive_manager) {
|
||||||
removable_drive_manager()->shutdown();
|
removable_drive_manager()->shutdown();
|
||||||
|
@ -1216,6 +1216,7 @@ void GUI_App::shutdown()
|
||||||
delete m_agent;
|
delete m_agent;
|
||||||
m_agent = nullptr;
|
m_agent = nullptr;
|
||||||
}
|
}
|
||||||
|
BOOST_LOG_TRIVIAL(info) << "GUI_App::shutdown exit";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1788,7 +1789,7 @@ static boost::optional<Semver> parse_semver_from_ini(std::string path)
|
||||||
return Semver::parse(body);
|
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");
|
std::string down_path = app_config->get("download_path");
|
||||||
|
|
||||||
|
@ -1971,6 +1972,7 @@ bool GUI_App::on_init_inner()
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
wxGetApp().Bind(wxEVT_QUERY_END_SESSION, [this](auto & e) {
|
wxGetApp().Bind(wxEVT_QUERY_END_SESSION, [this](auto & e) {
|
||||||
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__<< "received wxEVT_QUERY_END_SESSION";
|
||||||
if (mainframe) {
|
if (mainframe) {
|
||||||
wxCloseEvent e2(wxEVT_CLOSE_WINDOW);
|
wxCloseEvent e2(wxEVT_CLOSE_WINDOW);
|
||||||
e2.SetCanVeto(true);
|
e2.SetCanVeto(true);
|
||||||
|
@ -2762,6 +2764,7 @@ void GUI_App::check_printer_presets()
|
||||||
|
|
||||||
void GUI_App::recreate_GUI(const wxString& msg_name)
|
void GUI_App::recreate_GUI(const wxString& msg_name)
|
||||||
{
|
{
|
||||||
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "recreate_GUI enter";
|
||||||
m_is_recreating_gui = true;
|
m_is_recreating_gui = true;
|
||||||
|
|
||||||
mainframe->shutdown();
|
mainframe->shutdown();
|
||||||
|
@ -2809,6 +2812,8 @@ void GUI_App::recreate_GUI(const wxString& msg_name)
|
||||||
// });
|
// });
|
||||||
|
|
||||||
m_is_recreating_gui = false;
|
m_is_recreating_gui = false;
|
||||||
|
|
||||||
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "recreate_GUI exit";
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUI_App::system_info()
|
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());
|
const std::string name = into_u8(window->GetName());
|
||||||
|
|
||||||
window->Bind(wxEVT_CLOSE_WINDOW, [=](wxCloseEvent &event) {
|
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");
|
window_pos_save(window, "mainframe");
|
||||||
event.Skip();
|
event.Skip();
|
||||||
});
|
});
|
||||||
|
|
|
@ -394,7 +394,7 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, BORDERLESS_FRAME_
|
||||||
|
|
||||||
// declare events
|
// declare events
|
||||||
Bind(wxEVT_CLOSE_WINDOW, [this](wxCloseEvent& event) {
|
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)) {
|
if (event.CanVeto() && m_plater->get_view3D_canvas3D()->get_gizmos_manager().is_in_editing_mode(true)) {
|
||||||
// prevents to open the save dirty project dialog
|
// prevents to open the save dirty project dialog
|
||||||
event.Veto();
|
event.Veto();
|
||||||
|
@ -447,7 +447,7 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, BORDERLESS_FRAME_
|
||||||
this->shutdown();
|
this->shutdown();
|
||||||
// propagate event
|
// propagate event
|
||||||
event.Skip();
|
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?
|
//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.
|
// Called when closing the application and when switching the application language.
|
||||||
void MainFrame::shutdown()
|
void MainFrame::shutdown()
|
||||||
{
|
{
|
||||||
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "MainFrame::shutdown enter";
|
||||||
// BBS: backup
|
// BBS: backup
|
||||||
Slic3r::set_backup_callback(nullptr);
|
Slic3r::set_backup_callback(nullptr);
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -783,6 +784,8 @@ void MainFrame::shutdown()
|
||||||
wxGetApp().shutdown();
|
wxGetApp().shutdown();
|
||||||
// BBS: why clear ?
|
// BBS: why clear ?
|
||||||
//wxGetApp().plater_ = nullptr;
|
//wxGetApp().plater_ = nullptr;
|
||||||
|
|
||||||
|
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "MainFrame::shutdown exit";
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainFrame::update_title()
|
void MainFrame::update_title()
|
||||||
|
@ -1431,7 +1434,7 @@ wxBoxSizer* MainFrame::create_side_tools()
|
||||||
p->append_button(send_to_printer_btn);
|
p->append_button(send_to_printer_btn);
|
||||||
p->append_button(export_sliced_file_btn);
|
p->append_button(export_sliced_file_btn);
|
||||||
}
|
}
|
||||||
|
|
||||||
p->Popup(m_print_btn);
|
p->Popup(m_print_btn);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -749,28 +749,23 @@ bool GuideFrame::apply_config(AppConfig *app_config, PresetBundle *preset_bundle
|
||||||
const auto config = enabled_vendors.find(bundle_name);
|
const auto config = enabled_vendors.find(bundle_name);
|
||||||
if (config == enabled_vendors.end())
|
if (config == enabled_vendors.end())
|
||||||
return std::string();
|
return std::string();
|
||||||
auto vendor_profile = preset_bundle->vendors.find(bundle_name);
|
|
||||||
if (vendor_profile == preset_bundle->vendors.end()) {
|
const std::map<std::string, std::set<std::string>>& model_maps = config->second;
|
||||||
BOOST_LOG_TRIVIAL(info) << boost::format("%1%, can not find bundle %2% in preset bundles")%__FUNCTION__ %bundle_name;
|
|
||||||
return std::string();
|
|
||||||
}
|
|
||||||
//for (const auto& vendor_profile : preset_bundle->vendors) {
|
//for (const auto& vendor_profile : preset_bundle->vendors) {
|
||||||
for (const auto model: vendor_profile->second.models) {
|
for (const auto model_it: model_maps) {
|
||||||
if (const auto model_it = config->second.find(model.id);
|
if (model_it.second.size() > 0) {
|
||||||
model_it != config->second.end() && model_it->second.size() > 0 &&
|
variant = *model_it.second.begin();
|
||||||
preferred_pt == model.technology) {
|
|
||||||
variant = *model_it->second.begin();
|
|
||||||
const auto config_old = old_enabled_vendors.find(bundle_name);
|
const auto config_old = old_enabled_vendors.find(bundle_name);
|
||||||
if (config_old == old_enabled_vendors.end())
|
if (config_old == old_enabled_vendors.end())
|
||||||
return model.id;
|
return model_it.first;
|
||||||
const auto model_it_old = config_old->second.find(model.id);
|
const auto model_it_old = config_old->second.find(model_it.first);
|
||||||
if (model_it_old == config_old->second.end())
|
if (model_it_old == config_old->second.end())
|
||||||
return model.id;
|
return model_it.first;
|
||||||
else if (model_it_old->second != model_it->second) {
|
else if (model_it_old->second != model_it.second) {
|
||||||
for (const auto& var : model_it->second)
|
for (const auto& var : model_it.second)
|
||||||
if (model_it_old->second.find(var) == model_it_old->second.end()) {
|
if (model_it_old->second.find(var) == model_it_old->second.end()) {
|
||||||
variant = var;
|
variant = var;
|
||||||
return model.id;
|
return model_it.first;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue