From ba54ce030993ac00a1a58e3f646561f842d75d95 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Mon, 18 Mar 2019 15:10:40 +0100 Subject: [PATCH 1/3] Added "Edit Preset" buttons on the sidebar. + fixed Filament presets updating for the multi-material Printer (inside update_compatible(...) function) --- src/slic3r/GUI/Plater.cpp | 44 ++++++++++++++++++++++++++++++--- src/slic3r/GUI/Plater.hpp | 2 ++ src/slic3r/GUI/PresetBundle.cpp | 30 ++++++++++++---------- 3 files changed, 59 insertions(+), 17 deletions(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 601c2ddb6b..b5074ccc15 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -275,9 +275,36 @@ wxBitmapComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(15 * dialog->Destroy(); }); } + + edit_btn = new wxButton(parent, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER); +#ifdef __WINDOWS__ + edit_btn->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); +#endif + edit_btn->SetBitmap(create_scaled_bitmap("cog.png")); + edit_btn->SetToolTip(_(L("Click to Edit a selected Filament Preset"))); + + edit_btn->Bind(wxEVT_BUTTON, ([preset_type, this](wxCommandEvent) + { + Tab* tab = wxGetApp().get_tab(preset_type); + if (!tab) + return; + + int page_id = wxGetApp().tab_panel()->FindPage(tab); + if (page_id == wxNOT_FOUND) + return; + + wxGetApp().tab_panel()->ChangeSelection(page_id); + + tab->select_preset(GetString(GetSelection()).ToUTF8().data()); + + })); } -PresetComboBox::~PresetComboBox() {} +PresetComboBox::~PresetComboBox() +{ + if (edit_btn) + edit_btn->Destroy(); +} void PresetComboBox::set_label_marker(int item) @@ -611,13 +638,18 @@ Sidebar::Sidebar(Plater *parent) text->SetFont(wxGetApp().small_font()); *combo = new PresetComboBox(p->presets_panel, preset_type); + auto combo_and_btn_sizer = new wxBoxSizer(wxHORIZONTAL); + combo_and_btn_sizer->Add(*combo, 1, wxEXPAND); + if ((*combo)->edit_btn) + combo_and_btn_sizer->Add((*combo)->edit_btn, 0, wxLEFT|wxRIGHT, int(0.3*wxGetApp().em_unit())); + auto *sizer_presets = this->p->sizer_presets; auto *sizer_filaments = this->p->sizer_filaments; sizer_presets->Add(text, 0, wxALIGN_LEFT | wxEXPAND | wxRIGHT, 4); if (! filament) { - sizer_presets->Add(*combo, 0, wxEXPAND | wxBOTTOM, 1); + sizer_presets->Add(combo_and_btn_sizer, 0, wxEXPAND | wxBOTTOM, 1); } else { - sizer_filaments->Add(*combo, 0, wxEXPAND | wxBOTTOM, 1); + sizer_filaments->Add(combo_and_btn_sizer, 0, wxEXPAND | wxBOTTOM, 1); (*combo)->set_extruder_idx(0); sizer_presets->Add(sizer_filaments, 1, wxEXPAND); } @@ -714,8 +746,12 @@ void Sidebar::init_filament_combo(PresetComboBox **combo, const int extr_idx) { (*combo)->set_extruder_idx(extr_idx); + auto combo_and_btn_sizer = new wxBoxSizer(wxHORIZONTAL); + combo_and_btn_sizer->Add(*combo, 1, wxEXPAND); + combo_and_btn_sizer->Add((*combo)->edit_btn, 0, wxLEFT | wxRIGHT, int(0.3*wxGetApp().em_unit())); + auto /***/sizer_filaments = this->p->sizer_filaments; - sizer_filaments->Add(*combo, 1, wxEXPAND | wxBOTTOM, 1); + sizer_filaments->Add(combo_and_btn_sizer, 1, wxEXPAND | wxBOTTOM, 1); } void Sidebar::remove_unused_filament_combos(const int current_extruder_count) diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index ecce638055..d24a9bf32c 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -46,6 +46,8 @@ public: PresetComboBox(wxWindow *parent, Preset::Type preset_type); ~PresetComboBox(); + wxButton* edit_btn { nullptr }; + void set_label_marker(int item); void set_extruder_idx(const int extr_idx) { extruder_idx = extr_idx; } int get_extruder_idx() const { return extruder_idx; } diff --git a/src/slic3r/GUI/PresetBundle.cpp b/src/slic3r/GUI/PresetBundle.cpp index f0bb4de01e..b8c9fedacc 100644 --- a/src/slic3r/GUI/PresetBundle.cpp +++ b/src/slic3r/GUI/PresetBundle.cpp @@ -1308,19 +1308,23 @@ void PresetBundle::update_compatible(bool select_other_if_incompatible) { return std::find(prefered_filament_profiles.begin(), prefered_filament_profiles.end(), profile_name) != prefered_filament_profiles.end(); }); if (select_other_if_incompatible) { // Verify validity of the current filament presets. - this->filament_presets.front() = this->filaments.get_edited_preset().name; - for (size_t idx = 1; idx < this->filament_presets.size(); ++ idx) { - std::string &filament_name = this->filament_presets[idx]; - Preset *preset = this->filaments.find_preset(filament_name, false); - if (preset == nullptr || ! preset->is_compatible) { - // Pick a compatible profile. If there are prefered_filament_profiles, use them. - if (prefered_filament_profiles.empty()) - filament_name = this->filaments.first_compatible().name; - else { - const std::string &preferred = (idx < prefered_filament_profiles.size()) ? - prefered_filament_profiles[idx] : prefered_filament_profiles.front(); - filament_name = this->filaments.first_compatible( - [&preferred](const std::string& profile_name) { return profile_name == preferred; }).name; + if (this->filament_presets.size() == 1) + this->filament_presets.front() = this->filaments.get_edited_preset().name; + else + { + for (size_t idx = 0; idx < this->filament_presets.size(); ++idx) { + std::string &filament_name = this->filament_presets[idx]; + Preset *preset = this->filaments.find_preset(filament_name, false); + if (preset == nullptr || !preset->is_compatible) { + // Pick a compatible profile. If there are prefered_filament_profiles, use them. + if (prefered_filament_profiles.empty()) + filament_name = this->filaments.first_compatible().name; + else { + const std::string &preferred = (idx < prefered_filament_profiles.size()) ? + prefered_filament_profiles[idx] : prefered_filament_profiles.front(); + filament_name = this->filaments.first_compatible( + [&preferred](const std::string& profile_name) { return profile_name == preferred; }).name; + } } } } From b7a1bd927aec366478238269a6f9f0fef542fce3 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 19 Mar 2019 14:36:32 +0100 Subject: [PATCH 2/3] Some improvements --- src/slic3r/GUI/GUI_App.cpp | 7 +++++++ src/slic3r/GUI/GUI_App.hpp | 1 + src/slic3r/GUI/GUI_ObjectList.cpp | 3 +-- src/slic3r/GUI/Plater.cpp | 11 ++++++++++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 1cf2ca17c1..94b070e472 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -743,6 +743,13 @@ wxNotebook* GUI_App::tab_panel() const return mainframe->m_tabpanel; } +int GUI_App::extruders_cnt() const +{ + const Preset& preset = preset_bundle->printers.get_selected_preset(); + return preset.printer_technology() == ptSLA ? 1 : + preset.config.option("nozzle_diameter")->values.size(); +} + void GUI_App::window_pos_save(wxTopLevelWindow* window, const std::string &name) { if (name.empty()) { return; } diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index 4c23e3eb72..81ef3d0407 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -163,6 +163,7 @@ public: Plater* plater_{ nullptr }; wxNotebook* tab_panel() const ; + int extruders_cnt() const; std::vector tabs_list; diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index 7eef820631..d0f78a6da6 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -51,8 +51,7 @@ static DynamicPrintConfig& printer_config() static int extruders_count() { - return printer_technology() == ptSLA ? 1 : - printer_config().option("nozzle_diameter")->values.size(); + return wxGetApp().extruders_cnt(); } ObjectList::ObjectList(wxWindow* parent) : diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index b5074ccc15..92b9c41718 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -295,8 +295,17 @@ wxBitmapComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(15 * wxGetApp().tab_panel()->ChangeSelection(page_id); - tab->select_preset(GetString(GetSelection()).ToUTF8().data()); + /* In a case of a multi-material printing, for editing another Filament Preset + * it's needed to select this preset for the "Filament settings" Tab + */ + if (preset_type == Preset::TYPE_FILAMENT && wxGetApp().extruders_cnt() > 1) + { + const std::string& selected_preset = GetString(GetSelection()).ToUTF8().data(); + // Call select_preset() only if there is new preset and not just modified + if ( !boost::algorithm::ends_with(selected_preset, "(modified)") ) + tab->select_preset(selected_preset); + } })); } From 438010f0f86723bdd32ffc4c8d4f8e4b0676b2fb Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 20 Mar 2019 10:14:49 +0100 Subject: [PATCH 3/3] Some code refactoring --- src/slic3r/GUI/Plater.cpp | 4 ++-- src/slic3r/GUI/Preset.hpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 92b9c41718..b0140a1971 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -281,7 +281,7 @@ wxBitmapComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(15 * edit_btn->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); #endif edit_btn->SetBitmap(create_scaled_bitmap("cog.png")); - edit_btn->SetToolTip(_(L("Click to Edit a selected Filament Preset"))); + edit_btn->SetToolTip(_(L("Click to edit preset"))); edit_btn->Bind(wxEVT_BUTTON, ([preset_type, this](wxCommandEvent) { @@ -303,7 +303,7 @@ wxBitmapComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(15 * const std::string& selected_preset = GetString(GetSelection()).ToUTF8().data(); // Call select_preset() only if there is new preset and not just modified - if ( !boost::algorithm::ends_with(selected_preset, "(modified)") ) + if ( !boost::algorithm::ends_with(selected_preset, Preset::suffix_modified()) ) tab->select_preset(selected_preset); } })); diff --git a/src/slic3r/GUI/Preset.hpp b/src/slic3r/GUI/Preset.hpp index 074e665c9b..5113137157 100644 --- a/src/slic3r/GUI/Preset.hpp +++ b/src/slic3r/GUI/Preset.hpp @@ -201,6 +201,7 @@ public: static const std::vector& sla_print_options(); static void update_suffix_modified(); + static const std::string& suffix_modified(); static void normalize(DynamicPrintConfig &config); // Report configuration fields, which are misplaced into a wrong group, remove them from the config. static std::string remove_invalid_keys(DynamicPrintConfig &config, const DynamicPrintConfig &default_config); @@ -210,7 +211,6 @@ protected: friend class PresetBundle; // Resize the extruder specific vectors () static void set_num_extruders(DynamicPrintConfig &config, unsigned int n); - static const std::string& suffix_modified(); static std::string remove_suffix_modified(const std::string &name); };