-
Notifications
You must be signed in to change notification settings - Fork 821
Expand file tree
/
Copy pathCreatePresetsDialog.cpp
More file actions
5356 lines (4682 loc) · 272 KB
/
CreatePresetsDialog.cpp
File metadata and controls
5356 lines (4682 loc) · 272 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
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "CreatePresetsDialog.hpp"
#include <vector>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <openssl/md5.h>
#include <openssl/evp.h>
#include <boost/nowide/cstdio.hpp>
#include <wx/dcgraph.h>
#include <wx/tooltip.h>
#include "libslic3r/PresetBundle.hpp"
#include "I18N.hpp"
#include "GUI_App.hpp"
#include "MsgDialog.hpp"
#include "FileHelp.hpp"
#include "Tab.hpp"
#include "MainFrame.hpp"
#define NAME_OPTION_COMBOBOX_SIZE wxSize(FromDIP(200), FromDIP(24))
#define FILAMENT_PRESET_COMBOBOX_SIZE wxSize(FromDIP(300), FromDIP(24))
#define OPTION_SIZE wxSize(FromDIP(100), FromDIP(24))
#define PRINTER_LIST_SIZE wxSize(-1, FromDIP(100))
#define FILAMENT_LIST_SIZE wxSize(FromDIP(560), FromDIP(100))
#define FILAMENT_OPTION_SIZE wxSize(FromDIP(-1), FromDIP(30))
#define PRESET_TEMPLATE_SIZE wxSize(FromDIP(-1), FromDIP(100))
#define PRINTER_SPACE_SIZE wxSize(FromDIP(80), FromDIP(24))
#define ORIGIN_TEXT_SIZE wxSize(FromDIP(10), FromDIP(24))
#define PRINTER_PRESET_VENDOR_SIZE wxSize(FromDIP(150), FromDIP(24))
#define PRINTER_PRESET_MODEL_SIZE wxSize(FromDIP(280), FromDIP(24))
#define STATIC_TEXT_COLOUR wxColour("#363636")
#define PRINTER_LIST_COLOUR wxColour("#EEEEEE")
#define FILAMENT_OPTION_COLOUR wxColour("#D9D9D9")
#define SELECT_ALL_OPTION_COLOUR wxColour("#00AE42")
#define DEFAULT_PROMPT_TEXT_COLOUR wxColour("#ACACAC")
namespace Slic3r {
namespace GUI {
static const std::vector<std::string> filament_vendors = {"Polymaker", "OVERTURE", "Kexcelled", "HATCHBOX", "eSUN", "SUNLU", "Prusament", "Creality", "Protopasta",
"Anycubic", "Basf", "ELEGOO", "INLAND", "FLASHFORGE", "FusRock", "AMOLEN", "MIKA3D", "3DXTECH",
"Duramic", "Priline", "Eryone", "3Dgunius", "Novamaker", "Justmaker", "Giantarm", "iProspect", "LDO"};
static const std::vector<std::string> filament_types = {"PLA", "PLA+", "PLA Tough", "PETG", "ABS", "ASA", "FLEX", "HIPS", "PA", "PACF",
"NYLON", "PVA", "PC", "PCABS", "PCTG", "PCCF", "PP", "PEI", "PET", "PETG",
"PETGCF", "PTBA", "PTBA90A", "PEEK", "TPU93A", "TPU75D", "TPU","TPU-AMS", "TPU92A", "TPU98A", "Misc",
"TPE", "GLAZE", "Nylon", "CPE", "METAL", "ABST", "Carbon Fiber"};
static const std::vector<std::string> printer_vendors = {"Anycubic", "Artillery", "BIBO", "BIQU", "Creality ENDER", "Creality CR", "Creality SERMOON",
"FLSun", "gCreate", "Geeetech", "INAT", "Infinity3D", "Jubilee", "LNL3D",
"LulzBot", "MakerGear", "Original Prusa", "Papapiu", "Print4Taste", "RatRig", "Rigid3D",
"Snapmaker", "Sovol", "TriLAB", "Trimaker", "Ultimaker", "Voron", "Zonestar"};
static const std::unordered_map<std::string, std::vector<std::string>> printer_model_map =
{{"Anycubic", {"Kossel Linear Plus", "Kossel Pulley(Linear)", "Mega Zero", "i3 Mega", "Predator"}},
{"Artillery", {"sidewinder X1", "Genius", "Hornet"}},
{"BIBO", {"BIBO2 Touch"}},
{"BIQU", {"BX"}},
{"Creality ENDER", {"Ender-3", "Ender-3 BLTouch", "Ender-3 Pro", "Ender-3 Neo",
"Ender-3 V2 Neo", "Ender-3 S1 Plus", "Ender-3 Max", "Ender-3 Max Neo",
"Ender-4", "Ender-5 Pro", "Ender-5 Pro",
"Ender-7", "Ender-2", "Ender-2 Pro"}},
{"Creality CR", {"CR-5 Pro", "CR-5 Pro H", "CR-10 SMART", "CR-10 SMART Pro", "CR-10 Mini",
"CR-10", "CR-10 v3", "CR-10 S", "CR-10 v2", "CR-10 v2",
"CR-10 S Pro", "CR-10 S Pro v2", "CR-10 S4", "CR-10 S5", "CR-20", "CR-20 Pro", "CR-200B",
"CR-8"}},
{"Creality SERMOON",{"Sermoon-D1", "Sermoon-V1", "Sermoon-V1 Pro"}},
{"FLSun", {"FLSun QQs Pro", "FLSun Q5"}},
{"gCreate", {"gMax 1.5XT Plus", "gMax 2", "gMax 2 Pro", "gMax 2 Dual 2in1", "gMax 2 Dual Chimera"}},
{"Geeetech", {"Thunder", "Thunder Pro", "Mizar s", "Mizar Pro", "Mizar", "Mizar Max",
"Mizar M", "A10 Pro", "A10 M", "A10 T", "A20", "A20 M",
"A20T", "A30 Pro", "A30 M", "A30 T", "E180", "Me Ducer",
"Me creator", "Me Creator2", "GiantArmD200", "l3 ProB", "l3 Prow", "l3 ProC"}},
{"INAT", {"Proton X Rail", "Proton x Rod", "Proton XE-750"}},
{"Infinity3D", {"DEV-200", "DEV-350"}},
{"Jubilee", {"Jubilee"}},
{"LNL3D", {"D3 v2", "D3 Vulcan", "D5", "D6"}},
{"LulzBot", {"Mini Aero", "Taz6 Aero"}},
{"MakerGear", {"Micro", "M2(V4 Hotend)", "M2 Dual", "M3-single Extruder", "M3-Independent Dual Rev.0", "M3-Independent Dual Rev.0(Duplication Mode)",
"M3-Independent Dual Rev.1", "M3-Independent Dual Rev.1(Duplication Mode)", "ultra One", "Ultra One (DuplicationMode)"}},
{"Original Prusa", {"MK4", "SL1S SPEED", "MMU3"}},
{"Papapiu", {"N1s"}},
{"Print4Taste", {"mycusini 2.0"}},
{"RatRig", {"V-core-3 300mm", "V-Core-3 400mm", "V-Core-3 500mm", "V-Minion"}},
{"Rigid3D", {"Zero2", "Zero3"}},
{"Snapmaker", {"A250", "A350"}},
{"Sovol", {"SV06", "SV06 PLUS", "SV05", "SV04", "SV03 / SV03 BLTOUCH", "SVO2 / SV02 BLTOUCH", "SVO1 / SV01 BLToUCH", "SV01 PRO"}},
{"TriLAB", {"AzteQ Industrial","AzteQ Dynamic", "DeltiQ 2", "DeltiQ 2 Plus", "DeltiQ 2 + FlexPrint 2", "DeltiQ 2 Plus + FlexPrint 2", "DeltiQ 2 +FlexPrint",
"DeltiQ 2 Plus + FlexPrint", "DeltiQ M", "DeltiQ L", "DeltiQ XL"}},
{"Trimaker", {"Nebula cloud", "Nebula", "Cosmos ll"}},
{"Ultimaker", {"Ultimaker 2"}},
{"Voron", {"v2 250mm3", "v2 300mm3", "v2 350mm3", "v1 250mm3", "v1 300mm3", "v1 350mm3",
"Zero 120mm3", "Switchwire"}},
{"Zonestar", {"Z5", "Z6", "Z5x", "Z8", "Z9"}}};
static std::vector<std::string> nozzle_diameter_vec = {"0.4", "0.2", "0.25", "0.3", "0.35", "0.5", "0.6", "0.75", "0.8", "1.0", "1.2"};
static std::unordered_map<std::string, float> nozzle_diameter_map = {{"0.2", 0.2}, {"0.25", 0.25}, {"0.3", 0.3}, {"0.35", 0.35},
{"0.4", 0.4}, {"0.5", 0.5}, {"0.6", 0.6}, {"0.75", 0.75},
{"0.8", 0.8}, {"1.0", 1.0}, {"1.2", 1.2}};
static std::set<int> cannot_input_key = {9, 10, 13, 33, 35, 36, 37, 38, 40, 41, 42, 44, 46, 47, 59, 60, 62, 63, 64, 92, 94, 95, 124, 126};
static std::set<int> cannot_input_key_for_filament = {9, 10, 13, 33, 35, 36, 37, 38, 40, 41, 42, 44, 46, 59, 60, 62, 63, 64, 92, 94, 95, 124, 126};
static std::set<char> special_key = {'\n', '\t', '\r', '\v', '@', ';'};
static std::string remove_special_key(const std::string &str)
{
std::string res_str;
for (char c : str) {
if (special_key.find(c) == special_key.end()) {
res_str.push_back(c);
}
}
return res_str;
}
static bool str_is_all_digit(const std::string &str) {
for (const char &c : str) {
if (!std::isdigit(c)) return false;
}
return true;
}
static float my_stof(std::string str) {
const char dec_sep = is_decimal_separator_point() ? '.' : ',';
const char dec_sep_alt = dec_sep == '.' ? ',' : '.';
size_t alt_pos = str.find(dec_sep_alt);
if (alt_pos != std::string::npos) { str.replace(alt_pos, 1, 1, dec_sep); }
if (str == std::string(1, dec_sep)) { return 0.0f; }
try {
return static_cast<float>(std::stod(str));
} catch (...) {
return 0.f;
}
}
static bool delete_filament_preset_by_name(std::string delete_preset_name, std::string &selected_preset_name)
{
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format("select preset, name %1%") % delete_preset_name;
if (delete_preset_name.empty()) return false;
// Find an alternate preset to be selected after the current preset is deleted.
PresetCollection &m_presets = wxGetApp().preset_bundle->filaments;
if (delete_preset_name == selected_preset_name) {
const std::deque<Preset> &presets = m_presets.get_presets();
size_t idx_current = m_presets.get_idx_selected();
// Find the visible preset.
size_t idx_new = idx_current;
if (idx_current > presets.size()) idx_current = presets.size();
if (idx_current < 0) idx_current = 0;
if (idx_new < presets.size())
for (; idx_new < presets.size() && (presets[idx_new].name == delete_preset_name || !presets[idx_new].is_visible); ++idx_new)
;
if (idx_new == presets.size())
for (idx_new = idx_current - 1; idx_new > 0 && (presets[idx_new].name == delete_preset_name || !presets[idx_new].is_visible); --idx_new)
;
selected_preset_name = presets[idx_new].name;
BOOST_LOG_TRIVIAL(info) << boost::format("cause by delete current ,choose the next visible, idx %1%, name %2%") % idx_new % selected_preset_name;
}
try {
// BBS delete preset
Preset *need_delete_preset = m_presets.find_preset(delete_preset_name);
if (!need_delete_preset) BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" can't find delete preset and name: %1%") % delete_preset_name;
if (!need_delete_preset->setting_id.empty()) {
BOOST_LOG_TRIVIAL(info) << "delete preset = " << need_delete_preset->name << ", setting_id = " << need_delete_preset->setting_id;
m_presets.set_sync_info_and_save(need_delete_preset->name, need_delete_preset->setting_id, "delete", 0);
wxGetApp().delete_preset_from_cloud(need_delete_preset->setting_id);
} else {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(" can't preset setting id is empty and name: %1%") % delete_preset_name;
}
if (m_presets.get_edited_preset().name == delete_preset_name) {
m_presets.discard_current_changes();
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format("delete preset dirty and cancelled");
}
m_presets.delete_preset(need_delete_preset->name);
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " preset has been delete from filaments, and preset name is: " << delete_preset_name;
} catch (const std::exception &ex) {
// FIXME add some error reporting!
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format("found exception when delete: %1% and preset name: %%") % ex.what() % delete_preset_name;
return false;
}
return true;
}
static std::string get_curr_time()
{
std::chrono::system_clock::time_point now = std::chrono::system_clock::now();
std::time_t time = std::chrono::system_clock::to_time_t(now);
std::tm *local_time = std::localtime(&time);
std::ostringstream time_stream;
if (local_time == nullptr)
{
bool use_12h_format = wxGetApp().app_config->get("use_12h_time_format") == "true";
std::string hm_formatted = Slic3r::format_time_hm(local_time, use_12h_format);
// Replace colons with underscores for filename compatibility
std::replace(hm_formatted.begin(), hm_formatted.end(), ':', '_');
time_stream << std::put_time(local_time, "%Y_%m_%d_") << hm_formatted << "_"
<< std::put_time(local_time, "%S");
}
else
{
time_stream << std::put_time(local_time, "%Y_%m_%d_%H_%M_%S");
}
std::string current_time = time_stream.str();
return current_time;
}
static std::string get_curr_timestmp()
{
std::time_t currentTime = std::time(nullptr);
std::ostringstream oss;
oss << currentTime;
std::string timestampString = oss.str();
return timestampString;
}
static void get_filament_compatible_printer(Preset* preset, vector<std::string>& printers)
{
auto compatible_printers = dynamic_cast<ConfigOptionStrings *>(preset->config.option("compatible_printers"));
if (compatible_printers == nullptr) return;
for (const std::string &printer_name : compatible_printers->values) {
printers.push_back(printer_name);
}
}
static wxBoxSizer* create_checkbox(wxWindow* parent, Preset* preset, wxString& preset_name, std::vector<std::pair<::CheckBox*, Preset*>>& preset_checkbox)
{
wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
::CheckBox * checkbox = new ::CheckBox(parent);
sizer->Add(checkbox, 0, 0, 0);
preset_checkbox.push_back(std::make_pair(checkbox, preset));
wxStaticText *preset_name_str = new wxStaticText(parent, wxID_ANY, preset_name, wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END);
wxToolTip * toolTip = new wxToolTip(preset_name);
preset_name_str->SetToolTip(toolTip);
sizer->Add(preset_name_str, 0, wxLEFT, 5);
return sizer;
}
static wxBoxSizer *create_checkbox(wxWindow *parent, std::string &compatible_printer, Preset* preset, std::unordered_map<::CheckBox *, std::pair<std::string, Preset *>> &ptinter_compatible_filament_preset)
{
wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
::CheckBox *checkbox = new ::CheckBox(parent);
sizer->Add(checkbox, 0, 0, 0);
ptinter_compatible_filament_preset[checkbox] = std::make_pair(compatible_printer, preset);
wxStaticText *preset_name_str = new wxStaticText(parent, wxID_ANY, wxString::FromUTF8(compatible_printer));
sizer->Add(preset_name_str, 0, wxLEFT, 5);
return sizer;
}
static wxBoxSizer *create_checkbox(wxWindow *parent, wxString &preset_name, std::vector<std::pair<::CheckBox *, std::string>> &preset_checkbox)
{
wxBoxSizer *sizer = new wxBoxSizer(wxHORIZONTAL);
::CheckBox *checkbox = new ::CheckBox(parent);
sizer->Add(checkbox, 0, 0, 0);
preset_checkbox.push_back(std::make_pair(checkbox, into_u8(preset_name)));
wxStaticText *preset_name_str = new wxStaticText(parent, wxID_ANY, preset_name);
sizer->Add(preset_name_str, 0, wxLEFT, 5);
return sizer;
}
static wxArrayString get_exist_vendor_choices(VendorMap& vendors)
{
wxArrayString choices;
PresetBundle temp_preset_bundle;
temp_preset_bundle.load_system_models_from_json(ForwardCompatibilitySubstitutionRule::EnableSystemSilent);
PresetBundle *preset_bundle = wxGetApp().preset_bundle;
VendorProfile users_models = preset_bundle->get_custom_vendor_models();
vendors = temp_preset_bundle.vendors;
if (!users_models.models.empty()) {
vendors[users_models.name] = users_models;
}
for (const pair<std::string, VendorProfile> &vendor : vendors) {
if (vendor.second.models.empty() || vendor.second.id.empty()) continue;
choices.Add(vendor.first);
}
return choices;
}
static std::string get_machine_name(const std::string &preset_name)
{
size_t index_at = preset_name.find_last_of("@");
if (std::string::npos == index_at) {
return "";
} else {
return preset_name.substr(index_at + 1);
}
}
static std::string get_filament_name(std::string &preset_name)
{
size_t index_at = preset_name.find_last_of("@");
if (std::string::npos == index_at) {
return preset_name;
} else {
return preset_name.substr(0, index_at - 1);
}
}
static wxBoxSizer *create_preset_tree(wxWindow *parent, std::pair<std::string, std::vector<std::shared_ptr<Preset>>> printer_and_preset)
{
wxTreeCtrl *treeCtrl = new wxTreeCtrl(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTR_DEFAULT_STYLE | wxNO_BORDER);
wxColour backgroundColor = parent->GetBackgroundColour();
treeCtrl->SetBackgroundColour(backgroundColor);
wxString printer_name = wxString::FromUTF8(printer_and_preset.first);
wxTreeItemId rootId = treeCtrl->AddRoot(printer_name);
int row = 1;
for (std::shared_ptr<Preset> preset : printer_and_preset.second) {
wxString preset_name = wxString::FromUTF8(preset->name);
wxTreeItemId childId1 = treeCtrl->AppendItem(rootId, preset_name);
row++;
}
treeCtrl->Expand(rootId);
wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
treeCtrl->SetMinSize(wxSize(-1, row * 22));
treeCtrl->SetMaxSize(wxSize(-1, row * 22));
sizer->Add(treeCtrl, 0, wxEXPAND | wxALL, 0);
return sizer;
}
static std::string get_vendor_name(const Preset *preset)
{
if (!preset) return "";
assert(preset->type == Preset::Type::TYPE_FILAMENT || preset->type == Preset::Type::TYPE_PRINTER);
if (preset->type != Preset::Type::TYPE_FILAMENT && preset->type != Preset::Type::TYPE_PRINTER) return "";
if (preset->type == Preset::Type::TYPE_FILAMENT) {
auto vender = preset->config.option<ConfigOptionStrings>("filament_vendor");
if (vender && vender->values.size()) return vender->values[0];
}
if (preset->type == Preset::Type::TYPE_PRINTER) {
auto vender = preset->config.option<ConfigOptionStrings>("printer_model");
if (vender && vender->values.size()) return vender->values[0];
}
assert(false);
auto preset_name = preset->name;
int index = preset_name.find_first_of(' ');
if (std::string::npos == index)
return preset_name;
else
return preset_name.substr(0, index);
}
static wxBoxSizer *create_select_filament_preset_checkbox(wxWindow * parent,
std::string & compatible_printer,
std::vector<Preset *> presets,
std::unordered_map<::CheckBox *, std::pair<std::string, Preset *>> &machine_filament_preset)
{
wxBoxSizer *horizontal_sizer = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *checkbox_sizer = new wxBoxSizer(wxVERTICAL);
::CheckBox *checkbox = new ::CheckBox(parent);
checkbox_sizer->Add(checkbox, 0, wxEXPAND | wxRIGHT, 5);
wxBoxSizer *combobox_sizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *machine_name_str = new wxStaticText(parent, wxID_ANY, wxString::FromUTF8(compatible_printer));
ComboBox * combobox = new ComboBox(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(200, 24), 0, nullptr, wxCB_READONLY);
combobox->SetBackgroundColor(PRINTER_LIST_COLOUR);
combobox->SetBorderColor(*wxWHITE);
combobox->SetLabel(_L("Select filament preset"));
combobox->Bind(wxEVT_COMBOBOX, [combobox, checkbox, presets, &machine_filament_preset, compatible_printer](wxCommandEvent &e) {
combobox->SetLabelColor(*wxBLACK);
wxString preset_name = combobox->GetStringSelection();
checkbox->SetValue(true);
for (Preset *preset : presets) {
if (preset_name == wxString::FromUTF8(preset->name)) {
machine_filament_preset[checkbox] = std::make_pair(compatible_printer, preset);
}
}
e.Skip();
});
combobox_sizer->Add(machine_name_str, 0, wxEXPAND, 0);
combobox_sizer->Add(combobox, 0, wxEXPAND | wxTOP, 5);
wxArrayString choices;
for (Preset *preset : presets) {
choices.Add(wxString::FromUTF8(preset->name));
}
combobox->Set(choices);
horizontal_sizer->Add(checkbox_sizer);
horizontal_sizer->Add(combobox_sizer);
return horizontal_sizer;
}
static wxString get_curr_radio_type(std::vector<std::pair<RadioBox *, wxString>> &radio_btns)
{
for (std::pair<RadioBox *, wxString> radio_string : radio_btns) {
if (radio_string.first->GetValue()) {
return radio_string.second;
}
}
return "";
}
static std::string calculate_md5(const std::string &input)
{
unsigned char digest[MD5_DIGEST_LENGTH];
std::string md5;
EVP_MD_CTX *mdContext = EVP_MD_CTX_new();
EVP_DigestInit(mdContext, EVP_md5());
EVP_DigestUpdate(mdContext, input.c_str(), input.length());
EVP_DigestFinal(mdContext, digest, nullptr);
EVP_MD_CTX_free(mdContext);
char hexDigest[MD5_DIGEST_LENGTH * 2 + 1];
for (int i = 0; i < MD5_DIGEST_LENGTH; ++i) { sprintf(hexDigest + (i * 2), "%02x", digest[i]); }
hexDigest[MD5_DIGEST_LENGTH * 2] = '\0';
md5 = std::string(hexDigest);
return md5;
}
static std::string get_filament_id(std::string vendor_typr_serial)
{
std::unordered_map<std::string, std::set<std::string>> filament_id_to_filament_name;
// temp filament presets
PresetBundle temp_preset_bundle;
temp_preset_bundle.load_system_filaments_json(Slic3r::ForwardCompatibilitySubstitutionRule::EnableSilent);
std::string dir_user_presets = wxGetApp().app_config->get("preset_folder");
if (dir_user_presets.empty()) {
temp_preset_bundle.load_user_presets(DEFAULT_USER_FOLDER_NAME, ForwardCompatibilitySubstitutionRule::EnableSilent);
} else {
temp_preset_bundle.load_user_presets(dir_user_presets, ForwardCompatibilitySubstitutionRule::EnableSilent);
}
const std::deque<Preset> &filament_presets = temp_preset_bundle.filaments.get_presets();
for (const Preset &preset : filament_presets) {
std::string preset_name = preset.name;
size_t index_at = preset_name.find_first_of('@');
if (index_at == std::string::npos) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " filament preset name has no @ and name is: " << preset_name;
continue;
}
std::string filament_name = preset_name.substr(0, index_at - 1);
if (filament_name == vendor_typr_serial && preset.filament_id != "null")
return preset.filament_id;
filament_id_to_filament_name[preset.filament_id].insert(filament_name);
}
// global filament presets
PresetBundle * preset_bundle = wxGetApp().preset_bundle;
std::map<std::string, std::vector<Preset const *>> temp_filament_id_to_presets = preset_bundle->filaments.get_filament_presets();
for (std::pair<std::string, std::vector<Preset const *>> filament_id_to_presets : temp_filament_id_to_presets) {
if (filament_id_to_presets.first.empty()) continue;
for (const Preset *preset : filament_id_to_presets.second) {
std::string preset_name = preset->name;
size_t index_at = preset_name.find_first_of('@');
if (index_at == std::string::npos) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " filament preset name has no @ and name is: " << preset_name;
continue;
}
std::string filament_name = preset_name.substr(0, index_at - 1);
if (filament_name == vendor_typr_serial && preset->filament_id != "null")
return preset->filament_id;
filament_id_to_filament_name[preset->filament_id].insert(filament_name);
}
}
std::string user_filament_id = "P" + calculate_md5(vendor_typr_serial).substr(0, 7);
while (filament_id_to_filament_name.find(user_filament_id) != filament_id_to_filament_name.end()) {//find same filament id
bool have_same_filament_name = false;
for (const std::string &name : filament_id_to_filament_name.find(user_filament_id)->second) {
if (name == vendor_typr_serial) {
have_same_filament_name = true;
break;
}
}
if (have_same_filament_name) {
break;
}
else { //Different names correspond to the same filament id
user_filament_id = "P" + calculate_md5(vendor_typr_serial + get_curr_time()).substr(0, 7);
}
}
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " filament name is: " << vendor_typr_serial << "and create filament_id is: " << user_filament_id;
return user_filament_id;
}
static json get_config_json(const Preset* preset) {
json j;
// record the headers
j[BBL_JSON_KEY_VERSION] = preset->version.to_string();
j[BBL_JSON_KEY_NAME] = preset->name;
j[BBL_JSON_KEY_FROM] = "";
DynamicPrintConfig config = preset->config;
// record all the key-values
for (const std::string &opt_key : config.keys()) {
const ConfigOption *opt = config.option(opt_key);
if (opt->is_scalar()) {
if (opt->type() == coString)
// keep \n, \r, \t
j[opt_key] = (dynamic_cast<const ConfigOptionString *>(opt))->value;
else
j[opt_key] = opt->serialize();
} else {
const ConfigOptionVectorBase *vec = static_cast<const ConfigOptionVectorBase *>(opt);
std::vector<std::string> string_values = vec->vserialize();
json j_array(string_values);
j[opt_key] = j_array;
}
}
return j;
}
static char* read_json_file(const std::string &preset_path)
{
FILE *json_file = boost::nowide::fopen(boost::filesystem::path(preset_path).make_preferred().string().c_str(), "rb");
if (json_file == NULL) {
BOOST_LOG_TRIVIAL(info) << "Failed to open JSON file: " << preset_path;
return NULL;
}
fseek(json_file, 0, SEEK_END); // seek to end
long file_size = ftell(json_file); // get file size
fseek(json_file, 0, SEEK_SET); // seek to start
char * json_contents = (char *) malloc(file_size);
if (json_contents == NULL) {
BOOST_LOG_TRIVIAL(info) << "Failed to allocate memory for JSON file ";
fclose(json_file);
return NULL;
}
fread(json_contents, 1, file_size, json_file);
fclose(json_file);
return json_contents;
}
static std::string get_printer_nozzle_diameter(std::string printer_name) {
size_t index = printer_name.find(" nozzle");
if (std::string::npos == index) {
return "";
}
std::string nozzle = printer_name.substr(0, index);
size_t last_space_index = nozzle.find_last_of(" ");
if (std::string::npos == index) {
return "";
}
return nozzle.substr(last_space_index + 1);
}
static void adjust_dialog_in_screen(DPIDialog* dialog) {
wxSize screen_size = wxGetDisplaySize();
int pos_x, pos_y, size_x, size_y, screen_width, screen_height, dialog_x, dialog_y;
pos_x = dialog->GetPosition().x;
pos_y = dialog->GetPosition().y;
size_x = dialog->GetSize().x;
size_y = dialog->GetSize().y;
screen_width = screen_size.GetWidth();
screen_height = screen_size.GetHeight();
dialog_x = pos_x;
dialog_y = pos_y;
if (pos_x + size_x > screen_width) {
int exceed_x = pos_x + size_x - screen_width;
dialog_x -= exceed_x;
}
if (pos_y + size_y > screen_height - 50) {
int exceed_y = pos_y + size_y - screen_height + 50;
dialog_y -= exceed_y;
}
if (pos_x != dialog_x || pos_y != dialog_y) { dialog->SetPosition(wxPoint(dialog_x, dialog_y)); }
}
CreateFilamentPresetDialog::CreateFilamentPresetDialog(wxWindow *parent)
: DPIDialog(parent ? parent : nullptr, wxID_ANY, _L("Create Filament"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX | wxCENTRE | wxRESIZE_BORDER)
{
m_create_type.base_filament = _L("Create Based on Current Filament");
m_create_type.base_filament_preset = _L("Copy Current Filament Preset ");
get_all_filament_presets();
this->SetBackgroundColour(*wxWHITE);
this->SetSize(wxSize(FromDIP(600), FromDIP(480)));
std::string icon_path = (boost::format("%1%/images/BambuStudioTitle.ico") % resources_dir()).str();
SetIcon(wxIcon(encode_path(icon_path.c_str()), wxBITMAP_TYPE_ICO));
wxBoxSizer *m_main_sizer = new wxBoxSizer(wxVERTICAL);
// top line
auto m_line_top = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 1), wxTAB_TRAVERSAL);
m_line_top->SetBackgroundColour(wxColour(0xA6, 0xa9, 0xAA));
m_main_sizer->Add(m_line_top, 0, wxEXPAND, 0);
m_main_sizer->Add(0, 0, 0, wxTOP, FromDIP(5));
wxStaticText *basic_infomation = new wxStaticText(this, wxID_ANY, _L("Basic Information"));
basic_infomation->SetFont(Label::Head_16);
m_main_sizer->Add(basic_infomation, 0, wxLEFT, FromDIP(10));
m_main_sizer->Add(create_item(FilamentOptionType::VENDOR), 0, wxEXPAND | wxALL, FromDIP(5));
m_main_sizer->Add(create_item(FilamentOptionType::TYPE), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, FromDIP(5));
m_main_sizer->Add(create_item(FilamentOptionType::SERIAL), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, FromDIP(5));
// divider line
auto line_divider = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 1), wxTAB_TRAVERSAL);
line_divider->SetBackgroundColour(wxColour(0xA6, 0xa9, 0xAA));
m_main_sizer->Add(line_divider, 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(10));
m_main_sizer->Add(0, 0, 0, wxTOP, FromDIP(5));
wxStaticText *presets_infomation = new wxStaticText(this, wxID_ANY, _L("Add Filament Preset under this filament"));
presets_infomation->SetFont(Label::Head_16);
m_main_sizer->Add(presets_infomation, 0, wxLEFT | wxRIGHT, FromDIP(15));
m_main_sizer->Add(create_item(FilamentOptionType::FILAMENT_PRESET), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, FromDIP(5));
m_filament_preset_text = new wxStaticText(this, wxID_ANY, _L("We could create the filament presets for your following printer:"), wxDefaultPosition, wxDefaultSize);
m_main_sizer->Add(m_filament_preset_text, 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(15));
m_scrolled_preset_panel = new wxScrolledWindow(this, wxID_ANY);
m_scrolled_preset_panel->SetMaxSize(wxSize(-1, FromDIP(350)));
m_scrolled_preset_panel->SetBackgroundColour(*wxWHITE);
m_scrolled_preset_panel->SetScrollRate(5, 5);
m_scrolled_sizer = new wxBoxSizer(wxVERTICAL);
m_scrolled_sizer->Add(create_item(FilamentOptionType::PRESET_FOR_PRINTER), 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, FromDIP(5));
m_scrolled_sizer->Add(0, 0, 0, wxTOP, FromDIP(5));
m_scrolled_preset_panel->SetSizerAndFit(m_scrolled_sizer);
m_main_sizer->Add(m_scrolled_preset_panel, 0, wxEXPAND | wxLEFT | wxRIGHT, FromDIP(10));
m_main_sizer->Add(create_button_item(), 0, wxEXPAND | wxALL, FromDIP(10));
get_all_visible_printer_name();
select_curr_radiobox(m_create_type_btns, 0);
this->SetSizer(m_main_sizer);
Layout();
Fit();
this->Bind(wxEVT_SIZE, [this](wxSizeEvent &event) {
this->Refresh();
event.Skip();
});
wxGetApp().UpdateDlgDarkUI(this);
}
CreateFilamentPresetDialog::~CreateFilamentPresetDialog()
{
for (std::pair<std::string, Preset *> preset : m_all_presets_map) {
Preset *p = preset.second;
if (p) {
delete p;
p = nullptr;
}
}
}
void CreateFilamentPresetDialog::on_dpi_changed(const wxRect &suggested_rect) {
m_button_create->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_create->SetMaxSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_create->SetCornerRadius(FromDIP(12));
m_button_cancel->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_cancel->SetMaxSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_cancel->SetCornerRadius(FromDIP(12));
Layout();
}
bool CreateFilamentPresetDialog::is_check_box_selected()
{
for (const std::pair<::CheckBox *, std::pair<std::string, Preset *>> &checkbox_preset : m_filament_preset) {
if (checkbox_preset.first->GetValue()) { return true; }
}
for (const std::pair<::CheckBox *, std::pair<std::string, Preset *>> &checkbox_preset : m_machint_filament_preset) {
if (checkbox_preset.first->GetValue()) { return true; }
}
return false;
}
wxBoxSizer *CreateFilamentPresetDialog::create_item(FilamentOptionType option_type)
{
wxSizer *item = nullptr;
switch (option_type) {
case VENDOR: return create_vendor_item();
case TYPE: return create_type_item();
case SERIAL: return create_serial_item();
case FILAMENT_PRESET: return create_filament_preset_item();
case PRESET_FOR_PRINTER: return create_filament_preset_for_printer_item();
default: return nullptr;
}
}
wxBoxSizer *CreateFilamentPresetDialog::create_vendor_item()
{
wxBoxSizer *horizontal_sizer = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer * optionSizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *static_vendor_text = new wxStaticText(this, wxID_ANY, _L("Vendor"), wxDefaultPosition, wxDefaultSize);
optionSizer->Add(static_vendor_text, 0, wxEXPAND | wxALL, 0);
optionSizer->SetMinSize(OPTION_SIZE);
horizontal_sizer->Add(optionSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(5));
wxArrayString choices;
for (const wxString &vendor : filament_vendors) {
choices.push_back(vendor);
}
wxBoxSizer *vendor_sizer = new wxBoxSizer(wxHORIZONTAL);
m_filament_vendor_combobox = new ComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition, NAME_OPTION_COMBOBOX_SIZE, 0, nullptr, wxCB_READONLY);
m_filament_vendor_combobox->SetLabel(_L("Select Vendor"));
m_filament_vendor_combobox->SetLabelColor(DEFAULT_PROMPT_TEXT_COLOUR);
m_filament_vendor_combobox->Set(choices);
m_filament_vendor_combobox->Bind(wxEVT_COMBOBOX, [this](wxCommandEvent &e) {
m_filament_vendor_combobox->SetLabelColor(*wxBLACK);
e.Skip();
});
vendor_sizer->Add(m_filament_vendor_combobox, 0, wxEXPAND | wxALL, 0);
wxBoxSizer *textInputSizer = new wxBoxSizer(wxVERTICAL);
m_filament_custom_vendor_input = new TextInput(this, wxEmptyString, wxEmptyString, wxEmptyString, wxDefaultPosition, NAME_OPTION_COMBOBOX_SIZE, wxTE_PROCESS_ENTER);
m_filament_custom_vendor_input->GetTextCtrl()->SetMaxLength(50);
m_filament_custom_vendor_input->SetSize(NAME_OPTION_COMBOBOX_SIZE);
textInputSizer->Add(m_filament_custom_vendor_input, 0, wxEXPAND | wxALL, 0);
m_filament_custom_vendor_input->GetTextCtrl()->SetHint(_L("Input Custom Vendor"));
m_filament_custom_vendor_input->GetTextCtrl()->Bind(wxEVT_CHAR, [this](wxKeyEvent &event) {
int key = event.GetKeyCode();
if (cannot_input_key_for_filament.find(key) != cannot_input_key_for_filament.end()) {
event.Skip(false);
return;
}
event.Skip();
});
m_filament_custom_vendor_input->Hide();
vendor_sizer->Add(textInputSizer, 0, wxEXPAND | wxALIGN_CENTER_VERTICAL, FromDIP(10));
wxBoxSizer *comboBoxSizer = new wxBoxSizer(wxVERTICAL);
wxBoxSizer *checkbox_sizer = new wxBoxSizer(wxHORIZONTAL);
m_can_not_find_vendor_checkbox = new ::CheckBox(this);
checkbox_sizer->Add(m_can_not_find_vendor_checkbox, 0, wxALIGN_CENTER, 0);
checkbox_sizer->Add(0, 0, 0, wxEXPAND | wxRIGHT, FromDIP(5));
wxStaticText *m_can_not_find_vendor_text = new wxStaticText(this, wxID_ANY, _L("Can't find vendor I want"), wxDefaultPosition, wxDefaultSize, 0);
m_can_not_find_vendor_text->SetFont(::Label::Body_13);
wxSize size = m_can_not_find_vendor_text->GetTextExtent(_L("Can't find vendor I want"));
m_can_not_find_vendor_text->SetMinSize(wxSize(size.x + FromDIP(4), -1));
m_can_not_find_vendor_text->Wrap(-1);
checkbox_sizer->Add(m_can_not_find_vendor_text, 0, wxALIGN_CENTER, 0);
m_can_not_find_vendor_checkbox->Bind(wxEVT_TOGGLEBUTTON, [this](wxCommandEvent &e) {
bool value = m_can_not_find_vendor_checkbox->GetValue();
if (value) {
m_can_not_find_vendor_checkbox->SetValue(true);
m_filament_vendor_combobox->Hide();
m_filament_custom_vendor_input->Show();
} else {
m_can_not_find_vendor_checkbox->SetValue(false);
m_filament_vendor_combobox->Show();
m_filament_custom_vendor_input->Hide();
}
Refresh();
Layout();
Fit();
e.Skip();
});
comboBoxSizer->Add(vendor_sizer, 0, wxEXPAND | wxTOP, FromDIP(5));
comboBoxSizer->Add(checkbox_sizer, 0, wxEXPAND | wxTOP, FromDIP(5));
horizontal_sizer->Add(comboBoxSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(5));
return horizontal_sizer;
}
wxBoxSizer *CreateFilamentPresetDialog::create_type_item()
{
wxBoxSizer *horizontal_sizer = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer * optionSizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *static_type_text = new wxStaticText(this, wxID_ANY, _L("Type"), wxDefaultPosition, wxDefaultSize);
optionSizer->Add(static_type_text, 0, wxEXPAND | wxALL, 0);
optionSizer->SetMinSize(OPTION_SIZE);
horizontal_sizer->Add(optionSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(5));
wxArrayString filament_type;
for (const wxString &filament : m_system_filament_types_set) {
filament_type.Add(filament);
}
wxBoxSizer *comboBoxSizer = new wxBoxSizer(wxVERTICAL);
m_filament_type_combobox = new ComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition, NAME_OPTION_COMBOBOX_SIZE, 0, nullptr, wxCB_READONLY);
m_filament_type_combobox->SetLabel(_L("Select Type"));
m_filament_type_combobox->SetLabelColor(DEFAULT_PROMPT_TEXT_COLOUR);
m_filament_type_combobox->Set(filament_type);
comboBoxSizer->Add(m_filament_type_combobox, 0, wxEXPAND | wxALL, 0);
horizontal_sizer->Add(comboBoxSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(5));
m_filament_type_combobox->Bind(wxEVT_COMBOBOX, [this](wxCommandEvent &e) {
m_filament_type_combobox->SetLabelColor(*wxBLACK);
const wxString &curr_create_type = curr_create_filament_type();
clear_filament_preset_map();
if (curr_create_type == m_create_type.base_filament) {
wxArrayString filament_preset_choice = get_filament_preset_choices();
m_filament_preset_combobox->Set(filament_preset_choice);
m_filament_preset_combobox->SetLabel(_L("Select Filament Preset"));
m_filament_preset_combobox->SetLabelColor(DEFAULT_PROMPT_TEXT_COLOUR);
} else if (curr_create_type == m_create_type.base_filament_preset) {
get_filament_presets_by_machine();
}
m_scrolled_preset_panel->SetSizerAndFit(m_scrolled_sizer);
update_dialog_size();
e.Skip();
});
return horizontal_sizer;
}
wxBoxSizer *CreateFilamentPresetDialog::create_serial_item()
{
wxBoxSizer *horizontal_sizer = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer * optionSizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *static_serial_text = new wxStaticText(this, wxID_ANY, _L("Serial"), wxDefaultPosition, wxDefaultSize);
optionSizer->Add(static_serial_text, 0, wxEXPAND | wxALL, 0);
optionSizer->SetMinSize(OPTION_SIZE);
horizontal_sizer->Add(optionSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(5));
wxBoxSizer *comboBoxSizer = new wxBoxSizer(wxVERTICAL);
m_filament_serial_input = new TextInput(this, "", "", "", wxDefaultPosition, NAME_OPTION_COMBOBOX_SIZE, wxTE_PROCESS_ENTER);
m_filament_serial_input->GetTextCtrl()->SetMaxLength(50);
comboBoxSizer->Add(m_filament_serial_input, 0, wxEXPAND | wxALL, 0);
m_filament_serial_input->GetTextCtrl()->Bind(wxEVT_CHAR, [this](wxKeyEvent &event) {
int key = event.GetKeyCode();
if (cannot_input_key_for_filament.find(key) != cannot_input_key_for_filament.end()) {
event.Skip(false);
return;
}
event.Skip();
});
wxStaticText *static_eg_text = new wxStaticText(this, wxID_ANY, _L("e.g. Basic, Matte, Silk, Marble"), wxDefaultPosition, wxDefaultSize);
static_eg_text->SetForegroundColour(wxColour("#6B6B6B"));
static_eg_text->SetFont(::Label::Body_12);
comboBoxSizer->Add(static_eg_text, 0, wxEXPAND | wxTOP, FromDIP(5));
horizontal_sizer->Add(comboBoxSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(5));
return horizontal_sizer;
}
wxBoxSizer *CreateFilamentPresetDialog::create_filament_preset_item()
{
wxBoxSizer *horizontal_sizer = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer * optionSizer = new wxBoxSizer(wxVERTICAL);
wxStaticText *static_filament_preset_text = new wxStaticText(this, wxID_ANY, _L("Filament Preset"), wxDefaultPosition, wxDefaultSize);
optionSizer->Add(static_filament_preset_text, 0, wxEXPAND | wxALL, 0);
optionSizer->SetMinSize(OPTION_SIZE);
horizontal_sizer->Add(optionSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10));
wxBoxSizer * comboBoxSizer = new wxBoxSizer(wxVERTICAL);
comboBoxSizer->Add(create_radio_item(m_create_type.base_filament, this, wxEmptyString, m_create_type_btns), 0, wxEXPAND | wxALL, 0);
m_filament_preset_combobox = new ComboBox(this, wxID_ANY, wxEmptyString, wxDefaultPosition, FILAMENT_PRESET_COMBOBOX_SIZE, 0, nullptr, wxCB_READONLY);
m_filament_preset_combobox->SetLabel(_L("Select Filament Preset"));
m_filament_preset_combobox->SetLabelColor(DEFAULT_PROMPT_TEXT_COLOUR);
m_filament_preset_combobox->Bind(wxEVT_COMBOBOX, [this](wxCommandEvent &e) {
m_filament_preset_combobox->SetLabelColor(*wxBLACK);
wxString filament_type = m_filament_preset_combobox->GetStringSelection();
std::unordered_map<std::string, std::vector<Preset *>>::iterator iter = m_filament_choice_map.find(m_public_name_to_filament_id_map[filament_type]);
m_scrolled_preset_panel->Freeze();
m_filament_presets_sizer->Clear(true);
m_filament_preset.clear();
std::vector<std::pair<std::string, Preset *>> printer_name_to_filament_preset;
if (iter != m_filament_choice_map.end()) {
std::unordered_map<std::string, float> nozzle_diameter = nozzle_diameter_map;
for (Preset* preset : iter->second) {
auto compatible_printers = preset->config.option<ConfigOptionStrings>("compatible_printers", true);
if (!compatible_printers || compatible_printers->values.empty()) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "there is a preset has no compatible printers and the preset name is: " << preset->name;
continue;
}
for (std::string &compatible_printer_name : compatible_printers->values) {
if (m_visible_printers.find(compatible_printer_name) == m_visible_printers.end()) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "there is a comppatible printer no exist: " << compatible_printer_name
<< "and the preset name is: " << preset->name;
continue;
}
std::string nozzle = get_printer_nozzle_diameter(compatible_printer_name);
if (nozzle_diameter[nozzle] == 0) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " compatible printer nozzle encounter exception and name is: " << compatible_printer_name;
continue;
}
printer_name_to_filament_preset.push_back(std::make_pair(compatible_printer_name,preset));
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "show compatible printer name: " << compatible_printer_name << "and preset name is: " << preset;
}
}
} else {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << " not find filament_id corresponding to the type: and the type is" << filament_type;
}
sort_printer_by_nozzle(printer_name_to_filament_preset);
for (std::pair<std::string, Preset *> printer_to_preset : printer_name_to_filament_preset)
m_filament_presets_sizer->Add(create_checkbox(m_filament_preset_panel, printer_to_preset.first, printer_to_preset.second, m_filament_preset), 0,
wxEXPAND | wxTOP | wxLEFT, FromDIP(5));
m_scrolled_preset_panel->SetSizerAndFit(m_scrolled_sizer);
m_scrolled_preset_panel->Thaw();
update_dialog_size();
e.Skip();
});
comboBoxSizer->Add(m_filament_preset_combobox, 0, wxEXPAND | wxTOP, FromDIP(5));
comboBoxSizer->Add(create_radio_item(m_create_type.base_filament_preset, this, wxEmptyString, m_create_type_btns), 0, wxEXPAND | wxTOP, FromDIP(10));
horizontal_sizer->Add(comboBoxSizer, 0, wxEXPAND | wxALL | wxALIGN_CENTER_VERTICAL, FromDIP(10));
horizontal_sizer->Add(0, 0, 0, wxLEFT, FromDIP(30));
return horizontal_sizer;
}
wxBoxSizer *CreateFilamentPresetDialog::create_filament_preset_for_printer_item()
{
wxBoxSizer *vertical_sizer = new wxBoxSizer(wxVERTICAL);
m_filament_preset_panel = new wxPanel(m_scrolled_preset_panel, wxID_ANY);
m_filament_preset_panel->SetBackgroundColour(PRINTER_LIST_COLOUR);
m_filament_preset_panel->SetSize(PRINTER_LIST_SIZE);
m_filament_presets_sizer = new wxGridSizer(3, FromDIP(5), FromDIP(5));
m_filament_preset_panel->SetSizer(m_filament_presets_sizer);
vertical_sizer->Add(m_filament_preset_panel, 0, wxEXPAND | wxTOP | wxALIGN_CENTER_HORIZONTAL, FromDIP(5));
return vertical_sizer;
}
wxBoxSizer *CreateFilamentPresetDialog::create_button_item()
{
wxBoxSizer *bSizer_button = new wxBoxSizer(wxHORIZONTAL);
bSizer_button->Add(0, 0, 1, wxEXPAND, 0);
StateColor btn_bg_green(std::pair<wxColour, int>(wxColour(27, 136, 68), StateColor::Pressed), std::pair<wxColour, int>(wxColour(61, 203, 115), StateColor::Hovered),
std::pair<wxColour, int>(wxColour(0, 174, 66), StateColor::Normal));
m_button_create = new Button(this, _L("Create"));
m_button_create->SetBackgroundColor(btn_bg_green);
m_button_create->SetBorderColor(*wxWHITE);
m_button_create->SetTextColor(wxColour("#FFFFFE"));
m_button_create->SetFont(Label::Body_12);
m_button_create->SetSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_create->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
m_button_create->SetCornerRadius(FromDIP(12));
bSizer_button->Add(m_button_create, 0, wxRIGHT, FromDIP(10));
m_button_create->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent &e) {
//get vendor name
wxString vendor_str = m_filament_vendor_combobox->GetLabel();
std::string vendor_name;
if (!m_can_not_find_vendor_checkbox->GetValue()) {
if (_L("Select Vendor") == vendor_str) {
MessageDialog dlg(this, _L("Vendor is not selected, please reselect vendor."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"),
wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return;
} else {
vendor_name = into_u8(vendor_str);
}
} else {
if (m_filament_custom_vendor_input->GetTextCtrl()->GetValue().empty()) {
MessageDialog dlg(this, _L("Custom vendor is not input, please input custom vendor."), wxString(SLIC3R_APP_FULL_NAME) + " - " + _L("Info"),
wxYES | wxYES_DEFAULT | wxCENTRE);
dlg.ShowModal();
return;
} else {
vendor_name = into_u8(m_filament_custom_vendor_input->GetTextCtrl()->GetValue());
if (vendor_name == "Bambu" || vendor_name == "Generic") {