diff --git a/src/libslic3r/Config.cpp b/src/libslic3r/Config.cpp index e59022e79..bd91dc7bb 100644 --- a/src/libslic3r/Config.cpp +++ b/src/libslic3r/Config.cpp @@ -801,6 +801,9 @@ int ConfigBase::load_from_json(const std::string &file, ConfigSubstitutionContex else if (boost::iequals(it.key(), BBL_JSON_KEY_FROM)) { key_values.emplace(BBL_JSON_KEY_FROM, it.value()); } + else if (boost::iequals(it.key(), BBL_JSON_KEY_DESCRIPTION)) { + key_values.emplace(BBL_JSON_KEY_DESCRIPTION, it.value()); + } else if (boost::iequals(it.key(), BBL_JSON_KEY_INSTANTIATION)) { key_values.emplace(BBL_JSON_KEY_INSTANTIATION, it.value()); } diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 33105fc3b..5c87a47d2 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -1156,6 +1156,8 @@ void PresetCollection::load_presets( preset.filament_id = key_values[BBL_JSON_KEY_FILAMENT_ID]; if (key_values.find(BBL_JSON_KEY_IS_CUSTOM) != key_values.end()) preset.custom_defined = key_values[BBL_JSON_KEY_IS_CUSTOM]; + if (key_values.find(BBL_JSON_KEY_DESCRIPTION) != key_values.end()) + preset.description = key_values[BBL_JSON_KEY_DESCRIPTION]; if (key_values.find("instantiation") != key_values.end()) preset.is_visible = key_values["instantiation"] != "false"; diff --git a/src/libslic3r/Preset.hpp b/src/libslic3r/Preset.hpp index e1afe6596..08d020fa3 100644 --- a/src/libslic3r/Preset.hpp +++ b/src/libslic3r/Preset.hpp @@ -242,6 +242,7 @@ public: std::string base_id; // base id of preset std::string sync_info; // enum: "delete", "create", "update", "" std::string custom_defined; // enum: "1", "0", "" + std::string description; // long long updated_time{0}; //last updated time std::map key_values; diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index c3bda6624..a8d33899f 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -3243,7 +3243,7 @@ std::pair PresetBundle::load_vendor_configs_ // Load the print, filament or printer preset. std::string preset_name; DynamicPrintConfig config; - std::string alias_name, inherits, instantiation, setting_id, filament_id; + std::string alias_name, inherits, description, instantiation, setting_id, filament_id; std::vector renamed_from; const DynamicPrintConfig* default_config = nullptr; std::string reason; @@ -3259,7 +3259,8 @@ std::pair PresetBundle::load_vendor_configs_ return reason; } preset_name = key_values[BBL_JSON_KEY_NAME]; - instantiation = key_values[BBL_JSON_KEY_INSTANTIATION]; + description = key_values[BBL_JSON_KEY_DESCRIPTION]; + instantiation = key_values[BBL_JSON_KEY_INSTANTIATION]; auto setting_it = key_values.find(BBL_JSON_KEY_SETTING_ID); if (setting_it != key_values.end()) setting_id = setting_it->second; @@ -3370,6 +3371,7 @@ std::pair PresetBundle::load_vendor_configs_ loaded.is_system = true; loaded.vendor = current_vendor_profile; loaded.version = current_vendor_profile->config_version; + loaded.description = description; loaded.setting_id = setting_id; loaded.filament_id = filament_id; BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " " << __LINE__ << loaded.name << " load filament_id: " << filament_id; diff --git a/src/slic3r/GUI/PresetComboBoxes.cpp b/src/slic3r/GUI/PresetComboBoxes.cpp index 49410eb76..699cf65af 100644 --- a/src/slic3r/GUI/PresetComboBoxes.cpp +++ b/src/slic3r/GUI/PresetComboBoxes.cpp @@ -957,7 +957,8 @@ void PlaterPresetComboBox::update() std::map nonsys_presets; //BBS: add project embedded presets logic std::map project_embedded_presets; - std::map system_presets; + std::map system_presets; + std::map preset_descriptions; //BBS: move system to the end wxString selected_system_preset; @@ -998,13 +999,15 @@ void PlaterPresetComboBox::update() wxBitmap* bmp = get_bmp(preset); assert(bmp); - const std::string name = preset.alias.empty() ? preset.name : preset.alias; + const wxString name = get_preset_name(preset); + preset_descriptions.emplace(name, from_u8(preset.description)); + if (preset.is_default || preset.is_system) { //BBS: move system to the end - system_presets.emplace(get_preset_name(preset), bmp); + system_presets.emplace(name, bmp); if (is_selected) { tooltip = get_tooltip(preset); - selected_system_preset = get_preset_name(preset); + selected_system_preset = name; } //Append(get_preset_name(preset), *bmp); //validate_selection(is_selected); @@ -1015,17 +1018,17 @@ void PlaterPresetComboBox::update() //BBS: add project embedded preset logic else if (preset.is_project_embedded) { - project_embedded_presets.emplace(get_preset_name(preset), bmp); + project_embedded_presets.emplace(name, bmp); if (is_selected) { - selected_user_preset = get_preset_name(preset); + selected_user_preset = name; tooltip = wxString::FromUTF8(preset.name.c_str()); } } else { - nonsys_presets.emplace(get_preset_name(preset), bmp); + nonsys_presets.emplace(name, bmp); if (is_selected) { - selected_user_preset = get_preset_name(preset); + selected_user_preset = name; //BBS set tooltip tooltip = get_tooltip(preset); } @@ -1043,7 +1046,7 @@ void PlaterPresetComboBox::update() { set_label_marker(Append(separator(L("Project-inside presets")), wxNullBitmap)); for (std::map::iterator it = project_embedded_presets.begin(); it != project_embedded_presets.end(); ++it) { - Append(it->first, *it->second); + SetItemTooltip(Append(it->first, *it->second), preset_descriptions[it->first]); validate_selection(it->first == selected_user_preset); } } @@ -1051,7 +1054,7 @@ void PlaterPresetComboBox::update() { set_label_marker(Append(separator(L("User presets")), wxNullBitmap)); for (std::map::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) { - Append(it->first, *it->second); + SetItemTooltip(Append(it->first, *it->second), preset_descriptions[it->first]); validate_selection(it->first == selected_user_preset); } } @@ -1060,7 +1063,7 @@ void PlaterPresetComboBox::update() { set_label_marker(Append(separator(L("System presets")), wxNullBitmap)); for (std::map::iterator it = system_presets.begin(); it != system_presets.end(); ++it) { - Append(it->first, *it->second); + SetItemTooltip(Append(it->first, *it->second), preset_descriptions[it->first]); validate_selection(it->first == selected_system_preset); } } @@ -1209,6 +1212,7 @@ void TabPresetComboBox::update() std::map> project_embedded_presets; //BBS: move system to the end std::map> system_presets; + std::map preset_descriptions; wxString selected = ""; //BBS: move system to the end @@ -1235,11 +1239,14 @@ void TabPresetComboBox::update() wxBitmap* bmp = get_bmp(preset); assert(bmp); + const wxString name = get_preset_name(preset); + preset_descriptions.emplace(name, from_u8(preset.description)); + if (preset.is_default || preset.is_system) { //BBS: move system to the end - system_presets.emplace(get_preset_name(preset), std::pair(bmp, is_enabled)); + system_presets.emplace(name, std::pair(bmp, is_enabled)); if (i == idx_selected) - selected = get_preset_name(preset); + selected = name; //int item_id = Append(get_preset_name(preset), *bmp); //if (!is_enabled) // set_label_marker(item_id, LABEL_ITEM_DISABLED); @@ -1249,16 +1256,16 @@ void TabPresetComboBox::update() else if (preset.is_project_embedded) { //std::pair pair(bmp, is_enabled); - project_embedded_presets.emplace(get_preset_name(preset), std::pair(bmp, is_enabled)); + project_embedded_presets.emplace(name, std::pair(bmp, is_enabled)); if (i == idx_selected) - selected = get_preset_name(preset); + selected = name; } else { std::pair pair(bmp, is_enabled); - nonsys_presets.emplace(get_preset_name(preset), std::pair(bmp, is_enabled)); + nonsys_presets.emplace(name, std::pair(bmp, is_enabled)); if (i == idx_selected) - selected = get_preset_name(preset); + selected = name; } //BBS: move system to the end //if (i + 1 == m_collection->num_default_presets()) @@ -1274,6 +1281,7 @@ void TabPresetComboBox::update() set_label_marker(Append(separator(L("Project-inside presets")), wxNullBitmap)); for (std::map>::iterator it = project_embedded_presets.begin(); it != project_embedded_presets.end(); ++it) { int item_id = Append(it->first, *it->second.first); + SetItemTooltip(item_id, preset_descriptions[it->first]); bool is_enabled = it->second.second; if (!is_enabled) set_label_marker(item_id, LABEL_ITEM_DISABLED); @@ -1285,6 +1293,7 @@ void TabPresetComboBox::update() set_label_marker(Append(separator(L("User presets")), wxNullBitmap)); for (std::map>::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) { int item_id = Append(it->first, *it->second.first); + SetItemTooltip(item_id, preset_descriptions[it->first]); bool is_enabled = it->second.second; if (!is_enabled) set_label_marker(item_id, LABEL_ITEM_DISABLED); @@ -1297,6 +1306,7 @@ void TabPresetComboBox::update() set_label_marker(Append(separator(L("System presets")), wxNullBitmap)); for (std::map>::iterator it = system_presets.begin(); it != system_presets.end(); ++it) { int item_id = Append(it->first, *it->second.first); + SetItemTooltip(item_id, preset_descriptions[it->first]); bool is_enabled = it->second.second; if (!is_enabled) set_label_marker(item_id, LABEL_ITEM_DISABLED); diff --git a/src/slic3r/GUI/Widgets/ComboBox.cpp b/src/slic3r/GUI/Widgets/ComboBox.cpp index 00a3ce0b0..5f32294aa 100644 --- a/src/slic3r/GUI/Widgets/ComboBox.cpp +++ b/src/slic3r/GUI/Widgets/ComboBox.cpp @@ -39,7 +39,7 @@ ComboBox::ComboBox(wxWindow *parent, int n, const wxString choices[], long style) - : drop(texts, icons) + : drop(texts, tips, icons) { if (style & wxCB_READONLY) style |= wxRIGHT; @@ -155,6 +155,7 @@ int ComboBox::Append(const wxString &item, void * clientData) { texts.push_back(item); + tips.push_back(wxString{}); icons.push_back(bitmap); datas.push_back(clientData); types.push_back(wxClientData_None); @@ -165,6 +166,7 @@ int ComboBox::Append(const wxString &item, void ComboBox::DoClear() { texts.clear(); + tips.clear(); icons.clear(); datas.clear(); types.clear(); @@ -175,6 +177,7 @@ void ComboBox::DoDeleteOneItem(unsigned int pos) { if (pos >= texts.size()) return; texts.erase(texts.begin() + pos); + tips.erase(tips.begin() + pos); icons.erase(icons.begin() + pos); datas.erase(datas.begin() + pos); types.erase(types.begin() + pos); @@ -196,6 +199,18 @@ void ComboBox::SetString(unsigned int n, wxString const &value) if (n == drop.GetSelection()) SetLabel(value); } +wxString ComboBox::GetItemTooltip(unsigned int n) const +{ + if (n >= texts.size()) return wxString(); + return tips[n]; +} + +void ComboBox::SetItemTooltip(unsigned int n, wxString const &value) { + if (n >= texts.size()) return; + tips[n] = value; + if (n == drop.GetSelection()) drop.SetToolTip(value); +} + wxBitmap ComboBox::GetItemBitmap(unsigned int n) { return icons[n]; } void ComboBox::SetItemBitmap(unsigned int n, wxBitmap const &bitmap) @@ -213,6 +228,7 @@ int ComboBox::DoInsertItems(const wxArrayStringsAdapter &items, if (pos > texts.size()) return -1; for (int i = 0; i < items.GetCount(); ++i) { texts.insert(texts.begin() + pos, items[i]); + tips.insert(tips.begin() + pos, wxString{}); icons.insert(icons.begin() + pos, wxNullBitmap); datas.insert(datas.begin() + pos, clientData ? clientData[i] : NULL); types.insert(types.begin() + pos, type); diff --git a/src/slic3r/GUI/Widgets/ComboBox.hpp b/src/slic3r/GUI/Widgets/ComboBox.hpp index 82b719d6f..74bebd052 100644 --- a/src/slic3r/GUI/Widgets/ComboBox.hpp +++ b/src/slic3r/GUI/Widgets/ComboBox.hpp @@ -10,6 +10,7 @@ class ComboBox : public wxWindowWithItems { std::vector texts; + std::vector tips; std::vector icons; std::vector datas; std::vector types; @@ -59,6 +60,9 @@ public: wxString GetString(unsigned int n) const override; void SetString(unsigned int n, wxString const &value) override; + wxString GetItemTooltip(unsigned int n) const; + void SetItemTooltip(unsigned int n, wxString const &value); + wxBitmap GetItemBitmap(unsigned int n); void SetItemBitmap(unsigned int n, wxBitmap const &bitmap); bool is_drop_down(){return drop_down;} diff --git a/src/slic3r/GUI/Widgets/DropDown.cpp b/src/slic3r/GUI/Widgets/DropDown.cpp index c831bde7e..1ef65e55e 100644 --- a/src/slic3r/GUI/Widgets/DropDown.cpp +++ b/src/slic3r/GUI/Widgets/DropDown.cpp @@ -31,8 +31,10 @@ END_EVENT_TABLE() */ DropDown::DropDown(std::vector &texts, + std::vector &tips, std::vector &icons) : texts(texts) + , tips(tips) , icons(icons) , state_handler(this) , border_color(0xDBDBDB) @@ -46,9 +48,10 @@ DropDown::DropDown(std::vector &texts, DropDown::DropDown(wxWindow * parent, std::vector &texts, + std::vector &tips, std::vector &icons, long style) - : DropDown(texts, icons) + : DropDown(texts, tips, icons) { Create(parent, style); } @@ -306,7 +309,7 @@ void DropDown::render(wxDC &dc) if (!text_off && !text.IsEmpty()) { wxSize tSize = dc.GetMultiLineTextExtent(text); if (pt.x + tSize.x > rcContent.GetRight()) { - if (i == hover_item) + if (i == hover_item && tips[i].IsEmpty()) SetToolTip(text); text = wxControl::Ellipsize(text, dc, wxELLIPSIZE_END, rcContent.GetRight() - pt.x); @@ -459,7 +462,7 @@ void DropDown::mouseMove(wxMouseEvent &event) if (hover >= (int) texts.size()) hover = -1; if (hover == hover_item) return; hover_item = hover; - SetToolTip(""); + if (hover >= 0) SetToolTip(tips[hover]); } paintNow(); } @@ -482,7 +485,7 @@ void DropDown::mouseWheelMoved(wxMouseEvent &event) if (hover >= (int) texts.size()) hover = -1; if (hover != hover_item) { hover_item = hover; - if (hover >= 0) SetToolTip(texts[hover]); + if (hover >= 0) SetToolTip(tips[hover]); } paintNow(); } diff --git a/src/slic3r/GUI/Widgets/DropDown.hpp b/src/slic3r/GUI/Widgets/DropDown.hpp index 86f14aa27..e3cf9b453 100644 --- a/src/slic3r/GUI/Widgets/DropDown.hpp +++ b/src/slic3r/GUI/Widgets/DropDown.hpp @@ -16,6 +16,7 @@ wxDECLARE_EVENT(EVT_DISMISS, wxCommandEvent); class DropDown : public PopupWindow { std::vector & texts; + std::vector & tips; std::vector & icons; bool need_sync = false; int selection = -1; @@ -45,10 +46,12 @@ class DropDown : public PopupWindow public: DropDown(std::vector &texts, + std::vector &tips, std::vector &icons); DropDown(wxWindow * parent, std::vector &texts, + std::vector &tips, std::vector &icons, long style = 0);