ENH: group filament preset by vendor & list uncompatible filaments

Change-Id: Ice05956fca59fe130d927b505ac0f61dc8e8cb5e
Jira: STUDIO-11615
This commit is contained in:
chunmao.guo 2025-04-30 14:47:19 +08:00 committed by lane.wei
parent 39688286a7
commit 564e59bf4f
3 changed files with 37 additions and 8 deletions

View File

@ -1109,6 +1109,7 @@ void PlaterPresetComboBox::update()
//BBS: add project embedded presets logic //BBS: add project embedded presets logic
std::map<wxString, wxBitmap*> project_embedded_presets; std::map<wxString, wxBitmap*> project_embedded_presets;
std::map<wxString, wxBitmap *> system_presets; std::map<wxString, wxBitmap *> system_presets;
std::map<wxString, wxBitmap *> uncompatible_presets;
std::unordered_set<std::string> system_printer_models; std::unordered_set<std::string> system_printer_models;
std::map<wxString, wxString> preset_descriptions; std::map<wxString, wxString> preset_descriptions;
std::map<wxString, std::string> preset_filament_vendors; std::map<wxString, std::string> preset_filament_vendors;
@ -1132,7 +1133,7 @@ void PlaterPresetComboBox::update()
m_type == Preset::TYPE_PRINTER && m_preset_bundle->physical_printers.has_selection() ? false : m_type == Preset::TYPE_PRINTER && m_preset_bundle->physical_printers.has_selection() ? false :
i == m_collection->get_selected_idx(); i == m_collection->get_selected_idx();
if (!is_selected && (!preset.is_visible ||!preset.is_compatible)) if (!is_selected && !preset.is_visible)
{ {
continue; continue;
} }
@ -1155,16 +1156,29 @@ void PlaterPresetComboBox::update()
bitmap_key += single_bar ? filament_rgb : filament_rgb + extruder_rgb; bitmap_key += single_bar ? filament_rgb : filament_rgb + extruder_rgb;
#endif #endif
if (preset.is_system) {
if (!preset.is_compatible && preset_filament_vendors.count(name) > 0)
continue;
else if (preset.is_compatible && preset_filament_vendors.count(name) > 0)
uncompatible_presets.erase(name);
preset_filament_vendors[name] = preset.config.option<ConfigOptionStrings>("filament_vendor")->values.at(0); preset_filament_vendors[name] = preset.config.option<ConfigOptionStrings>("filament_vendor")->values.at(0);
if (preset_filament_vendors[name] == "Bambu Lab")
preset_filament_vendors[name] = "Bambu";
preset_filament_types[name] = preset.config.option<ConfigOptionStrings>("filament_type")->values.at(0); preset_filament_types[name] = preset.config.option<ConfigOptionStrings>("filament_type")->values.at(0);
} }
}
wxBitmap* bmp = get_bmp(preset); wxBitmap* bmp = get_bmp(preset);
assert(bmp); assert(bmp);
preset_descriptions.emplace(name, _L(preset.description)); preset_descriptions.emplace(name, _L(preset.description));
if (preset.is_default || preset.is_system) { if (!preset.is_compatible) {
if (boost::ends_with(name, " template"))
continue;
uncompatible_presets.emplace(name, bmp);
}
else if (preset.is_default || preset.is_system) {
//BBS: move system to the end //BBS: move system to the end
if (m_type == Preset::TYPE_PRINTER) { if (m_type == Preset::TYPE_PRINTER) {
auto printer_model = preset.config.opt_string("printer_model"); auto printer_model = preset.config.opt_string("printer_model");
@ -1218,7 +1232,7 @@ void PlaterPresetComboBox::update()
std::vector<std::string> filament_orders = {"Bambu PLA Basic", "Bambu PLA Matte", "Bambu PETG HF", "Bambu ABS", "Bambu PLA Silk", "Bambu PLA-CF", std::vector<std::string> filament_orders = {"Bambu PLA Basic", "Bambu PLA Matte", "Bambu PETG HF", "Bambu ABS", "Bambu PLA Silk", "Bambu PLA-CF",
"Bambu PLA Galaxy", "Bambu PLA Metal", "Bambu PLA Marble", "Bambu PETG-CF", "Bambu PETG Translucent", "Bambu ABS-GF"}; "Bambu PLA Galaxy", "Bambu PLA Metal", "Bambu PLA Marble", "Bambu PETG-CF", "Bambu PETG Translucent", "Bambu ABS-GF"};
std::vector<std::string> first_vendors = {"Bambu Lab", "Generic"}; std::vector<std::string> first_vendors = {"Bambu", "Generic"};
std::vector<std::string> first_types = {"PLA", "PETG", "ABS", "TPU"}; std::vector<std::string> first_types = {"PLA", "PETG", "ABS", "TPU"};
auto add_presets = [this, &preset_descriptions, &filament_orders, &preset_filament_vendors, &first_vendors, &preset_filament_types, &first_types, &selected_in_ams] auto add_presets = [this, &preset_descriptions, &filament_orders, &preset_filament_vendors, &first_vendors, &preset_filament_types, &first_types, &selected_in_ams]
(std::map<wxString, wxBitmap *> const &presets, wxString const &selected, std::string const &group) { (std::map<wxString, wxBitmap *> const &presets, wxString const &selected, std::string const &group) {
@ -1250,7 +1264,10 @@ void PlaterPresetComboBox::update()
return l->first < r->first; return l->first < r->first;
}); });
for (auto it : list) { for (auto it : list) {
SetItemTooltip(Append(it->first, *it->second), preset_descriptions[it->first]); auto vendor = preset_filament_vendors[it->first];
if (!vendor.empty() && group == "Unsupported presets")
vendor.push_back(' ');
SetItemTooltip(Append(it->first, *it->second, vendor), preset_descriptions[it->first]);
bool is_selected = it->first == selected; bool is_selected = it->first == selected;
validate_selection(is_selected); validate_selection(is_selected);
if (is_selected && selected_in_ams) { if (is_selected && selected_in_ams) {
@ -1273,6 +1290,7 @@ void PlaterPresetComboBox::update()
add_presets(nonsys_presets, selected_user_preset, L("User presets")); add_presets(nonsys_presets, selected_user_preset, L("User presets"));
// BBS: move system to the end // BBS: move system to the end
add_presets(system_presets, selected_system_preset, L("System presets")); add_presets(system_presets, selected_system_preset, L("System presets"));
add_presets(uncompatible_presets, {}, L("Unsupported presets"));
//BBS: remove unused pysical printer logic //BBS: remove unused pysical printer logic
/*if (m_type == Preset::TYPE_PRINTER) /*if (m_type == Preset::TYPE_PRINTER)

View File

@ -59,6 +59,7 @@ void DropDown::Create(wxWindow *parent, long style)
state_handler.update_binds(); state_handler.update_binds();
if ((style & DD_NO_CHECK_ICON) == 0) if ((style & DD_NO_CHECK_ICON) == 0)
check_bitmap = ScalableBitmap(this, "checked", 16); check_bitmap = ScalableBitmap(this, "checked", 16);
arrow_bitmap = ScalableBitmap(this, "hms_arrow", 16);
text_off = style & DD_NO_TEXT; text_off = style & DD_NO_TEXT;
// BBS set default font // BBS set default font
@ -323,7 +324,7 @@ void DropDown::render(wxDC &dc)
} }
auto text = group.IsEmpty() auto text = group.IsEmpty()
? (item.group.IsEmpty() ? item.text : item.group) ? (item.group.IsEmpty() ? item.text : item.group)
: item.text.substr(group.size()).Trim(false); : (item.text.StartsWith(group) ? item.text.substr(group.size()).Trim(false) : item.text);
if (!text_off && !text.IsEmpty()) { if (!text_off && !text.IsEmpty()) {
wxSize tSize = dc.GetMultiLineTextExtent(text); wxSize tSize = dc.GetMultiLineTextExtent(text);
if (pt.x + tSize.x > rcContent.GetRight()) { if (pt.x + tSize.x > rcContent.GetRight()) {
@ -335,6 +336,12 @@ void DropDown::render(wxDC &dc)
pt.y += (rcContent.height - textSize.y) / 2; pt.y += (rcContent.height - textSize.y) / 2;
dc.SetFont(GetFont()); dc.SetFont(GetFont());
dc.DrawText(text, pt); dc.DrawText(text, pt);
if (group.IsEmpty() && !item.group.IsEmpty()) {
auto szBmp = arrow_bitmap.GetBmpSize();
pt.x = rcContent.GetRight() - szBmp.x - 5;
pt.y = rcContent.y += (rcContent.height - szBmp.y) / 2;
dc.DrawBitmap(arrow_bitmap.bmp(), pt);
}
} }
rcContent.y += rowSize.y; rcContent.y += rowSize.y;
} }
@ -407,6 +414,7 @@ void DropDown::messureSize()
iconSize = wxSize(); iconSize = wxSize();
count = 0; count = 0;
wxClientDC dc(GetParent() ? GetParent() : this); wxClientDC dc(GetParent() ? GetParent() : this);
dc.SetFont(GetFont());
std::set<wxString> groups; std::set<wxString> groups;
for (size_t i = 0; i < items.size(); ++i) { for (size_t i = 0; i < items.size(); ++i) {
auto &item = items[i]; auto &item = items[i];
@ -427,7 +435,7 @@ void DropDown::messureSize()
if (!text_off) { if (!text_off) {
auto text = group.IsEmpty() auto text = group.IsEmpty()
? (item.group.IsEmpty() ? item.text : item.group) ? (item.group.IsEmpty() ? item.text : item.group)
: item.text.substr(group.size()).Trim(false); : (item.text.StartsWith(group) ? item.text.substr(group.size()).Trim(false) : item.text);
size1 = dc.GetMultiLineTextExtent(text); size1 = dc.GetMultiLineTextExtent(text);
} }
if (item.icon.IsOk()) { if (item.icon.IsOk()) {
@ -442,6 +450,8 @@ void DropDown::messureSize()
} }
if (!align_icon) iconSize.x = 0; if (!align_icon) iconSize.x = 0;
wxSize szContent = textSize; wxSize szContent = textSize;
if (szContent.x < FromDIP(120))
szContent.x = FromDIP(120);
szContent.x += 10; szContent.x += 10;
if (check_bitmap.bmp().IsOk()) { if (check_bitmap.bmp().IsOk()) {
auto szBmp = check_bitmap.GetBmpSize(); auto szBmp = check_bitmap.GetBmpSize();

View File

@ -54,6 +54,7 @@ private:
StateColor selector_border_color; StateColor selector_border_color;
StateColor selector_background_color; StateColor selector_background_color;
ScalableBitmap check_bitmap; ScalableBitmap check_bitmap;
ScalableBitmap arrow_bitmap;
bool pressedDown = false; bool pressedDown = false;
boost::posix_time::ptime dismissTime; boost::posix_time::ptime dismissTime;