From 9fff7967f36d7692767aeb3f03d4434b1d84a484 Mon Sep 17 00:00:00 2001 From: "xin.zhang" Date: Fri, 14 Mar 2025 15:58:25 +0800 Subject: [PATCH] ENH: support ams remain in popup jira: [STUDIO-9942] Change-Id: I8514d1a1ac8e893ed46f18e1a42261c3af3f294c --- resources/images/ams_mapping_container_1.svg | 21 ++-- resources/images/ams_mapping_container_4.svg | 13 +-- src/slic3r/GUI/AmsMappingPopup.cpp | 116 +++++++++++++------ src/slic3r/GUI/AmsMappingPopup.hpp | 14 ++- src/slic3r/GUI/DeviceManager.hpp | 58 +++++++--- 5 files changed, 150 insertions(+), 72 deletions(-) diff --git a/resources/images/ams_mapping_container_1.svg b/resources/images/ams_mapping_container_1.svg index 18b77cb30..6e1928189 100644 --- a/resources/images/ams_mapping_container_1.svg +++ b/resources/images/ams_mapping_container_1.svg @@ -1,15 +1,20 @@ - - - - + + + + - - + + + + + + + - - + + diff --git a/resources/images/ams_mapping_container_4.svg b/resources/images/ams_mapping_container_4.svg index e33702e10..c31d7f34e 100644 --- a/resources/images/ams_mapping_container_4.svg +++ b/resources/images/ams_mapping_container_4.svg @@ -1,12 +1,3 @@ - - - - - - - - - - - + + diff --git a/src/slic3r/GUI/AmsMappingPopup.cpp b/src/slic3r/GUI/AmsMappingPopup.cpp index 6acc69afb..66562c125 100644 --- a/src/slic3r/GUI/AmsMappingPopup.cpp +++ b/src/slic3r/GUI/AmsMappingPopup.cpp @@ -27,6 +27,9 @@ namespace Slic3r { namespace GUI { #define MATERIAL_ITEM_SIZE wxSize(FromDIP(65), FromDIP(50)) #define MATERIAL_REC_WHEEL_SIZE wxSize(FromDIP(17), FromDIP(16)) #define MAPPING_ITEM_REAL_SIZE wxSize(FromDIP(48), FromDIP(60)) + +#define MAPPING_ITEM_REMAIN_AREA_H FromDIP(10) + wxDEFINE_EVENT(EVT_SET_FINISH_MAPPING, wxCommandEvent); const int LEFT_OFFSET = 2; MaterialItem::MaterialItem(wxWindow *parent, wxColour mcolour, wxString mname) @@ -821,7 +824,7 @@ void AmsMapingPopup::update_ams_data_multi_machines() if (m_amsmapping_container_list.size() > m_amsmapping_container_list_index ) { m_amsmapping_container_list[m_amsmapping_container_list_index]->Show(); - add_ams_mapping(tray_datas, m_amsmapping_container_list[m_amsmapping_container_list_index], m_amsmapping_container_sizer_list[m_amsmapping_container_list_index]); + add_ams_mapping(tray_datas, m_ams_remain_detect_flag, m_amsmapping_container_list[m_amsmapping_container_list_index], m_amsmapping_container_sizer_list[m_amsmapping_container_list_index]); } Layout(); @@ -925,6 +928,7 @@ void AmsMapingPopup::update(MachineObject* obj, const std::vector& if (!obj) {return;} + m_ams_remain_detect_flag = obj->ams_calibrate_remain_flag; for (auto& ams_container : m_amsmapping_container_list) { ams_container->Destroy(); @@ -1013,6 +1017,7 @@ void AmsMapingPopup::update(MachineObject* obj, const std::vector& } else { td.type = NORMAL; + td.remain = tray_data->remain; td.colour = AmsTray::decode_color(tray_data->color); td.name = tray_data->get_display_filament_type(); td.filament_type = tray_data->get_filament_type(); @@ -1047,7 +1052,8 @@ void AmsMapingPopup::update(MachineObject* obj, const std::vector& if (ams_type >=1 || ams_type <= 3) { //1:ams 2:ams-lite 3:n3f auto sizer_mapping_list = new wxBoxSizer(wxHORIZONTAL); - auto ams_mapping_item_container = new MappingContainer(nozzle_id == 0? m_right_marea_panel:m_left_marea_panel, ams_iter->second->trayList.size()); + auto ams_mapping_item_container = new MappingContainer(nozzle_id == 0 ? m_right_marea_panel : m_left_marea_panel, + ams_iter->second->get_ams_device_name(), ams_iter->second->trayList.size()); ams_mapping_item_container->SetSizer(sizer_mapping_list); ams_mapping_item_container->Layout(); @@ -1076,6 +1082,7 @@ void AmsMapingPopup::update(MachineObject* obj, const std::vector& } else { td.type = NORMAL; + td.remain = tray_data->remain; td.colour = AmsTray::decode_color(tray_data->color); td.name = tray_data->get_display_filament_type(); td.filament_type = tray_data->get_filament_type(); @@ -1090,7 +1097,7 @@ void AmsMapingPopup::update(MachineObject* obj, const std::vector& } ams_mapping_item_container->Show(); - add_ams_mapping(tray_datas, ams_mapping_item_container, sizer_mapping_list); + add_ams_mapping(tray_datas, obj->ams_calibrate_remain_flag, ams_mapping_item_container, sizer_mapping_list); m_amsmapping_container_sizer_list.push_back(sizer_mapping_list); m_amsmapping_container_list.push_back(ams_mapping_item_container); @@ -1155,6 +1162,7 @@ std::vector AmsMapingPopup::parse_ams_mapping(std::mapremain; td.colour = AmsTray::decode_color(tray_data->color); td.name = tray_data->get_display_filament_type(); td.filament_type = tray_data->get_filament_type(); @@ -1168,7 +1176,7 @@ std::vector AmsMapingPopup::parse_ams_mapping(std::map tray_data, wxWindow* container, wxBoxSizer* sizer) +void AmsMapingPopup::add_ams_mapping(std::vector tray_data, bool remain_detect_flag, wxWindow* container, wxBoxSizer* sizer) { sizer->Add(0,0,0,wxLEFT,FromDIP(6)); @@ -1189,9 +1197,9 @@ void AmsMapingPopup::add_ams_mapping(std::vector tray_data, wxWindow* if (tray_data[i].type == NORMAL) { if (is_match_material(tray_data[i].filament_type)) { - m_mapping_item->set_data(tray_data[i].colour, tray_data[i].name, tray_data[i]); + m_mapping_item->set_data(tray_data[i].colour, tray_data[i].name, remain_detect_flag, tray_data[i]); } else { - m_mapping_item->set_data(wxColour(0xEE,0xEE,0xEE), tray_data[i].name, tray_data[i], true); + m_mapping_item->set_data(wxColour(0xEE, 0xEE, 0xEE), tray_data[i].name, remain_detect_flag, tray_data[i], true); m_has_unmatch_filament = true; } @@ -1205,7 +1213,7 @@ void AmsMapingPopup::add_ams_mapping(std::vector tray_data, wxWindow* // temp if (tray_data[i].type == EMPTY) { - m_mapping_item->set_data(wxColour(0xCE, 0xCE, 0xCE), "-", tray_data[i]); + m_mapping_item->set_data(wxColour(0xCE, 0xCE, 0xCE), "-", remain_detect_flag, tray_data[i]); m_mapping_item->Bind(wxEVT_LEFT_DOWN, [this, tray_data, i, m_mapping_item](wxMouseEvent &e) { return; //not allowed to map to empty slots m_mapping_item->send_event(m_current_filament_id); @@ -1215,7 +1223,7 @@ void AmsMapingPopup::add_ams_mapping(std::vector tray_data, wxWindow* // third party if (tray_data[i].type == THIRD) { - m_mapping_item->set_data(wxColour(0xCE, 0xCE, 0xCE), "?", tray_data[i]); + m_mapping_item->set_data(wxColour(0xCE, 0xCE, 0xCE), "?", remain_detect_flag, tray_data[i]); m_mapping_item->Bind(wxEVT_LEFT_DOWN, [this, tray_data, i, m_mapping_item](wxMouseEvent &e) { m_mapping_item->send_event(m_current_filament_id); Dismiss(); @@ -1235,10 +1243,10 @@ void AmsMapingPopup::add_ext_ams_mapping(TrayData tray_data, MappingItem* item) // set button if (tray_data.type == NORMAL) { if (is_match_material(tray_data.filament_type)) { - item->set_data(tray_data.colour, tray_data.name, tray_data); + item->set_data(tray_data.colour, tray_data.name, false, tray_data); } else { - item->set_data(wxColour(0xEE, 0xEE, 0xEE), tray_data.name, tray_data, true); + item->set_data(wxColour(0xEE, 0xEE, 0xEE), tray_data.name, false, tray_data, true); m_has_unmatch_filament = true; } @@ -1252,7 +1260,7 @@ void AmsMapingPopup::add_ext_ams_mapping(TrayData tray_data, MappingItem* item) // temp if (tray_data.type == EMPTY) { - item->set_data(wxColour(0xCE, 0xCE, 0xCE), "-", tray_data); + item->set_data(wxColour(0xCE, 0xCE, 0xCE), "-", false, tray_data); item->Bind(wxEVT_LEFT_DOWN, [this, tray_data,item](wxMouseEvent& e) { item->send_event(m_current_filament_id); Dismiss(); @@ -1261,7 +1269,7 @@ void AmsMapingPopup::add_ext_ams_mapping(TrayData tray_data, MappingItem* item) // third party if (tray_data.type == THIRD) { - item->set_data(tray_data.colour, "?", tray_data); + item->set_data(tray_data.colour, "?", false, tray_data); //item->set_data(wxColour(0xCE, 0xCE, 0xCE), "?", tray_data); item->Bind(wxEVT_LEFT_DOWN, [this, tray_data, item](wxMouseEvent& e) { item->send_event(m_current_filament_id); @@ -1337,6 +1345,39 @@ void MappingItem::paintEvent(wxPaintEvent &evt) // PrepareDC(dc); } +static void _DrawRemainArea(const MappingItem *item, const TrayData &dd, bool support_remain_dect, wxDC &dc) +{ + int to_paint_remain = dd.remain; + + /*paint invalid data as 100*/ + if (!support_remain_dect) { to_paint_remain = 100;} + if (dd.ams_id == VIRTUAL_TRAY_MAIN_ID || dd.ams_id == VIRTUAL_TRAY_DEPUTY_ID) { to_paint_remain = 100; } + if (0 > to_paint_remain || to_paint_remain > 100) { to_paint_remain = 100; } + + wxSize size = item->GetSize(); + int x_margin = item->FromDIP(4); + int y_margin = item->FromDIP(2); + int full_range_width = size.x; + + /*range background*/ + dc.SetPen(wxColour(0xE4E4E4)); + dc.SetBrush(wxColour(0xE4E4E4)); + int bg_height = item->FromDIP(6); + int bg_width = full_range_width - (2 * x_margin); + dc.DrawRoundedRectangle(x_margin, y_margin, bg_width, bg_height, item->FromDIP(2)); + + /*remain fill*/ + if (!dd.name.empty()) + { + dc.SetPen(dd.colour); + dc.SetBrush(dd.colour); + int border = item->FromDIP(1); + int remain_width = (bg_width - (2 * border)) * to_paint_remain / 100; + int remain_height = bg_height - (2 * border); + dc.DrawRoundedRectangle(x_margin + border, y_margin + border, remain_width, remain_height, item->FromDIP(2)); + } +} + void MappingItem::render(wxDC &dc) { wxSize size = GetSize(); @@ -1358,12 +1399,16 @@ void MappingItem::render(wxDC &dc) doRender(dc); #endif + /*remain*/ + _DrawRemainArea(this, m_tray_data, m_support_remain_detect, dc); + auto top = MAPPING_ITEM_REMAIN_AREA_H; + // checked if (m_checked) { - dc.DrawBitmap(mapping_item_checked.bmp(), size.x - mapping_item_checked.GetBmpWidth() - FromDIP(4), 0); + dc.DrawBitmap(mapping_item_checked.bmp(), size.x - mapping_item_checked.GetBmpWidth() - FromDIP(4), top); } - auto top = mapping_item_checked.GetBmpHeight() - FromDIP(4); + top += 0.5 * mapping_item_checked.GetBmpHeight(); // materials name dc.SetFont(::Label::Head_13); @@ -1384,14 +1429,15 @@ void MappingItem::render(wxDC &dc) dc.DrawText(m_name, wxPoint((GetSize().x - txt_size.x) / 2, top)); } -void MappingItem::set_data(wxColour colour, wxString name, TrayData data, bool unmatch) +void MappingItem::set_data(wxColour colour, wxString name, bool remain_dect, TrayData data, bool unmatch) { m_unmatch = unmatch; m_tray_data = data; - if (m_coloul != colour || m_name != name) { + if (m_coloul != colour || m_name != name || (m_support_remain_detect != remain_dect)) { m_coloul = colour; m_name = name; + m_support_remain_detect = remain_dect; Refresh(); } @@ -1431,7 +1477,7 @@ void MappingItem::doRender(wxDC &dc) //gradient if (m_tray_data.ctype == 0) { for (int i = 0; i < m_tray_data.material_cols.size() - 1; i++) { - auto rect = wxRect(left, (size.y - MAPPING_ITEM_REAL_SIZE.y) / 2, MAPPING_ITEM_REAL_SIZE.x, MAPPING_ITEM_REAL_SIZE.y); + auto rect = wxRect(left, (size.y - MAPPING_ITEM_REAL_SIZE.y) / 2 + MAPPING_ITEM_REMAIN_AREA_H, MAPPING_ITEM_REAL_SIZE.x, MAPPING_ITEM_REAL_SIZE.y); dc.GradientFillLinear(rect, m_tray_data.material_cols[i], m_tray_data.material_cols[i + 1], wxEAST); left += gwidth; } @@ -1441,28 +1487,23 @@ void MappingItem::doRender(wxDC &dc) for (int i = 0; i < cols_size; i++) { dc.SetBrush(wxBrush(m_tray_data.material_cols[i])); float x = (float)MAPPING_ITEM_REAL_SIZE.x * i / cols_size; - dc.DrawRectangle(x, (size.y - MAPPING_ITEM_REAL_SIZE.y) / 2, (float)MAPPING_ITEM_REAL_SIZE.x / cols_size, MAPPING_ITEM_REAL_SIZE.y); + dc.DrawRectangle(x, (size.y - MAPPING_ITEM_REAL_SIZE.y) / 2 + MAPPING_ITEM_REMAIN_AREA_H, (float) MAPPING_ITEM_REAL_SIZE.x / cols_size, MAPPING_ITEM_REAL_SIZE.y); } } } else if (color.Alpha() == 0 && !m_unmatch) { - dc.DrawBitmap( m_transparent_mapping_item.bmp(), 0, (size.y - MAPPING_ITEM_REAL_SIZE.y) / 2); + dc.DrawBitmap(m_transparent_mapping_item.bmp(), 0, (size.y - MAPPING_ITEM_REAL_SIZE.y) / 2 + MAPPING_ITEM_REMAIN_AREA_H); } else { - dc.DrawRectangle(0, (size.y - MAPPING_ITEM_REAL_SIZE.y) / 2, MAPPING_ITEM_REAL_SIZE.x, MAPPING_ITEM_REAL_SIZE.y); + dc.DrawRectangle(0, (size.y - MAPPING_ITEM_REAL_SIZE.y) / 2 + MAPPING_ITEM_REMAIN_AREA_H, MAPPING_ITEM_REAL_SIZE.x, MAPPING_ITEM_REAL_SIZE.y); } wxColour side_colour = wxColour(0xE4E4E4); dc.SetPen(side_colour); dc.SetBrush(wxBrush(side_colour)); -#ifdef __APPLE__ - dc.DrawRectangle(0, 0, FromDIP(4), size.y); - dc.DrawRectangle(size.x - FromDIP(4), 0, FromDIP(4), size.y); -#else - dc.DrawRectangle(0, 0, FromDIP(4), size.y); - dc.DrawRectangle(size.x - FromDIP(4), 0, FromDIP(4), size.y); -#endif // __APPLE__ + dc.DrawRectangle(0, MAPPING_ITEM_REMAIN_AREA_H, FromDIP(4), size.y); + dc.DrawRectangle(size.x - FromDIP(4), MAPPING_ITEM_REMAIN_AREA_H, FromDIP(4), size.y); } @@ -1873,7 +1914,7 @@ bool AmsIntroducePopup::ProcessLeftDown(wxMouseEvent& event) { } -MappingContainer::MappingContainer(wxWindow* parent, int slots_num) +MappingContainer::MappingContainer(wxWindow *parent, const wxString &ams_type, int slots_num) : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize) { #ifdef __WINDOWS__ @@ -1882,18 +1923,19 @@ MappingContainer::MappingContainer(wxWindow* parent, int slots_num) SetBackgroundColour(StateColor::darkModeColorFor(*wxWHITE)); Bind(wxEVT_PAINT, &MappingContainer::paintEvent, this); + m_ams_type = ams_type; m_slots_num = slots_num; if (slots_num == 1) { - ams_mapping_item_container = create_scaled_bitmap("ams_mapping_container_1", this, 78); - SetMinSize(wxSize(FromDIP(74), FromDIP(78))); - SetMaxSize(wxSize(FromDIP(230), FromDIP(78))); + ams_mapping_item_container = create_scaled_bitmap("ams_mapping_container_1", this, 82); + SetMinSize(wxSize(FromDIP(74), FromDIP(82))); + SetMaxSize(wxSize(FromDIP(74), FromDIP(82))); } else { - ams_mapping_item_container = create_scaled_bitmap("ams_mapping_container_4", this, 78); - SetMinSize(wxSize(FromDIP(230), FromDIP(78))); - SetMaxSize(wxSize(FromDIP(230), FromDIP(78))); + ams_mapping_item_container = create_scaled_bitmap("ams_mapping_container_4", this, 82); + SetMinSize(wxSize(FromDIP(230), FromDIP(82))); + SetMaxSize(wxSize(FromDIP(230), FromDIP(82))); } } @@ -1932,6 +1974,12 @@ void MappingContainer::render(wxDC& dc) void MappingContainer::doRender(wxDC& dc) { dc.DrawBitmap(ams_mapping_item_container, 0, 0); + + dc.SetFont(::Label::Head_11); + auto size = GetSize(); + auto extent = dc.GetTextExtent(m_ams_type); + dc.SetTextForeground(wxColour("#F1F1F1")); + dc.DrawText(m_ams_type, FromDIP(10), size.GetHeight() - extent.GetHeight()); } AmsReplaceMaterialDialog::AmsReplaceMaterialDialog(wxWindow* parent) diff --git a/src/slic3r/GUI/AmsMappingPopup.hpp b/src/slic3r/GUI/AmsMappingPopup.hpp index cc1be1253..118fb2525 100644 --- a/src/slic3r/GUI/AmsMappingPopup.hpp +++ b/src/slic3r/GUI/AmsMappingPopup.hpp @@ -38,6 +38,8 @@ #include #include +#define MAPPING_ITEM_INVALID_REMAIN -1 + namespace Slic3r { namespace GUI { @@ -60,6 +62,7 @@ struct TrayData TrayType type; int id; int ctype = 0; + int remain = MAPPING_ITEM_INVALID_REMAIN; std::string name; std::string filament_type; wxColour colour; @@ -159,7 +162,7 @@ public: public: void update_data(TrayData data); void send_event(int fliament_id); - void set_data(wxColour colour, wxString name, TrayData data, bool unmatch = false); + void set_data(wxColour colour, wxString name, bool remain_detect, TrayData data, bool unmatch = false); void set_checked(bool checked); void set_tray_index(wxString t_index) { m_tray_index = t_index; }; @@ -172,16 +175,18 @@ private: private: bool m_checked = false; + bool m_support_remain_detect = false; }; class MappingContainer : public wxPanel { private: int m_slots_num = 4;/*1 or 4*/ + wxString m_ams_type; wxBitmap ams_mapping_item_container; public: - MappingContainer(wxWindow* parent, int slots_num = 4); + MappingContainer(wxWindow* parent, const wxString& ams_type, int slots_num = 4); ~MappingContainer(); public: @@ -196,6 +201,7 @@ protected: class AmsMapingPopup : public PopupWindow { bool m_use_in_sync_dialog = false; + bool m_ams_remain_detect_flag = false; wxStaticText* m_title_text{ nullptr }; public: @@ -252,8 +258,8 @@ public: void update_title(MachineObject* obj); void update_items_check_state(const std::vector& ams_mapping_result); void update_ams_data_multi_machines(); - void add_ams_mapping(std::vector tray_data, wxWindow* container, wxBoxSizer* sizer); - void add_ext_ams_mapping(TrayData tray_data, MappingItem* item); + void add_ams_mapping(std::vector tray_data, bool remain_detect_flag, wxWindow *container, wxBoxSizer *sizer); + void add_ext_ams_mapping(TrayData tray_data, MappingItem *item); void set_current_filament_id(int id) { m_current_filament_id = id; }; int get_current_filament_id(){return m_current_filament_id;}; bool is_match_material(std::string material); diff --git a/src/slic3r/GUI/DeviceManager.hpp b/src/slic3r/GUI/DeviceManager.hpp index e70d1d553..5927ea508 100644 --- a/src/slic3r/GUI/DeviceManager.hpp +++ b/src/slic3r/GUI/DeviceManager.hpp @@ -357,25 +357,53 @@ public: #define INVALID_AMS_TEMPERATURE std::numeric_limits::min() -class Ams { +class Ams +{ public: - Ams(std::string ams_id, int nozzle_id, int type_id) { - id = ams_id; + Ams(std::string ams_id, int nozzle_id, int type_id) + { + id = ams_id; nozzle = nozzle_id; - type = type_id; + type = type_id; } - std::string id; - int left_dry_time = 0; - int humidity = 5; - int humidity_raw = -1;// the percentage, -1 means invalid. eg. 100 means 100% - float current_temperature = INVALID_AMS_TEMPERATURE; // the temperature - bool startup_read_opt{true}; - bool tray_read_opt{false}; - bool is_exists{false}; - std::map trayList; + std::string id; + int left_dry_time = 0; + int humidity = 5; + int humidity_raw = -1; // the percentage, -1 means invalid. eg. 100 means 100% + float current_temperature = INVALID_AMS_TEMPERATURE; // the temperature + bool startup_read_opt{true}; + bool tray_read_opt{false}; + bool is_exists{false}; + std::map trayList; - int nozzle; - int type{1}; //0:dummy 1:ams 2:ams-lite 3:n3f 4:n3s + int nozzle; + int type{1}; // 0:dummy 1:ams 2:ams-lite 3:n3f 4:n3s + +public: + wxString get_ams_device_name() const + { + wxString ams_device_name; + if (type == 1) { + ams_device_name = "AMS-%d"; + } else if (type == 2) { + ams_device_name = "AMS Lite-%d"; + } else if (type == 3) { + ams_device_name = "AMS 2 PRO-%d"; + } else if (type == 4) { + ams_device_name = "AMS HT-%d"; + } else { + assert(0); + ams_device_name = "AMS-%d"; + } + + int num_id; + try { + num_id = std::stoi(id); + } catch (...) {} + + int loc = (num_id > 127) ? (num_id - 127) : (num_id + 1); + return wxString::Format(ams_device_name, loc); + }; }; enum PrinterFirmwareType {