50{
52
54 if (!plater) {
55 BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": plater is nullptr";
56 return -1;
57 }
58
60 if (!gcode_result) {
61 BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": gcode_result is nullptr";
62 return -1;
63 }
64
66 if (!result) {
67 assert(false && "gcode_result->nozzle_group_result");
68 BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": gcode_result->nozzle_group_result is NULL";
69 return -1;
70 }
71
72 if (ams_mapping.empty()) {
73 BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": the ams mapping is empty";
74 return -1;
75 }
76
78 command_jj["print"]["command"] = "get_auto_nozzle_mapping";
81 command_jj["print"]["calibration"] = flow_cali_opt;
82 command_jj["print"]["extrude_cali_manual_mode"] = pa_value;
83
84
86 int max_fila_id = 0;
87 std::unordered_set<int> filaid_set;
88 for (int idx = 0; idx < gcode_result->filament_change_sequence.size(); idx++) {
89 int fila_id = gcode_result->filament_change_sequence[idx];
90 if (filaid_set.count(fila_id) == 0) {
91 filaid_set.insert(fila_id);
92 filament_seq_jj[fila_id + 1] = idx;
93 max_fila_id = std::max(max_fila_id, fila_id + 1);
94 }
95 }
96
97 for (int fila_id = 0; fila_id <= max_fila_id; fila_id++) {
98 if (filament_seq_jj[fila_id].is_null()) {
99 filament_seq_jj[fila_id] = -1;
100 }
101 }
102
103 command_jj["print"]["filament_seq"] = filament_seq_jj;
104
105
106 std::vector<int> ams_mapping_vec(33, 0xFFFF);
107 for (auto item : ams_mapping) {
108 try {
109 int ams_id = stoi(item.ams_id);
110 int slot_id = !item.slot_id.empty() ? stoi(item.slot_id) : 0;
111 ams_mapping_vec[item.id + 1] = (ams_id << 8) | slot_id;
112 } catch (std::exception& e) {
113 assert(false && "invalid ams_id or slot_id");
114 BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << " exception: " << e.what();
115 ams_mapping_vec[item.id + 1] = item.tray_id;
116 }
117 }
118 command_jj["print"]["ams_mapping"] = ams_mapping_vec;
119
120
121 json filament_info_jj;
122 for (int fila_id = 0; fila_id < ams_mapping.size(); fila_id++) {
123 const auto& fila = ams_mapping[fila_id];
124 const auto& nozzle_list = result->get_nozzles_for_filament(fila.id);
125 if (nozzle_list.empty()) {
126 assert(false && "nozzle_list should not be empty");
127 BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << "nozzle_list should not be nullptr";
128 continue;
129 }
130
131 for (const auto& nozzle_info : nozzle_list) {
133 fila_item_jj["id"] = (fila.id + 1);
135 fila_item_jj["group"] = nozzle_info.group_id;
138 fila_item_jj["cate"] = fila.filament_id;
139 fila_item_jj["color"] = fila.color;
140 filament_info_jj.push_back(fila_item_jj);
141 }
142 }
143
144 command_jj["print"]["fila_info"] = filament_info_jj;
145
146
148 const auto& nozzle_system =
m_obj->GetNozzleSystem();
149 const auto& extruder_nozzles = nozzle_system->GetExtNozzles();
150 for (const auto& nozzle : extruder_nozzles) {
151 if (nozzle.second.IsNormal()) {
153 nozzle_item_jj["pos"] = nozzle.second.GetNozzleId();
154 if (nozzle_system->GetReplaceNozzleTar().has_value() && nozzle_item_jj[
"pos"] ==
MAIN_EXTRUDER_ID) {
155 nozzle_item_jj["pos"] = nozzle_system->GetReplaceNozzleTar().value();
156 }
157
160 nozzle_item_jj["wear"] = nozzle.second.GetNozzleWear();
161 nozzle_item_jj["cate"] = nozzle.second.GetFilamentId();
162 nozzle_item_jj["color"] = nozzle.second.GetFilamentColor();
163 nozzle_info_jj.push_back(nozzle_item_jj);
164 }
165 }
166
167 const auto& rack_nozzles = nozzle_system->GetNozzleRack()->GetRackNozzles();
168 for (const auto& nozzle : rack_nozzles) {
169 if (nozzle.second.IsNormal()) {
171 nozzle_item_jj["pos"] = (nozzle.second.GetNozzleId() + 0x10);
172 if (nozzle_system->GetReplaceNozzleTar().has_value() && nozzle_item_jj[
"pos"] ==
MAIN_EXTRUDER_ID) {
173 nozzle_item_jj["pos"] = nozzle_system->GetReplaceNozzleTar().value();
174 }
175
178 nozzle_item_jj["wear"] = nozzle.second.GetNozzleWear();
179 nozzle_item_jj["cate"] = nozzle.second.GetFilamentId();
180 nozzle_item_jj["color"] = nozzle.second.GetFilamentColor();
181 nozzle_info_jj.push_back(nozzle_item_jj);
182 }
183 }
184
185 command_jj["print"]["nozzle_info"] = nozzle_info_jj;
187 return m_obj->publish_json(command_jj);
188}
#define LOGIC_L_EXTRUDER_ID
Definition DevDefs.h:108
#define MAIN_EXTRUDER_ID
Definition DevDefs.h:101
GCodeProcessorResult * get_current_gcode_result()
Definition BackgroundSlicingProcess.hpp:110
Slic3r::GUI::Plater * m_plater
Definition DevMappingNozzle.h:87
void Clear()
Definition DevMappingNozzle.cpp:277
NozzleMappingVersion m_req_version
Definition DevMappingNozzle.h:105
BackgroundSlicingProcess & background_process()
Definition Plater.cpp:22331
static int m_sequence_id
Definition DeviceManager.hpp:197
@ nvtHighFlow
Definition PrintConfig.hpp:620
nlohmann::json json
Definition AssembleList.cpp:42
static std::string s_get_diameter_str(float diameter)
Definition DevUtil.h:175
static std::string ToNozzleFlowString(const NozzleFlowType &type)
Definition DevNozzleSystem.cpp:94
std::shared_ptr< MultiNozzleUtils::NozzleGroupResultBase > nozzle_group_result
Definition GCodeProcessor.hpp:220