ENH:display different thumbnails according to the printer type

Change-Id: I1534594923fdcafb231661a1a7fa289221277449
This commit is contained in:
tao wang 2022-12-09 18:34:28 +08:00 committed by Lane.Wei
parent 5139edb876
commit b5e38e02fe
14 changed files with 474 additions and 387 deletions

View File

@ -23,7 +23,8 @@
"camera_resolution":["720p"],
"bed_temperature_limit": 100,
"model_id": "C11",
"printer_type": "C11"
"printer_type": "C11",
"printer_thumbnail_image": "printer_thumbnail_p1p"
},
{
"display_name": "Bambu Lab X1",
@ -32,7 +33,8 @@
},
"camera_resolution":["720p","1080p"],
"model_id": "BL-P002",
"printer_type": "3DPrinter-X1"
"printer_type": "3DPrinter-X1",
"printer_thumbnail_image": "printer_thumbnail"
},
{
"display_name": "Bambu Lab X1 Carbon",
@ -41,7 +43,8 @@
},
"model_id": "BL-P001",
"camera_resolution":["720p","1080p"],
"printer_type": "3DPrinter-X1-Carbon"
"printer_type": "3DPrinter-X1-Carbon",
"printer_thumbnail_image": "printer_thumbnail"
}
]
}

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 87 KiB

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 76 KiB

After

Width:  |  Height:  |  Size: 86 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 87 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 122 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 122 KiB

View File

@ -37,8 +37,9 @@ namespace GUI {
wxBoxSizer *m_sizere_left_h = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *m_sizere_left_v= new wxBoxSizer(wxVERTICAL);
auto m_printer_img = new wxStaticBitmap(m_panel_left, wxID_ANY, create_scaled_bitmap("printer_thumbnail", nullptr, 96), wxDefaultPosition, wxSize(FromDIP(100), FromDIP(96)), 0);
m_printer_img = new wxStaticBitmap(m_panel_left, wxID_ANY, create_scaled_bitmap("printer_thumbnail", nullptr, FromDIP(100)), wxDefaultPosition, wxSize(FromDIP(120), FromDIP(120)), 0);
m_printer_img->SetBackgroundColour(BIND_DIALOG_GREY200);
m_printer_img->Hide();
m_printer_name = new wxStaticText(m_panel_left, wxID_ANY, wxEmptyString);
m_printer_name->SetBackgroundColour(BIND_DIALOG_GREY200);
m_printer_name->SetFont(::Label::Head_14);
@ -274,9 +275,18 @@ void BindMachineDialog::on_dpi_changed(const wxRect &suggested_rect)
void BindMachineDialog::on_show(wxShowEvent &event)
{
//m_printer_name->SetLabelText(m_machine_info->get_printer_type_string());
m_printer_name->SetLabelText(from_u8(m_machine_info->dev_name));
Layout();
if (event.IsShown()) {
auto img = m_machine_info->get_printer_thumbnail_img_str();
if (wxGetApp().dark_mode()) { img += "_dark"; }
auto bitmap = create_scaled_bitmap(img, this, FromDIP(100));
m_printer_img->SetBitmap(bitmap);
m_printer_img->Refresh();
m_printer_img->Show();
m_printer_name->SetLabelText(from_u8(m_machine_info->dev_name));
Layout();
event.Skip();
}
}
@ -302,8 +312,9 @@ UnBindMachineDialog::UnBindMachineDialog(Plater *plater /*= nullptr*/)
wxBoxSizer *m_sizere_left_h = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *m_sizere_left_v= new wxBoxSizer(wxVERTICAL);
auto m_printer_img = new wxStaticBitmap(m_panel_left, wxID_ANY, create_scaled_bitmap("printer_thumbnail", nullptr, 96), wxDefaultPosition, wxSize(FromDIP(100), FromDIP(96)),0);
m_printer_img = new wxStaticBitmap(m_panel_left, wxID_ANY, create_scaled_bitmap("printer_thumbnail", nullptr, FromDIP(100)), wxDefaultPosition, wxSize(FromDIP(120), FromDIP(120)), 0);
m_printer_img->SetBackgroundColour(BIND_DIALOG_GREY200);
m_printer_img->Hide();
m_printer_name = new wxStaticText(m_panel_left, wxID_ANY, wxEmptyString);
m_printer_name->SetFont(::Label::Head_14);
m_printer_name->SetBackgroundColour(BIND_DIALOG_GREY200);
@ -488,9 +499,18 @@ void UnBindMachineDialog::on_unbind_printer(wxCommandEvent &event)
void UnBindMachineDialog::on_show(wxShowEvent &event)
{
//m_printer_name->SetLabelText(m_machine_info->get_printer_type_string());
m_printer_name->SetLabelText(from_u8(m_machine_info->dev_name));
Layout();
if (event.IsShown()) {
auto img = m_machine_info->get_printer_thumbnail_img_str();
if (wxGetApp().dark_mode()) { img += "_dark"; }
auto bitmap = create_scaled_bitmap(img, this, FromDIP(100));
m_printer_img->SetBitmap(bitmap);
m_printer_img->Refresh();
m_printer_img->Show();
m_printer_name->SetLabelText(from_u8(m_machine_info->dev_name));
Layout();
event.Skip();
}
}
}} // namespace Slic3r::GUI

