ENH: support preset description(tooltip)

Change-Id: Iff005baac4974c538d1109fb0ba1df20b04a8f69
Jira: STUDIO-5754
This commit is contained in:
chunmao.guo 2023-12-29 14:34:58 +08:00 committed by Lane.Wei
parent e04e39cecf
commit 657050aa5c
9 changed files with 68 additions and 24 deletions

View File

@ -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());
}

View File

@ -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";

View File

@ -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<std::string, std::string> key_values;

View File

@ -3243,7 +3243,7 @@ std::pair<PresetsConfigSubstitutions, size_t> 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<std::string> renamed_from;
const DynamicPrintConfig* default_config = nullptr;
std::string reason;
@ -3259,7 +3259,8 @@ std::pair<PresetsConfigSubstitutions, size_t> 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<PresetsConfigSubstitutions, size_t> 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;

View File

@ -957,7 +957,8 @@ void PlaterPresetComboBox::update()
std::map<wxString, wxBitmap*> nonsys_presets;
//BBS: add project embedded presets logic
std::map<wxString, wxBitmap*> project_embedded_presets;
std::map<wxString, wxBitmap*> system_presets;
std::map<wxString, wxBitmap *> system_presets;
std::map<wxString, wxString> 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<wxString, wxBitmap*>::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<wxString, wxBitmap*>::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<wxString, wxBitmap*>::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<wxString, std::pair<wxBitmap*, bool>> project_embedded_presets;
//BBS: move system to the end
std::map<wxString, std::pair<wxBitmap*, bool>> system_presets;
std::map<wxString, wxString> 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<wxBitmap *, bool>(bmp, is_enabled));
system_presets.emplace(name, std::pair<wxBitmap *, bool>(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<wxBitmap*, bool> pair(bmp, is_enabled);
project_embedded_presets.emplace(get_preset_name(preset), std::pair<wxBitmap *, bool>(bmp, is_enabled));
project_embedded_presets.emplace(name, std::pair<wxBitmap *, bool>(bmp, is_enabled));
if (i == idx_selected)
selected = get_preset_name(preset);
selected = name;
}
else
{
std::pair<wxBitmap*, bool> pair(bmp, is_enabled);
nonsys_presets.emplace(get_preset_name(preset), std::pair<wxBitmap*, bool>(bmp, is_enabled));
nonsys_presets.emplace(name, std::pair<wxBitmap *, bool>(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<wxString, std::pair<wxBitmap*, bool>>::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<wxString, std::pair<wxBitmap*, bool>>::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<wxString, std::pair<wxBitmap*, bool>>::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);

View File

@ -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);

View File

@ -10,6 +10,7 @@
class ComboBox : public wxWindowWithItems<TextInput, wxItemContainer>
{
std::vector<wxString> texts;
std::vector<wxString> tips;
std::vector<wxBitmap> icons;
std::vector<void *> datas;
std::vector<wxClientDataType> 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;}

View File

@ -31,8 +31,10 @@ END_EVENT_TABLE()
*/
DropDown::DropDown(std::vector<wxString> &texts,
std::vector<wxString> &tips,
std::vector<wxBitmap> &icons)
: texts(texts)
, tips(tips)
, icons(icons)
, state_handler(this)
, border_color(0xDBDBDB)
@ -46,9 +48,10 @@ DropDown::DropDown(std::vector<wxString> &texts,
DropDown::DropDown(wxWindow * parent,
std::vector<wxString> &texts,
std::vector<wxString> &tips,
std::vector<wxBitmap> &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();
}

View File

@ -16,6 +16,7 @@ wxDECLARE_EVENT(EVT_DISMISS, wxCommandEvent);
class DropDown : public PopupWindow
{
std::vector<wxString> & texts;
std::vector<wxString> & tips;
std::vector<wxBitmap> & icons;
bool need_sync = false;
int selection = -1;
@ -45,10 +46,12 @@ class DropDown : public PopupWindow
public:
DropDown(std::vector<wxString> &texts,
std::vector<wxString> &tips,
std::vector<wxBitmap> &icons);
DropDown(wxWindow * parent,
std::vector<wxString> &texts,
std::vector<wxString> &tips,
std::vector<wxBitmap> &icons,
long style = 0);