From 8c8235c1c93201f85dcab2e74ce4639d1946ee6e Mon Sep 17 00:00:00 2001 From: tao wang Date: Wed, 2 Aug 2023 18:09:36 +0800 Subject: [PATCH] ENH:fixed display the wrong tray type in AMS 1. no longer using track_type 2. type using tray_info_idx query Change-Id: I3ad08dc92e90c86041232d57b80331c563fe24c5 --- src/slic3r/GUI/DeviceManager.cpp | 37 ++++++++++++++++++++++++++++---- src/slic3r/GUI/DeviceManager.hpp | 1 + 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/slic3r/GUI/DeviceManager.cpp b/src/slic3r/GUI/DeviceManager.cpp index bbdcff7550..46246e97be 100644 --- a/src/slic3r/GUI/DeviceManager.cpp +++ b/src/slic3r/GUI/DeviceManager.cpp @@ -2665,6 +2665,31 @@ int MachineObject::local_publish_json(std::string json_str, int qos) return result; } +std::string MachineObject::setting_id_to_type(std::string setting_id, std::string tray_type) +{ + std::string type; + + PresetBundle* preset_bundle = GUI::wxGetApp().preset_bundle; + if (preset_bundle) { + for (auto it = preset_bundle->filaments.begin(); it != preset_bundle->filaments.end(); it++) { + + if (it->filament_id.compare(setting_id) == 0) { + std::string display_filament_type; + it->config.get_filament_type(display_filament_type); + type = display_filament_type; + break; + } + } + } + + if (tray_type != type || type.empty()) { + if (type.empty()) {type = tray_type;} + BOOST_LOG_TRIVIAL(info) << "The values of tray_info_idx and tray_type do not match tray_info_idx " << setting_id << " tray_type " << tray_type; + } + + return type; +} + int MachineObject::parse_json(std::string payload) { CNumericLocalesSetter locales_setter; @@ -3492,7 +3517,8 @@ int MachineObject::parse_json(std::string payload) curr_tray->tag_uid = "0"; if (tray_it->contains("tray_info_idx") && tray_it->contains("tray_type")) { curr_tray->setting_id = (*tray_it)["tray_info_idx"].get(); - std::string type = (*tray_it)["tray_type"].get(); + //std::string type = (*tray_it)["tray_type"].get(); + std::string type = setting_id_to_type(curr_tray->setting_id, (*tray_it)["tray_type"].get()); if (curr_tray->setting_id == "GFS00") { curr_tray->type = "PLA-S"; } @@ -3653,7 +3679,8 @@ int MachineObject::parse_json(std::string payload) vt_tray.tag_uid = "0"; if (jj["vt_tray"].contains("tray_info_idx") && jj["vt_tray"].contains("tray_type")) { vt_tray.setting_id = jj["vt_tray"]["tray_info_idx"].get(); - std::string type = jj["vt_tray"]["tray_type"].get(); + //std::string type = jj["vt_tray"]["tray_type"].get(); + std::string type = setting_id_to_type(vt_tray.setting_id, jj["vt_tray"]["tray_type"].get()); if (vt_tray.setting_id == "GFS00") { vt_tray.type = "PLA-S"; } @@ -3792,9 +3819,10 @@ int MachineObject::parse_json(std::string payload) BOOST_LOG_TRIVIAL(trace) << "ams_filament_setting, parse tray info"; vt_tray.nozzle_temp_max = std::to_string(jj["nozzle_temp_max"].get()); vt_tray.nozzle_temp_min = std::to_string(jj["nozzle_temp_min"].get()); - vt_tray.type = jj["tray_type"].get(); vt_tray.color = jj["tray_color"].get(); vt_tray.setting_id = jj["tray_info_idx"].get(); + //vt_tray.type = jj["tray_type"].get(); + vt_tray.type = setting_id_to_type(vt_tray.setting_id, jj["tray_info_idx"].get()); // delay update vt_tray.set_hold_count(); } else { @@ -3806,7 +3834,7 @@ int MachineObject::parse_json(std::string payload) BOOST_LOG_TRIVIAL(trace) << "ams_filament_setting, parse tray info"; tray_it->second->nozzle_temp_max = std::to_string(jj["nozzle_temp_max"].get()); tray_it->second->nozzle_temp_min = std::to_string(jj["nozzle_temp_min"].get()); - tray_it->second->type = jj["tray_type"].get(); + //tray_it->second->type = jj["tray_type"].get(); tray_it->second->color = jj["tray_color"].get(); /*tray_it->second->cols.clear(); @@ -3819,6 +3847,7 @@ int MachineObject::parse_json(std::string payload) }*/ tray_it->second->setting_id = jj["tray_info_idx"].get(); + tray_it->second->type = setting_id_to_type(tray_it->second->setting_id, jj["tray_type"].get()); // delay update tray_it->second->set_hold_count(); } else { diff --git a/src/slic3r/GUI/DeviceManager.hpp b/src/slic3r/GUI/DeviceManager.hpp index d5437c50e5..f50787e546 100644 --- a/src/slic3r/GUI/DeviceManager.hpp +++ b/src/slic3r/GUI/DeviceManager.hpp @@ -880,6 +880,7 @@ public: int parse_json(std::string payload); int publish_gcode(std::string gcode_str); + std::string setting_id_to_type(std::string setting_id, std::string tray_type); BBLSubTask* get_subtask(); BBLModelTask* get_modeltask(); void set_modeltask(BBLModelTask* task);