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);
|
field->SetColour(wxTransparentColour);
|
||||||
|
|
||||||
wxButton* btn = dynamic_cast<wxButton*>(field->GetPickerCtrl());
|
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);
|
wxMemoryDC dc(bmp);
|
||||||
if (!dc.IsOk()) return;
|
if (!dc.IsOk()) return;
|
||||||
dc.SetTextForeground(*wxWHITE);
|
#ifdef __WXMSW__
|
||||||
dc.SetFont(wxGetApp().normal_font());
|
wxGCDC dc2(dc);
|
||||||
|
#else
|
||||||
|
wxDC &dc2(dc);
|
||||||
|
#endif
|
||||||
|
dc2.SetPen(wxPen("#F1754E", 1));
|
||||||
|
|
||||||
const wxRect rect = wxRect(0, 0, bmp.GetWidth(), bmp.GetHeight());
|
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);
|
dc.SelectObject(wxNullBitmap);
|
||||||
btn->SetBitmapLabel(bmp);
|
btn->SetBitmapLabel(bmp);
|
||||||
|
|
|
@ -224,16 +224,22 @@ int PresetComboBox::update_ams_color()
|
||||||
{
|
{
|
||||||
if (m_filament_idx < 0) return -1;
|
if (m_filament_idx < 0) return -1;
|
||||||
int idx = selected_ams_filament();
|
int idx = selected_ams_filament();
|
||||||
if (idx < 0) return -1;
|
std::string color;
|
||||||
auto &ams_list = wxGetApp().preset_bundle->filament_ams_list;
|
if (idx < 0) {
|
||||||
if (idx >= ams_list.size()) {
|
auto *preset = m_collection->find_preset(Preset::remove_suffix_modified(GetLabel().ToUTF8().data()));
|
||||||
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": ams %1% out of range %2%") % idx % ams_list.size();
|
if (preset) color = preset->config.opt_string("default_filament_colour", 0u);
|
||||||
return -1;
|
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;
|
DynamicPrintConfig *cfg = &wxGetApp().preset_bundle->project_config;
|
||||||
auto colors = static_cast<ConfigOptionStrings*>(cfg->option("filament_colour")->clone());
|
auto colors = static_cast<ConfigOptionStrings*>(cfg->option("filament_colour")->clone());
|
||||||
colors->values[m_filament_idx] = ams_list[idx]
|
colors->values[m_filament_idx] = color;
|
||||||
.opt_string("filament_colour", 0u);
|
|
||||||
DynamicPrintConfig new_cfg;
|
DynamicPrintConfig new_cfg;
|
||||||
new_cfg.set_key_value("filament_colour", colors);
|
new_cfg.set_key_value("filament_colour", colors);
|
||||||
cfg->apply(new_cfg);
|
cfg->apply(new_cfg);
|
||||||
|
@ -304,15 +310,7 @@ void PresetComboBox::update(std::string select_preset_name)
|
||||||
if (select_preset_name.empty() && is_enabled)
|
if (select_preset_name.empty() && is_enabled)
|
||||||
select_preset_name = preset.name;
|
select_preset_name = preset.name;
|
||||||
|
|
||||||
std::string bitmap_key = "cb";
|
wxBitmap* bmp = get_bmp(preset);
|
||||||
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);
|
|
||||||
assert(bmp);
|
assert(bmp);
|
||||||
|
|
||||||
if (!is_enabled)
|
if (!is_enabled)
|
||||||
|
@ -523,7 +521,36 @@ wxBitmap* PresetComboBox::get_bmp( std::string bitmap_key, bool wide_icons, con
|
||||||
#endif
|
#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*/)
|
bool is_enabled/* = true*/, bool is_compatible/* = true*/, bool is_system/* = false*/)
|
||||||
{
|
{
|
||||||
// BBS: no icon
|
// BBS: no icon
|
||||||
|
@ -939,9 +966,6 @@ void PlaterPresetComboBox::update()
|
||||||
if (!preset.is_visible || (!preset.is_compatible && !is_selected))
|
if (!preset.is_visible || (!preset.is_compatible && !is_selected))
|
||||||
continue;
|
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;
|
bool single_bar = false;
|
||||||
if (m_type == Preset::TYPE_FILAMENT)
|
if (m_type == Preset::TYPE_FILAMENT)
|
||||||
{
|
{
|
||||||
|
@ -955,15 +979,8 @@ 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
|
||||||
}
|
}
|
||||||
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,
|
wxBitmap* bmp = get_bmp(preset);
|
||||||
preset.is_compatible, preset.is_system || preset.is_default,
|
|
||||||
single_bar, filament_rgb, extruder_rgb, material_rgb);
|
|
||||||
assert(bmp);
|
assert(bmp);
|
||||||
|
|
||||||
const std::string name = preset.alias.empty() ? preset.name : preset.alias;
|
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
|
// marker used for disable incompatible printer models for the selected physical printer
|
||||||
bool is_enabled = true;
|
bool is_enabled = true;
|
||||||
|
|
||||||
std::string bitmap_key = "tab";
|
wxBitmap* bmp = get_bmp(preset);
|
||||||
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);
|
|
||||||
assert(bmp);
|
assert(bmp);
|
||||||
|
|
||||||
if (preset.is_default || preset.is_system) {
|
if (preset.is_default || preset.is_system) {
|
||||||
|
@ -1361,6 +1370,7 @@ void TabPresetComboBox::update_dirty()
|
||||||
|
|
||||||
if (old_label != new_label) {
|
if (old_label != new_label) {
|
||||||
SetString(ui_id, from_u8(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
|
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,
|
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);
|
bool is_enabled = true, bool is_compatible = true, bool is_system = false);
|
||||||
|
|
||||||
|
wxBitmap *get_bmp(Preset const &preset);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void fill_width_height();
|
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]; }
|
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,
|
int ComboBox::DoInsertItems(const wxArrayStringsAdapter &items,
|
||||||
unsigned int pos,
|
unsigned int pos,
|
||||||
void ** clientData,
|
void ** clientData,
|
||||||
|
|
|
@ -58,6 +58,7 @@ public:
|
||||||
void SetString(unsigned int n, wxString const &value) override;
|
void SetString(unsigned int n, wxString const &value) override;
|
||||||
|
|
||||||
wxBitmap GetItemBitmap(unsigned int n);
|
wxBitmap GetItemBitmap(unsigned int n);
|
||||||
|
void SetItemBitmap(unsigned int n, wxBitmap const &bitmap);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual int DoInsertItems(const wxArrayStringsAdapter &items,
|
virtual int DoInsertItems(const wxArrayStringsAdapter &items,
|
||||||
|
|
Loading…
Reference in New Issue