From ae959b74001728ee42b9a4e84c387f0ee8c2a630 Mon Sep 17 00:00:00 2001 From: "chunmao.guo" Date: Mon, 9 Jan 2023 14:13:14 +0800 Subject: [PATCH] ENH: [STUDIO-1871] merge changes of user presets from other sessions Change-Id: I2841ff4e23b18ebe7cdf374b69a494a4c05a49ee --- src/libslic3r/Preset.cpp | 4 ++++ src/libslic3r/PresetBundle.cpp | 27 ++++++++++++++++++++++----- src/libslic3r/PresetBundle.hpp | 2 +- src/slic3r/GUI/Tab.cpp | 10 +--------- 4 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index b942af884..1666572f9 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -1543,6 +1543,10 @@ bool PresetCollection::load_user_preset(std::string name, std::mapname == m_edited_preset.name && iter->is_dirty) { + // Keep modifies when update from remote + new_config.apply_only(m_edited_preset.config, m_edited_preset.config.diff(iter->config)); + } iter->config = new_config; iter->updated_time = cloud_update_time; iter->version = cloud_version.value(); diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index 2bdc67ac1..c81608860 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -553,6 +553,10 @@ PresetsConfigSubstitutions PresetBundle::load_user_presets(AppConfig & BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" print's selected_idx %1%, selected_name %2%") %prints.get_selected_idx() %prints.get_selected_preset_name(); BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" filament's selected_idx %1%, selected_name %2%") %filaments.get_selected_idx() %filaments.get_selected_preset_name(); BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" printers's selected_idx %1%, selected_name %2%") %printers.get_selected_idx() %printers.get_selected_preset_name(); + + // Sync removing + remove_users_preset(config, &my_presets); + std::map>::iterator it; for (it = my_presets.begin(); it != my_presets.end(); it++) { std::string name = it->first; @@ -838,13 +842,26 @@ bool PresetBundle::validate_printers(const std::string &name, DynamicPrintConfig #endif } -void PresetBundle::remove_users_preset(AppConfig& config) +void PresetBundle::remove_users_preset(AppConfig &config, std::map> *my_presets) { + auto check_removed = [my_presets, this](Preset &preset) -> bool { + if (my_presets == nullptr) return true; + if (my_presets->find(preset.name) != my_presets->end()) return false; + if (!preset.sync_info.empty()) return false; // syncing, not remove + if (preset.setting_id.empty()) return false; // no id, not remove + // Saved preset is removed by another session + if (preset.is_dirty) { + preset.setting_id.clear(); + return false; + } + preset.remove_files(); + return true; + }; std::string preset_folder_user_id = config.get("preset_folder"); std::string printer_selected_preset_name = printers.get_selected_preset().name; bool need_reset_printer_preset = false; for (auto it = printers.begin(); it != printers.end();) { - if (it->is_user() && !it->user_id.empty() && it->user_id.compare(preset_folder_user_id) == 0) { + if (it->is_user() && !it->user_id.empty() && it->user_id.compare(preset_folder_user_id) == 0 && check_removed(*it)) { BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(":printers erase %1%, type %2%, user_id %3%") % it->name % Preset::get_type_string(it->type) % it->user_id; if (it->name == printer_selected_preset_name) need_reset_printer_preset = true; @@ -875,7 +892,7 @@ void PresetBundle::remove_users_preset(AppConfig& config) bool need_reset_print_preset = false; // remove preset if user_id is not current user for (auto it = prints.begin(); it != prints.end();) { - if (it->is_user() && !it->user_id.empty() && it->user_id.compare(preset_folder_user_id) == 0) { + if (it->is_user() && !it->user_id.empty() && it->user_id.compare(preset_folder_user_id) == 0 && check_removed(*it)) { BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(":prints erase %1%, type %2%, user_id %3%")%it->name %Preset::get_type_string(it->type) %it->user_id; if (it->name == selected_print_name) need_reset_print_preset = true; @@ -895,7 +912,7 @@ void PresetBundle::remove_users_preset(AppConfig& config) std::string selected_filament_name = filaments.get_selected_preset().name; bool need_reset_filament_preset = false; for (auto it = filaments.begin(); it != filaments.end();) { - if (it->is_user() && !it->user_id.empty() && it->user_id.compare(preset_folder_user_id) == 0) { + if (it->is_user() && !it->user_id.empty() && it->user_id.compare(preset_folder_user_id) == 0 && check_removed(*it)) { BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << boost::format(":filaments erase %1%, type %2%, user_id %3%")%it->name %Preset::get_type_string(it->type) %it->user_id; if (it->name == selected_filament_name) need_reset_filament_preset = true; @@ -1348,7 +1365,7 @@ void PresetBundle::load_selections(AppConfig &config, const PresetPreferences& p void PresetBundle::export_selections(AppConfig &config) { assert(this->printers.get_edited_preset().printer_technology() != ptFFF || filament_presets.size() >= 1); - assert(this->printers.get_edited_preset().printer_technology() != ptFFF || filament_presets.size() > 1 || filaments.get_selected_preset_name() == filament_presets.front()); + //assert(this->printers.get_edited_preset().printer_technology() != ptFFF || filament_presets.size() > 1 || filaments.get_selected_preset_name() == filament_presets.front()); config.clear_section("presets"); config.set("presets", PRESET_PRINT_NAME, prints.get_selected_preset_name()); config.set("presets", PRESET_FILAMENT_NAME, filament_presets.front()); diff --git a/src/libslic3r/PresetBundle.hpp b/src/libslic3r/PresetBundle.hpp index 65caee6be..854baf804 100644 --- a/src/libslic3r/PresetBundle.hpp +++ b/src/libslic3r/PresetBundle.hpp @@ -51,7 +51,7 @@ public: PresetsConfigSubstitutions load_user_presets(AppConfig &config, std::map>& my_presets, ForwardCompatibilitySubstitutionRule rule); PresetsConfigSubstitutions import_presets(std::vector &files, std::function override_confirm, ForwardCompatibilitySubstitutionRule rule); void save_user_presets(AppConfig& config, std::vector& need_to_delete_list); - void remove_users_preset(AppConfig &config); + void remove_users_preset(AppConfig &config, std::map> * my_presets = nullptr); void update_user_presets_directory(const std::string preset_folder); void remove_user_presets_directory(const std::string preset_folder); void update_system_preset_setting_ids(std::map>& system_presets); diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index e108cca33..7e0a1ce20 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -3939,9 +3939,9 @@ bool Tab::select_preset(std::string preset_name, bool delete_current /*=false*/, try { //BBS delete preset Preset ¤t_preset = m_presets->get_selected_preset(); - current_preset.sync_info = "delete"; if (!current_preset.setting_id.empty()) { BOOST_LOG_TRIVIAL(info) << "delete preset = " << current_preset.name << ", setting_id = " << current_preset.setting_id; + m_presets->set_sync_info_and_save(current_preset.name, current_preset.setting_id, "delete"); wxGetApp().delete_preset_from_cloud(current_preset.setting_id); } BOOST_LOG_TRIVIAL(info) << boost::format("will delete current preset..."); @@ -4559,14 +4559,6 @@ void Tab::delete_preset() if (m_type == Preset::TYPE_PRINTER && !physical_printers.empty()) physical_printers.delete_preset_from_printers(current_preset.name); - //BBS delete preset - //will delete in select_preset - current_preset.sync_info = "delete"; - if (!current_preset.setting_id.empty()) { - BOOST_LOG_TRIVIAL(info) << "delete preset = " << current_preset.name << ", setting_id = " << current_preset.setting_id; - wxGetApp().delete_preset_from_cloud(current_preset.setting_id); - } - // Select will handle of the preset dependencies, of saving & closing the depending profiles, and // finally of deleting the preset. this->select_preset("", true);