From bcc23428fa7b0e5ec777f567516bcb8843bdbf3f Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 7 Oct 2020 20:13:12 +0200 Subject: [PATCH] UnsavedChangesDialog : added correct icons for the categories + fixed a crash when try to save changes for the SLA printer preset --- resources/icons/dot_small.svg | 8 +++++ resources/icons/empty.svg | 8 +++++ resources/icons/white/dot_small.svg | 8 +++++ src/slic3r/GUI/Tab.cpp | 5 +++ src/slic3r/GUI/Tab.hpp | 3 ++ src/slic3r/GUI/UnsavedChangesDialog.cpp | 43 ++++++++++++++++--------- src/slic3r/GUI/UnsavedChangesDialog.hpp | 9 +++--- 7 files changed, 65 insertions(+), 19 deletions(-) create mode 100644 resources/icons/dot_small.svg create mode 100644 resources/icons/empty.svg create mode 100644 resources/icons/white/dot_small.svg diff --git a/resources/icons/dot_small.svg b/resources/icons/dot_small.svg new file mode 100644 index 000000000..474142a57 --- /dev/null +++ b/resources/icons/dot_small.svg @@ -0,0 +1,8 @@ + + + + + + + diff --git a/resources/icons/empty.svg b/resources/icons/empty.svg new file mode 100644 index 000000000..b8ba0a651 --- /dev/null +++ b/resources/icons/empty.svg @@ -0,0 +1,8 @@ + + + + + + + diff --git a/resources/icons/white/dot_small.svg b/resources/icons/white/dot_small.svg new file mode 100644 index 000000000..74df44208 --- /dev/null +++ b/resources/icons/white/dot_small.svg @@ -0,0 +1,8 @@ + + + + + + + diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 9a037d9d7..6c4d0a71d 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -402,6 +402,11 @@ Slic3r::GUI::PageShp Tab::add_options_page(const wxString& title, const std::str icon_idx = ++m_icon_count; m_icon_index[icon] = icon_idx; } + + if (m_category_icon.find(title) == m_category_icon.end()) { + // Add new category to the category_to_icon list. + m_category_icon[title] = icon; + } } // Initialize the page. #ifdef __WXOSX__ diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index eac0eca15..0aaadb7d7 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -198,6 +198,7 @@ protected: int m_icon_count; std::map m_icon_index; // Map from an icon file name to its index + std::map m_category_icon; // Map from a category name to an icon file name std::vector m_pages; Page* m_active_page {nullptr}; bool m_disable_tree_sel_changed_event {false}; @@ -349,6 +350,8 @@ public: void cache_config_diff(const std::vector& selected_options); void apply_config_from_cache(); + const std::map& get_category_icon_map() { return m_category_icon; } + protected: void create_line_with_widget(ConfigOptionsGroup* optgroup, const std::string& opt_key, widget_t widget); wxSizer* compatible_widget_create(wxWindow* parent, PresetDependencies &deps); diff --git a/src/slic3r/GUI/UnsavedChangesDialog.cpp b/src/slic3r/GUI/UnsavedChangesDialog.cpp index 68ecd49d1..4ab3d0897 100644 --- a/src/slic3r/GUI/UnsavedChangesDialog.cpp +++ b/src/slic3r/GUI/UnsavedChangesDialog.cpp @@ -38,6 +38,10 @@ static const std::map type_icon_names = { {Preset::TYPE_PRINTER, "printer" }, }; +static std::string get_icon_name(Preset::Type type, PrinterTechnology pt) { + return pt == ptSLA && type == Preset::TYPE_PRINTER ? "sla_printer" : type_icon_names.at(type); +} + static std::string black = "#000000"; static std::string grey = "#808080"; static std::string orange = "#ed6b21"; @@ -57,17 +61,17 @@ static void make_string_bold(wxString& str) } // preset(root) node -ModelNode::ModelNode(Preset::Type preset_type, const wxString& text, wxWindow* parent_win) : +ModelNode::ModelNode(Preset::Type preset_type, wxWindow* parent_win, const wxString& text, const std::string& icon_name) : m_parent_win(parent_win), m_parent(nullptr), m_preset_type(preset_type), - m_icon_name(type_icon_names.at(preset_type)), + m_icon_name(icon_name), m_text(text) { UpdateIcons(); } -// group node +// category node ModelNode::ModelNode(ModelNode* parent, const wxString& text, const std::string& icon_name) : m_parent_win(parent->m_parent_win), m_parent(parent), @@ -77,12 +81,14 @@ ModelNode::ModelNode(ModelNode* parent, const wxString& text, const std::string& UpdateIcons(); } -// category node +// group node ModelNode::ModelNode(ModelNode* parent, const wxString& text) : m_parent_win(parent->m_parent_win), m_parent(parent), - m_text(text) + m_text(text), + m_icon_name("dot_small") { + UpdateIcons(); } #ifdef __linux__ @@ -119,6 +125,7 @@ ModelNode::ModelNode(ModelNode* parent, const wxString& text, const wxString& ol m_new_color(new_value.StartsWith("#") ? new_value : ""), m_container(false), m_text(text), + m_icon_name("empty"), m_old_value(old_value), m_new_value(new_value) { @@ -144,6 +151,8 @@ ModelNode::ModelNode(ModelNode* parent, const wxString& text, const wxString& ol // "color" strings color_string(m_old_value, black); color_string(m_new_value, orange); + + UpdateIcons(); } void ModelNode::UpdateEnabling() @@ -206,13 +215,13 @@ UnsavedChangesModel::~UnsavedChangesModel() delete preset_node; } -wxDataViewItem UnsavedChangesModel::AddPreset(Preset::Type type, wxString preset_name) +wxDataViewItem UnsavedChangesModel::AddPreset(Preset::Type type, wxString preset_name, PrinterTechnology pt) { // "color" strings color_string(preset_name, black); make_string_bold(preset_name); - auto preset = new ModelNode(type, preset_name, m_parent_win); + auto preset = new ModelNode(type, m_parent_win, preset_name, get_icon_name(type, pt)); m_preset_nodes.emplace_back(preset); wxDataViewItem child((void*)preset); @@ -242,9 +251,10 @@ ModelNode* UnsavedChangesModel::AddOptionWithGroup(ModelNode* category_node, wxS return AddOption(group_node, option_name, old_value, new_value); } -ModelNode* UnsavedChangesModel::AddOptionWithGroupAndCategory(ModelNode* preset_node, wxString category_name, wxString group_name, wxString option_name, wxString old_value, wxString new_value) +ModelNode* UnsavedChangesModel::AddOptionWithGroupAndCategory(ModelNode* preset_node, wxString category_name, wxString group_name, + wxString option_name, wxString old_value, wxString new_value, const std::string category_icon_name) { - ModelNode* category_node = new ModelNode(preset_node, category_name, "cog"); + ModelNode* category_node = new ModelNode(preset_node, category_name, category_icon_name); preset_node->Append(category_node); ItemAdded(wxDataViewItem((void*)preset_node), wxDataViewItem((void*)category_node)); @@ -252,7 +262,7 @@ ModelNode* UnsavedChangesModel::AddOptionWithGroupAndCategory(ModelNode* preset_ } wxDataViewItem UnsavedChangesModel::AddOption(Preset::Type type, wxString category_name, wxString group_name, wxString option_name, - wxString old_value, wxString new_value) + wxString old_value, wxString new_value, const std::string category_icon_name) { // "color" strings color_string(category_name, black); @@ -277,7 +287,7 @@ wxDataViewItem UnsavedChangesModel::AddOption(Preset::Type type, wxString catego return wxDataViewItem((void*)AddOptionWithGroup(category, group_name, option_name, old_value, new_value)); } - return wxDataViewItem((void*)AddOptionWithGroupAndCategory(preset, category_name, group_name, option_name, old_value, new_value)); + return wxDataViewItem((void*)AddOptionWithGroupAndCategory(preset, category_name, group_name, option_name, old_value, new_value, category_icon_name)); } return wxDataViewItem(nullptr); @@ -972,10 +982,13 @@ void UnsavedChangesDialog::update_tree(Preset::Type type, PresetCollection* pres for (PresetCollection* presets : presets_list) { const DynamicPrintConfig& old_config = presets->get_selected_preset().config; + const PrinterTechnology& old_pt = presets->get_selected_preset().printer_technology(); const DynamicPrintConfig& new_config = presets->get_edited_preset().config; type = presets->type(); - m_tree_model->AddPreset(type, from_u8(presets->get_edited_preset().name)); + const std::map& category_icon_map = wxGetApp().get_tab(type)->get_category_icon_map(); + + m_tree_model->AddPreset(type, from_u8(presets->get_edited_preset().name), old_pt); // Collect dirty options. const bool deep_compare = (type == Preset::TYPE_PRINTER || type == Preset::TYPE_SLA_MATERIAL); @@ -983,14 +996,14 @@ void UnsavedChangesDialog::update_tree(Preset::Type type, PresetCollection* pres auto dirty_options_ = presets->current_dirty_options(); // process changes of extruders count - if (type == Preset::TYPE_PRINTER && + if (type == Preset::TYPE_PRINTER && old_pt == ptFFF && old_config.opt("extruder_colour")->values.size() != new_config.opt("extruder_colour")->values.size()) { wxString local_label = _L("Extruders count"); wxString old_val = from_u8((boost::format("%1%") % old_config.opt("extruder_colour")->values.size()).str()); wxString new_val = from_u8((boost::format("%1%") % new_config.opt("extruder_colour")->values.size()).str()); ItemData item_data = { "extruders_count", local_label, old_val, new_val, type }; - m_items_map.emplace(m_tree_model->AddOption(type, _L("General"), _L("Capabilities"), local_label, old_val, new_val), item_data); + m_items_map.emplace(m_tree_model->AddOption(type, _L("General"), _L("Capabilities"), local_label, old_val, new_val, category_icon_map.at("General")), item_data); } @@ -1004,7 +1017,7 @@ void UnsavedChangesDialog::update_tree(Preset::Type type, PresetCollection* pres if (old_val != item_data.old_val || new_val != item_data.new_val) item_data.is_long = true; - m_items_map.emplace(m_tree_model->AddOption(type, option.category_local, option.group_local, option.label_local, old_val, new_val), item_data); + m_items_map.emplace(m_tree_model->AddOption(type, option.category_local, option.group_local, option.label_local, old_val, new_val, category_icon_map.at(option.category)), item_data); } } } diff --git a/src/slic3r/GUI/UnsavedChangesDialog.hpp b/src/slic3r/GUI/UnsavedChangesDialog.hpp index a50a5f480..01f9f6d2e 100644 --- a/src/slic3r/GUI/UnsavedChangesDialog.hpp +++ b/src/slic3r/GUI/UnsavedChangesDialog.hpp @@ -76,7 +76,7 @@ public: wxString m_new_value; // preset(root) node - ModelNode(Preset::Type preset_type, const wxString& text, wxWindow* parent_win); + ModelNode(Preset::Type preset_type, wxWindow* parent_win, const wxString& text, const std::string& icon_name); // category node ModelNode(ModelNode* parent, const wxString& text, const std::string& icon_name); @@ -141,7 +141,8 @@ class UnsavedChangesModel : public wxDataViewModel wxString group_name, wxString option_name, wxString old_value, - wxString new_value); + wxString new_value, + const std::string category_icon_name); public: enum { @@ -157,9 +158,9 @@ public: void SetAssociatedControl(wxDataViewCtrl* ctrl) { m_ctrl = ctrl; } - wxDataViewItem AddPreset(Preset::Type type, wxString preset_name); + wxDataViewItem AddPreset(Preset::Type type, wxString preset_name, PrinterTechnology pt); wxDataViewItem AddOption(Preset::Type type, wxString category_name, wxString group_name, wxString option_name, - wxString old_value, wxString new_value); + wxString old_value, wxString new_value, const std::string category_icon_name); void UpdateItemEnabling(wxDataViewItem item); bool IsEnabledItem(const wxDataViewItem& item);