View File

@ -55,6 +55,7 @@ private:
Button * m_button_cancel;
wxSimplebook *m_simplebook;
wxStaticBitmap *m_avatar;
wxStaticBitmap *m_printer_img;
wxWebRequest web_request;
MachineObject * m_machine_info{nullptr};
@ -86,6 +87,7 @@ protected:
Button * m_button_cancel;
MachineObject *m_machine_info{nullptr};
wxStaticBitmap *m_avatar;
wxStaticBitmap *m_printer_img;
public:
UnBindMachineDialog(Plater *plater = nullptr);

View File

@ -335,7 +335,15 @@ wxBitmap* BitmapCache::load_svg(const std::string &bitmap_name, unsigned target_
//if (!new_color.empty())
// replaces["\"#ED6B21\""] = "\"" + new_color + "\"";
NSVGimage *image = nsvgParseFromFileWithReplace(Slic3r::var(bitmap_name + ".svg").c_str(), "px", 96.0f, replaces);
NSVGimage *image = nullptr;
if (strstr(bitmap_name.c_str(), "printer_thumbnail") == NULL) {
image = nsvgParseFromFileWithReplace(Slic3r::var(bitmap_name + ".svg").c_str(), "px", 96.0f, replaces);
}
else {
std::map<std::string, std::string> temp_replaces;
image = nsvgParseFromFileWithReplace(Slic3r::var(bitmap_name + ".svg").c_str(), "px", 96.0f, temp_replaces);
}
if (image == nullptr)
return nullptr;

View File

@ -279,6 +279,11 @@ std::string MachineObject::get_preset_printer_model_name(std::string printer_typ
return DeviceManager::get_printer_display_name(printer_type);
}
std::string MachineObject::get_preset_printer_thumbnail_img(std::string printer_type)
{
return DeviceManager::get_printer_thumbnail_img(printer_type);
}
wxString MachineObject::get_printer_type_display_str()
{
std::string display_name = get_preset_printer_model_name(printer_type);
@ -288,6 +293,15 @@ wxString MachineObject::get_printer_type_display_str()
return _L("Unknown");
}
std::string MachineObject::get_printer_thumbnail_img_str()
{
std::string img_str = get_preset_printer_thumbnail_img(printer_type);
if (!img_str.empty())
return img_str;
else
return "printer_thumbnail";
}
void MachineObject::set_access_code(std::string code)
{
this->access_code = code;
@ -3696,6 +3710,20 @@ std::string DeviceManager::get_printer_display_name(std::string type_str)
return "";
}
std::string DeviceManager::get_printer_thumbnail_img(std::string type_str)
{
if (DeviceManager::function_table.contains("printers")) {
for (auto printer : DeviceManager::function_table["printers"]) {
if (printer.contains("model_id") && printer["model_id"].get<std::string>() == type_str) {
if (printer.contains("printer_thumbnail_image")) {
return printer["printer_thumbnail_image"].get<std::string>();
}
}
}
}
return "";
}
bool DeviceManager::is_function_supported(std::string type_str, std::string function_name)
{
if (DeviceManager::function_table.contains("printers")) {

View File

@ -368,6 +368,7 @@ public:
static inline int m_sequence_id = 20000;
static std::string parse_printer_type(std::string type_str);
static std::string get_preset_printer_model_name(std::string printer_type);
static std::string get_preset_printer_thumbnail_img(std::string printer_type);
static bool is_bbl_filament(std::string tag_uid);
typedef std::function<void()> UploadedFn;
@ -387,8 +388,13 @@ public:
bool is_lan_mode_printer();
//PRINTER_TYPE printer_type = PRINTER_3DPrinter_UKNOWN;
std::string printer_type; /* model_id */
std::string printer_thumbnail_img;
std::string monitor_upgrade_printer_img;
wxString get_printer_type_display_str();
std::string get_printer_thumbnail_img_str();
std::string product_name; // set by iot service, get /user/print
std::string bind_user_name;
@ -767,6 +773,7 @@ public:
static json function_table;
static std::string parse_printer_type(std::string type_str);
static std::string get_printer_display_name(std::string type_str);
static std::string get_printer_thumbnail_img(std::string type_str);
static bool is_function_supported(std::string type_str, std::string function_name);
static std::vector<std::string> get_resolution_supported(std::string type_str);

View File

@ -248,6 +248,7 @@ wxWindow* MonitorPanel::create_side_tools()
void MonitorPanel::on_sys_color_changed()
{
m_status_info_panel->on_sys_color_changed();
m_upgrade_panel->on_sys_color_changed();
}
void MonitorPanel::msw_rescale()

View File

@ -281,7 +281,7 @@ void MachineInfoPanel::msw_rescale()
void MachineInfoPanel::init_bitmaps()
{
m_img_printer = create_scaled_bitmap("monitor_upgrade_printer", nullptr, 200);
m_img_printer = create_scaled_bitmap("printer_thumbnail", nullptr, 160);
m_img_monitor_ams = create_scaled_bitmap("monitor_upgrade_ams", nullptr, 200);
m_img_ext = create_scaled_bitmap("monitor_upgrade_ext", nullptr, 200);
upgrade_green_icon = create_scaled_bitmap("monitor_upgrade_online", nullptr, 5);
@ -298,8 +298,21 @@ MachineInfoPanel::~MachineInfoPanel()
delete confirm_dlg;
}
void MachineInfoPanel::Update_printer_img(MachineObject* obj)
{
if (!obj) {return;}
auto img = obj->get_printer_thumbnail_img_str();
if (wxGetApp().dark_mode()) {img += "_dark";}
m_img_printer = create_scaled_bitmap(img, nullptr, 160);
m_printer_img->SetBitmap(m_img_printer);
m_printer_img->Refresh();
}
void MachineInfoPanel::update(MachineObject* obj)
{
if (m_obj != obj)
Update_printer_img(obj);
m_obj = obj;
if (obj) {
this->Freeze();
@ -723,6 +736,11 @@ void MachineInfoPanel::show_ext(bool show, bool force_update)
m_last_ext_show = show;
}
void MachineInfoPanel::on_sys_color_changed()
{
Update_printer_img(m_obj);
}
void MachineInfoPanel::upgrade_firmware_internal() {
if (!m_obj)
return;
@ -947,6 +965,11 @@ void UpgradePanel::show_status(int status)
}
}
void UpgradePanel::on_sys_color_changed()
{
m_push_upgrade_panel->on_sys_color_changed();
}
bool UpgradePanel::Show(bool show)
{
if (show) {

View File

@ -114,6 +114,8 @@ public:
MachineInfoPanel(wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxTAB_TRAVERSAL, const wxString& name = wxEmptyString);
~MachineInfoPanel();
void on_sys_color_changed();
void Update_printer_img(MachineObject* obj);
void init_bitmaps();
Button* get_btn() {
@ -181,6 +183,7 @@ public:
void refresh_version_and_firmware(MachineObject* obj);
void update(MachineObject *obj);
void show_status(int status);
void on_sys_color_changed();
MachineObject *m_obj { nullptr };
};