From 32d5d2e8ce2c66a9694044c90e8f02c343f3ca64 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 3 Jan 2023 13:43:50 +0100 Subject: [PATCH] Folllow-up https://github.com/Prusa-Development/PrusaSlicerPrivate/commit/8c36ea00f4e484f60983f32cd610e2a3ff01cb27: Code refactoring for other related places --- src/libslic3r/PresetBundle.hpp | 8 ++++++++ src/slic3r/GUI/MainFrame.cpp | 4 +--- src/slic3r/GUI/SavePresetDialog.cpp | 6 +----- src/slic3r/GUI/UnsavedChangesDialog.cpp | 10 ++++------ src/slic3r/GUI/UnsavedChangesDialog.hpp | 2 ++ 5 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/libslic3r/PresetBundle.hpp b/src/libslic3r/PresetBundle.hpp index 549a132866..7d5a3a4f69 100644 --- a/src/libslic3r/PresetBundle.hpp +++ b/src/libslic3r/PresetBundle.hpp @@ -7,6 +7,7 @@ #include #include +#include #include namespace Slic3r { @@ -155,6 +156,13 @@ public: const std::string& new_name, const std::vector& options); static const char *PRUSA_BUNDLE; + + static std::array types_list(PrinterTechnology pt) { + if (pt == ptFFF) + return { Preset::TYPE_PRINTER, Preset::TYPE_PRINT, Preset::TYPE_FILAMENT }; + return { Preset::TYPE_PRINTER, Preset::TYPE_SLA_PRINT, Preset::TYPE_SLA_MATERIAL }; + } + private: std::pair load_system_presets(ForwardCompatibilitySubstitutionRule compatibility_rule); // Merge one vendor's presets with the other vendor's presets, report duplicates. diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index b095d46c21..93baac4489 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -307,9 +307,7 @@ void MainFrame::bind_diff_dialog() auto process_options = [this](std::function process) { const Preset::Type diff_dlg_type = diff_dialog.view_type(); if (diff_dlg_type == Preset::TYPE_INVALID) { - for (const Preset::Type& type : diff_dialog.printer_technology() == ptFFF ? - std::initializer_list{Preset::TYPE_PRINTER, Preset::TYPE_PRINT, Preset::TYPE_FILAMENT} : - std::initializer_list{ Preset::TYPE_PRINTER, Preset::TYPE_SLA_PRINT, Preset::TYPE_SLA_MATERIAL } ) + for (const Preset::Type& type : diff_dialog.types_list() ) process(type); } else diff --git a/src/slic3r/GUI/SavePresetDialog.cpp b/src/slic3r/GUI/SavePresetDialog.cpp index fbb84d08b4..d9ee5f58c1 100644 --- a/src/slic3r/GUI/SavePresetDialog.cpp +++ b/src/slic3r/GUI/SavePresetDialog.cpp @@ -141,11 +141,7 @@ const Preset* SavePresetDialog::Item::get_existing_preset() const if (m_presets) return m_presets->find_preset(m_preset_name, false); - const auto types = m_printer_technology == ptFFF ? - std::initializer_list{Preset::TYPE_PRINTER, Preset::TYPE_PRINT, Preset::TYPE_FILAMENT } : - std::initializer_list{Preset::TYPE_PRINTER, Preset::TYPE_SLA_PRINT, Preset::TYPE_SLA_MATERIAL }; - - for (auto type : types) { + for (const Preset::Type& type : PresetBundle::types_list(m_printer_technology)) { const PresetCollection& presets = wxGetApp().preset_bundle->get_presets(type); if (const Preset* preset = presets.find_preset(m_preset_name, false)) return preset; diff --git a/src/slic3r/GUI/UnsavedChangesDialog.cpp b/src/slic3r/GUI/UnsavedChangesDialog.cpp index 222a566cda..da1446fd63 100644 --- a/src/slic3r/GUI/UnsavedChangesDialog.cpp +++ b/src/slic3r/GUI/UnsavedChangesDialog.cpp @@ -1571,11 +1571,9 @@ void DiffPresetDialog::create_tree() m_tree->GetColumn(DiffModel::colToggle)->SetHidden(true); } -static std::array types_list(PrinterTechnology pt) +std::array DiffPresetDialog::types_list() const { - if (pt == ptFFF) - return { Preset::TYPE_PRINTER, Preset::TYPE_PRINT, Preset::TYPE_FILAMENT }; - return { Preset::TYPE_PRINTER, Preset::TYPE_SLA_PRINT, Preset::TYPE_SLA_MATERIAL }; + return PresetBundle::types_list(m_pr_technology); } void DiffPresetDialog::create_buttons() @@ -1605,7 +1603,7 @@ void DiffPresetDialog::create_buttons() bool enable = m_tree->has_selection(); if (enable) { if (m_view_type == Preset::TYPE_INVALID) { - for (const Preset::Type& type : types_list(m_pr_technology)) + for (const Preset::Type& type : types_list()) if (!enable_transfer(type)) { enable = false; break; @@ -2030,7 +2028,7 @@ bool DiffPresetDialog::is_save_confirmed() std::vector types_for_save; - for (const Preset::Type& type : types_list(m_pr_technology)) { + for (const Preset::Type& type : types_list()) { if (!m_tree->options(type, true).empty()) { types_for_save.emplace_back(type); presets_to_save.emplace_back(PresetToSave{ type, get_left_preset_name(type), get_right_preset_name(type), get_right_preset_name(type) }); diff --git a/src/slic3r/GUI/UnsavedChangesDialog.hpp b/src/slic3r/GUI/UnsavedChangesDialog.hpp index a0b53dadf9..a2934d4ccb 100644 --- a/src/slic3r/GUI/UnsavedChangesDialog.hpp +++ b/src/slic3r/GUI/UnsavedChangesDialog.hpp @@ -416,6 +416,8 @@ public: std::vector get_selected_options(Preset::Type type) const { return m_tree->options(type, true); } + std::array types_list() const; + protected: void on_dpi_changed(const wxRect& suggested_rect) override; void on_sys_color_changed() override;