diff --git a/xs/src/slic3r/GUI/GUI.hpp b/xs/src/slic3r/GUI/GUI.hpp index ceb004f8c..dd4387039 100644 --- a/xs/src/slic3r/GUI/GUI.hpp +++ b/xs/src/slic3r/GUI/GUI.hpp @@ -182,6 +182,8 @@ bool select_language(wxArrayString & names, wxArrayLong & identifiers); // update right panel of the Plater according to view mode void update_mode(); +void show_info_sizer(bool show); + std::vector& get_tabs_list(); bool checked_tab(Tab* tab); void delete_tab_from_list(Tab* tab); diff --git a/xs/src/slic3r/GUI/GUI_ObjectParts.cpp b/xs/src/slic3r/GUI/GUI_ObjectParts.cpp index 119d73470..092ba2756 100644 --- a/xs/src/slic3r/GUI/GUI_ObjectParts.cpp +++ b/xs/src/slic3r/GUI/GUI_ObjectParts.cpp @@ -69,8 +69,6 @@ bool m_part_settings_changed = false; wxString g_selected_extruder = ""; #endif //__WXOSX__ -// typedef std::map t_category_icon; -typedef std::map t_category_icon; inline t_category_icon& get_category_icon() { static t_category_icon CATEGORY_ICON; if (CATEGORY_ICON.empty()){ @@ -896,6 +894,7 @@ void update_settings_list() std::map> cat_options; auto opt_keys = (*m_config)->keys(); m_og_settings.resize(0); + std::vector categories; if (!(opt_keys.size() == 1 && opt_keys[0] == "extruder"))// return; { auto extruders_cnt = get_preset_bundle()->printers.get_selected_preset().printer_technology() == ptSLA ? 1 : @@ -933,6 +932,8 @@ void update_settings_list() optgroup->reload_config(); m_option_sizer->Add(optgroup->sizer, 0, wxEXPAND | wxALL, 0); m_og_settings.push_back(optgroup); + + categories.push_back(cat.first); } } @@ -940,11 +941,15 @@ void update_settings_list() m_objects_ctrl->Select(m_objects_model->Delete(item)); part_selection_changed(); } - else + else { + if (!categories.empty()) + m_objects_model->UpdateSettingsDigest(item, categories); show_manipulations = false; + } } show_manipulation_og(show_manipulations); + show_info_sizer(show_manipulations); #ifdef __linux__ no_updates.reset(nullptr); @@ -1032,11 +1037,11 @@ wxMenuItem* menu_item_split(wxMenu* menu, int id) { return menu_item; } -wxMenuItem* menu_item_settings(wxMenu* menu, int id) { +wxMenuItem* menu_item_settings(wxMenu* menu, int id, const bool is_part) { auto menu_item = new wxMenuItem(menu, id, _(L("Add settings"))); menu_item->SetBitmap(m_bmp_cog); - auto sub_menu = create_add_settings_popupmenu(false); + auto sub_menu = create_add_settings_popupmenu(is_part); menu_item->SetSubMenu(sub_menu); return menu_item; } @@ -1063,7 +1068,7 @@ wxMenu *create_add_part_popupmenu() menu->AppendSeparator(); // Append settings popupmenu - menu->Append(menu_item_settings(menu, config_id_base + i + 1)); + menu->Append(menu_item_settings(menu, config_id_base + i + 1, false)); wxWindow* win = get_tab_panel()->GetPage(0); @@ -1099,7 +1104,7 @@ wxMenu *create_part_settings_popupmenu() menu->AppendSeparator(); // Append settings popupmenu - menu->Append(menu_item_settings(menu, config_id_base + 1)); + menu->Append(menu_item_settings(menu, config_id_base + 1, true)); menu->Bind(wxEVT_MENU, [config_id_base, menu](wxEvent &event){ switch (event.GetId() - config_id_base) { diff --git a/xs/src/slic3r/GUI/GUI_ObjectParts.hpp b/xs/src/slic3r/GUI/GUI_ObjectParts.hpp index 5a3b96761..630912fb4 100644 --- a/xs/src/slic3r/GUI/GUI_ObjectParts.hpp +++ b/xs/src/slic3r/GUI/GUI_ObjectParts.hpp @@ -10,6 +10,7 @@ class wxMenu; class wxDataViewEvent; class wxKeyEvent; class wxGLCanvas; +class wxBitmap; namespace Slic3r { class ModelObject; @@ -45,6 +46,9 @@ struct OBJECT_PARAMETERS double slab_z = 0.0; }; +typedef std::map t_category_icon; +inline t_category_icon& get_category_icon(); + void add_collapsible_panes(wxWindow* parent, wxBoxSizer* sizer); void add_objects_list(wxWindow* parent, wxBoxSizer* sizer); void add_object_settings(wxWindow* parent, wxBoxSizer* sizer); diff --git a/xs/src/slic3r/GUI/wxExtensions.cpp b/xs/src/slic3r/GUI/wxExtensions.cpp index 0dfc21e16..1642828fb 100644 --- a/xs/src/slic3r/GUI/wxExtensions.cpp +++ b/xs/src/slic3r/GUI/wxExtensions.cpp @@ -2,6 +2,7 @@ #include "GUI.hpp" #include "../../libslic3r/Utils.hpp" +#include "BitmapCache.hpp" #include #include @@ -361,11 +362,52 @@ void PrusaObjectDataViewModelNode::set_settings_list_icon(const wxIcon& icon) { m_icon = icon; } +Slic3r::GUI::BitmapCache *m_bitmap_cache = nullptr; +bool PrusaObjectDataViewModelNode::update_settings_digest(const std::vector& categories) +{ + if (m_type != "settings" || m_opt_categories == categories) + return false; + + m_opt_categories = categories; + m_name = wxEmptyString; + m_icon = m_empty_icon; + + auto categories_icon = Slic3r::GUI::get_category_icon(); + + for (auto& cat : m_opt_categories) + m_name += cat + "; "; + + wxBitmap *bmp = m_bitmap_cache->find(m_name.ToStdString()); + if (bmp == nullptr) { + std::vector bmps; + for (auto& cat : m_opt_categories) + bmps.emplace_back(categories_icon.find(cat) == categories_icon.end() ? + wxNullBitmap : categories_icon.at(cat)); + bmp = m_bitmap_cache->insert(m_name.ToStdString(), bmps); + } + m_icon.CopyFromBitmap(*bmp); + + return true; +} + // ***************************************************************************** // ---------------------------------------------------------------------------- // PrusaObjectDataViewModel // ---------------------------------------------------------------------------- +PrusaObjectDataViewModel::PrusaObjectDataViewModel() +{ + m_bitmap_cache = new Slic3r::GUI::BitmapCache; +} + +PrusaObjectDataViewModel::~PrusaObjectDataViewModel() +{ + for (auto object : m_objects) + delete object; + delete m_bitmap_cache; + m_bitmap_cache = nullptr; +} + wxDataViewItem PrusaObjectDataViewModel::Add(const wxString &name) { auto root = new PrusaObjectDataViewModelNode(name); @@ -792,6 +834,18 @@ bool PrusaObjectDataViewModel::IsSettingsItem(const wxDataViewItem &item) const return node->m_type == "settings"; } + + +void PrusaObjectDataViewModel::UpdateSettingsDigest(const wxDataViewItem &item, + const std::vector& categories) +{ + if (!item.IsOk()) return; + PrusaObjectDataViewModelNode *node = (PrusaObjectDataViewModelNode*)item.GetID(); + if (!node->update_settings_digest(categories)) + return; + ItemChanged(item); +} + // ---------------------------------------------------------------------------- // PrusaDoubleSlider // ---------------------------------------------------------------------------- diff --git a/xs/src/slic3r/GUI/wxExtensions.hpp b/xs/src/slic3r/GUI/wxExtensions.hpp index 3ead72f2f..cefe680aa 100644 --- a/xs/src/slic3r/GUI/wxExtensions.hpp +++ b/xs/src/slic3r/GUI/wxExtensions.hpp @@ -155,7 +155,8 @@ class PrusaObjectDataViewModelNode { PrusaObjectDataViewModelNode* m_parent; MyObjectTreeModelNodePtrArray m_children; - wxIcon m_empty_icon; + wxIcon m_empty_icon; + std::vector< std::string > m_opt_categories; public: PrusaObjectDataViewModelNode(const wxString &name, const int instances_count=1) { m_parent = NULL; @@ -340,6 +341,7 @@ public: void set_object_action_icon(); void set_part_action_icon(); void set_settings_list_icon(const wxIcon& icon); + bool update_settings_digest(const std::vector& categories); }; // ---------------------------------------------------------------------------- @@ -350,12 +352,8 @@ class PrusaObjectDataViewModel :public wxDataViewModel { std::vector m_objects; public: - PrusaObjectDataViewModel(){} - ~PrusaObjectDataViewModel() - { - for (auto object : m_objects) - delete object; - } + PrusaObjectDataViewModel(); + ~PrusaObjectDataViewModel(); wxDataViewItem Add(const wxString &name); wxDataViewItem Add(const wxString &name, const int instances_count); @@ -411,6 +409,7 @@ public: wxDataViewItem HasSettings(const wxDataViewItem &item) const; bool IsSettingsItem(const wxDataViewItem &item) const; + void UpdateSettingsDigest(const wxDataViewItem &item, const std::vector& categories); };