From 5f0dc7faedd2c30782a6b4c10b0192e90c6eba8f Mon Sep 17 00:00:00 2001 From: "maosheng.wei" Date: Tue, 31 Oct 2023 18:17:41 +0800 Subject: [PATCH] FIX: export and import configs issue Jira: XXXX import config lose xxx_settings_id issue export process config should not have user printer export process config shoule remove duplicate presets export filamnent config: filament list should have no third print compatible presets Change-Id: I94bac062e07b3a989ff86142e3fb8266a48364c6 --- src/libslic3r/Preset.cpp | 18 +++++------ src/libslic3r/PresetBundle.cpp | 2 +- src/slic3r/GUI/CreatePresetsDialog.cpp | 44 ++++++++++++++++++++++++++ src/slic3r/GUI/CreatePresetsDialog.hpp | 1 + 4 files changed, 55 insertions(+), 10 deletions(-) diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index c40d1f433..cf18086be 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -2126,11 +2126,11 @@ bool PresetCollection::clone_presets(std::vector const &presets, } preset.file = this->path_for_preset(preset); if (m_type == Preset::TYPE_PRINT) - preset.config.option("print_settings_id", true)->value.clear(); + preset.config.option("print_settings_id", true)->value = preset.name; else if (m_type == Preset::TYPE_FILAMENT) - preset.config.option("filament_settings_id", true)->values[0].clear(); + preset.config.option("filament_settings_id", true)->values[0] = preset.name; else if (m_type == Preset::TYPE_PRINTER) - preset.config.option("printer_settings_id", true)->value.clear(); + preset.config.option("printer_settings_id", true)->value = preset.name; } if (!failures.empty() && !force_rewritten) return false; @@ -2245,11 +2245,11 @@ void PresetCollection::save_current_preset(const std::string &new_name, bool det //BBS: add lock logic for sync preset in background if (m_type == Preset::TYPE_PRINT) - preset.config.option("print_settings_id", true)->value.clear(); + preset.config.option("print_settings_id", true)->value = new_name; else if (m_type == Preset::TYPE_FILAMENT) - preset.config.option("filament_settings_id", true)->values[0].clear(); + preset.config.option("filament_settings_id", true)->values[0] = new_name; else if (m_type == Preset::TYPE_PRINTER) - preset.config.option("printer_settings_id", true)->value.clear(); + preset.config.option("printer_settings_id", true)->value = new_name; final_inherits = preset.inherits(); unlock(); // TODO: apply change from custom root to devided presets. @@ -2293,11 +2293,11 @@ void PresetCollection::save_current_preset(const std::string &new_name, bool det else preset.is_project_embedded = false; if (m_type == Preset::TYPE_PRINT) - preset.config.option("print_settings_id", true)->value.clear(); + preset.config.option("print_settings_id", true)->value = new_name; else if (m_type == Preset::TYPE_FILAMENT) - preset.config.option("filament_settings_id", true)->values[0].clear(); + preset.config.option("filament_settings_id", true)->values[0] = new_name; else if (m_type == Preset::TYPE_PRINTER) - preset.config.option("printer_settings_id", true)->value.clear(); + preset.config.option("printer_settings_id", true)->value = new_name; //BBS: add lock logic for sync preset in background final_inherits = inherits; unlock(); diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index 79fd46514..a1a2e68e9 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -707,7 +707,7 @@ PresetsConfigSubstitutions PresetBundle::import_presets(std::vector // create target file path std::string target_file_path = boost::filesystem::path(temp_folder / file_name).make_preferred().string(); - status = mz_zip_reader_extract_to_file(&zip_archive, i, target_file_path.c_str(), MZ_ZIP_FLAG_CASE_SENSITIVE); + status = mz_zip_reader_extract_to_file(&zip_archive, i, encode_path(target_file_path.c_str()).c_str(), MZ_ZIP_FLAG_CASE_SENSITIVE); // target file is opened if (MZ_FALSE == status) { BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " Failed to open target file: " << target_file_path; diff --git a/src/slic3r/GUI/CreatePresetsDialog.cpp b/src/slic3r/GUI/CreatePresetsDialog.cpp index 9f0da5560..b26d0cbf8 100644 --- a/src/slic3r/GUI/CreatePresetsDialog.cpp +++ b/src/slic3r/GUI/CreatePresetsDialog.cpp @@ -3084,6 +3084,19 @@ bool ExportConfigsDialog::has_check_box_selected() return false; } +bool ExportConfigsDialog::preset_is_not_compatible_bbl_printer(Preset *preset) +{ + if (preset->type != Preset::Type::TYPE_PRINT && preset->type != Preset::Type::TYPE_FILAMENT) return true; + PresetBundle * preset_bundle = wxGetApp().preset_bundle; + vector printers; + get_filament_compatible_printer(preset, printers); + if (printers.empty()) return true; + Preset *printer_preset = preset_bundle->printers.find_preset(printers[0], false); + if (!printer_preset) return true; + if (!printer_preset->is_bbl_vendor_preset(preset_bundle)) return true; + return false; +} + std::string ExportConfigsDialog::initial_file_path(const wxString &path, const std::string &sub_file_path) { std::string export_path = into_u8(path); @@ -3305,6 +3318,7 @@ void ExportConfigsDialog::select_curr_radiobox(std::vectorClear(true); m_printer_name.clear(); m_preset.clear(); + PresetBundle *preset_bundle = wxGetApp().preset_bundle; if (export_type == m_exprot_type.preset_bundle) { for (std::pair preset : m_printer_presets) { std::string preset_name = preset.first; @@ -3316,6 +3330,13 @@ void ExportConfigsDialog::select_curr_radiobox(std::vectorSetLabel(_L("Only display printer names with changes to printer, filament, and process presets for uploading to the model mall.")); }else if (export_type == m_exprot_type.filament_bundle) { for (std::pair>> filament_name_to_preset : m_filament_name_to_presets) { + if (filament_name_to_preset.second.empty()) continue; + bool all_preset_is_compatible_third_printer = true; + for (std::pair filament_preset : filament_name_to_preset.second) { + if (!preset_is_not_compatible_bbl_printer(filament_preset.second)) + all_preset_is_compatible_third_printer = false; + } + if (all_preset_is_compatible_third_printer) continue; wxString filament_name = wxString::FromUTF8(filament_name_to_preset.first); m_preset_sizer->Add(create_checkbox(m_presets_window, filament_name, m_printer_name), 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, FromDIP(5)); } @@ -3330,12 +3351,23 @@ void ExportConfigsDialog::select_curr_radiobox(std::vectorSetLabel(_L("Only printer names with user printer presets will be displayed, and each preset you choose will be exported as a zip.")); } else if (export_type == m_exprot_type.filament_preset) { for (std::pair>> filament_name_to_preset : m_filament_name_to_presets) { + if (filament_name_to_preset.second.empty()) continue; + bool all_preset_is_compatible_third_printer = true; + for (std::pair filament_preset : filament_name_to_preset.second) { + if (!preset_is_not_compatible_bbl_printer(filament_preset.second)) + all_preset_is_compatible_third_printer = false; + } + if (all_preset_is_compatible_third_printer) continue; wxString filament_name = wxString::FromUTF8(filament_name_to_preset.first); m_preset_sizer->Add(create_checkbox(m_presets_window, filament_name, m_printer_name), 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, FromDIP(5)); } m_serial_text->SetLabel(_L("Only the filament names with user filament presets will be displayed, \nand all user filament presets in each filament name you select will be exported as a zip.")); } else if (export_type == m_exprot_type.process_preset) { for (std::pair> presets : m_process_presets) { + Preset * printer_preset = preset_bundle->printers.find_preset(presets.first, false); + if (!printer_preset) continue; + if (!printer_preset->is_system) continue; + if (preset_bundle->printers.get_preset_base(*printer_preset) != printer_preset) continue; for (Preset *preset : presets.second) { if (!preset->is_system) { wxString printer_name = wxString::FromUTF8(presets.first); @@ -3519,10 +3551,14 @@ ExportConfigsDialog::ExportCase ExportConfigsDialog::archive_filament_bundle_to_ BOOST_LOG_TRIVIAL(info) << "Filament name do not find, filament name:" << filament_name; continue; } + std::set> vendor_to_filament_name; for (std::pair printer_name_to_preset : iter->second) { std::string printer_vendor = printer_name_to_preset.first; if (printer_vendor.empty()) continue; Preset * filament_preset = printer_name_to_preset.second; + if (preset_is_not_compatible_bbl_printer(filament_preset)) continue; + if (vendor_to_filament_name.find(std::make_pair(printer_vendor, filament_preset->name)) != vendor_to_filament_name.end()) continue; + vendor_to_filament_name.insert(std::make_pair(printer_vendor, filament_preset->name)); std::string preset_path = boost::filesystem::path(filament_preset->file).make_preferred().string(); if (preset_path.empty()) { BOOST_LOG_TRIVIAL(info) << "Export printer preset: " << filament_preset->name << " skip because of the preset file path is empty."; @@ -3615,6 +3651,7 @@ ExportConfigsDialog::ExportCase ExportConfigsDialog::archive_filament_preset_to_ std::vector> config_paths; + std::set filament_presets; for (std::pair checkbox_preset : m_printer_name) { if (checkbox_preset.first->GetValue()) { std::string filament_name = checkbox_preset.second; @@ -3626,6 +3663,9 @@ ExportConfigsDialog::ExportCase ExportConfigsDialog::archive_filament_preset_to_ } for (std::pair printer_name_preset : iter->second) { Preset * filament_preset = printer_name_preset.second; + if (preset_is_not_compatible_bbl_printer(filament_preset)) continue; + if (filament_presets.find(filament_preset->name) != filament_presets.end()) continue; + filament_presets.insert(filament_preset->name); std::string preset_path = boost::filesystem::path(filament_preset->file).make_preferred().string(); if (preset_path.empty()) { BOOST_LOG_TRIVIAL(info) << "Export filament preset: " << filament_preset->name << " skip because of the filament file path is empty."; @@ -3655,12 +3695,16 @@ ExportConfigsDialog::ExportCase ExportConfigsDialog::archive_process_preset_to_f std::vector> config_paths; + std::set process_presets; for (std::pair checkbox_preset : m_printer_name) { if (checkbox_preset.first->GetValue()) { std::string printer_name = checkbox_preset.second; std::unordered_map>::iterator iter = m_process_presets.find(printer_name); if (m_process_presets.end() != iter) { for (Preset *process_preset : iter->second) { + if (preset_is_not_compatible_bbl_printer(process_preset)) continue; + if (process_presets.find(process_preset->name) != process_presets.end()) continue; + process_presets.insert(process_preset->name); std::string preset_path = boost::filesystem::path(process_preset->file).make_preferred().string(); if (preset_path.empty()) { BOOST_LOG_TRIVIAL(info) << "Export process preset: " << process_preset->name << " skip because of the preset file path is empty."; diff --git a/src/slic3r/GUI/CreatePresetsDialog.hpp b/src/slic3r/GUI/CreatePresetsDialog.hpp index e5e9c3c0a..710e6143d 100644 --- a/src/slic3r/GUI/CreatePresetsDialog.hpp +++ b/src/slic3r/GUI/CreatePresetsDialog.hpp @@ -262,6 +262,7 @@ private: void on_dpi_changed(const wxRect &suggested_rect) override; void show_export_result(const ExportCase &export_case); bool has_check_box_selected(); + bool preset_is_not_compatible_bbl_printer(Preset *preset); std::string initial_file_path(const wxString &path, const std::string &sub_file_path); std::string initial_file_name(const wxString &path, const std::string file_name); wxBoxSizer *create_export_config_item(wxWindow *parent);