ENH: [STUDIO-1272] handle default filament color in presetcomboxbox
Change-Id: Id78749db063fd222915b1aa5ad6abf47fb4294ca
This commit is contained in:
parent
8340e1ceec
commit
5761f8c050
|
@ -1444,14 +1444,21 @@ void ColourPicker::set_undef_value(wxColourPickerCtrl* field)
|
|||
field->SetColour(wxTransparentColour);
|
||||
|
||||
wxButton* btn = dynamic_cast<wxButton*>(field->GetPickerCtrl());
|
||||
wxBitmap bmp = btn->GetBitmap();
|
||||
wxImage image(btn->GetBitmap().GetSize());
|
||||
image.InitAlpha();
|
||||
memset(image.GetAlpha(), 0, image.GetWidth() * image.GetHeight());
|
||||
wxBitmap bmp(std::move(image));
|
||||
wxMemoryDC dc(bmp);
|
||||
if (!dc.IsOk()) return;
|
||||
dc.SetTextForeground(*wxWHITE);
|
||||
dc.SetFont(wxGetApp().normal_font());
|
||||
#ifdef __WXMSW__
|
||||
wxGCDC dc2(dc);
|
||||
#else
|
||||
wxDC &dc2(dc);
|
||||
#endif
|
||||
dc2.SetPen(wxPen("#F1754E", 1));
|
||||
|
||||
const wxRect rect = wxRect(0, 0, bmp.GetWidth(), bmp.GetHeight());
|
||||
dc.DrawLabel("undef", rect, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL);
|
||||
dc2.DrawLine(rect.GetLeftBottom(), rect.GetTopRight());
|
||||
|
||||
dc.SelectObject(wxNullBitmap);
|
||||
btn->SetBitmapLabel(bmp);
|
||||
|
|
|
@ -224,16 +224,22 @@ int PresetComboBox::update_ams_color()
|
|||
{
|
||||
if (m_filament_idx < 0) return -1;
|
||||
int idx = selected_ams_filament();
|
||||
if (idx < 0) return -1;
|
||||
auto &ams_list = wxGetApp().preset_bundle->filament_ams_list;
|
||||
if (idx >= ams_list.size()) {
|
||||
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": ams %1% out of range %2%") % idx % ams_list.size();
|
||||
return -1;
|
||||
std::string color;
|
||||
if (idx < 0) {
|
||||
auto *preset = m_collection->find_preset(Preset::remove_suffix_modified(GetLabel().ToUTF8().data()));
|
||||
if (preset) color = preset->config.opt_string("default_filament_colour", 0u);
|
||||
if (color.empty()) return -1;
|
||||
} else {
|
||||
auto &ams_list = wxGetApp().preset_bundle->filament_ams_list;
|
||||
if (idx >= ams_list.size()) {
|
||||
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": ams %1% out of range %2%") % idx % ams_list.size();
|
||||
return -1;
|
||||
}
|
||||
color = ams_list[idx].opt_string("filament_colour", 0u);
|
||||
}
|
||||
DynamicPrintConfig *cfg = &wxGetApp().preset_bundle->project_config;
|
||||
auto colors = static_cast<ConfigOptionStrings*>(cfg->option("filament_colour")->clone());
|
||||
colors->values[m_filament_idx] = ams_list[idx]
|
||||
.opt_string("filament_colour", 0u);
|
||||
colors->values[m_filament_idx] = color;
|
||||
DynamicPrintConfig new_cfg;
|
||||
new_cfg.set_key_value("filament_colour", colors);
|
||||
cfg->apply(new_cfg);
|
||||
|
@ -304,15 +310,7 @@ void PresetComboBox::update(std::string select_preset_name)
|
|||
if (select_preset_name.empty() && is_enabled)
|
||||
select_preset_name = preset.name;
|
||||
|
||||
std::string bitmap_key = "cb";
|
||||
if (m_type == Preset::TYPE_PRINTER) {
|
||||
bitmap_key += "_printer";
|
||||
if (preset.printer_technology() == ptSLA)
|
||||
bitmap_key += "_sla";
|
||||
}
|
||||
std::string main_icon_name = m_type == Preset::TYPE_PRINTER && preset.printer_technology() == ptSLA ? "printer" : m_main_bitmap_name;
|
||||
|
||||
wxBitmap* bmp = get_bmp(bitmap_key, main_icon_name, "unlock_normal", is_enabled, preset.is_compatible, preset.is_system || preset.is_default);
|
||||
wxBitmap* bmp = get_bmp(preset);
|
||||
assert(bmp);
|
||||
|
||||
if (!is_enabled)
|
||||
|
@ -523,7 +521,36 @@ wxBitmap* PresetComboBox::get_bmp( std::string bitmap_key, bool wide_icons, con
|
|||
#endif
|
||||
}
|
||||
|
||||
wxBitmap* PresetComboBox::get_bmp( std::string bitmap_key, const std::string& main_icon_name, const std::string& next_icon_name,
|
||||
wxBitmap *PresetComboBox::get_bmp(Preset const &preset)
|
||||
{
|
||||
static wxBitmap sbmp;
|
||||
if (m_type == Preset::TYPE_FILAMENT) {
|
||||
Preset const & preset2 = &m_collection->get_selected_preset() == &preset ? m_collection->get_edited_preset() : preset;
|
||||
wxString color = preset2.config.opt_string("default_filament_colour", 0);
|
||||
wxColour clr(color);
|
||||
if (clr.IsOk()) {
|
||||
std::string bitmap_key = "default_filament_colour_" + color.ToStdString();
|
||||
wxBitmap *bmp = bitmap_cache().find(bitmap_key);
|
||||
if (bmp == nullptr) {
|
||||
wxImage img(16, 16);
|
||||
if (clr.Red() > 224 && clr.Blue() > 224 && clr.Green() > 224) {
|
||||
img.SetRGB(wxRect({0, 0}, img.GetSize()), 128, 128, 128);
|
||||
img.SetRGB(wxRect({1, 1}, img.GetSize() - wxSize{2, 2}), clr.Red(), clr.Green(), clr.Blue());
|
||||
} else {
|
||||
img.SetRGB(wxRect({0, 0}, img.GetSize()), clr.Red(), clr.Green(), clr.Blue());
|
||||
}
|
||||
bmp = new wxBitmap(img);
|
||||
bmp = bitmap_cache().insert(bitmap_key, *bmp);
|
||||
}
|
||||
return bmp;
|
||||
}
|
||||
}
|
||||
return &sbmp;
|
||||
}
|
||||
|
||||
wxBitmap *PresetComboBox::get_bmp(std::string bitmap_key,
|
||||
const std::string &main_icon_name,
|
||||
const std::string &next_icon_name,
|
||||
bool is_enabled/* = true*/, bool is_compatible/* = true*/, bool is_system/* = false*/)
|
||||
{
|
||||
// BBS: no icon
|
||||
|
@ -939,9 +966,6 @@ void PlaterPresetComboBox::update()
|
|||
if (!preset.is_visible || (!preset.is_compatible && !is_selected))
|
||||
continue;
|
||||
|
||||
std::string bitmap_key, filament_rgb, extruder_rgb, material_rgb;
|
||||
std::string bitmap_type_name = bitmap_key = m_type == Preset::TYPE_PRINTER && preset.printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name;
|
||||
|
||||
bool single_bar = false;
|
||||
if (m_type == Preset::TYPE_FILAMENT)
|
||||
{
|
||||
|
@ -955,15 +979,8 @@ void PlaterPresetComboBox::update()
|
|||
bitmap_key += single_bar ? filament_rgb : filament_rgb + extruder_rgb;
|
||||
#endif
|
||||
}
|
||||
else if (m_type == Preset::TYPE_SLA_MATERIAL) {
|
||||
material_rgb = is_selected ? m_preset_bundle->sla_materials.get_edited_preset().config.opt_string("material_colour") : preset.config.opt_string("material_colour");
|
||||
if (material_rgb.empty())
|
||||
material_rgb = print_config_def.get("material_colour")->get_default_value<ConfigOptionString>()->value;
|
||||
}
|
||||
|
||||
wxBitmap* bmp = get_bmp(bitmap_key, wide_icons, bitmap_type_name,
|
||||
preset.is_compatible, preset.is_system || preset.is_default,
|
||||
single_bar, filament_rgb, extruder_rgb, material_rgb);
|
||||
wxBitmap* bmp = get_bmp(preset);
|
||||
assert(bmp);
|
||||
|
||||
const std::string name = preset.alias.empty() ? preset.name : preset.alias;
|
||||
|
@ -1198,15 +1215,7 @@ void TabPresetComboBox::update()
|
|||
// marker used for disable incompatible printer models for the selected physical printer
|
||||
bool is_enabled = true;
|
||||
|
||||
std::string bitmap_key = "tab";
|
||||
if (m_type == Preset::TYPE_PRINTER) {
|
||||
bitmap_key += "_printer";
|
||||
if (preset.printer_technology() == ptSLA)
|
||||
bitmap_key += "_sla";
|
||||
}
|
||||
std::string main_icon_name = m_type == Preset::TYPE_PRINTER && preset.printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name;
|
||||
|
||||
wxBitmap* bmp = get_bmp(bitmap_key, main_icon_name, "unlock_normal", is_enabled, preset.is_compatible, preset.is_system || preset.is_default);
|
||||
wxBitmap* bmp = get_bmp(preset);
|
||||
assert(bmp);
|
||||
|
||||
if (preset.is_default || preset.is_system) {
|
||||
|
@ -1361,6 +1370,7 @@ void TabPresetComboBox::update_dirty()
|
|||
|
||||
if (old_label != new_label) {
|
||||
SetString(ui_id, from_u8(new_label));
|
||||
SetItemBitmap(ui_id, *get_bmp(*preset));
|
||||
if (ui_id == GetSelection()) SetToolTip(wxString::FromUTF8(new_label.c_str())); // BBS
|
||||
}
|
||||
}
|
||||
|
|
|
@ -145,6 +145,8 @@ protected:
|
|||
wxBitmap* get_bmp( std::string bitmap_key, const std::string& main_icon_name, const std::string& next_icon_name,
|
||||
bool is_enabled = true, bool is_compatible = true, bool is_system = false);
|
||||
|
||||
wxBitmap *get_bmp(Preset const &preset);
|
||||
|
||||
private:
|
||||
void fill_width_height();
|
||||
};
|
||||
|
|
|
@ -179,6 +179,13 @@ void ComboBox::SetString(unsigned int n, wxString const &value)
|
|||
|
||||
wxBitmap ComboBox::GetItemBitmap(unsigned int n) { return icons[n]; }
|
||||
|
||||
void ComboBox::SetItemBitmap(unsigned int n, wxBitmap const &bitmap)
|
||||
{
|
||||
if (n >= texts.size()) return;
|
||||
icons[n] = bitmap;
|
||||
drop.Invalidate();
|
||||
}
|
||||
|
||||
int ComboBox::DoInsertItems(const wxArrayStringsAdapter &items,
|
||||
unsigned int pos,
|
||||
void ** clientData,
|
||||
|
|
|
@ -58,6 +58,7 @@ public:
|
|||
void SetString(unsigned int n, wxString const &value) override;
|
||||
|
||||
wxBitmap GetItemBitmap(unsigned int n);
|
||||
void SetItemBitmap(unsigned int n, wxBitmap const &bitmap);
|
||||
|
||||
protected:
|
||||
virtual int DoInsertItems(const wxArrayStringsAdapter &items,
|
||||
|
|
Loading…
Reference in New Issue