From 75769461f4523dbf81e359a7d970f489ca5a6873 Mon Sep 17 00:00:00 2001 From: "maosheng.wei" Date: Fri, 20 Oct 2023 16:36:40 +0800 Subject: [PATCH] FIX: export config issue Jira: 4850 4862 4859 4852 4850 import config failed 4862 export filament configs show filament preset name 4859 export presets add file filed issue 4852 not select preset but can export issue Signed-off-by: maosheng.wei Change-Id: I40a800028fd293bd24af9e9ce074b0c7073730ae --- src/slic3r/GUI/CreatePresetsDialog.cpp | 33 +++++++++++++++++++++----- src/slic3r/GUI/CreatePresetsDialog.hpp | 1 + 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/slic3r/GUI/CreatePresetsDialog.cpp b/src/slic3r/GUI/CreatePresetsDialog.cpp index e16fcf6d1..d5081072f 100644 --- a/src/slic3r/GUI/CreatePresetsDialog.cpp +++ b/src/slic3r/GUI/CreatePresetsDialog.cpp @@ -2808,6 +2808,18 @@ void ExportConfigsDialog::show_export_result(const ExportCase &export_case) } } +bool ExportConfigsDialog::has_check_box_selected() +{ + for (std::pair checkbox_preset : m_preset) { + if (checkbox_preset.first->GetValue()) return true; + } + for (std::pair checkbox_filament_name : m_printer_name) { + if (checkbox_filament_name.first->GetValue()) 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); @@ -3007,7 +3019,7 @@ ExportConfigsDialog::ExportCase ExportConfigsDialog::save_presets_to_zip(const s std::string preset_name = config_path.first; // Add a file to the ZIP file - status = mz_zip_writer_add_file(&zip_archive, encode_path((preset_name).c_str()).c_str(), encode_path(config_path.second.c_str()).c_str(), NULL, 0, MZ_DEFAULT_COMPRESSION); + status = mz_zip_writer_add_file(&zip_archive, (preset_name).c_str(), encode_path(config_path.second.c_str()).c_str(), NULL, 0, MZ_DEFAULT_COMPRESSION); // status = mz_zip_writer_add_mem(&zip_archive, ("printer/" + printer_preset->name + ".json").c_str(), json_contents, strlen(json_contents), MZ_DEFAULT_COMPRESSION); if (MZ_FALSE == status) { BOOST_LOG_TRIVIAL(info) << preset_name << " Filament preset failed to add file to ZIP archive"; @@ -3126,7 +3138,7 @@ ExportConfigsDialog::ExportCase ExportConfigsDialog::archive_preset_bundle_to_fi // Add a file to the ZIP file std::string printer_config_file_name = "printer/" + pronter_file_path.filename().string(); - status = mz_zip_writer_add_file(&zip_archive, encode_path(printer_config_file_name.c_str()).c_str(), encode_path(preset_path.c_str()).c_str(), NULL, 0, MZ_DEFAULT_COMPRESSION); + status = mz_zip_writer_add_file(&zip_archive, printer_config_file_name.c_str(), encode_path(preset_path.c_str()).c_str(), NULL, 0, MZ_DEFAULT_COMPRESSION); //status = mz_zip_writer_add_mem(&zip_archive, ("printer/" + printer_preset->name + ".json").c_str(), json_contents, strlen(json_contents), MZ_DEFAULT_COMPRESSION); if (MZ_FALSE == status) { BOOST_LOG_TRIVIAL(info) << printer_preset->name << " Failed to add file to ZIP archive"; @@ -3148,7 +3160,7 @@ ExportConfigsDialog::ExportCase ExportConfigsDialog::archive_preset_bundle_to_fi } std::string filament_config_file_name = "filament/" + filament_file_path.filename().string(); - status = mz_zip_writer_add_file(&zip_archive, encode_path(filament_config_file_name.c_str()).c_str(), encode_path(filament_preset_path.c_str()).c_str(), NULL, 0, MZ_DEFAULT_COMPRESSION); + status = mz_zip_writer_add_file(&zip_archive, filament_config_file_name.c_str(), encode_path(filament_preset_path.c_str()).c_str(), NULL, 0, MZ_DEFAULT_COMPRESSION); if (MZ_FALSE == status) { BOOST_LOG_TRIVIAL(info) << preset->name << " Failed to add file to ZIP archive"; mz_zip_writer_end(&zip_archive); @@ -3170,7 +3182,7 @@ ExportConfigsDialog::ExportCase ExportConfigsDialog::archive_preset_bundle_to_fi } std::string process_config_file_name = "process/" + process_file_path.filename().string(); - status = mz_zip_writer_add_file(&zip_archive, encode_path(process_config_file_name.c_str()).c_str(), encode_path(process_preset_path.c_str()).c_str(), NULL, 0, MZ_DEFAULT_COMPRESSION); + status = mz_zip_writer_add_file(&zip_archive, process_config_file_name.c_str(), encode_path(process_preset_path.c_str()).c_str(), NULL, 0, MZ_DEFAULT_COMPRESSION); if (MZ_FALSE == status) { BOOST_LOG_TRIVIAL(info) << preset->name << " Failed to add file to ZIP archive"; mz_zip_writer_end(&zip_archive); @@ -3254,7 +3266,7 @@ ExportConfigsDialog::ExportCase ExportConfigsDialog::archive_filament_bundle_to_ } // Add a file to the ZIP file std::string file_name = printer_vendor + "/" + filament_preset->name + ".json"; - status = mz_zip_writer_add_file(&zip_archive, encode_path(file_name.c_str()).c_str(), encode_path(preset_path.c_str()).c_str(), NULL, 0, MZ_DEFAULT_COMPRESSION); + status = mz_zip_writer_add_file(&zip_archive, file_name.c_str(), encode_path(preset_path.c_str()).c_str(), NULL, 0, MZ_DEFAULT_COMPRESSION); // status = mz_zip_writer_add_mem(&zip_archive, ("printer/" + printer_preset->name + ".json").c_str(), json_contents, strlen(json_contents), MZ_DEFAULT_COMPRESSION); if (MZ_FALSE == status) { BOOST_LOG_TRIVIAL(info) << filament_preset->name << " Failed to add file to ZIP archive"; @@ -3425,6 +3437,13 @@ wxBoxSizer *ExportConfigsDialog::create_button_item(wxWindow* parent) bSizer_button->Add(m_button_ok, 0, wxRIGHT, FromDIP(10)); m_button_ok->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) { + if (!has_check_box_selected()) { + MessageDialog dlg(this, _L("Please select at least one printer or filament."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"), + wxYES | wxYES_DEFAULT | wxCENTRE); + dlg.ShowModal(); + return; + } + wxDirDialog dlg(this, _L("Choose a directory"), from_u8(wxGetApp().app_config->get_last_dir()), wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST); wxString path; if (dlg.ShowModal() == wxID_OK) path = dlg.GetPath(); @@ -3532,7 +3551,9 @@ void ExportConfigsDialog::data_init() for (const Preset &filament_preset : filament_presets) { if (filament_preset.is_system || "Default Filament" == filament_preset.name) continue; Preset *new_filament_preset = new Preset(filament_preset); - std::string filament_preset_name = filament_preset.name; + const Preset *base_filament_preset = preset_bundle.filaments.get_preset_base(*new_filament_preset); + + std::string filament_preset_name = base_filament_preset->name; std::string machine_name = get_machine_name(filament_preset_name); m_filament_name_to_presets[get_filament_name(filament_preset_name)].push_back(std::make_pair(get_vendor_name(machine_name), new_filament_preset)); } diff --git a/src/slic3r/GUI/CreatePresetsDialog.hpp b/src/slic3r/GUI/CreatePresetsDialog.hpp index 391c2dab5..a5d194e60 100644 --- a/src/slic3r/GUI/CreatePresetsDialog.hpp +++ b/src/slic3r/GUI/CreatePresetsDialog.hpp @@ -250,6 +250,7 @@ private: void select_curr_radiobox(std::vector> &radiobox_list, int btn_idx); void on_dpi_changed(const wxRect &suggested_rect) override; void show_export_result(const ExportCase &export_case); + bool has_check_box_selected(); 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);