-
Notifications
You must be signed in to change notification settings - Fork 883
Expand file tree
/
Copy pathAmsMappingPopupUpdate.cpp
More file actions
713 lines (622 loc) · 28.5 KB
/
Copy pathAmsMappingPopupUpdate.cpp
File metadata and controls
713 lines (622 loc) · 28.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
/*****************************************************************//**
* \file AmsMappingPopupUpdate.cpp
* \brief do update for AmsMappingPopup
* \note moved from AmsMappingPopup.cpp to here to reduce the code size of AmsMappingPopup.cpp
*
* \author xin.zhang
* \date February 2026
*********************************************************************/
#include "AmsMappingPopup.hpp"
#include "I18N.hpp"
#include "DeviceCore/DevConfigUtil.h"
#include "libslic3r/Utils.hpp"
#include "slic3r/Utils/WxFontUtils.hpp"
#include "GUI.hpp"
#include "GUI_App.hpp"
#include "GUI_Preview.hpp"
#include "MainFrame.hpp"
#include "format.hpp"
#include "Widgets/ProgressDialog.hpp"
#include "Widgets/RoundedRectangle.hpp"
#include "Widgets/StaticBox.hpp"
#include <wx/progdlg.h>
#include <wx/clipbrd.h>
#include <wx/dcgraph.h>
#include <wx/graphics.h>
#include <miniz.h>
#include <algorithm>
#include <optional>
#include "Plater.hpp"
#include "BitmapCache.hpp"
#include "DeviceCore/DevFilaSystem.h"
#include "DeviceCore/DevFilaSwitch.h"
#include "DeviceCore/DevMappingNozzle.h"
#include "DeviceTab/wgtDeviceNozzleSelect.h"
#include "DeviceTab/wgtMsgPanel.h"
namespace Slic3r::GUI {
static wxString s_external_spool_with_switcher_tip()
{
return _L("External spool can be selected while Filament Track Switch is installed. "
"Route the filament through the external buffer or bypass the Filament Track Switch directly to the selected toolhead. "
"Printer firmware may still reject unsupported routes.");
}
static wxString s_external_spool_wrong_nozzle_tip()
{
return _L("This external spool is connected to the other nozzle. Select the external spool for the nozzle used by this filament.");
}
static void _add_containers(const AmsMapingPopup* win,
std::list<MappingContainer*>& one_slot_containers,
const std::vector<MappingContainer*>& four_slots_containers,
wxBoxSizer* target_sizer)
{
for (auto container : four_slots_containers) { target_sizer->Add(container, 0, wxTOP, win->FromDIP(5)); }
while (!one_slot_containers.empty()) {
wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
for (int i = 0; i < 3; i++) {
if (one_slot_containers.empty()) { break; }
sizer->Add(one_slot_containers.front(), 0, wxLEFT, (i == 0) ? 0 : win->FromDIP(5));
one_slot_containers.pop_front();
}
target_sizer->Add(sizer, 0, wxTOP, win->FromDIP(5));
}
}
void AmsMapingPopup::update(MachineObject* obj,
const std::vector<FilamentInfo>& ams_mapping_result,
bool use_dynamic_switch,
std::optional<PrintFromType> print_type)
{
BOOST_LOG_TRIVIAL(info) << "ams_mapping total count " << obj->GetFilaSystem()->GetAmsCount();
if (!obj) { return; }
for (auto& ams_container : m_amsmapping_container_list) {
ams_container->Destroy();
}
m_amsmapping_container_list.clear();
m_amsmapping_container_sizer_list.clear();
m_mapping_item_list.clear();
/*title*/
update_title(obj);
/*ams mapping*/
update_ams_tips(obj);
update_mapping_items(obj, ams_mapping_result, use_dynamic_switch);
/*rack*/
update_rack_select(obj, use_dynamic_switch, print_type);
update_flush_waste(obj);
if (wxGetApp().dark_mode() && m_reset_btn->GetName() != "erase_dark") {
m_reset_btn->SetName("erase_dark");
m_reset_btn->SetBitmap(ScalableBitmap(m_right_first_text_panel, "erase_dark", 14).bmp());
} else if (!wxGetApp().dark_mode() && m_reset_btn->GetName() != "erase") {
m_reset_btn->SetName("erase");
m_reset_btn->SetBitmap(ScalableBitmap(m_right_first_text_panel, "erase", 14).bmp());
}
size_t extruder_num = obj->GetExtderSystem()->GetTotalExtderCount();
if (extruder_num == 1) {
m_left_marea_panel->Hide();
m_left_extra_slot->Hide();
m_split_line_panel->Hide();
m_right_marea_panel->Show();
m_right_marea_panel->Enable(true);
m_right_extra_slot->Show();
m_right_extra_slot->Enable(true);
m_right_split_ext_sizer->Show(true);
set_sizer_title(m_right_split_ams_sizer, _L("AMS"));
} else if (extruder_num > 1) {
if (m_show_type == ShowType::LEFT_AND_RIGHT_DYNAMIC) {
m_left_marea_panel->Show(false);
m_left_extra_slot->Show(false);
m_right_extra_slot->Show(false);
m_left_split_ams_sizer->Show(false);
m_right_split_ams_sizer->Show(false);
m_right_split_ext_sizer->Show(false);
m_split_line_panel->Hide();
m_right_marea_panel->Show();
m_right_marea_panel->Enable(true);
} else {
m_left_marea_panel->Show();
m_left_extra_slot->Show();
m_split_line_panel->Show();
m_right_marea_panel->Show();
m_right_extra_slot->Show();
m_right_split_ext_sizer->Show(true);
m_left_tips->SetLabel(m_left_tip_text);
m_right_tips->SetLabel(m_right_tip_text);
set_sizer_title(m_left_split_ams_sizer, _L("Left AMS"));
set_sizer_title(m_right_split_ams_sizer, _L("Right AMS"));
if (m_show_type == ShowType::LEFT) {
m_left_marea_panel->Enable(true);
m_left_extra_slot->Enable(true);
m_right_marea_panel->Enable(false);
m_right_extra_slot->Enable(false);
if (m_use_in_sync_dialog) {
m_left_tips->SetLabel(m_single_tip_text);
m_right_tips->SetLabel("");
}
} else if (m_show_type == ShowType::RIGHT) {
m_left_marea_panel->Enable(false);
m_left_extra_slot->Enable(false);
m_right_marea_panel->Enable(true);
m_right_extra_slot->Enable(true);
if (m_use_in_sync_dialog) {
// m_right_tips->SetLabel(m_single_tip_text);
m_left_tips->SetLabel("");
}
} else if (m_show_type == ShowType::LEFT_AND_RIGHT) {
m_left_marea_panel->Enable(true);
m_left_extra_slot->Enable(true);
m_right_marea_panel->Enable(true);
m_right_extra_slot->Enable(true);
if (m_use_in_sync_dialog) {
m_left_tips->SetLabel(m_single_tip_text);
m_right_tips->SetLabel("");
}
} else if (m_show_type == ShowType::LEFT_AND_RIGHT_DYNAMIC) {
m_left_marea_panel->Show(false);
m_left_extra_slot->Show(false);
m_right_extra_slot->Show(false);
m_left_split_ams_sizer->Show(false);
m_right_split_ams_sizer->Show(false);
m_right_split_ext_sizer->Show(false);
m_split_line_panel->Hide();
m_right_marea_panel->Show();
m_right_marea_panel->Enable(true);
}
}
}
Layout();
Fit();
Refresh();
}
static std::optional<TrayData> sGetTrayData(DevAmsTray* tray,
const std::string& ams_id_str)
{
int ams_id = 0;
int tray_id = 0;
try {
ams_id = std::stoi(ams_id_str);
tray_id = atoi(tray->id.c_str());
} catch (const std::exception& e) {
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ":[error] invalid ams_id or tray_id: " << e.what();
return std::nullopt;
}
TrayData td;
td.ams_id = ams_id;
if (tray->ams_type != DevAmsType::EXT_SPOOL) {
td.slot_id = tray_id;
} else {
td.slot_id = 0;
}
if (tray->ams_type == DevAmsType::AMS ||
tray->ams_type == DevAmsType::AMS_LITE ||
tray->ams_type == DevAmsType::N3F) {
td.id = ams_id * 4 + tray_id;
} else if (tray->ams_type == DevAmsType::N3S) {
td.id = ams_id + tray_id;
} else if(tray->ams_type == DevAmsType::EXT_SPOOL){
td.id = tray_id;
}
if (tray->ams_type != EXT_SPOOL && !tray->is_exists) {
td.type = EMPTY;
} else {
if (!tray->is_tray_info_ready()) {
td.type = THIRD;
} else {
td.type = NORMAL;
td.remain = tray->remain;
td.colour = DevAmsTray::decode_color(tray->color);
td.name = tray->get_display_filament_type();
td.filament_type = tray->get_filament_type();
td.ctype = tray->ctype;
for (const auto& col : tray->cols) {
td.material_cols.push_back(DevAmsTray::decode_color(col));
}
}
}
return td;
}
void AmsMapingPopup::update_mapping_items(MachineObject* obj, const std::vector<FilamentInfo>& ams_mapping_result, bool use_dynamic_switch)
{
std::list<MappingContainer*> left_one_slot_containers;
std::list<MappingContainer*> right_one_slot_containers;
std::vector<MappingContainer*> left_four_slots_containers;
std::vector<MappingContainer*> right_four_slot_containers;
const auto& ams_list = obj->GetFilaSystem()->GetAmsList();
for (auto ams_iter = ams_list.begin(); ams_iter != ams_list.end(); ams_iter++) {
const auto& extruder_set = ams_iter->second->GetBindedExtruderSet();
if (extruder_set.size() <= 0) {
continue;
}
wxPanel* target_panel = nullptr;
if (m_show_type == ShowType::LEFT_AND_RIGHT_DYNAMIC) {
target_panel = m_right_marea_panel;
} else {
int extruder_id = *extruder_set.begin();
if (extruder_id == MAIN_EXTRUDER_ID) {
target_panel = m_right_marea_panel;
} else if (extruder_id == DEPUTY_EXTRUDER_ID) {
target_panel = m_left_marea_panel;
}
}
if (!target_panel) {
continue;
}
auto sizer_mapping_list = new wxBoxSizer(wxHORIZONTAL);
auto ams_mapping_item_container = new MappingContainer(target_panel, ams_iter->second->GetDisplayName(), ams_iter->second->GetSlotCount());
ams_mapping_item_container->SetName(target_panel->GetName());
ams_mapping_item_container->SetSizer(sizer_mapping_list);
ams_mapping_item_container->Layout();
BOOST_LOG_TRIVIAL(trace) << "ams_mapping ams id " << ams_iter->first.c_str();
DevAms* ams_group = ams_iter->second;
auto ams_type = ams_group->GetAmsType();
std::vector<TrayData> tray_datas;
std::map<std::string, DevAmsTray*>::const_iterator tray_iter;
for (tray_iter = ams_group->GetTrays().cbegin(); tray_iter != ams_group->GetTrays().cend(); tray_iter++) {
const auto& td_opt = sGetTrayData(tray_iter->second, ams_group->GetAmsId());
if (td_opt.has_value()) {
tray_datas.push_back(td_opt.value());
}
}
ams_mapping_item_container->Show();
add_ams_mapping(tray_datas, obj->GetFilaSystem()->IsDetectRemainEnabled(), 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);
if (target_panel == m_right_marea_panel) {
if (ams_mapping_item_container->get_slots_num() == 1) {
right_one_slot_containers.push_back(ams_mapping_item_container);
} else {
right_four_slot_containers.push_back(ams_mapping_item_container);
}
} else if (target_panel == m_left_marea_panel) {
if (ams_mapping_item_container->get_slots_num() == 1) {
left_one_slot_containers.push_back(ams_mapping_item_container);
} else {
left_four_slots_containers.push_back(ams_mapping_item_container);
}
}
}
for (int i = obj->vt_slot.size() - 1; i >= 0; i--) {
DevAmsTray* tray_data = &obj->vt_slot[i];
const auto& td_opt = sGetTrayData(tray_data, tray_data->id);
if (!td_opt.has_value()) {
continue;
}
if (m_show_type == ShowType::LEFT_AND_RIGHT_DYNAMIC) {
auto sizer_mapping_list = new wxBoxSizer(wxHORIZONTAL);
const auto& shown_name = td_opt->ams_id == VIRTUAL_TRAY_MAIN_ID ? "Ext-R" : "Ext-L";
auto ams_mapping_item_container = new MappingContainer(m_right_marea_panel, shown_name, 1);
ams_mapping_item_container->SetName(m_right_marea_panel->GetName());
ams_mapping_item_container->SetSizer(sizer_mapping_list);
ams_mapping_item_container->Layout();
std::vector<TrayData> tray_datas;
tray_datas.push_back(td_opt.value());
add_ams_mapping(tray_datas, false, 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);
right_one_slot_containers.push_back(ams_mapping_item_container);
} else {
if (td_opt->ams_id == VIRTUAL_TRAY_MAIN_ID) {
m_right_extra_slot->send_win = send_win;
add_ext_ams_mapping(td_opt.value(), m_right_extra_slot);
} else if (td_opt->ams_id == VIRTUAL_TRAY_DEPUTY_ID) {
m_left_extra_slot->send_win = send_win;
add_ext_ams_mapping(td_opt.value(), m_left_extra_slot);
}
}
}
_add_containers(this, left_one_slot_containers, left_four_slots_containers, m_sizer_ams_basket_left);
_add_containers(this, right_one_slot_containers, right_four_slot_containers, m_sizer_ams_basket_right);
if (m_show_type != ShowType::LEFT_AND_RIGHT_DYNAMIC){
m_left_split_ams_sizer->Show(!left_one_slot_containers.empty() || !left_four_slots_containers.empty());
m_right_split_ams_sizer->Show(!right_one_slot_containers.empty() || !right_four_slot_containers.empty());
} else {
m_left_split_ams_sizer->Show(false);
m_right_split_ams_sizer->Show(false);
}
update_items_check_state(ams_mapping_result);
}
void AmsMapingPopup::update_ams_data_multi_machines()
{
m_mapping_from_multi_machines = true;
std::vector<TrayData> tray_datas;
for (int i = 0; i < 4; ++i) {
TrayData td;
td.id = i;
td.type = EMPTY;
td.colour = wxColour(166, 169, 170);
td.name = "";
td.filament_type = "";
td.ctype = 0;
tray_datas.push_back(td);
}
for (auto& ams_container : m_amsmapping_container_list) {
ams_container->Destroy();
}
m_amsmapping_container_list.clear();
m_amsmapping_container_sizer_list.clear();
m_mapping_item_list.clear();
if (wxGetApp().dark_mode() && m_reset_btn->GetName() != "erase_dark") {
m_reset_btn->SetName("erase_dark");
m_reset_btn->SetBitmap(ScalableBitmap(m_right_first_text_panel, "erase_dark", 14).bmp());
} else if (!wxGetApp().dark_mode() && m_reset_btn->GetName() != "erase") {
m_reset_btn->SetName("erase");
m_reset_btn->SetBitmap(ScalableBitmap(m_right_first_text_panel, "erase", 14).bmp());
}
size_t nozzle_nums = 1;
m_show_type = ShowType::RIGHT;
m_left_marea_panel->Hide();
m_left_extra_slot->Hide();
// m_left_marea_panel->Show();
m_right_marea_panel->Show();
set_sizer_title(m_right_split_ams_sizer, _L("AMS"));
// m_right_tips->SetLabel(m_single_tip_text);
m_right_extra_slot->Hide();
m_left_extra_slot->Hide();
/*ams*/
bool has_left_ams = false, has_right_ams = false;
std::list<MappingContainer*> left_one_slot_containers;
std::list<MappingContainer*> right_one_slot_containers;
std::vector<MappingContainer*> left_four_slots_containers;
std::vector<MappingContainer*> right_four_slot_containers;
for (int i = 0; i < 1; i++) {
int ams_indx = 0;
int ams_type = 1;
int nozzle_id = 0;
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-1", 4);
ams_mapping_item_container->SetName(nozzle_id == 0 ? m_right_marea_panel->GetName() : m_left_marea_panel->GetName());
ams_mapping_item_container->SetSizer(sizer_mapping_list);
ams_mapping_item_container->Layout();
m_has_unmatch_filament = false;
ams_mapping_item_container->Show();
add_ams_mapping(tray_datas, false, 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);
if (nozzle_id == 0) {
has_right_ams = true;
if (ams_mapping_item_container->get_slots_num() == 1) {
right_one_slot_containers.push_back(ams_mapping_item_container);
} else {
right_four_slot_containers.push_back(ams_mapping_item_container);
}
} else if (nozzle_id == 1) {
has_left_ams = true;
if (ams_mapping_item_container->get_slots_num() == 1) {
left_one_slot_containers.push_back(ams_mapping_item_container);
} else {
left_four_slots_containers.push_back(ams_mapping_item_container);
}
}
} else if (ams_type == 4) { // 4:n3s
}
}
_add_containers(this, left_one_slot_containers, left_four_slots_containers, m_sizer_ams_basket_left);
_add_containers(this, right_one_slot_containers, right_four_slot_containers, m_sizer_ams_basket_right);
m_left_split_ams_sizer->Show(has_left_ams);
m_right_split_ams_sizer->Show(has_right_ams);
//update_items_check_state(ams_mapping_result);
Layout();
Fit();
}
void AmsMapingPopup::update_title(MachineObject* obj)
{
const auto& full_config = wxGetApp().preset_bundle->full_config();
size_t nozzle_nums = full_config.option<ConfigOptionFloatsNullable>("nozzle_diameter")->values.size();
if (nozzle_nums > 1) {
m_split_line_panel->Show();
if (m_show_type == ShowType::LEFT) {
wxString nozzle_name = obj ? _L(DevPrinterConfigUtil::get_toolhead_display_name(
obj->printer_type, DEPUTY_EXTRUDER_ID, ToolHeadComponent::Nozzle, ToolHeadNameCase::LowerCase)) : _L("left nozzle");
m_title_text->SetLabelText(wxString::Format(_L("Please select the filament installed on the %s."), nozzle_name));
return;
} else if (m_show_type == ShowType::RIGHT) {
wxString nozzle_name = obj ? _L(DevPrinterConfigUtil::get_toolhead_display_name(
obj->printer_type, MAIN_EXTRUDER_ID, ToolHeadComponent::Nozzle, ToolHeadNameCase::LowerCase)) : _L("right nozzle");
m_title_text->SetLabelText(wxString::Format(_L("Please select the filament installed on the %s."), nozzle_name));
return;
} else if (m_show_type == ShowType::LEFT_AND_RIGHT_DYNAMIC) {
m_title_text->SetLabelText(_L("Please select the filament."));
return;
}
} else if (nozzle_nums == 1) {
m_split_line_panel->Hide();
}
m_title_text->SetLabelText(_L("Nozzle"));
}
void AmsMapingPopup::update_ams_tips(MachineObject* obj)
{
const auto& full_config = wxGetApp().preset_bundle->full_config();
size_t nozzle_nums = full_config.option<ConfigOptionFloatsNullable>("nozzle_diameter")->values.size();
if (m_ams_tips_msg_panel) {
m_ams_tips_msg_panel->Clear();
if (nozzle_nums == 2 && m_show_type != ShowType::LEFT_AND_RIGHT) {
m_ams_tips_msg_panel->AddMessage(_L("To learn about the filaments matching rules."),
"#FF6F00", "https://e.bambulab.com/t?c=v4Q4e7Rm2dR0dWkw");
}
if (obj && obj->GetFilaSwitch()->IsInstalled()) {
m_ams_tips_msg_panel->AddMessage(s_external_spool_with_switcher_tip(), "#FF6F00", "");
}
m_ams_tips_msg_panel->Layout();
m_ams_tips_msg_panel->Fit();
m_ams_tips_msg_panel->Show(m_ams_tips_msg_panel->GetMessageCount() > 0);
}
}
void AmsMapingPopup::update_rack_select(MachineObject* obj, bool use_dynamic_switch, std::optional<PrintFromType> print_from_type)
{
m_rack = obj ? obj->GetNozzleRack() : nullptr;
bool show_rack_select_area = false;
if (!m_mapping_from_multi_machines && !m_use_in_sync_dialog &&
obj && obj->GetNozzleRack()->IsSupported() &&
print_from_type.has_value() && print_from_type.value() == PrintFromType::FROM_NORMAL) {
const auto& nozzle_pos_vec = obj->get_nozzle_mapping_result()->GetMappedNozzlePosVecByFilaId(m_current_filament_id);
m_rack_nozzle_select->UpdatSelectedNozzles(obj->GetNozzleRack(), nozzle_pos_vec, use_dynamic_switch, print_from_type);
show_rack_select_area = true;
}
if (show_rack_select_area != m_rack_nozzle_select->IsShown()) {
m_right_tip_text = show_rack_select_area ? _L("Select Filament && Hotends") : _L("Select Filament");
m_right_tips->SetLabel(m_right_tip_text);
m_rack_nozzle_select->Show(show_rack_select_area);
Layout();
Fit();
}
}
void AmsMapingPopup::update_items_check_state(const std::vector<FilamentInfo>& ams_mapping_result)
{
/*update check states*/
if (m_parent_item) {
auto update_item_check_state = [&ams_mapping_result, this](MappingItem* item) {
if (item) {
for (const auto& mapping_res : ams_mapping_result) {
if (mapping_res.id == this->m_current_filament_id) {
if (mapping_res.ams_id == std::to_string(item->m_ams_id) &&
mapping_res.slot_id == std::to_string(item->m_slot_id)) {
item->set_checked(true);
} else {
item->set_checked(false);
}
return;
}
}
item->set_checked(false);
}
};
update_item_check_state(m_left_extra_slot);
update_item_check_state(m_right_extra_slot);
for (auto mapping_item : m_mapping_item_list) {
update_item_check_state(mapping_item);
}
}
}
void AmsMapingPopup::add_ams_mapping(std::vector<TrayData> tray_data,
bool remain_detect_flag,
wxWindow* container,
wxBoxSizer* sizer)
{
sizer->Add(0, 0, 0, wxLEFT, FromDIP(6));
for (auto i = 0; i < tray_data.size(); i++) {
// set button
MappingItem* m_mapping_item = new MappingItem(container);
m_mapping_item->send_win = send_win;
m_mapping_item->m_ams_id = tray_data[i].ams_id;
m_mapping_item->m_slot_id = tray_data[i].slot_id;
if (m_show_type == ShowType::LEFT_AND_RIGHT || m_show_type == ShowType::LEFT_AND_RIGHT_DYNAMIC) {
m_mapping_item->set_tray_index(wxGetApp().transition_tridid(tray_data[i].id, 2));
} else {
m_mapping_item->set_tray_index(wxGetApp().transition_tridid(tray_data[i].id));
}
m_mapping_item->SetSize(wxSize(FromDIP(48), FromDIP(60)));
m_mapping_item->SetMinSize(wxSize(FromDIP(48), FromDIP(60)));
m_mapping_item->SetMaxSize(wxSize(FromDIP(48), FromDIP(60)));
// traversal if can pick the item or not
bool can_pick_the_item = true;
std::optional<wxString> item_tooltip_msg;
// check filament area
if (m_use_in_sync_dialog) {
if (can_pick_the_item) {
if (m_show_type == ShowType::LEFT_AND_RIGHT_DYNAMIC) {
if (devPrinterUtil::IsVirtualSlot(m_mapping_item->m_ams_id)) {
if (is_ext_slot_compatible_with_current_filament(m_mapping_item->m_ams_id)) {
item_tooltip_msg = s_external_spool_with_switcher_tip();
} else {
can_pick_the_item = false;
item_tooltip_msg = s_external_spool_wrong_nozzle_tip();
}
}
}
}
}
else {
if (can_pick_the_item) {
auto parent = container->GetParent();
if (parent == m_left_marea_panel) {
can_pick_the_item = (m_show_type == ShowType::LEFT);
} else if (parent == m_right_marea_panel) {
if (m_show_type == ShowType::LEFT_AND_RIGHT_DYNAMIC) {
if (devPrinterUtil::IsVirtualSlot(m_mapping_item->m_ams_id)) {
if (is_ext_slot_compatible_with_current_filament(m_mapping_item->m_ams_id)) {
item_tooltip_msg = s_external_spool_with_switcher_tip();
} else {
can_pick_the_item = false;
item_tooltip_msg = s_external_spool_wrong_nozzle_tip();
}
}
} else if (m_show_type != ShowType::RIGHT) {
can_pick_the_item = false;
}
}
}
}
// check filament type
if (can_pick_the_item) {
if (tray_data[i].type == NORMAL && !is_match_material(tray_data[i].filament_type)){
can_pick_the_item = false;
} else if(tray_data[i].type == EMPTY){
can_pick_the_item = false;
}
}
wxColour display_color;
if (can_pick_the_item) {
display_color = tray_data[i].type == NORMAL ? tray_data[i].colour : wxColour(0xCE, 0xCE, 0xCE);
} else {
display_color = wxColour(0xEE, 0xEE, 0xEE);
}
wxString display_name;
if (tray_data[i].type == THIRD) {
display_name = "?";
} else if (tray_data[i].type == EMPTY) {
display_name = "-";
} else {
display_name = tray_data[i].name;
}
m_mapping_item->set_data(m_tag_material, display_color, display_name, remain_detect_flag, tray_data[i], !can_pick_the_item, item_tooltip_msg);
m_mapping_item->Bind(wxEVT_LEFT_DOWN, [this, can_pick_the_item, m_mapping_item](wxMouseEvent& e) {
if (can_pick_the_item) {
m_mapping_item->send_event(m_current_filament_id);
Dismiss();
}
});
sizer->Add(0, 0, 0, wxRIGHT, FromDIP(6));
sizer->Add(m_mapping_item, 0, wxTOP, FromDIP(1));
m_mapping_item_list.push_back(m_mapping_item);
}
}
void AmsMapingPopup::add_ext_ams_mapping(TrayData tray_data, MappingItem* item)
{
#ifdef __APPLE__
m_mapping_item_list.push_back(item);
#endif
// set button
if (tray_data.type == NORMAL) {
if (is_match_material(tray_data.filament_type)) {
item->set_data(m_tag_material, tray_data.colour, tray_data.name, false, tray_data);
} else {
item->set_data(m_tag_material, m_ext_mapping_filatype_check ? wxColour(0xEE, 0xEE, 0xEE) : tray_data.colour, tray_data.name, false, tray_data, true);
m_has_unmatch_filament = true;
}
item->Bind(wxEVT_LEFT_DOWN, [this, tray_data, item](wxMouseEvent& e) {
if (!item->GetParent() || !item->GetParent()->IsEnabled()) return;
if (m_ext_mapping_filatype_check && !is_match_material(tray_data.filament_type)) return;
item->send_event(m_current_filament_id);
Dismiss();
});
}
// temp
if (tray_data.type == EMPTY) {
item->set_data(m_tag_material, wxColour(0xCE, 0xCE, 0xCE), "-", false, tray_data);
item->Bind(wxEVT_LEFT_DOWN, [this, tray_data, item](wxMouseEvent& e) {
if (!item->GetParent() || !item->GetParent()->IsEnabled()) return;
item->send_event(m_current_filament_id);
Dismiss();
});
}
// third party
if (tray_data.type == THIRD) {
item->set_data(m_tag_material, 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) {
if (!item->GetParent() || !item->GetParent()->IsEnabled()) return;
item->send_event(m_current_filament_id);
Dismiss();
});
}
item->set_tray_index("Ext");
}
} // namespace Slic3r::GUI