From 13df80ffb790eca574e30f23ea7c5daeef420093 Mon Sep 17 00:00:00 2001 From: "zhimin.zeng" Date: Tue, 25 Oct 2022 18:47:58 +0800 Subject: [PATCH] ENH: remember the filament_opts and limit minimum flushing volumes Change-Id: I7b2538fcaf5b5fc5e4f86191207de981bd766a89 (cherry picked from commit 392be8d2a4e9465fffc4018da77c6ee00ad46ade) --- src/libslic3r/AppConfig.cpp | 21 +++++++++++++++++++- src/libslic3r/AppConfig.hpp | 20 +++++++++++++++++++ src/libslic3r/PresetBundle.cpp | 30 +++++++++++++++++++++++++++++ src/libslic3r/PresetBundle.hpp | 2 ++ src/slic3r/GUI/GUI_App.cpp | 1 + src/slic3r/GUI/Plater.cpp | 6 ++++++ src/slic3r/GUI/PresetComboBoxes.cpp | 1 + src/slic3r/GUI/WipeTowerDialog.cpp | 21 ++++++++++++++++++-- 8 files changed, 99 insertions(+), 3 deletions(-) diff --git a/src/libslic3r/AppConfig.cpp b/src/libslic3r/AppConfig.cpp index 7c7e89f0a..98dd5cd1e 100644 --- a/src/libslic3r/AppConfig.cpp +++ b/src/libslic3r/AppConfig.cpp @@ -482,7 +482,14 @@ std::string AppConfig::load() } else { m_storage[it.key()][iter.key()] = "false"; } - } else { + } else if (iter.key() == "filament_presets") { + m_filament_presets = iter.value().get>(); + } else if (iter.key() == "filament_colors") { + m_filament_colors = iter.value().get>(); + } else if (iter.key() == "flushing_volumes") { + m_flush_volumes_matrix = iter.value().get>(); + } + else { if (iter.value().is_string()) m_storage[it.key()][iter.key()] = iter.value().get(); else { @@ -565,6 +572,18 @@ void AppConfig::save() j["app"][kvp.first] = kvp.second; } + for (const auto &filament_preset : m_filament_presets) { + j["app"]["filament_presets"].push_back(filament_preset); + } + + for (const auto &filament_color : m_filament_colors) { + j["app"]["filament_colors"].push_back(filament_color); + } + + for (double flushing_volume : m_flush_volumes_matrix) { + j["app"]["flushing_volumes"].push_back(flushing_volume); + } + // Write the other categories. for (const auto& category : m_storage) { if (category.first.empty()) diff --git a/src/libslic3r/AppConfig.hpp b/src/libslic3r/AppConfig.hpp index cd415d439..27ad86b64 100644 --- a/src/libslic3r/AppConfig.hpp +++ b/src/libslic3r/AppConfig.hpp @@ -164,6 +164,22 @@ public: void set_vendors(VendorMap &&vendors) { m_vendors = std::move(vendors); m_dirty = true; } const VendorMap& vendors() const { return m_vendors; } + const std::vector &get_filament_presets() const { return m_filament_presets; } + void set_filament_presets(const std::vector &filament_presets){ + m_filament_presets = filament_presets; + m_dirty = true; + } + const std::vector &get_filament_colors() const { return m_filament_colors; } + void set_filament_colors(const std::vector &filament_colors){ + m_filament_colors = filament_colors; + m_dirty = true; + } + const std::vector &get_flush_volumes_matrix() const { return m_flush_volumes_matrix; } + void set_flush_volumes_matrix(const std::vector &flush_volumes_matrix){ + m_flush_volumes_matrix = flush_volumes_matrix; + m_dirty = true; + } + // return recent/last_opened_folder or recent/settings_folder or empty string. std::string get_last_dir() const; void update_config_dir(const std::string &dir); @@ -259,6 +275,10 @@ private: bool m_legacy_datadir; std::string m_loading_path; + + std::vector m_filament_presets; + std::vector m_filament_colors; + std::vector m_flush_volumes_matrix; }; } // namespace Slic3r diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index 389a9f6b7..94faebd2a 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -809,6 +809,36 @@ void PresetBundle::update_system_preset_setting_ids(std::mapfilament_presets = config_filament_presets; + + auto config_filament_colors = config.get_filament_colors(); + if (!config_filament_colors.empty()) { + ConfigOptionStrings *filament_color = project_config.option("filament_colour"); + filament_color->resize(config_filament_colors.size()); + filament_color->values = config_filament_colors; + } + + auto config_flush_volumes_matrix = config.get_flush_volumes_matrix(); + if (!config_flush_volumes_matrix.empty()) { + ConfigOptionFloats *flush_volumes_matrix = project_config.option("flush_volumes_matrix"); + flush_volumes_matrix->values = std::vector(config_flush_volumes_matrix.begin(), config_flush_volumes_matrix.end()); + } +} + +void PresetBundle::update_filament_info_to_app_config(AppConfig &config) +{ + config.set_filament_presets(this->filament_presets); + + ConfigOptionStrings *filament_color = project_config.option("filament_colour"); + config.set_filament_colors(filament_color->values); + + ConfigOptionFloats *flush_volumes_matrix = project_config.option("flush_volumes_matrix"); + config.set_flush_volumes_matrix(std::vector(flush_volumes_matrix->values.begin(), flush_volumes_matrix->values.end())); +} + //BBS: validate printers from previous project bool PresetBundle::validate_printers(const std::string &name, DynamicPrintConfig& config) { diff --git a/src/libslic3r/PresetBundle.hpp b/src/libslic3r/PresetBundle.hpp index 7e554283e..1f2a07351 100644 --- a/src/libslic3r/PresetBundle.hpp +++ b/src/libslic3r/PresetBundle.hpp @@ -54,6 +54,8 @@ public: 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); + void load_default_setting_from_app_config(const AppConfig &config); + void update_filament_info_to_app_config(AppConfig &config); //BBS: add API to get previous machine bool validate_printers(const std::string &name, DynamicPrintConfig& config); diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index d566fb685..699eaed81 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -2099,6 +2099,7 @@ bool GUI_App::on_init_inner() BOOST_LOG_TRIVIAL(info) << "loading systen presets..."; preset_bundle = new PresetBundle(); + preset_bundle->load_default_setting_from_app_config(*app_config); // just checking for existence of Slic3r::data_dir is not enough : it may be an empty directory // supplied as argument to --datadir; in that case we should still run the wizard diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 7c0b6a887..a7cee414a 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -663,6 +663,7 @@ Sidebar::Sidebar(Plater *parent) #if !BBL_RELEASE_TO_PUBLIC (project_config.option("flush_multiplier"))->set(new ConfigOptionFloat(dlg.get_flush_multiplier())); #endif + wxGetApp().preset_bundle->update_filament_info_to_app_config(*wxGetApp().app_config); wxGetApp().plater()->update_project_dirty_from_presets(); wxPostEvent(parent, SimpleEvent(EVT_SCHEDULE_BACKGROUND_PROCESS, parent)); @@ -685,6 +686,7 @@ Sidebar::Sidebar(Plater *parent) wxGetApp().preset_bundle->set_num_filaments(filament_count, new_color); wxGetApp().plater()->on_filaments_change(filament_count); wxGetApp().get_tab(Preset::TYPE_PRINT)->update(); + wxGetApp().preset_bundle->update_filament_info_to_app_config(*wxGetApp().app_config); }); p->m_bpButton_add_filament = add_btn; @@ -709,6 +711,7 @@ Sidebar::Sidebar(Plater *parent) wxGetApp().preset_bundle->set_num_filaments(filament_count); wxGetApp().plater()->on_filaments_change(filament_count); wxGetApp().get_tab(Preset::TYPE_PRINT)->update(); + wxGetApp().preset_bundle->update_filament_info_to_app_config(*wxGetApp().app_config); }); p->m_bpButton_del_filament = del_btn; @@ -1288,6 +1291,7 @@ void Sidebar::sync_ams_list() for (auto &c : p->combos_filament) c->update(); wxGetApp().get_tab(Preset::TYPE_PRINT)->update(); + wxGetApp().preset_bundle->update_filament_info_to_app_config(*wxGetApp().app_config); } ObjectList* Sidebar::obj_list() @@ -5200,6 +5204,7 @@ void Plater::priv::on_select_preset(wxCommandEvent &evt) if (preset_type == Preset::TYPE_FILAMENT) { wxGetApp().preset_bundle->set_filament_preset(idx, preset_name); wxGetApp().plater()->update_project_dirty_from_presets(); + wxGetApp().preset_bundle->update_filament_info_to_app_config(*wxGetApp().app_config); } bool select_preset = !combo->selection_is_changed_according_to_physical_printers(); @@ -7084,6 +7089,7 @@ void Plater::load_project(wxString const& filename2, reset_project_dirty_initial_presets(); update_project_dirty_from_presets(); + wxGetApp().preset_bundle->update_filament_info_to_app_config(*wxGetApp().app_config); // if res is empty no data has been loaded if (!res.empty() && (load_restore || !(strategy & LoadStrategy::Silence))) { diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index 379c99d5d..bdd8f057a 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -670,6 +670,7 @@ PlaterPresetComboBox::PlaterPresetComboBox(wxWindow *parent, Preset::Type preset //wxGetApp().get_tab(Preset::TYPE_PRINTER)->load_config(cfg_new); cfg->apply(cfg_new); wxGetApp().plater()->update_project_dirty_from_presets(); + wxGetApp().preset_bundle->update_filament_info_to_app_config(*wxGetApp().app_config); update(); wxGetApp().plater()->on_config_change(cfg_new); diff --git a/src/slic3r/GUI/WipeTowerDialog.cpp b/src/slic3r/GUI/WipeTowerDialog.cpp index b7f65e4c1..6c646cf13 100644 --- a/src/slic3r/GUI/WipeTowerDialog.cpp +++ b/src/slic3r/GUI/WipeTowerDialog.cpp @@ -11,6 +11,8 @@ #include +using namespace Slic3r::GUI; + int scale(const int val) { return val * Slic3r::GUI::wxGetApp().em_unit() / 10; } int ITEM_WIDTH() { return scale(30); } static const wxColour text_color = wxColour(107, 107, 107, 255); @@ -253,7 +255,7 @@ WipingPanel::WipingPanel(wxWindow* parent, const std::vector& matrix, con for (unsigned int j = 0; j < m_number_of_extruders; ++j) { #ifdef _WIN32 - wxTextCtrl* text = new wxTextCtrl(m_page_advanced, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(ITEM_WIDTH(), -1), wxTE_CENTER | wxBORDER_NONE); + wxTextCtrl* text = new wxTextCtrl(m_page_advanced, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(ITEM_WIDTH(), -1), wxTE_CENTER | wxBORDER_NONE | wxTE_PROCESS_ENTER); update_ui(text); edit_boxes.back().push_back(text); #else @@ -272,12 +274,27 @@ WipingPanel::WipingPanel(wxWindow* parent, const std::vector& matrix, con wxString str = edit_boxes[i][j]->GetValue(); int value = wxAtoi(str); if (value > MAX_FLUSH_VALUE) { - value = MAX_FLUSH_VALUE; str = wxString::Format(("%d"), MAX_FLUSH_VALUE); edit_boxes[i][j]->SetValue(str); } }); + auto on_apply_text_modify = [this, i, j](wxEvent &e) { + wxString str = edit_boxes[i][j]->GetValue(); + int value = wxAtoi(str); + if (value < int(m_extra_flush_volume)) { + wxGetApp().plater(); + str = wxString::Format(("%d"), int(m_extra_flush_volume)); + edit_boxes[i][j]->SetValue(str); + MessageDialog dlg(nullptr, + _L("The flush volume is less than the minimum value and will be automatically set to the minimum value."), + _L("Warning"), wxICON_WARNING | wxOK); + dlg.ShowModal(); + } + }; + + edit_boxes[i][j]->Bind(wxEVT_TEXT_ENTER, on_apply_text_modify); + edit_boxes[i][j]->Bind(wxEVT_KILL_FOCUS, on_apply_text_modify); } } }